/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* TCM Warm Green + Earth palette */
  --primary: #2D7D46;
  --primary-dark: #1A5C2E;
  --primary-light: #E8F0E3;
  --primary-50: #F4F8F1;
  --accent: #C9A84C;
  --accent-light: #FDF6E3;
  --accent-dark: #9E7E2A;

  /* Neutrals — warm-toned */
  --gray-50: #FAF8F5;
  --gray-100: #F5F1EC;
  --gray-200: #EBE5DC;
  --gray-300: #D4CCC0;
  --gray-400: #A0988C;
  --gray-500: #7A7268;
  --gray-600: #5C554C;
  --gray-700: #3D3630;
  --gray-800: #2A241F;
  --gray-900: #1A1612;

  --red: #C94A4A;
  --red-light: #FDF0F0;
  --green: #2D7D46;
  --amber: #C9A84C;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 12px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-md: 0 8px 24px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.10), 0 4px 12px rgba(0,0,0,.04);

  --transition: 180ms ease;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== Login ===== */
#login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #F4F8F1 0%, #FAF8F5 40%, #FDF6E3 100%);
}
.login-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  border: 1px solid var(--gray-200);
}
.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-card h1 { font-size: 24px; color: var(--gray-800); margin-bottom: 4px; font-weight: 600; }
.login-subtitle { color: var(--gray-500); margin-bottom: 28px; font-size: 15px; }

/* ===== Top Nav ===== */
#top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 56px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: 10px; }
.nav-logo { font-size: 26px; }
.nav-title { font-size: 17px; font-weight: 600; color: var(--gray-800); }
.nav-subtitle { font-size: 12px; color: var(--gray-400); background: var(--primary-light); padding: 2px 10px; border-radius: var(--radius-sm); }
.nav-actions { display: flex; align-items: center; gap: 14px; }
.nav-user { color: var(--gray-600); font-size: 14px; }

/* ===== Layout ===== */
#app-container { display: flex; min-height: calc(100vh - 56px); }
#sidebar {
  width: 224px;
  background: white;
  border-right: 1px solid var(--gray-200);
  padding: 20px 0;
  flex-shrink: 0;
}
#main-content {
  flex: 1;
  padding: 28px 36px;
  overflow-y: auto;
  max-height: calc(100vh - 56px);
}

/* ===== Side Nav ===== */
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--gray-600);
  text-decoration: none;
  font-size: 14px;
  transition: all var(--transition);
  border-radius: var(--radius);
  border-left: none;
}
.side-link:hover { background: var(--primary-50); color: var(--gray-800); }
.side-link.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.side-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.side-divider { height: 1px; background: var(--gray-200); margin: 10px 14px; }
.disabled-link { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.disabled-link:hover { background: transparent; color: var(--gray-600); }

/* Sidebar sections */
.side-section { margin: 4px 0; }
.side-section-title {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 18px;
  border: none;
  background: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .06em;
  cursor: pointer;
  font-family: inherit;
  transition: color var(--transition);
}
.side-section-title:hover { color: var(--gray-600); }
.side-section-arrow { font-size: 10px; width: 14px; text-align: center; flex-shrink: 0; }
.side-section-body { margin: 2px 0 8px; }
.side-section-body .side-link { padding-left: 38px; font-size: 13px; }

/* ===== Badge ===== */
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-dark);
}
.badge-gray { background: var(--gray-100); color: var(--gray-500); }

/* ===== View ===== */
.view { display: none; }
.view.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.view-title { font-size: 22px; font-weight: 700; color: var(--gray-800); margin-bottom: 24px; letter-spacing: -.02em; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.view-header .view-title { margin-bottom: 0; }
.view-header-actions { display: flex; gap: 10px; align-items: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: var(--shadow-sm); }
.btn-outline {
  background: white;
  color: var(--gray-700);
  border-color: var(--gray-300);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-400); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--gray-400); padding: 4px 8px; border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-close:hover { color: var(--gray-600); background: var(--gray-100); }

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; flex: 1; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-600); margin-bottom: 5px; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--gray-800);
  background: white;
  transition: all var(--transition);
  font-family: inherit;
}
.form-group input:hover, .form-group textarea:hover, .form-group select:hover { border-color: var(--gray-400); }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,125,70,.12);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--gray-400); }
.form-row { display: flex; gap: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--gray-200); }
.form-select { padding: 9px 13px; border: 1.5px solid var(--gray-300); border-radius: var(--radius); font-size: 14px; color: var(--gray-700); background: white; font-family: inherit; }
.form-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,125,70,.12); }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 32px; }
.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  text-align: center;
  border: 1px solid var(--gray-100);
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-num { font-size: 36px; font-weight: 700; color: var(--primary-dark); letter-spacing: -.02em; }
.stat-label { font-size: 13px; color: var(--gray-500); margin-top: 6px; font-weight: 500; }

