Kietcudo commited on
Commit
d64d887
·
verified ·
1 Parent(s): d4ae59a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +283 -216
app.py CHANGED
@@ -316,22 +316,23 @@ def delete_current_ticket(selected_option):
316
 
317
  def format_ticket_detail(ticket):
318
  status_label, _ = get_ticket_status_display(ticket)
 
319
  if "CHƯA TRẢ LỜI" in status_label and "HỎI THÊM" not in status_label:
320
- status_str = "⏳ ĐANG CHỜ CHUYÊN GIA TRẢ LỜI"
321
- status_color = "#2980b9"
322
  elif "HỎI THÊM" in status_label:
323
- status_str = "🔄 NHÀ NÔNG ĐÃ HỎI THÊM (CHỜ PHẢN HỒI)"
324
- status_color = "#d35400"
325
  else:
326
- status_str = "✅ ĐÃ ĐƯỢC CHUYÊN GIA TRẢ LỜI"
327
- status_color = "#c0392b"
328
 
329
  reply_str = ticket.get('admin_reply', 'Chưa có phản hồi.')
330
-
331
- header_html = f"""<div style="font-size: 15px; color: #111111; line-height: 1.6; font-weight: 500;">
332
- 📌 <b>MÃ YÊU CẦU:</b> #{ticket['id']} | ⏱️ <b>Thời gian:</b> {ticket['time']}<br>
333
- 🌱 <b>Loại cây:</b> <span style="color: #27ae60; font-weight: bold;">{ticket['plant']}</span><br>
334
- 💬 <b>Câu hỏi từ nhà nông:</b> <span style="color: #2c3e50; font-weight: bold; background: #eef9f5; padding: 2px 8px; border-radius: 4px;">{ticket['user_query']}</span>
335
  </div>"""
336
 
337
  history_conversation = ""
@@ -341,20 +342,16 @@ def format_ticket_detail(ticket):
341
  time_stamp = msg.get("time", "")
342
  text = msg.get("text", "")
343
  if sender == "USER":
344
- history_conversation += f"""<div style="background: #eef9f5; border-left: 4px solid #27ae60; padding: 10px 14px; margin: 8px 0; border-radius: 6px; font-size: 15px; line-height: 1.5; color: #111111;">
345
- <b style="font-size: 15px; color: #1e7e34;">👤 Nhà nông ({time_stamp}):</b> {text}
346
- </div>"""
347
  else:
348
- history_conversation += f"""<div style="background: #eef6ff; border-left: 4px solid #2980b9; padding: 10px 14px; margin: 8px 0; border-radius: 6px; font-size: 15px; line-height: 1.5; color: #111111;">
349
- <b style="font-size: 15px; color: #1b4f72;">👨‍⚕️ Chuyên gia ({time_stamp}):</b> {text}
350
- </div>"""
351
 
352
  if not history_conversation:
353
- history_conversation = f"""<div style="color: #1b4f72; font-weight: 600; font-size: 15px; background: #eef6ff; padding: 10px 14px; border-left: 4px solid #2980b9; border-radius: 6px; margin-top: 8px;">{reply_str}</div>"""
354
 
355
- conversation_html = f"""<div style="font-size: 15px; color: #111111; line-height: 1.6; width: 100%;">
356
- 🚥 <b>Trạng thái:</b> <span style="font-weight: bold; color: {status_color};">{status_str}</span><br>
357
- 👨‍⚕️ <b>Nội dung trao đổi với Chuyên gia:</b><br>
358
  {history_conversation}
359
  </div>"""
360
 
@@ -450,7 +447,7 @@ def check_user_expert_status():
450
  last_ticket = user_tickets[-1]
451
  img_p = last_ticket.get('image_path', None)
452
  h_info, c_info = format_ticket_detail(last_ticket)
453
- return h_info + "<br><hr style='border: 1px solid #d4deda; margin: 12px 0;'><br>" + c_info, img_p
454
 
455
  def submit_expert_request(user_question, selected_plant, input_image):
456
  global current_detected_disease_context
@@ -490,7 +487,7 @@ def submit_expert_request(user_question, selected_plant, input_image):
490
  tickets.append(new_ticket)
491
  save_expert_tickets(tickets)
492
  h_info, c_info = format_ticket_detail(new_ticket)
493
- return "📩 Đã gửi câu hỏi đến Hộp thư chờ Chuyên gia! Chuyên gia sẽ sớm xem xét và trả lời.", h_info + "<br><hr style='border: 1px solid #d4deda; margin: 12px 0;'><br>" + c_info, saved_img_path
494
 
495
  def go_to_history_panel():
496
  global current_user_role
@@ -702,7 +699,7 @@ LEAF_HERO_HEAD = r"""
702
  const C = {
703
  leaves: LEAF_CASES, cycleSeconds: 16, trailCycles: 2.6, compress: 0.42,
704
  maxTurns: 3, planeSpread: 1, eccentricity: 0.25, alignToCourse: 1,
705
- driftSpeed: 1.5, driftDir: [272, 53], viewRadius: 3.1, tilt: 45, spin: 252, roll: 13.5,
706
  lead: 0.12, focus: [0.74, 0.42], scrim: "left", scrimStrength: 0.90,
707
  moteCount: 400, glow: 1, showCoreBeam: true, interactive: true, crossColor: "#2d7a12",
708
  pulseColor: "#10b981", rayColor: "#8fd45a"
@@ -716,14 +713,17 @@ LEAF_HERO_HEAD = r"""
716
  else {
717
  // đặt chữ thập vào giữa khoảng trống bên phải khối đăng nhập (khối ~13vw + 27rem)
718
  const panelRight = 0.13 * w + Math.min(432, 0.81 * w);
719
- const fx = ((panelRight + w) / 2) / w;
720
- C.focus = [Math.min(0.82, Math.max(0.62, fx)), 0.5];
721
  }
722
  C.scrim = narrow ? "top" : "left";
723
  C.scrimStrength = narrow ? 0.90 : 0.90;
724
- C.viewRadius = narrow ? 2.4 : 3.1;
725
  C.lead = narrow ? 0.05 : 0.12;
726
  C.glow = narrow ? 0.8 : 1;
 
 
 
727
  }
728
  applyResponsive();
729
 
@@ -810,7 +810,7 @@ LEAF_HERO_HEAD = r"""
810
  else if (edge === 1) { x = width - rng() * width * 0.25; y = rng() * height; }
811
  else if (edge === 2) { x = rng() * width; y = rng() * height * 0.2; }
812
  else { x = rng() * width; y = height - rng() * height * 0.2; }
813
- BORDER_LEAVES.push({ x, y, size: (40 + rng() * 60) * 0.95, baseAngle: (rng() - 0.5) * 1.2, swaySpeed: 0.4 + rng() * 0.8, swayAmp: 0.06 + rng() * 0.1, phase: rng() * TAU, color: LEAF_GREENS[Math.floor(rng() * LEAF_GREENS.length)], alpha: 0.35 + rng() * 0.45 });
814
  }
815
  }
816
  function drawBorderLeaves(t) {
@@ -854,7 +854,7 @@ LEAF_HERO_HEAD = r"""
854
  const T = 1.05, p = (clk % T) / T, g = (x, mu, s) => Math.exp(-((x - mu) * (x - mu)) / (2 * s * s));
855
  return Math.min(1, g(p, 0.07, 0.045) + 0.58 * g(p, 0.27, 0.05));
856
  }
857
- function crossBaseR() { return Math.max(27, Math.min(width, height) * 0.0594); } /* nhỏ hơn 10% */
858
 
859
  // Tia sáng xoay quanh chữ thập