/* ===== Quick Actions ===== */
.quick-actions {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 28px;
  border: 1px solid var(--gray-100);
}
.quick-actions h3 { font-size: 16px; margin-bottom: 14px; color: var(--gray-700); font-weight: 600; }
.action-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Cards & Lists ===== */
.recent-section {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
}
.recent-section h3 { font-size: 16px; margin-bottom: 14px; color: var(--gray-700); font-weight: 600; }

.card-list { display: flex; flex-direction: column; gap: 8px; }
.card-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-100);
  cursor: pointer;
  transition: all var(--transition);
  gap: 12px;
}
.card-item:hover { background: var(--primary-50); border-color: var(--primary-light); box-shadow: var(--shadow-xs); }
.card-item-main { flex: 1; min-width: 0; }
.card-item-title { font-weight: 600; color: var(--gray-800); font-size: 14px; }
.card-item-sub { font-size: 13px; color: var(--gray-500); margin-top: 2px; }
.card-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: #eef3ec;
  color: var(--primary-dark);
  border: 1px solid #dce8d8;
  font-size: 12px;
  font-weight: 600;
}

.source-pill.warn {
  background: #fff7ed;
  color: #9a4d0b;
  border-color: #f1d2a8;
}

.source-block {
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
}

.source-line {
  color: var(--gray-700);
  font-size: 13px;
  line-height: 1.65;
}

.tongue-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.tongue-card {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px;
  background: white;
}

.protected-media {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  margin-bottom: 8px;
}

.tongue-annotation-layout {
  display: grid;
  grid-template-columns: minmax(260px, 42%) 1fr;
  gap: 22px;
  align-items: start;
}

.tongue-image-pane {
  position: sticky;
  top: 16px;
}

.tongue-image-pane img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
}

.tongue-form-pane {
  min-width: 0;
}

.compact-actions {
  margin-top: 12px;
  padding-top: 12px;
}

.taxonomy-group {
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-200);
}

.taxonomy-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 8px;
}

.taxonomy-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.taxonomy-options label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
  font-size: 13px;
}

/* ===== Overlay ===== */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(26,22,18,.35);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  overflow-y: auto;
  animation: fadeIn .15s ease;
}
.overlay-content {
  background: white;
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 580px;
  box-shadow: var(--shadow-lg);
  margin: 40px 0;
}
.overlay-content.wide { max-width: 840px; }
.overlay-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.overlay-header h3 { font-size: 18px; color: var(--gray-800); font-weight: 600; }

/* ===== Record Form Tabs ===== */
.form-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--gray-200); overflow-x: auto; }
.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 600; }
.record-section { display: none; }
.record-section.active { display: block; }

/* ===== Editor Panel ===== */
.editor-panel {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-top: 20px;
  border: 1px solid var(--gray-100);
}
.editor-panel h3 { margin-bottom: 20px; font-size: 17px; font-weight: 600; }

/* ===== Education Workbench ===== */
.education-mode-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.education-mode {
  min-height: 72px;
  padding: 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  background: white;
  color: var(--gray-700);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}
.education-mode strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--gray-800);
}
.education-mode span {
  display: block;
  font-size: 12px;
  color: var(--gray-500);
  line-height: 1.35;
}
.education-mode:hover {
  border-color: var(--primary);
  background: var(--primary-50);
}
.education-mode.active {
  border-color: var(--primary);
  background: var(--primary-50);
  box-shadow: 0 0 0 3px rgba(45,125,70,.08);
}
.education-mode.active strong { color: var(--primary-dark); }
.result-kicker {
  color: var(--primary-dark);
  font-weight: 700;
  margin-bottom: 10px;
}

/* ===== Upload Grid ===== */
.upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.upload-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
  transition: box-shadow var(--transition);
}
.upload-card:hover { box-shadow: var(--shadow); }
.upload-card h3 { font-size: 16px; margin-bottom: 8px; font-weight: 600; }
.upload-card input[type="file"] { margin: 12px 0; font-size: 13px; }

/* ===== File Preview ===== */
.file-preview { margin: 8px 0; }
.file-preview img { max-width: 100%; max-height: 200px; border-radius: var(--radius); border: 1px solid var(--gray-200); }

/* ===== Result Box ===== */
.result-box {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 18px;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.7;
}

/* ===== Grayed Out Section ===== */
.grayed-out-section {
  background: var(--gray-100);
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 56px;
  text-align: center;
  color: var(--gray-500);
}
.grayed-out-section p { margin-bottom: 8px; font-size: 15px; }

/* ===== Record Detail ===== */
.record-detail-section { margin-bottom: 24px; }
.record-detail-section h4 {
  font-size: 15px;
  color: var(--primary-dark);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-light);
  font-weight: 600;
}
.record-detail-field { margin-bottom: 8px; }
.record-detail-field .field-label { font-size: 12px; color: var(--gray-400); text-transform: uppercase; }
.record-detail-field .field-value { font-size: 14px; color: var(--gray-700); line-height: 1.6; }

/* ===== Text Muted ===== */
.text-muted { color: var(--gray-400); font-size: 14px; }

/* ===== Session Messages ===== */
.session-msg { padding: 12px 16px; margin-bottom: 10px; border-radius: var(--radius); }
.session-msg.user { background: #F4F8F1; border-left: 3px solid var(--primary); }
.session-msg.assistant { background: #FDF6E3; border-left: 3px solid var(--accent); }
.session-role {
  font-size: 12px; font-weight: 700; color: var(--gray-500);
  margin-bottom: 6px; display: block; text-transform: uppercase; letter-spacing: .03em;
}
.session-content { font-size: 14px; color: var(--gray-800); line-height: 1.75; white-space: pre-wrap; }

/* ===== Knowledge Base Layout ===== */
.knowledge-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: start;
}
.knowledge-sidebar {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
  max-height: 60vh;
  overflow-y: auto;
}
.knowledge-sidebar h4 { font-size: 14px; color: var(--gray-600); margin-bottom: 14px; font-weight: 600; }
.knowledge-main {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
}

/* ===== Product Admin ===== */
.check-line {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--gray-600); cursor: pointer;
  padding: 8px 0;
}
.check-line input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer;
}

/* ===== Patient Search Results ===== */
.patient-result {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 12px 16px; border: none; border-bottom: 1px solid var(--gray-100);
  background: white; cursor: pointer; transition: all var(--transition);
  font-family: inherit; text-align: left; gap: 12px;
}
.patient-result:hover { background: var(--primary-50); }
.patient-result:last-child { border-bottom: none; }
.patient-result-main {
  display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0;
}
.patient-result-main strong { font-size: 14px; color: var(--gray-800); }
.patient-result-main small { font-size: 12px; color: var(--gray-500); }
.patient-result-action {
  color: var(--primary); font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.patient-search-empty {
  padding: 16px; text-align: center; color: var(--gray-400); font-size: 13px;
}
.patient-search-results {
  position: absolute; top: 100%; left: 0; right: 0;
  background: white; border: 1.5px solid var(--gray-300); border-radius: var(--radius);
  box-shadow: var(--shadow-md); z-index: 10; max-height: 280px; overflow-y: auto;
  margin-top: 4px;
}

/* ===== Chat Layout (Education) ===== */
.chat-layout {
  display: flex;
  height: calc(100vh - 56px - 56px - 80px);
  min-height: 500px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--gray-200);
  background: white;
}
.chat-sidebar {
  width: 260px; flex-shrink: 0;
  border-right: 1px solid var(--gray-200);
  display: flex; flex-direction: column;
  background: var(--gray-50);
}
.chat-sidebar-header { padding: 12px; border-bottom: 1px solid var(--gray-200); }
.chat-session-list { flex: 1; overflow-y: auto; padding: 6px; }
.chat-session-item {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; border-radius: var(--radius);
  cursor: pointer; transition: all var(--transition);
  border: none; background: none; width: 100%;
  text-align: left; font-family: inherit; font-size: 13px;
  color: var(--gray-700); line-height: 1.3;
}
.chat-session-item:hover { background: var(--gray-100); }
.chat-session-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.chat-session-item-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-session-item-date { font-size: 10px; color: var(--gray-400); flex-shrink: 0; }
.chat-session-item-btn {
  opacity: 0; transition: opacity var(--transition);
  border: none; background: none; cursor: pointer;
  font-size: 13px; padding: 2px 4px; border-radius: 3px;
  color: var(--gray-400); flex-shrink: 0;
}
.chat-session-item:hover .chat-session-item-btn { opacity: 1; }
.chat-session-item-btn:hover { color: var(--red); background: #fef2f2; }

/* Main chat area */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; padding: 40px; text-align: center;
}
.chat-empty-icon { font-size: 44px; opacity: .5; }
.chat-empty h3 { font-size: 17px; color: var(--gray-600); }
.chat-empty p { max-width: 420px; line-height: 1.7; font-size: 13px; }