860
  function drawRays(clk, env) {
@@ -995,7 +995,7 @@ LEAF_HERO_HEAD = r"""
995
  }
996
 
997
  shots.sort((a, b) => b.depth - a.depth);
998
- const sizeScale = Math.min(width, height) / 500 * 0.95; /* lá nhỏ hơn 5% */
999
  const drawShot = (o, index) => {
1000
  const depth = Math.min(1.3, Math.max(0.5, o.s)), size = o.el.p.size * depth * sizeScale, bright = (o.el.p.glow ?? 1) * k, R = size * 3;
1001
  ctx.globalAlpha = Math.min(0.7, 0.5 * bright); ctx.drawImage(glowSprite(o.el.p.color), o.x - R, o.y - R, R * 2, R * 2); ctx.globalAlpha = 1;
@@ -1004,9 +1004,11 @@ LEAF_HERO_HEAD = r"""
1004
 
1005
  let idx = 0;
1006
  while (idx < shots.length && shots[idx].depth > camDist) drawShot(shots[idx], idx++);
 
1007
  drawRays(clock, env);
1008
  drawHeartbeat(clock, env);
1009
  drawCross(k, env);
 
1010
  while (idx < shots.length) drawShot(shots[idx], idx++);
1011
  drawBorderLeaves(t);
1012
 
@@ -1035,10 +1037,11 @@ LEAF_HERO_HEAD = r"""
1035
  let prevOnLogin = null;
1036
  setInterval(function () {
1037
  const el = document.getElementById("login_wrapper");
1038
- const onLogin = !!el && el.offsetParent !== null;
 
1039
  document.body.classList.toggle("leaf-on", onLogin);
1040
- active = onLogin;
1041
- if (!onLogin) lastFrame = 0;
1042
  // Khi vừa quay lại màn đăng nhập (vd sau khi đăng xuất) -> đưa trang về đầu để login không bị lạc
1043
  if (onLogin && prevOnLogin === false) { try { window.scrollTo(0, 0); } catch (e) {} }
1044
  prevOnLogin = onLogin;
@@ -1056,158 +1059,173 @@ LEAF_HERO_HEAD = r"""
1056
  """
1057
 
1058
  custom_css = """
1059
- .gradio-container {
1060
- background: linear-gradient(180deg, #eff5f3 0%, #e1ebe7 100%) !important;
1061
- font-family: 'Inter', system-ui, sans-serif !important;
 
 
 
 
 
 
 
 
 
 
 
1062
  }
1063
- #login_wrapper { padding: 0 !important; } /* cũ: display:flex !important gây kẹt ẩn/hiện — đã bỏ */
1064
- .login-card {
1065
- background: #ffffff !important; border-radius: 24px !important; padding: 45px 40px !important;
1066
- box-shadow: 0 20px 45px rgba(0, 60, 40, 0.06) !important; border: 1px solid rgba(0, 129, 112, 0.1) !important;
 
1067
  }
1068
- .logo-container { display: flex; justify-content: center; align-items: center; margin-bottom: 25px; position: relative; height: 70px; gap: 12px; }
1069
-
1070
- /* CẤU HÌNH LOGO BÔNG LÚA ĐỨNG IM VÀ HƯỚNG RA NGOÀI */
1071
- .rice-icon-left, .rice-icon-right {
1072
- font-size: 38px;
1073
- line-height: 1;
1074
- display: inline-block;
1075
- filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
 
 
 
 
 
1076
  }
1077
- .rice-icon-left {
1078
- transform: scaleX(-1);
 
 
 
1079
  }
1080
- .rice-icon-right {
1081
- transform: scaleX(1);
 
 
 
 
 
 
 
 
 
 
 
1082
  }
1083
 
1084
- .medical-cross-css {
1085
- width: 46px; height: 46px; background: #007965; position: relative; border-radius: 10px; z-index: 2;
1086
- box-shadow: 0 4px 12px rgba(0, 121, 101, 0.25); animation: pulseGlow 2.5s infinite ease-in-out;
1087
- }
1088
- .medical-cross-css::before, .medical-cross-css::after { content: ""; position: absolute; background: white; border-radius: 2px; }
1089
- .medical-cross-css::before { top: 19px; left: 9px; width: 28px; height: 8px; }
1090
- .medical-cross-css::after { top: 9px; left: 19px; width: 8px; height: 28px; }
1091
- .main-title-layout { display: flex; align-items: center; justify-content: center; gap: 15px; margin: 0 auto; width: fit-content; }
1092
- .medical-cross-red {
1093
- width: 42px; height: 42px; background: #e74c3c; position: relative; border-radius: 8px; flex-shrink: 0;
1094
- box-shadow: 0 4px 12px rgba(231, 76, 60, 0.35); display: inline-block; vertical-align: middle;
1095
- animation: pulseGlow 2.5s infinite ease-in-out;
1096
  }
1097
- .medical-cross-red::before, .medical-cross-red::after { content: ""; position: absolute; background: white; border-radius: 2px; }
1098
- .medical-cross-red::before { top: 17px; left: 8px; width: 26px; height: 8px; }
1099
- .medical-cross-red::after { top: 8px; left: 17px; width: 8px; height: 26px; }
1100
- .app-main-title { color: #004b39 !important; font-weight: 800 !important; font-size: 28px !important; text-align: center !important; margin: 0 0 8px 0 !important; }
1101
- .app-sub-title { color: #557067 !important; font-size: 14px !important; text-align: center !important; margin: 0 0 30px 0 !important; font-weight: 500 !important; }
1102
- .hospital-header-center { text-align: center !important; width: 100%; }
1103
- .hospital-header-center .title-wrapper-h1 { display: inline-flex; align-items: center; justify-content: center; gap: 16px; text-align: center; margin: 0 auto; }
1104
- .hospital-header-center h1 { text-align: center !important; color: white !important; font-weight: 800 !important; font-size: 28px !important; margin: 0 !important; display: inline-block; }
1105
- .hospital-header-center p { text-align: center !important; margin: 8px auto 0 auto !important; color: #b2dfdb !important; font-size: 14px !important; }
1106
- .scan-btn {
1107
- background: linear-gradient(135deg, #007965, #00bfa5) !important; color: white !important; font-weight: 700 !important;
1108
- border: none !important; border-radius: 12px !important; box-shadow: 0 5px 15px rgba(0, 121, 101, 0.2) !important; height: 48px; cursor: pointer;
1109
- transition: all 0.25s ease !important;
1110
  }
1111
- .scan-btn:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0, 191, 165, 0.35) !important; }
1112
-
1113
- /* CSS MỚI NỔI BẬT NÚT GỬI YÊU CẦU CHO CHUYÊN GIA */
1114
- .expert-send-btn {
1115
- background: linear-gradient(135deg, #d35400 0%, #e67e22 50%, #e74c3c 100%) !important;
1116
- color: white !important;
1117
- font-weight: 800 !important;
1118
- font-size: 15px !important;
1119
- border: none !important;
1120
- border-radius: 12px !important;
1121
- height: 48px !important;
1122
- cursor: pointer !important;
1123
- box-shadow: 0 6px 18px rgba(211, 84, 0, 0.4) !important;
1124
- transition: all 0.25s ease !important;
1125
- margin-top: 10px !important;
1126
  }
1127
- .expert-send-btn:hover {
1128
- filter: brightness(1.1) !important;
1129
- transform: translateY(-2px) !important;
1130
- box-shadow: 0 8px 24px rgba(230, 126, 34, 0.55) !important;
1131
  }
1132
-
1133
- .inline-history-btn {
1134
- background: #ffffff !important; color: #007965 !important; border: 1.5px solid #007965 !important;
1135
- font-weight: 700 !important; border-radius: 8px !important; padding: 0px 14px !important;
1136
- height: 32px !important; font-size: 13px !important; cursor: pointer; transition: all 0.2s ease !important;
1137
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) !important; display: inline-flex !important; align-items: center; justify-content: center;
1138
  }
1139
- .inline-history-btn:hover { background: #007965 !important; color: #ffffff !important; box-shadow: 0 4px 10px rgba(0,121,101,0.15) !important; }
 
1140
 
1141
- /* TÙY CHỈNH NÚT ĐĂNG XUẤT CHO RỘNG RÃI TRỌN CHỮ */
1142
- .logout-btn-style {
1143
- background: linear-gradient(135deg, #e74c3c, #c0392b) !important; color: white !important; font-weight: 700 !important;
1144
- border: none !important; border-radius: 10px !important; cursor: pointer; height: 45px !important; min-width: 210px !important; padding: 0 18px !important;
1145
- font-size: 14px !important;
1146
- box-shadow: 0 4px 10px rgba(231, 76, 60, 0.2) !important; transition: all 0.2s ease !important; margin-top: 5px;
1147
- display: flex !important; align-items: center !important; justify-content: center !important; white-space: nowrap !important;
1148
  }
1149
- .logout-btn-style:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 5px 15px rgba(192, 57, 43, 0.4) !important; }
1150
 
1151
- /* CĂN CHỈNH BẰNG CAO HOÀN TOÀN VỚI KHUNG TRẮNG CỦA DROPDOWN (BAO GỒM CẢ LABEL TRÊN) */
1152
  .delete-btn-style {
1153
- background: linear-gradient(135deg, #e74c3c, #c0392b) !important;
1154
- color: white !important;
1155
- font-weight: 700 !important;
1156
- font-size: 14px !important;
1157
- border: 1.5px solid #a93226 !important;
1158
- border-radius: 10px !important;
1159
- cursor: pointer !important;
1160
- height: 100% !important;
1161
- min-height: 82px !important;
1162
- margin: 0 !important;
1163
- box-shadow: 0 4px 12px rgba(231, 76, 60, 0.25) !important;
1164
- transition: all 0.25s ease !important;
1165
- display: flex !important;
1166
- align-items: center !important;
1167
- justify-content: center !important;
1168
- }
1169
- .delete-btn-style:hover {
1170
- filter: brightness(1.1) !important;
1171
- transform: translateY(-1px) !important;
1172
- box-shadow: 0 6px 18px rgba(192, 57, 43, 0.4) !important;
1173
  }
 
1174
 
1175
- .history-back-btn-style {
1176
- background: linear-gradient(135deg, #f39c12, #d35400) !important; color: white !important; font-weight: 700 !important;
1177
- border: none !important; border-radius: 12px !important; cursor: pointer; height: 48px !important;
1178
- box-shadow: 0 5px 15px rgba(243, 156, 18, 0.3) !important; transition: all 0.25s ease !important;
1179
- }
1180
- .history-back-btn-style:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(211, 84, 0, 0.45) !important; }
1181
- .hospital-header { background: linear-gradient(135deg, #004b39 0%, #007965 60%, #00bfa5 100%); color: white; padding: 25px; border-radius: 20px; margin-bottom: 15px; }
1182
- .gr-group {
1183
- border: 1px solid #d4deda !important;
1184
- background: #ffffff !important;
1185
- border-radius: 16px !important;
1186
- margin-bottom: 12px !important;
1187
- }
1188
  #prescription_col .textbox_custom {
1189
- border-left: 6px solid #007965 !important;
1190
- background-color: #f7faf9 !important;
1191
- border-radius: 12px !important;
1192
  }
 
 
1193
  #chatbot_col {
1194
- background: #ffffff !important;
1195
- border: 1px solid #d4deda !important;
1196
- border-radius: 16px !important;
1197
- padding: 15px !important;
1198
- margin-top: 10px !important;
1199
  }
1200
  #chatbot_col .chatbot_custom {
1201
- border-left: 6px solid #3498db !important;
1202
- background-color: #f2f7fa !important;
1203
- border-radius: 12px !important;
1204
  }
1205
- .chatbot-title-container { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 8px; }
1206
- .footer-text { text-align: center; margin-top: 25px; color: #728681; font-size: 13px; font-weight: 500; }
1207
- @keyframes pulseGlow {
1208
- 0%, 100% { transform: scale(1); filter: drop-shadow(0 2px 5px rgba(0,129,112,0.2)); }
1209
- 50% { transform: scale(1.04); filter: drop-shadow(0 4px 12px rgba(0,191,165,0.4)); }
 
 
 
 
 
 
 
1210
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1211
  /* ===================== LEAF HERO LOGIN (v4) ===================== */
1212
  #leaf-bg {
1213
  position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0;
@@ -1234,12 +1252,14 @@ body.leaf-on footer { display: none !important; }
1234
  #login_content_col {
1235
  position: fixed !important; top: 0 !important; bottom: 0 !important; left: 13vw !important; right: auto !important;
1236
  z-index: 20 !important;
1237
- width: 27rem !important; max-width: 80vw !important; margin: 0 !important; padding: 0 !important;
 
1238
  box-sizing: border-box !important;
1239
- display: flex !important; flex-direction: column !important; justify-content: center !important; gap: 10px !important;
1240
  overflow-y: auto !important;
1241
  background: transparent !important; border: none !important; box-shadow: none !important;
1242
  -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
 
1243
  }
1244
  /* Khối sát nhau: bỏ margin thừa của Gradio, thu gọn ô lỗi rỗng */
1245
  #login_wrapper .block, #login_wrapper .form { margin: 0 !important; }
@@ -1251,29 +1271,33 @@ body.leaf-on footer { display: none !important; }
1251
  }
1252
 
1253
  /* Brand head: badge (nhịp tim) + tên trung tâm nổi bật */
1254
- .lv4-head { display: flex; align-items: flex-start; gap: .85rem; margin-bottom: .3rem; }
1255
- .lv4-badge { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 14px; margin-top: 3px;
1256
  display: grid; place-items: center;
1257
  background: radial-gradient(circle at 35% 30%, #8fcb5e, #2f8b1c);
1258
  box-shadow: 0 8px 20px -8px rgba(45,122,18,0.7), inset 0 1px 0 rgba(255,255,255,0.5); }
1259
  .lv4-badge svg { width: 23px; height: 23px; }
1260
  .lv4-heart { transform-origin: center; animation: lv4-beat 1.05s ease-in-out infinite; }
1261
  .lv4-copy { min-width: 0; }
1262
- .lv4-title { margin: 0; font-weight: 800; line-height: 1.12; letter-spacing: -.02em;
1263
  font-size: clamp(1.5rem, 2.6vw, 2.1rem); color: #16281a; }
1264
  .lv4-accent { background: linear-gradient(120deg, #34d399, #059669 55%, #2d7a12);
1265
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
1266
- .lv4-sub { margin: .45rem 0 0; font-size: .92rem; color: #3d5233; }
1267
  @keyframes lv4-beat { 0%,100%{transform:scale(1);} 6%{transform:scale(1.22);} 12%{transform:scale(1);} 26%{transform:scale(1.13);} 34%{transform:scale(1);} }
1268
- @media (prefers-reduced-motion: reduce){ .lv4-heart{ animation: none; } }
 
 
1269
 
1270
  /* Ô nhập kiểu leaf v4 */
1271
  #login_wrapper .gr-form, #login_wrapper .block, #login_wrapper .form { background: transparent !important; border: none !important; box-shadow: none !important; }
1272
- #login_wrapper label span, #login_wrapper .gr-box label { color: #3d5233 !important; font-size: 13px !important; font-weight: 600 !important; letter-spacing: .01em !important; }
 
1273
  #login_wrapper input[type="text"], #login_wrapper input[type="password"] {
1274
- background: rgba(255,255,255,0.55) !important; border: 1px solid rgba(90,110,70,0.32) !important;
1275
- border-radius: 14px !important; color: #16281a !important; font-size: 15px !important; min-height: 50px !important;
1276
  padding: 0 16px !important; -webkit-backdrop-filter: blur(6px) !important; backdrop-filter: blur(6px) !important;
 
1277
  transition: all 0.2s ease !important;
1278
  }
1279
  #login_wrapper input::placeholder { color: #5f7255 !important; }
@@ -1285,15 +1309,20 @@ body.leaf-on footer { display: none !important; }
1285
 
1286
  /* Nút lớn KÍCH HOẠT PHIÊN XÉT NGHIỆM */
1287
  #login_wrapper .scan-btn {
1288
- border-radius: 14px !important; min-height: 54px !important; margin-top: 2px !important; width: 100% !important;
1289
- font-size: 15px !important; font-weight: 800 !important; letter-spacing: .08em !important; text-transform: uppercase !important;
 
1290
  color: #fff !important; border: none !important; cursor: pointer;
1291
  background: linear-gradient(135deg, #10b981, #047857) !important;
1292
  box-shadow: 0 16px 34px -14px rgba(5,150,105,0.75), inset 0 1px 0 rgba(255,255,255,0.25) !important;
1293
  transition: all 0.2s ease !important;
1294
  }
 
 
1295
  #login_wrapper .scan-btn:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 20px 40px -14px rgba(5,150,105,0.85) !important; }
 
1296
  #login_wrapper .scan-btn:active { transform: translateY(0); }
 
1297
 
1298
  /* Tài khoản thử nghiệm */
1299
  .lv4-demo { margin-top: .8rem; font-size: .8rem; color: #5f7255; }
@@ -1311,6 +1340,43 @@ body.leaf-on footer { display: none !important; }
1311
  /* =================== END LEAF HERO LOGIN =================== */
1312
  """
1313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1314
  initial_ticket_text, initial_ticket_img = check_user_expert_status()
1315
 
1316
  with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI", css=custom_css, head=LEAF_HERO_HEAD) as demo:
@@ -1321,11 +1387,9 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
1321
  <div class="lv4-badge" aria-hidden="true">
1322
  <svg class="lv4-heart" viewBox="0 0 24 24" fill="none"><path d="M12 5v14M5 12h14" stroke="#fff" stroke-width="3.4" stroke-linecap="round"/></svg>
1323
  </div>
1324
- <div class="lv4-copy">
1325
- <h1 class="lv4-title">Trung tâm Chẩn đoán &amp; Điều trị Bệnh <span class="lv4-accent">Cây trồng</span> Công nghệ cao</h1>
1326
- <p class="lv4-sub">Xác thực để mở phiên xét nghiệm mô lá.</p>
1327
- </div>
1328
  </div>
 
1329
  """)
1330
  username_input = gr.Textbox(label="Tên đăng nhập", placeholder="Nhập tên đăng nhập", max_lines=1)
1331
  password_input = gr.Textbox(label="Mật khẩu", type="password", placeholder="••••••••", max_lines=1)
@@ -1342,33 +1406,27 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
1342
  with gr.Column(visible=False) as main_panel:
1343
  with gr.Row(elem_classes="hospital-header"):
1344
  with gr.Column(scale=10, elem_classes="hospital-header-center"):
1345
- gr.HTML("""
1346
- <div class="title-wrapper-h1">
1347
- <div class="medical-cross-red"></div>
1348
- <h1>TRUNG TÂM CHẨN ĐOÁN & ĐIỀU TRỊ BỆNH CÂY TRỒNG CÔNG NGHỆ CAO</h1>
1349
- </div>
1350
- <p>Hệ thống tự động phân tích thị giác học sâu v8, phát hiện mầm bệnh thực vật và kết xuất phác đồ điều trị thời gian thực</p>
1351
- """)
1352
- with gr.Column(scale=2, min_width=210):
1353
  with gr.Row():
1354
- btn_logout = gr.Button("🚪 ĐĂNG XUẤT HỆ THỐNG", elem_classes="logout-btn-style")
1355
  with gr.Row():
1356
  with gr.Column(scale=10):
1357
  with gr.Group(elem_classes="gr-group"):
1358
- gr.Markdown("<p style='color: #004b39; font-weight: 700; margin: 8px 10px; font-size: 15px;'>🗂️ 1. TIẾP NHẬN MẪU XÉT NGHIỆM</p>")
1359
  plant_dropdown = gr.Dropdown(
1360
  choices=["Cây lúa", "Cây ớt", "Cây cà chua", "Cây dâu tây", "Cây cà phê", "Cây ngô (Bắp)"],
1361
  value="Cây cà chua", label="Lựa chọn phân khoa điều trị thực vật" )
1362
  with gr.Group(elem_classes="gr-group"):
1363
  image_input = gr.Image(type="numpy", label="Ảnh quét tế bào bề mặt lá", height=370)
1364
  gr.HTML("<div style='padding: 0 10px 10px 10px;'>")
1365
- btn_analyze = gr.Button("🩺 TIẾN HÀNH QUÉT & CHẨN ĐOÁN LÂM SÀNG", variant="primary", elem_classes="scan-btn")
1366
  gr.HTML("</div>")
1367
  with gr.Column(scale=11, elem_id="prescription_col"):
1368
  with gr.Group(elem_classes="gr-group"):
1369
- gr.Markdown("<p style='color: #004b39; font-weight: 700; margin: 8px 10px; font-size: 15px;'>🔬 2. KẾT QUẢ QUÉT THỊ GIÁC HỌC SÂU (AI DETECT)</p>")
1370
  image_output = gr.Image(type="numpy", label="Bản đồ nội soi vi vị trí: Khoanh vùng khu trú ổ bệnh", height=370)
1371
- gr.Markdown("<p style='color: #004b39; font-weight: 700; margin: 8px 10px 4px 10px; font-size: 15px;'>📄 3. ĐƠN THUỐC LÂM SÀNG SƠ BỘ</p>")
1372
  text_output = gr.Textbox(
1373
  label="Hồ sơ bệnh án điện tử xuất từ thuật toán",
1374
  lines=5,
@@ -1377,8 +1435,8 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
1377
 
1378
  with gr.Column(scale=12, elem_id="chatbot_col"):
1379
  with gr.Row(elem_classes="chatbot-title-container"):
1380
- gr.Markdown("<p style='color: #2980b9; font-weight: 700; margin: 0; font-size: 16px; display: inline-block;'>💬 4. HỘI ĐỒNG TƯ VẤN THUỐC BẢO VỆ THỰC VẬT (CHATBOT AI)</p>")
1381
- btn_history_nav = gr.Button("📂 Xem Lại Lịch Sử Bệnh Án", elem_classes="inline-history-btn")
1382
  chatbot = gr.Chatbot(
1383
  value=[{"role": "assistant", "content": "🤖 Hệ thống đang đợi mẫu quét. Sau khi phân tích xong ảnh lá, tôi sẽ tự động nắm thông tin bệnh lý để kê đơn thuốc chính xác cho bà con!"}],
1384
  height=550,
@@ -1391,75 +1449,84 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
1391
  btn_send = gr.Button("GỬI AI", scale=1, variant="primary", elem_classes="scan-btn")
1392
 
1393
  with gr.Group(elem_classes="gr-group", visible=True) as user_expert_section:
1394
- gr.Markdown("<p style='color: #d35400; font-weight: 700; margin: 8px 10px; font-size: 15px;'>👨‍⚕️ HỖ TRỢ TƯ VẤN TỪ CHUYÊN GIA</p>")
1395
- gr.Markdown("<p style='font-size: 13px; color: #555; margin: 0 10px;'>Nghi ngờ AI đoán sai hoặc muốn hỏi chi tiết cách điều trị? Gửi câu hỏi tại đây, chỉ Chuyên gia mới xem và trả lời trực tiếp cho bạn!</p>")
1396
  expert_user_query = gr.Textbox(label="Thắc mắc về tình trạng lá cây / nghi ngờ bệnh:", placeholder="Ví dụ: AI đoán cháy bìa lá nhưng tui nghi là đốm vằn, nhờ chuyên gia xem kỹ lại...", lines=2)
1397
- btn_send_expert = gr.Button("📩 GỬI YÊU CẦU CHO CHUYÊN GIA (HỘP THƯ CHỜ)", elem_classes="expert-send-btn")
1398
  expert_status_box = gr.HTML(value=initial_ticket_text)
1399
  expert_ticket_img_view = gr.Image(value=initial_ticket_img, label="Ảnh mẫu lá bệnh do nhà nông gửi lên", height=250, interactive=False)
1400
 
1401
- gr.HTML("<div class='footer-text'>🔏 Hệ thống lõi được bảo mật bởi AI Doctor Lab © 2026 | Nền tảng Phân tích Công nghệ cao Học máy Ultralytics YOLOv8 & Google Gemini AI</div>")
1402
 
1403
  with gr.Column(visible=False) as history_panel:
1404
  with gr.Row(elem_classes="hospital-header"):
1405
  with gr.Column(scale=10):
1406
  gr.HTML("""
1407
- <h1 style='text-align: left;'>📜 KHO LƯU TRỮ HỒ SƠ & LỊCH SỬ HỆ THỐNG</h1>
1408
- <p style='text-align: left;'>Xem lại toàn bộ nhật ký quét mô bệnh học thực vật, lịch sử hội thoại và Quản lý Hàng chờ Chuyên gia</p>
 
 
 
 
 
 
 
 
 
1409
  """)
1410
  with gr.Column(scale=2, min_width=150):
1411
- btn_back_to_clinic = gr.Button("⬅️ QUAY LẠI PHÒNG KHÁM", elem_classes="history-back-btn-style")
1412
 
1413
  with gr.Row():
1414
  with gr.Column(visible=True) as user_diagnose_col:
1415
- gr.Markdown("### ⏳ Nhật Ký Chẩn Đoán Ảnh:")
1416
  history_diagnose_box = gr.Textbox(
1417
  value=load_diagnose_history(),
1418
  label="Lịch sử các ca bệnh đã quét",
1419
  lines=15,
1420
  interactive=False )
1421
- btn_clear_diagnose = gr.Button("🗑️ XÓA NHẬT KÝ CHẤN ĐOÁN", variant="stop")
1422
  with gr.Column(visible=True) as user_chat_col:
1423
- gr.Markdown("### 💬 Nhật Ký Hội Thoại Với AI:")
1424
  history_chat_box = gr.Textbox(
1425
  value=load_chat_history(),
1426
  label="Lịch sử chat kê đơn thuốc",
1427
  lines=15,
1428
  interactive=False
1429
  )
1430
- btn_clear_chat = gr.Button("🗑️ XÓA NHẬT KÝ CHAT", variant="stop")
1431
-
1432
- gr.HTML("<hr style='margin: 25px 0; border: 1px solid #d4deda;'>")
1433
 
 
 
1434
  with gr.Group(elem_classes="gr-group"):
1435
- gr.Markdown("<h3 style='color: #004b39; font-weight: 800; margin: 10px 12px; font-size: 18px;'>👨‍⚕️ HỘP THƯ TƯ VẤN CHUYÊN GIA (LỊCH SỬ HỎI ĐÁP)</h3>")
1436
 
1437
  with gr.Row(elem_id="expert_select_row"):
1438
  admin_ticket_select = gr.Dropdown(label="Danh sách các câu hỏi hỗ trợ:", choices=[], value=None, scale=8)
1439
- btn_delete_ticket = gr.Button("🗑️ XÓA CÂU HỎI / HỘI THOẠI NÀY", elem_classes="delete-btn-style", scale=2)
1440
 
1441
  with gr.Row():
1442
  with gr.Column(scale=1):
1443
  admin_ticket_detail = gr.HTML(value="Hiện chưa có yêu cầu hỗ trợ nào.")
1444
  with gr.Column(scale=1):
1445
- admin_ticket_img_display = gr.Image(label="📷 Mẫu lá bệnh do nhà nông gửi lên:", height=300, interactive=False)
1446
 
1447
  with gr.Row():
1448
  admin_ticket_conversation = gr.HTML(value="", elem_id="full_width_conversation")
1449
 
1450
  with gr.Row():
1451
  with gr.Column(scale=1, visible=False) as admin_control_panel:
1452
- gr.Markdown("<hr style='margin: 15px 0; border: 1px dashed #007965;'>")
1453
- gr.Markdown("<p style='font-weight: 700; color: #007965; font-size: 16px;'>✍️ GỬI PHẢN HỒI BỆNH ÁN TỪ CHUYÊN GIA:</p>")
1454
- admin_reply_input = gr.Textbox(label="Nhập phản hồi chuyên gia / Phác đồ điều trị chuẩn:", placeholder="Gõ câu trả lời của Admin/Chuyên gia tại đây...", lines=4)
1455
- btn_submit_admin_reply = gr.Button("🚀 GỬI CÂU TRẢ LỜI CHO NHÀ NÔNG", variant="primary", elem_classes="scan-btn")
1456
  admin_reply_status = gr.Markdown("")
1457
 
1458
  with gr.Group(visible=True) as user_followup_panel:
1459
- gr.Markdown("<hr style='margin: 15px 0; border: 1px dashed #27ae60;'>")
1460
- gr.Markdown("<p style='font-weight: 700; color: #27ae60; font-size: 16px; margin-bottom: 4px;'>💬 BẠN VẪN CHƯA RÕ VỀ BỆNH ÁN TRÊN? HỎI TIẾP CHUYÊN GIA VỀ VẤN ĐỀ NÀY:</p>")
1461
- user_followup_input = gr.Textbox(label="Nội dung câu hỏi thêm:", placeholder="Ví dụ: Cảm ơn chuyên gia, nhưng cho tôi hỏi thêm là phun thuốc này vào buổi sáng hay chiều thì tốt hơn...", lines=2)
1462
- btn_send_followup = gr.Button("💬 GỬI CÂU HỎI TIẾP TỤC CHO CHUYÊN GIA", variant="primary")
1463
 
1464
  btn_login.click(
1465
  login_auth,
 
316
 
317
  def format_ticket_detail(ticket):
318
  status_label, _ = get_ticket_status_display(ticket)
319
+ # Màu mang thông tin: hổ phách = đang chờ xử lý, xanh = đã xong.
320
  if "CHƯA TRẢ LỜI" in status_label and "HỎI THÊM" not in status_label:
321
+ status_str = "Đang chờ chuyên gia trả lời"
322
+ status_color = "#b45309"
323
  elif "HỎI THÊM" in status_label:
324
+ status_str = "Nhà nông đã hỏi thêm — chờ phản hồi"
325
+ status_color = "#b45309"
326
  else:
327
+ status_str = "Đã được chuyên gia trả lời"
328
+ status_color = "#047857"
329
 
330
  reply_str = ticket.get('admin_reply', 'Chưa có phản hồi.')
331
+
332
+ header_html = f"""<div style="font-size: 14.5px; color: #16281a; line-height: 1.7;">
333
+ <b>Mã yêu cầu:</b> #{ticket['id']} &nbsp;·&nbsp; <b>Thời gian:</b> {ticket['time']}<br>
334
+ <b>Loại cây:</b> <span style="color: #047857; font-weight: 700;">{ticket['plant']}</span><br>
335
+ <b>Câu hỏi từ nhà nông:</b> <span class="chip-q">{ticket['user_query']}</span>
336
  </div>"""
337
 
338
  history_conversation = ""
 
342
  time_stamp = msg.get("time", "")
343
  text = msg.get("text", "")
344
  if sender == "USER":
345
+ history_conversation += f"""<div class="msg msg-user"><b>Nhà nông ({time_stamp}):</b> {text}</div>"""
 
 
346
  else:
347
+ history_conversation += f"""<div class="msg msg-expert"><b>Chuyên gia ({time_stamp}):</b> {text}</div>"""
 
 
348
 
349
  if not history_conversation:
350
+ history_conversation = f"""<div class="msg msg-expert">{reply_str}</div>"""
351
 
352
+ conversation_html = f"""<div style="font-size: 14.5px; color: #16281a; line-height: 1.7; width: 100%;">
353
+ <b>Trạng thái:</b> <span class="chip-status" style="color: {status_color};">{status_str}</span><br>
354
+ <b>Nội dung trao đổi với chuyên gia:</b>
355
  {history_conversation}
356
  </div>"""
357
 
 
447
  last_ticket = user_tickets[-1]
448
  img_p = last_ticket.get('image_path', None)
449
  h_info, c_info = format_ticket_detail(last_ticket)
450
+ return h_info + "<hr class='soft-rule'>" + c_info, img_p
451
 
452
  def submit_expert_request(user_question, selected_plant, input_image):
453
  global current_detected_disease_context
 
487
  tickets.append(new_ticket)
488
  save_expert_tickets(tickets)
489
  h_info, c_info = format_ticket_detail(new_ticket)
490
+ return "📩 Đã gửi câu hỏi đến Hộp thư chờ Chuyên gia! Chuyên gia sẽ sớm xem xét và trả lời.", h_info + "<hr class='soft-rule'>" + c_info, saved_img_path
491
 
492
  def go_to_history_panel():
493
  global current_user_role
 
699
  const C = {
700
  leaves: LEAF_CASES, cycleSeconds: 16, trailCycles: 2.6, compress: 0.42,
701
  maxTurns: 3, planeSpread: 1, eccentricity: 0.25, alignToCourse: 1,
702
+ driftSpeed: 1.5, driftDir: [272, 53], viewRadius: 2.6, tilt: 45, spin: 252, roll: 13.5,
703
  lead: 0.12, focus: [0.74, 0.42], scrim: "left", scrimStrength: 0.90,
704
  moteCount: 400, glow: 1, showCoreBeam: true, interactive: true, crossColor: "#2d7a12",
705
  pulseColor: "#10b981", rayColor: "#8fd45a"
 
713
  else {
714
  // đặt chữ thập vào giữa khoảng trống bên phải khối đăng nhập (khối ~13vw + 27rem)
715
  const panelRight = 0.13 * w + Math.min(432, 0.81 * w);
716
+ const fx = ((panelRight + w * 0.92) / 2) / w; /* dời tâm ra giữa-phải để không trống bên phải */
717
+ C.focus = [Math.min(0.80, Math.max(0.60, fx)), 0.5];
718
  }
719
  C.scrim = narrow ? "top" : "left";
720
  C.scrimStrength = narrow ? 0.90 : 0.90;
721
+ C.viewRadius = narrow ? 2.2 : 2.6;
722
  C.lead = narrow ? 0.05 : 0.12;
723
  C.glow = narrow ? 0.8 : 1;
724
+ /* Ở màn hẹp (<=767px) khối đăng nhập chiếm gần hết bề ngang -> chữ thập buộc phải
725
+ nằm trong vùng đó. Làm nó mờ hẳn (watermark) để không phá chữ, thay vì đè cứng lên form. */
726
+ C.heroAlpha = narrow ? 0.16 : 1;
727
  }
728
  applyResponsive();
729
 
 
810
  else if (edge === 1) { x = width - rng() * width * 0.25; y = rng() * height; }
811
  else if (edge === 2) { x = rng() * width; y = rng() * height * 0.2; }
812
  else { x = rng() * width; y = height - rng() * height * 0.2; }
813
+ BORDER_LEAVES.push({ x, y, size: (40 + rng() * 60) * 1.14, baseAngle: (rng() - 0.5) * 1.2, swaySpeed: 0.4 + rng() * 0.8, swayAmp: 0.06 + rng() * 0.1, phase: rng() * TAU, color: LEAF_GREENS[Math.floor(rng() * LEAF_GREENS.length)], alpha: 0.35 + rng() * 0.45 });
814
  }
815
  }
816
  function drawBorderLeaves(t) {
 
854
  const T = 1.05, p = (clk % T) / T, g = (x, mu, s) => Math.exp(-((x - mu) * (x - mu)) / (2 * s * s));
855
  return Math.min(1, g(p, 0.07, 0.045) + 0.58 * g(p, 0.27, 0.05));
856
  }
857
+ function crossBaseR() { return Math.max(32, Math.min(width, height) * 0.0713); } /* to hơn ~20% */
858
 
859
  // Tia sáng xoay quanh chữ thập
860
  function drawRays(clk, env) {
 
995
  }
996
 
997
  shots.sort((a, b) => b.depth - a.depth);
998
+ const sizeScale = Math.min(width, height) / 500 * 1.14; /* lá to hơn ~20% */
999
  const drawShot = (o, index) => {
1000
  const depth = Math.min(1.3, Math.max(0.5, o.s)), size = o.el.p.size * depth * sizeScale, bright = (o.el.p.glow ?? 1) * k, R = size * 3;
1001
  ctx.globalAlpha = Math.min(0.7, 0.5 * bright); ctx.drawImage(glowSprite(o.el.p.color), o.x - R, o.y - R, R * 2, R * 2); ctx.globalAlpha = 1;
 
1004
 
1005
  let idx = 0;
1006
  while (idx < shots.length && shots[idx].depth > camDist) drawShot(shots[idx], idx++);
1007
+ ctx.save(); ctx.globalAlpha = C.heroAlpha ?? 1;
1008
  drawRays(clock, env);
1009
  drawHeartbeat(clock, env);
1010
  drawCross(k, env);
1011
+ ctx.restore();
1012
  while (idx < shots.length) drawShot(shots[idx], idx++);
1013
  drawBorderLeaves(t);
1014
 
 
1037
  let prevOnLogin = null;
1038
  setInterval(function () {
1039
  const el = document.getElementById("login_wrapper");
1040
+ const exists = !!el;
1041
+ const onLogin = exists && el.offsetParent !== null;
1042
  document.body.classList.toggle("leaf-on", onLogin);
1043
+ document.body.classList.toggle("app-on", exists && !onLogin); /* khu làm việc: lá vẫn bay nhưng rất mờ */
1044
+ active = true;
1045
  // Khi vừa quay lại màn đăng nhập (vd sau khi đăng xuất) -> đưa trang về đầu để login không bị lạc
1046
  if (onLogin && prevOnLogin === false) { try { window.scrollTo(0, 0); } catch (e) {} }
1047
  prevOnLogin = onLogin;
 
1059
  """
1060
 
1061
  custom_css = """
1062
+ /* ================= HỆ THỐNG THIẾT KẾ CHUNG (đồng bộ với màn đăng nhập) ================= */
1063
+ :root {
1064
+ --ink: #16281a;
1065
+ --ink-2: #3d5233;
1066
+ --ink-3: #6b7c68;
1067
+ --emerald: #10b981;
1068
+ --emerald-d: #047857;
1069
+ --leaf: #2d7a12;
1070
+ --line: rgba(90,110,70,0.20);
1071
+ --card: rgba(255,255,255,0.78);
1072
+ --card-2: rgba(255,255,255,0.62);
1073
+ --warn: #b45309; /* cảnh báo bệnh — màu mang thông tin, không trang trí */
1074
+ --danger: #b91c1c; /* chỉ dùng cho hành động xoá */
1075
+ --r: 16px;
1076
  }
1077
+
1078
+ .gradio-container {
1079
+ background: transparent !important;
1080
+ font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
1081
+ color: var(--ink) !important;
1082
  }
1083
+ body { background: #eaf5da !important; }
1084
+ body.app-on #leaf-bg { opacity: 0.12; } /* lá bay rất mờ phía sau khu làm việc */
1085
+ body.app-on footer { display: none !important; }
1086
+
1087
+ /* ---------------- Topbar mảnh (thay banner gradient lớn) ---------------- */
1088
+ .hospital-header {
1089
+ background: var(--card) !important;
1090
+ -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
1091
+ border: 1px solid rgba(255,255,255,0.6) !important;
1092
+ box-shadow: 0 10px 30px -20px rgba(20,60,25,0.5) !important;
1093
+ color: var(--ink) !important;
1094
+ padding: 10px 16px !important; border-radius: 18px !important; margin-bottom: 14px !important;
1095
+ align-items: center !important;
1096
  }
1097
+ .topbar { display: flex; align-items: center; gap: .75rem; min-width: 0; }
1098
+ .tb-badge {
1099
+ width: 40px; height: 40px; flex: 0 0 40px; border-radius: 13px; display: grid; place-items: center;
1100
+ background: radial-gradient(circle at 35% 30%, #8fcb5e, #2f8b1c);
1101
+ box-shadow: 0 8px 18px -8px rgba(45,122,18,0.7), inset 0 1px 0 rgba(255,255,255,0.5);
1102
  }
1103
+ .tb-badge svg { width: 21px; height: 21px; }
1104
+ .tb-name { font-weight: 800; font-size: 15.5px; line-height: 1.25; letter-spacing: -.01em; color: var(--ink); }
1105
+ .tb-sub { font-size: 10.5px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; color: var(--ink-3); margin-top: 3px; }
1106
+ .hospital-header-center { text-align: left !important; width: 100%; }
1107
+
1108
+ /* ---------------- Thẻ nội dung ---------------- */
1109
+ .gr-group {
1110
+ border: 1px solid var(--line) !important;
1111
+ background: var(--card) !important;
1112
+ -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
1113
+ border-radius: var(--r) !important;
1114
+ margin-bottom: 12px !important;
1115
+ box-shadow: 0 10px 26px -22px rgba(20,60,25,0.55) !important;
1116
  }
1117
 
1118
+ /* ------ Tiêu đề mục: số thứ tự + icon + chữ IN HOA (cùng ngôn ngữ với nhãn ở màn đăng nhập) ------ */
1119
+ .sec-head { display: flex; align-items: center; gap: .55rem; margin: 12px 12px 8px; }
1120
+ .sec-num {
1121
+ width: 22px; height: 22px; flex: 0 0 22px; border-radius: 7px; display: grid; place-items: center;
1122
+ font-size: 11.5px; font-weight: 800; color: #fff;
1123
+ background: linear-gradient(135deg, var(--emerald), var(--emerald-d));
1124
+ box-shadow: 0 6px 14px -8px rgba(5,150,105,0.9);
 
 
 
 
 
1125
  }
1126
+ .sec-ico { width: 17px; height: 17px; flex: 0 0 17px; color: var(--emerald-d); }
1127
+ .sec-title { font-size: 11.5px; font-weight: 800; letter-spacing: .085em; line-height: 1.4; text-transform: uppercase; color: var(--ink-2); }
1128
+ .sec-note { margin: 0 12px 12px; font-size: 12.5px; line-height: 1.6; color: var(--ink-3); }
1129
+
1130
+ /* ---------------- Nút chính ---------------- */
1131
+ .scan-btn {
1132
+ background: linear-gradient(135deg, var(--emerald), var(--emerald-d)) !important;
1133
+ color: #fff !important; font-weight: 800 !important; letter-spacing: .04em !important;
1134
+ border: none !important; border-radius: 13px !important; min-height: 48px !important; cursor: pointer;
1135
+ box-shadow: 0 14px 30px -14px rgba(5,150,105,0.8), inset 0 1px 0 rgba(255,255,255,0.25) !important;
1136
+ transition: all .2s ease !important;
 
 
1137
  }
1138
+ .scan-btn:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 18px 36px -14px rgba(5,150,105,0.9) !important; }
1139
+ .scan-btn:active { transform: translateY(0); }
1140
+
1141
+ /* Nút phụ (đăng xuất / quay lại / lịch sử): viền nhẹ, không tô đặc */
1142
+ .logout-btn-style, .history-back-btn-style, .inline-history-btn {
1143
+ background: rgba(255,255,255,0.72) !important; color: var(--emerald-d) !important;
1144
+ border: 1px solid rgba(16,185,129,0.42) !important; font-weight: 700 !important;
1145
+ border-radius: 12px !important; cursor: pointer; box-shadow: none !important; filter: none !important;
1146
+ transition: all .2s ease !important;
 
 
 
 
 
 
1147
  }
1148
+ .logout-btn-style:hover, .history-back-btn-style:hover, .inline-history-btn:hover {
1149
+ background: rgba(16,185,129,0.13) !important; border-color: var(--emerald) !important;
1150
+ color: var(--emerald-d) !important; transform: translateY(-1px); filter: none !important;
 
1151
  }
1152
+ .logout-btn-style {
1153
+ height: 42px !important; min-width: 0 !important; padding: 0 18px !important; font-size: 13px !important;
1154
+ margin: 0 !important; white-space: nowrap !important;
1155
+ display: flex !important; align-items: center !important; justify-content: center !important;
 
 
1156
  }
1157
+ .history-back-btn-style { height: 44px !important; }
1158
+ .inline-history-btn { height: 34px !important; font-size: 12.5px !important; padding: 0 14px !important; display: inline-flex !important; align-items: center; justify-content: center; }
1159
 
1160
+ /* Gửi chuyên gia — hành động chính của thẻ đó */
1161
+ .expert-send-btn {
1162
+ background: linear-gradient(135deg, #0ea371, var(--emerald-d)) !important; color: #fff !important;
1163
+ font-weight: 800 !important; font-size: 14.5px !important; border: none !important;
1164
+ border-radius: 13px !important; height: 48px !important; cursor: pointer !important; margin-top: 10px !important;
1165
+ box-shadow: 0 14px 30px -14px rgba(5,150,105,0.8) !important; transition: all .25s ease !important;
 
1166
  }
1167
+ .expert-send-btn:hover { filter: brightness(1.06) !important; transform: translateY(-1px) !important; }
1168
 
1169
+ /* Xoá — đỏ vì đây thật sự là hành động phá huỷ dữ liệu */
1170
  .delete-btn-style {
1171
+ background: rgba(185,28,28,0.08) !important; color: var(--danger) !important;
1172
+ border: 1px solid rgba(185,28,28,0.35) !important;
1173
+ font-weight: 700 !important; font-size: 13.5px !important; border-radius: 12px !important;
1174
+ cursor: pointer !important; height: 100% !important; min-height: 82px !important; margin: 0 !important;
1175
+ box-shadow: none !important; transition: all .2s ease !important;
1176
+ display: flex !important; align-items: center !important; justify-content: center !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1177
  }
1178
+ .delete-btn-style:hover { background: rgba(185,28,28,0.16) !important; border-color: var(--danger) !important; filter: none !important; transform: none !important; }
1179
 
1180
+ /* ---------------- Khu 3: đơn thuốc (ưu tiên cao) ---------------- */
 
 
 
 
 
 
 
 
 
 
 
 
1181
  #prescription_col .textbox_custom {
1182
+ border-left: 4px solid var(--emerald) !important;
1183
+ background: rgba(255,255,255,0.85) !important;
1184
+ border-radius: 13px !important;
1185
  }
1186
+
1187
+ /* ---------------- Khu 4: chatbot (ưu tiên thấp hơn — nhẹ hơn về thị giác) ---------------- */
1188
  #chatbot_col {
1189
+ background: var(--card-2) !important;
1190
+ border: 1px solid var(--line) !important;
1191
+ border-radius: var(--r) !important;
1192
+ padding: 14px !important; margin-top: 10px !important;
1193
+ -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
1194
  }
1195
  #chatbot_col .chatbot_custom {
1196
+ border-left: 3px solid rgba(16,185,129,0.5) !important;
1197
+ background: rgba(255,255,255,0.62) !important;
1198
+ border-radius: 12px !important;
1199
  }
1200
+ .chatbot-title-container { display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 10px; margin-bottom: 8px; }
1201
+
1202
+ /* ---------------- Ô nhập trong khu làm việc ---------------- */
1203
+ .gradio-container input[type="text"], .gradio-container input[type="password"],
1204
+ .gradio-container textarea, .gradio-container select { border-radius: 12px !important; }
1205
+ .gradio-container label span { color: var(--ink-2) !important; }
1206
+
1207
+ .soft-rule { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
1208
+ .danger-soft, button.danger-soft {
1209
+ background: rgba(185,28,28,0.08) !important; color: var(--danger) !important;
1210
+ border: 1px solid rgba(185,28,28,0.32) !important; font-weight: 700 !important;
1211
+ border-radius: 12px !important; box-shadow: none !important;
1212
  }
1213
+ .danger-soft:hover, button.danger-soft:hover { background: rgba(185,28,28,0.15) !important; border-color: var(--danger) !important; filter: none !important; }
1214
+
1215
+ /* Bong bóng hội thoại trong hồ sơ (sinh từ Python) */
1216
+ .msg { padding: 10px 14px; margin: 8px 0; border-radius: 12px; font-size: 14.5px; line-height: 1.55; color: var(--ink); }
1217
+ .msg b { font-size: 14px; }
1218
+ .msg-user { background: rgba(16,185,129,0.10); border-left: 4px solid var(--emerald); }
1219
+ .msg-user b { color: var(--emerald-d); }
1220
+ .msg-expert { background: rgba(255,255,255,0.85); border-left: 4px solid var(--leaf); }
1221
+ .msg-expert b { color: var(--leaf); }
1222
+ .chip-status { font-weight: 800; }
1223
+ .chip-q { background: rgba(16,185,129,0.12); padding: 2px 8px; border-radius: 6px; font-weight: 700; }
1224
+
1225
+ .footer-text { text-align: center; margin-top: 22px; color: var(--ink-3); font-size: 12.5px; font-weight: 500; }
1226
+
1227
+ @keyframes pulseGlow { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
1228
+
1229
  /* ===================== LEAF HERO LOGIN (v4) ===================== */
1230
  #leaf-bg {
1231
  position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0;
 
1252
  #login_content_col {
1253
  position: fixed !important; top: 0 !important; bottom: 0 !important; left: 13vw !important; right: auto !important;
1254
  z-index: 20 !important;
1255
+ width: 27rem !important; max-width: 80vw !important; margin: 0 !important;
1256
+ padding: 0 0 12vh 0 !important; /* padding-bottom kéo khối lên cao hơn một chút cho thoáng */
1257
  box-sizing: border-box !important;
1258
+ display: flex !important; flex-direction: column !important; justify-content: center !important; gap: 12px !important;
1259
  overflow-y: auto !important;
1260
  background: transparent !important; border: none !important; box-shadow: none !important;
1261
  -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
1262
+ animation: lv4-in .6s cubic-bezier(.16,1,.3,1) both;
1263
  }
1264
  /* Khối sát nhau: bỏ margin thừa của Gradio, thu gọn ô lỗi rỗng */
1265
  #login_wrapper .block, #login_wrapper .form { margin: 0 !important; }
 
1271
  }
1272
 
1273
  /* Brand head: badge (nhịp tim) + tên trung tâm nổi bật */
1274
+ .lv4-head { display: flex; align-items: center; gap: .85rem; margin-bottom: .35rem; }
1275
+ .lv4-badge { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 14px;
1276
  display: grid; place-items: center;
1277
  background: radial-gradient(circle at 35% 30%, #8fcb5e, #2f8b1c);
1278
  box-shadow: 0 8px 20px -8px rgba(45,122,18,0.7), inset 0 1px 0 rgba(255,255,255,0.5); }
1279
  .lv4-badge svg { width: 23px; height: 23px; }
1280
  .lv4-heart { transform-origin: center; animation: lv4-beat 1.05s ease-in-out infinite; }
1281
  .lv4-copy { min-width: 0; }
1282
+ .lv4-title { margin: 0; min-width: 0; font-weight: 800; line-height: 1.15; letter-spacing: -.015em;
1283
  font-size: clamp(1.5rem, 2.6vw, 2.1rem); color: #16281a; }
1284
  .lv4-accent { background: linear-gradient(120deg, #34d399, #059669 55%, #2d7a12);
1285
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
1286
+ .lv4-sub { margin: .5rem 0 0; font-size: .9rem; line-height: 1.5; color: #4a5f47; }
1287
  @keyframes lv4-beat { 0%,100%{transform:scale(1);} 6%{transform:scale(1.22);} 12%{transform:scale(1);} 26%{transform:scale(1.13);} 34%{transform:scale(1);} }
1288
+ @keyframes lv4-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
1289
+ @keyframes lv4-sheen { to { left: 150%; } }
1290
+ @media (prefers-reduced-motion: reduce){ .lv4-heart{ animation: none; } #login_content_col{ animation: none !important; } }
1291
 
1292
  /* Ô nhập kiểu leaf v4 */
1293
  #login_wrapper .gr-form, #login_wrapper .block, #login_wrapper .form { background: transparent !important; border: none !important; box-shadow: none !important; }
1294
+ #login_wrapper label span, #login_wrapper .gr-box label { color: #4a5f47 !important; font-size: 11px !important; font-weight: 700 !important; letter-spacing: .1em !important; text-transform: uppercase !important; }
1295
+ #login_wrapper [data-testid="status-tracker"], #login_wrapper .status-tracker { display: none !important; }
1296
  #login_wrapper input[type="text"], #login_wrapper input[type="password"] {
1297
+ background: rgba(255,255,255,0.62) !important; border: 1px solid rgba(90,110,70,0.3) !important;
1298
+ border-radius: 14px !important; color: #16281a !important; font-size: 15px !important; min-height: 52px !important;
1299
  padding: 0 16px !important; -webkit-backdrop-filter: blur(6px) !important; backdrop-filter: blur(6px) !important;
1300
+ box-shadow: inset 0 1px 0 rgba(255,255,255,0.65), 0 1px 2px rgba(20,50,25,0.04) !important;
1301
  transition: all 0.2s ease !important;
1302
  }
1303
  #login_wrapper input::placeholder { color: #5f7255 !important; }
 
1309
 
1310
  /* Nút lớn KÍCH HOẠT PHIÊN XÉT NGHIỆM */
1311
  #login_wrapper .scan-btn {
1312
+ position: relative !important; overflow: hidden !important;
1313
+ border-radius: 14px !important; min-height: 54px !important; margin-top: 4px !important; width: 100% !important;
1314
+ font-size: 15px !important; font-weight: 800 !important; letter-spacing: .06em !important; text-transform: uppercase !important;
1315
  color: #fff !important; border: none !important; cursor: pointer;
1316
  background: linear-gradient(135deg, #10b981, #047857) !important;
1317
  box-shadow: 0 16px 34px -14px rgba(5,150,105,0.75), inset 0 1px 0 rgba(255,255,255,0.25) !important;
1318
  transition: all 0.2s ease !important;
1319
  }
1320
+ #login_wrapper .scan-btn::after { content: ""; position: absolute; top: 0; left: -120%; width: 55%; height: 100%;
1321
+ background: linear-gradient(100deg, transparent, rgba(255,255,255,0.35), transparent); transform: skewX(-18deg); pointer-events: none; }
1322
  #login_wrapper .scan-btn:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 20px 40px -14px rgba(5,150,105,0.85) !important; }
1323
+ #login_wrapper .scan-btn:hover::after { animation: lv4-sheen 1.1s ease; }
1324
  #login_wrapper .scan-btn:active { transform: translateY(0); }
1325
+ @media (prefers-reduced-motion: reduce){ #login_wrapper .scan-btn:hover::after { animation: none; } }
1326
 
1327
  /* Tài khoản thử nghiệm */
1328
  .lv4-demo { margin-top: .8rem; font-size: .8rem; color: #5f7255; }
 
1340
  /* =================== END LEAF HERO LOGIN =================== */
1341
  """
1342
 
1343
+ # ── Bộ icon nét mảnh + tiêu đề mục (thay emoji, đồng bộ với nhãn IN HOA ở màn đăng nhập) ──
1344
+ ICO_INTAKE = '<path d="M4 13h4l1.5 2.5h5L16 13h4"/><path d="M6 4h12l2 9v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-4l2-9Z"/>'
1345
+ ICO_SCAN = '<path d="M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2"/><circle cx="12" cy="12" r="3"/>'
1346
+ ICO_RX = '<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-5-5Z"/><path d="M14 3v5h5"/><path d="M9 13h6M9 17h4"/>'
1347
+ ICO_CHAT = '<path d="M20 12a7 7 0 0 1-7 7H8l-4 3v-10a7 7 0 0 1 7-7h2a7 7 0 0 1 7 7Z"/><path d="M9 11h6M9 14h4"/>'
1348
+ ICO_EXPERT = '<path d="M16 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2"/><circle cx="9.5" cy="7" r="3.5"/><path d="m16.5 10.5 2 2 4-4"/>'
1349
+ ICO_ARCHIVE = '<rect x="3" y="4" width="18" height="4" rx="1"/><path d="M5 8v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8"/><path d="M10 12h4"/>'
1350
+ ICO_REPLY = '<path d="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 6 6v5"/>'
1351
+
1352
+ def _svg(icon):
1353
+ return (f'<svg class="sec-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" '
1354
+ f'stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">{icon}</svg>')
1355
+
1356
+ def sec_head(num, title, icon):
1357
+ """Tiêu đề mục có đánh số — chỉ dùng cho quy trình khám thật sự theo thứ tự 1→4."""
1358
+ return (f'<div class="sec-head"><span class="sec-num">{num}</span>{_svg(icon)}'
1359
+ f'<span class="sec-title">{title}</span></div>')
1360
+
1361
+ def sec_head_plain(title, icon):
1362
+ """Tiêu đề mục không đánh số — cho các khu nằm ngoài quy trình tuần tự."""
1363
+ return f'<div class="sec-head">{_svg(icon)}<span class="sec-title">{title}</span></div>'
1364
+
1365
+ def sec_note(text):
1366
+ return f'<p class="sec-note">{text}</p>'
1367
+
1368
+ TOPBAR_HTML = """
1369
+ <div class="topbar">
1370
+ <div class="tb-badge" aria-hidden="true">
1371
+ <svg class="lv4-heart" viewBox="0 0 24 24" fill="none"><path d="M12 5v14M5 12h14" stroke="#fff" stroke-width="3.4" stroke-linecap="round"/></svg>
1372
+ </div>
1373
+ <div>
1374
+ <div class="tb-name">Trung tâm Chẩn đoán &amp; Điều trị Bệnh <span class="lv4-accent">Cây trồng</span> Công nghệ cao</div>
1375
+ <div class="tb-sub">Phòng xét nghiệm số · YOLOv8 &amp; Gemini</div>
1376
+ </div>
1377
+ </div>
1378
+ """
1379
+
1380
  initial_ticket_text, initial_ticket_img = check_user_expert_status()
1381
 
1382
  with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI", css=custom_css, head=LEAF_HERO_HEAD) as demo:
 
1387
  <div class="lv4-badge" aria-hidden="true">
1388
  <svg class="lv4-heart" viewBox="0 0 24 24" fill="none"><path d="M12 5v14M5 12h14" stroke="#fff" stroke-width="3.4" stroke-linecap="round"/></svg>
1389
  </div>
1390
+ <h1 class="lv4-title">Trung tâm Chẩn đoán &amp; Điều trị Bệnh <span class="lv4-accent">Cây trồng</span> Công nghệ cao</h1>
 
 
 
1391
  </div>
1392
+ <p class="lv4-sub">Xác thực để mở phiên xét nghiệm mô lá.</p>
1393
  """)
1394
  username_input = gr.Textbox(label="Tên đăng nhập", placeholder="Nhập tên đăng nhập", max_lines=1)
1395
  password_input = gr.Textbox(label="Mật khẩu", type="password", placeholder="••••••••", max_lines=1)
 
1406
  with gr.Column(visible=False) as main_panel:
1407
  with gr.Row(elem_classes="hospital-header"):
1408
  with gr.Column(scale=10, elem_classes="hospital-header-center"):
1409
+ gr.HTML(TOPBAR_HTML)
1410
+ with gr.Column(scale=2, min_width=150):
 
 
 
 
 
 
1411
  with gr.Row():
1412
+ btn_logout = gr.Button("Đăng xuất", elem_classes="logout-btn-style")
1413
  with gr.Row():
1414
  with gr.Column(scale=10):
1415
  with gr.Group(elem_classes="gr-group"):
1416
+ gr.HTML(sec_head(1, "Tiếp nhận mẫu xét nghiệm", ICO_INTAKE))
1417
  plant_dropdown = gr.Dropdown(
1418
  choices=["Cây lúa", "Cây ớt", "Cây cà chua", "Cây dâu tây", "Cây cà phê", "Cây ngô (Bắp)"],
1419
  value="Cây cà chua", label="Lựa chọn phân khoa điều trị thực vật" )
1420
  with gr.Group(elem_classes="gr-group"):
1421
  image_input = gr.Image(type="numpy", label="Ảnh quét tế bào bề mặt lá", height=370)
1422
  gr.HTML("<div style='padding: 0 10px 10px 10px;'>")
1423
+ btn_analyze = gr.Button("Quét & chẩn đoán lâm sàng", variant="primary", elem_classes="scan-btn")
1424
  gr.HTML("</div>")
1425
  with gr.Column(scale=11, elem_id="prescription_col"):
1426
  with gr.Group(elem_classes="gr-group"):
1427
+ gr.HTML(sec_head(2, "Kết quả quét thị giác học sâu", ICO_SCAN))
1428
  image_output = gr.Image(type="numpy", label="Bản đồ nội soi vi vị trí: Khoanh vùng khu trú ổ bệnh", height=370)
1429
+ gr.HTML(sec_head(3, "Đơn thuốc lâm sàng sơ bộ", ICO_RX))
1430
  text_output = gr.Textbox(
1431
  label="Hồ sơ bệnh án điện tử xuất từ thuật toán",
1432
  lines=5,
 
1435
 
1436
  with gr.Column(scale=12, elem_id="chatbot_col"):
1437
  with gr.Row(elem_classes="chatbot-title-container"):
1438
+ gr.HTML(sec_head(4, "Tư vấn thuốc bảo vệ thực vật (AI)", ICO_CHAT))
1439
+ btn_history_nav = gr.Button("Xem lịch sử bệnh án", elem_classes="inline-history-btn")
1440
  chatbot = gr.Chatbot(
1441
  value=[{"role": "assistant", "content": "🤖 Hệ thống đang đợi mẫu quét. Sau khi phân tích xong ảnh lá, tôi sẽ tự động nắm thông tin bệnh lý để kê đơn thuốc chính xác cho bà con!"}],
1442
  height=550,
 
1449
  btn_send = gr.Button("GỬI AI", scale=1, variant="primary", elem_classes="scan-btn")
1450
 
1451
  with gr.Group(elem_classes="gr-group", visible=True) as user_expert_section:
1452
+ gr.HTML(sec_head_plain("Hỗ trợ tư vấn từ chuyên gia", ICO_EXPERT))
1453
+ gr.HTML(sec_note("Nghi ngờ AI đoán sai hoặc muốn hỏi chi tiết cách điều trị? Gửi câu hỏi tại đây, chỉ chuyên gia mới xem và trả lời trực tiếp cho bạn."))
1454
  expert_user_query = gr.Textbox(label="Thắc mắc về tình trạng lá cây / nghi ngờ bệnh:", placeholder="Ví dụ: AI đoán cháy bìa lá nhưng tui nghi là đốm vằn, nhờ chuyên gia xem kỹ lại...", lines=2)
1455
+ btn_send_expert = gr.Button("Gửi yêu cầu cho chuyên gia", elem_classes="expert-send-btn")
1456
  expert_status_box = gr.HTML(value=initial_ticket_text)
1457
  expert_ticket_img_view = gr.Image(value=initial_ticket_img, label="Ảnh mẫu lá bệnh do nhà nông gửi lên", height=250, interactive=False)
1458
 
1459
+ gr.HTML("<div class='footer-text'>Bảo mật bởi AI Doctor Lab © 2026 · Ultralytics YOLOv8 &amp; Google Gemini AI</div>")
1460
 
1461
  with gr.Column(visible=False) as history_panel:
1462
  with gr.Row(elem_classes="hospital-header"):
1463
  with gr.Column(scale=10):
1464
  gr.HTML("""
1465
+ <div class="topbar">
1466
+ <div class="tb-badge" aria-hidden="true">
1467
+ <svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
1468
+ <rect x="3" y="4" width="18" height="4" rx="1"/><path d="M5 8v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8"/><path d="M10 12h4"/>
1469
+ </svg>
1470
+ </div>
1471
+ <div>
1472
+ <div class="tb-name">Kho lưu trữ hồ sơ &amp; lịch sử hệ thống</div>
1473
+ <div class="tb-sub">Nhật ký chẩn đoán · Hội thoại · Hộp thư chuyên gia</div>
1474
+ </div>
1475
+ </div>
1476
  """)
1477
  with gr.Column(scale=2, min_width=150):
1478
+ btn_back_to_clinic = gr.Button("Quay lại phòng khám", elem_classes="history-back-btn-style")
1479
 
1480
  with gr.Row():
1481
  with gr.Column(visible=True) as user_diagnose_col:
1482
+ gr.HTML(sec_head_plain("Nhật ký chẩn đoán ảnh", ICO_SCAN))
1483
  history_diagnose_box = gr.Textbox(
1484
  value=load_diagnose_history(),
1485
  label="Lịch sử các ca bệnh đã quét",
1486
  lines=15,
1487
  interactive=False )
1488
+ btn_clear_diagnose = gr.Button("Xoá nhật ký chẩn đoán", variant="stop", elem_classes="danger-soft")
1489
  with gr.Column(visible=True) as user_chat_col:
1490
+ gr.HTML(sec_head_plain("Nhật ký hội thoại với AI", ICO_CHAT))
1491
  history_chat_box = gr.Textbox(
1492
  value=load_chat_history(),
1493
  label="Lịch sử chat kê đơn thuốc",
1494
  lines=15,
1495
  interactive=False
1496
  )
1497
+ btn_clear_chat = gr.Button("Xoá nhật ký chat", variant="stop", elem_classes="danger-soft")
 
 
1498
 
1499
+ gr.HTML("<hr class='soft-rule'>")
1500
+
1501
  with gr.Group(elem_classes="gr-group"):
1502
+ gr.HTML(sec_head_plain("Hộp thư tư vấn chuyên gia", ICO_EXPERT))
1503
 
1504
  with gr.Row(elem_id="expert_select_row"):
1505
  admin_ticket_select = gr.Dropdown(label="Danh sách các câu hỏi hỗ trợ:", choices=[], value=None, scale=8)
1506
+ btn_delete_ticket = gr.Button("Xoá hội thoại này", elem_classes="delete-btn-style", scale=2)
1507
 
1508
  with gr.Row():
1509
  with gr.Column(scale=1):
1510
  admin_ticket_detail = gr.HTML(value="Hiện chưa có yêu cầu hỗ trợ nào.")
1511
  with gr.Column(scale=1):
1512
+ admin_ticket_img_display = gr.Image(label="Mẫu lá bệnh do nhà nông gửi lên", height=300, interactive=False)
1513
 
1514
  with gr.Row():
1515
  admin_ticket_conversation = gr.HTML(value="", elem_id="full_width_conversation")
1516
 
1517
  with gr.Row():
1518
  with gr.Column(scale=1, visible=False) as admin_control_panel:
1519
+ gr.HTML("<hr class='soft-rule'>")
1520
+ gr.HTML(sec_head_plain("Gửi phản hồi bệnh án từ chuyên gia", ICO_REPLY))
1521
+ admin_reply_input = gr.Textbox(label="Phản hồi chuyên gia / Phác đồ điều trị chuẩn", placeholder="Gõ câu trả lời của chuyên gia tại đây...", lines=4)
1522
+ btn_submit_admin_reply = gr.Button("Gửi câu trả lời cho nhà nông", variant="primary", elem_classes="scan-btn")
1523
  admin_reply_status = gr.Markdown("")
1524
 
1525
  with gr.Group(visible=True) as user_followup_panel:
1526
+ gr.HTML("<hr class='soft-rule'>")
1527
+ gr.HTML(sec_head_plain("Hỏi tiếp chuyên gia về bệnh án này", ICO_CHAT))
1528
+ user_followup_input = gr.Textbox(label="Nội dung câu hỏi thêm", placeholder="Ví dụ: Cảm ơn chuyên gia, cho tôi hỏi thêm phun thuốc này buổi sáng hay chiều thì tốt hơn...", lines=2)
1529
+ btn_send_followup = gr.Button("Gửi câu hỏi tiếp tục", variant="primary", elem_classes="scan-btn")
1530
 
1531
  btn_login.click(
1532
  login_auth,