/* Session header */
.chat-session-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0; background: white;
}
.chat-session-title-area { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-session-title-area h3 {
  font-size: 14px; font-weight: 600; color: var(--gray-800);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px;
}
.btn-icon {
  border: none; background: none; cursor: pointer; font-size: 14px;
  padding: 4px 8px; border-radius: var(--radius-sm); color: var(--gray-400);
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--gray-100); color: var(--gray-600); }
.chat-rename-input {
  font-size: 14px; font-weight: 600; font-family: inherit;
  padding: 2px 6px; border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm); outline: none; max-width: 300px;
  color: var(--gray-800); background: white;
}

/* Messages */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--gray-50);
}
.chat-bubble {
  max-width: 78%; padding: 12px 16px;
  border-radius: var(--radius-lg); font-size: 14px;
  line-height: 1.7; white-space: pre-wrap; word-break: break-word;
  animation: fadeIn .2s ease;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary); color: white;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: white; color: var(--gray-800);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 4px;
}
.chat-bubble.error {
  align-self: flex-start;
  background: #fef2f2; color: #991b1b;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 4px;
  font-size: 13px;
}
.chat-bubble .bubble-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 6px; display: block;
}
.chat-bubble.user .bubble-label { color: rgba(255,255,255,.65); }
.chat-bubble.assistant .bubble-label { color: var(--gray-400); }

/* Section headers inside assistant messages */
.chat-bubble .section-title {
  display: block; color: var(--primary-dark); font-weight: 700;
  font-size: 13px; margin: 10px 0 4px;
}
.chat-bubble .section-title:first-child { margin-top: 0; }
.chat-bubble .source-link { color: var(--primary); text-decoration: underline; font-size: 12px; word-break: break-all; }

/* Loading */
.chat-loading {
  padding: 10px 20px; display: flex; align-items: center; gap: 12px;
  flex-shrink: 0; background: var(--gray-50); border-top: 1px solid var(--gray-200);
}
.chat-loading-dots { display: flex; gap: 4px; }
.chat-loading-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary);
  animation: chatBounce 1.4s infinite ease-in-out both;
}
.chat-loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.chat-loading-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes chatBounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input */
.chat-input-area {
  flex-shrink: 0; padding: 12px 18px 16px;
  background: white; border-top: 1px solid var(--gray-200);
}
.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-row textarea {
  flex: 1; resize: none; padding: 10px 14px;
  border: 1.5px solid var(--gray-300); border-radius: var(--radius-lg);
  font-size: 14px; font-family: inherit; line-height: 1.5;
  max-height: 150px; overflow-y: auto;
  transition: all var(--transition); background: var(--gray-50);
}
.chat-input-row textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,125,70,.12); background: white;
}
.chat-input-row textarea::placeholder { color: var(--gray-400); }
.chat-send-btn {
  height: 42px; padding: 0 22px; border-radius: var(--radius-lg);
  flex-shrink: 0; font-weight: 600;
}

/* Knowledge page simplified */
.knowledge-docs-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.knowledge-docs-table th {
  text-align: left; padding: 10px 14px; border-bottom: 2px solid var(--gray-200);
  color: var(--gray-600); font-weight: 600; font-size: 12px;
}
.knowledge-docs-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700); vertical-align: middle;
}
.knowledge-docs-table tr:hover td { background: var(--gray-50); }
.knowledge-doc-name { font-weight: 600; color: var(--gray-800); }
.knowledge-doc-meta { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.knowledge-empty { padding: 40px; text-align: center; color: var(--gray-400); }

/* ===== Responsive ===== */
#view-education { display: none; }
#view-education.active { display: flex; flex-direction: column; }
#view-education .view-header { flex-shrink: 0; }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .knowledge-layout { grid-template-columns: 1fr; }
  .tongue-annotation-layout { grid-template-columns: 1fr; }
  .tongue-image-pane { position: static; }
  .chat-sidebar { width: 200px; }
}
@media (max-width: 768px) {
  #sidebar { width: 64px; }
  .side-link { justify-content: center; padding: 12px; }
  .side-link span:not(.side-icon) { display: none; }
  .side-link .badge { display: none; }
  .upload-grid { grid-template-columns: 1fr; }
  #main-content { padding: 20px; }
  .form-row { flex-direction: column; }
  .overlay-content.wide { max-width: 100%; }
  .chat-layout { flex-direction: column; height: auto; min-height: 0; }
  .chat-sidebar { width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--gray-200); }
  .chat-session-header { flex-wrap: wrap; gap: 8px; }
}

/* ===== Site Footer (ICP备案) ===== */
.site-footer {
  text-align: center;
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.site-footer .site-copyright {
  color: var(--gray-500);
  font-size: 13px;
}

.site-footer a {
  color: var(--gray-500);
  font-size: 13px;
  text-decoration: none;
  transition: color var(--transition);
}

.site-footer a:hover {
  color: var(--primary-dark);
}
