/* ── Design tokens ──────────────────────────────────────────────── */
:root {
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --surface-2:    #f4f4f5;
  --border:       #e4e4e7;
  --border-light: #f0f0f2;
  --text:         #09090b;
  --text-2:       #52525b;
  --text-3:       #a1a1aa;
  --sidebar-bg:   #18181b;
  --sidebar-text: #a1a1aa;
  --sidebar-active-bg: rgba(255,255,255,0.1);
  --sidebar-active-text: #ffffff;
  --color-blue:   #3b82f6;
  --color-blue-bg:#eff6ff;
  --color-green:  #22c55e;
  --color-green-bg:#f0fdf4;
  --color-amber:  #f59e0b;
  --color-amber-bg:#fffbeb;
  --color-red:    #ef4444;
  --color-red-bg: #fef2f2;
  --color-purple: #a855f7;
  --color-purple-bg:#faf5ff;
  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    14px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:       0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg:    0 12px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
  --sidebar-w:    220px;
  --header-h:     56px;
  --transition:   150ms ease;
}
/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  font-size: 14px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }
mark { background: #fef08a; border-radius: 2px; padding: 0 1px; color: inherit; }

/* ── Layout ─────────────────────────────────────────────────────── */
#app { position: relative; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0;
  z-index: 100;
  transition: width var(--transition);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
}
.brand-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--color-blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.brand-name  { font-size: 14px; font-weight: 600; color: #fff; line-height: 1.2; }
.brand-sub   { font-size: 11px; color: var(--sidebar-text); margin-top: 1px; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  user-select: none;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: #e4e4e7; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.nav-badge {
  margin-left: auto;
  background: var(--color-red);
  color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 5px; border-radius: 10px;
  min-width: 18px; text-align: center;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.user-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
}
.user-row:hover { background: rgba(255,255,255,0.07); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--color-blue);
  color: #fff; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.user-avatar.md { width: 36px; height: 36px; font-size: 14px; }
.user-name-text  { font-size: 13px; font-weight: 500; color: #e4e4e7; line-height: 1.2; }
.user-role-text  { font-size: 11px; color: var(--sidebar-text); }

/* ── Main content ───────────────────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.top-bar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
.top-bar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.top-bar-spacer { flex: 1; }
.page-content { padding: 24px; flex: 1; }

/* ── Login page ─────────────────────────────────────────────────── */
#login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f0f9ff 0%, #e8f4fd 50%, #f5f0ff 100%);
}
.login-card {
  width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px;
}
.login-logo-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--color-blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
}
.login-logo-name  { font-size: 18px; font-weight: 700; }
.login-logo-sub   { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.login-title      { font-size: 16px; font-weight: 600; margin-bottom: 20px; }
.login-footer     { margin-top: 20px; text-align: center; font-size: 12px; color: var(--text-3); }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm); border: none;
  font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  white-space: nowrap; flex-shrink: 0;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-sm  { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-lg  { height: 40px; padding: 0 20px; font-size: 14.5px; }
.btn-full { width: 100%; }
.btn-primary   { background: var(--text);       color: #fff; }
.btn-primary:hover  { background: #27272a; }
.btn-secondary { background: var(--surface-2);  color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #ebebed; }
.btn-blue      { background: var(--color-blue); color: #fff; }
.btn-blue:hover { background: #2563eb; }
.btn-danger    { background: var(--color-red);  color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost     { background: transparent;        color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }

/* ── Form elements ──────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 13px; font-weight: 500;
  margin-bottom: 6px; color: var(--text-2);
}
.form-input, .form-select, .form-textarea {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}
.form-textarea { height: auto; padding: 8px 12px; resize: vertical; min-height: 80px; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; cursor: pointer; }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.input-with-icon { position: relative; }
.input-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 16px; height: 16px; }
.input-with-icon .form-input { padding-left: 34px; }
.form-hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ── Tags input ─────────────────────────────────────────────────── */
.tags-wrap {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  min-height: 36px; background: var(--surface);
  cursor: text;
}
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); color: var(--text-2);
  border-radius: 4px; padding: 2px 8px;
  font-size: 12px;
}
.tag-chip button { background: none; border: none; cursor: pointer; color: var(--text-3); padding: 0; display: flex; }
.tags-wrap input { border: none; outline: none; background: none; font-size: 13px; flex: 1; min-width: 80px; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-hover { transition: box-shadow var(--transition), transform var(--transition); }
.card-hover:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-pad { padding: 20px; }

/* ── Badges / status ────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500;
}
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.badge-blue   { background: var(--color-blue-bg);   color: #1d4ed8; }
.badge-green  { background: var(--color-green-bg);  color: #15803d; }
.badge-amber  { background: var(--color-amber-bg);  color: #b45309; }
.badge-red    { background: var(--color-red-bg);    color: #b91c1c; }
.badge-gray   { background: var(--surface-2);       color: var(--text-2); }
.badge-purple { background: var(--color-purple-bg); color: #7e22ce; }
.source-badge { font-size: 11px; font-weight: 600; padding: 2px 7px; letter-spacing: 0.02em; }

/* ── Divider ────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 0; }
.section-label {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 12px; margin-top: 4px;
}

/* ── Tables ─────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 14px;
  font-size: 12px; font-weight: 600; color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table .actions { display: flex; gap: 6px; }

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tab-item {
  padding: 10px 16px;
  font-size: 13.5px; font-weight: 500;
  color: var(--text-3); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
  user-select: none;
}
.tab-item:hover { color: var(--text-2); }
.tab-item.active { color: var(--text); border-bottom-color: var(--text); }
.tab-content { display: none; padding-top: 20px; }
.tab-content.active { display: block; }

/* ── Progress bar ───────────────────────────────────────────────── */
.progress-bar {
  height: 4px; border-radius: 4px;
  background: var(--surface-2); overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 4px;
  background: var(--color-blue);
}

/* ── Utility ────────────────────────────────────────────────────── */
.hidden     { display: none !important; }
.flex       { display: flex; }
.flex-col   { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: 8px;  }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-sm  { font-size: 12.5px; }
.text-xs  { font-size: 11.5px; }
.text-muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }

/* ── Toast ──────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999; pointer-events: none;
}
.toast {
  pointer-events: all;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 280px; max-width: 380px;
}
.toast-icon svg { width: 16px; height: 16px; }
.toast-icon.success { color: var(--color-green); }
.toast-icon.error   { color: var(--color-red); }
.toast-icon.info    { color: var(--color-blue); }
.toast-title   { font-size: 13.5px; font-weight: 500; color: var(--text); }
.toast-message { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 480px; max-width: calc(100vw - 40px);
  max-height: 85vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-3); padding: 4px; border-radius: 4px; display: flex; }
.modal-close:hover { background: var(--surface-2); }
.modal-body   { padding: 20px 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ════════════════════════════════════════════════════════════════
   Page: Home
   ════════════════════════════════════════════════════════════════ */
.home-hero {
  text-align: center;
  padding: 40px 20px 32px;
}
.home-hero h1  { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.home-hero p   { color: var(--text-2); margin-bottom: 24px; }
.search-bar-wrap {
  max-width: 580px; margin: 0 auto;
  display: flex; gap: 0;
}
.search-bar {
  flex: 1; height: 46px; padding: 0 16px 0 44px;
  border: 1.5px solid var(--border);
  border-right: none;
  border-radius: 10px 0 0 10px;
  font-size: 14.5px; outline: none;
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar:focus { border-color: var(--color-blue); box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
.search-bar-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.search-bar-container { position: relative; flex: 1; }
.search-bar-btn {
  height: 46px; padding: 0 22px;
  background: var(--text); color: #fff;
  border: none; border-radius: 0 10px 10px 0;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background var(--transition);
}
.search-bar-btn:hover { background: #27272a; }

.stats-row {
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  margin-top: 20px;
}
.stat-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px; color: var(--text-2);
}
.stat-chip span { font-weight: 600; color: var(--text); }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-title { font-size: 14px; font-weight: 600; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center; cursor: pointer;
  transition: all var(--transition);
}
.category-card:hover { border-color: var(--color-blue); box-shadow: 0 0 0 3px rgba(59,130,246,0.08); }
.category-card .count { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.category-card .name  { font-size: 13px; font-weight: 500; margin-top: 4px; }

.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.recent-item:hover { border-color: #d4d4d8; box-shadow: var(--shadow-sm); }
.file-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.file-icon.pdf    { background: #fef2f2; color: #dc2626; }
.file-icon.docx   { background: #eff6ff; color: #2563eb; }
.file-icon.gmail  { background: #fff7ed; color: #c2410c; }
.file-icon.imap   { background: #f0fdf4; color: #16a34a; }
.file-icon.img    { background: #faf5ff; color: #7e22ce; }
.recent-item-info { flex: 1; min-width: 0; }
.recent-item-title { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item-meta  { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.recent-item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }

/* ════════════════════════════════════════════════════════════════
   Page: Search results
   ════════════════════════════════════════════════════════════════ */
.search-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky; top: calc(var(--header-h) + 20px);
}
.filter-section { margin-bottom: 16px; }
.filter-section:last-child { margin-bottom: 0; }
.filter-label { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.filter-checkbox {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 0; cursor: pointer; font-size: 13px; color: var(--text-2);
}
.filter-checkbox input { accent-color: var(--color-blue); cursor: pointer; }

.results-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.results-count { font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.results-count strong { color: var(--text); }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all var(--transition);
}
.result-card:hover { border-color: #d4d4d8; box-shadow: var(--shadow); }
.result-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.result-title { font-size: 14.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.result-snippet { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 10px; }
.result-footer { display: flex; align-items: center; justify-content: space-between; }
.result-meta { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 10px; }

/* ════════════════════════════════════════════════════════════════
   Page: Document detail
   ════════════════════════════════════════════════════════════════ */
.doc-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
.doc-status-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.status-step {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text-2);
}
.status-step svg { width: 14px; height: 14px; }
.status-step.done   { color: var(--color-green); }
.status-step.failed { color: var(--color-red); }
.status-step.pending{ color: var(--text-3); }

.doc-text {
  font-size: 13.5px; line-height: 1.75;
  color: var(--text); white-space: pre-wrap;
  background: var(--bg);
  border-radius: var(--radius-sm); padding: 16px;
  border: 1px solid var(--border-light);
  min-height: 300px;
}
.doc-text h1, .doc-text h2, .doc-text h3 { margin-bottom: 6px; margin-top: 12px; }
.doc-text strong { font-weight: 600; }
.doc-text table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.doc-text th, .doc-text td { border: 1px solid var(--border); padding: 6px 10px; }
.doc-text th { background: var(--surface-2); }
.doc-text blockquote { border-left: 3px solid var(--color-blue); padding-left: 12px; color: var(--text-2); }

.meta-panel {}
.meta-row { padding: 10px 0; border-bottom: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 4px; }
.meta-row:last-child { border-bottom: none; }
.meta-label { font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.meta-value { font-size: 13px; color: var(--text); }
.meta-actions { display: flex; gap: 8px; padding-top: 14px; }

/* ════════════════════════════════════════════════════════════════
   Page: Upload
   ════════════════════════════════════════════════════════════════ */
.upload-layout {
  display: grid; grid-template-columns: 1fr 280px; gap: 20px;
}
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--color-blue);
  background: var(--color-blue-bg);
}
.drop-icon { margin-bottom: 14px; color: var(--text-3); }
.drop-zone h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.drop-zone p  { font-size: 13px; color: var(--text-2); }
.drop-zone .link-text { color: var(--color-blue); cursor: pointer; }
.drop-zone .hint { font-size: 12px; color: var(--text-3); margin-top: 8px; }

.file-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.file-row-info { flex: 1; min-width: 0; }
.file-row-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-row-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.file-row-status { flex-shrink: 0; display: flex; align-items: center; gap: 8px; }

/* ════════════════════════════════════════════════════════════════
   Page: Mail
   ════════════════════════════════════════════════════════════════ */
.mail-section { margin-bottom: 28px; }
.mail-section-title {
  font-size: 13.5px; font-weight: 600;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 14px;
}
.account-card.error { border-color: #fca5a5; background: #fff8f8; }
.account-type-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.account-type-icon.gmail { background: #fff7ed; color: #c2410c; }
.account-type-icon.imap  { background: #f0fdf4; color: #16a34a; }
.account-info { flex: 1; min-width: 0; }
.account-email { font-size: 13.5px; font-weight: 500; }
.account-meta  { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.account-error { font-size: 12px; color: var(--color-red); margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.account-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ════════════════════════════════════════════════════════════════
   Page: Jobs
   ════════════════════════════════════════════════════════════════ */
.job-stats-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.job-stat-card {
  flex: 1; min-width: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.job-stat-num  { font-size: 24px; font-weight: 700; line-height: 1.2; }
.job-stat-label { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.job-stat-blue   .job-stat-num { color: var(--color-blue); }
.job-stat-green  .job-stat-num { color: var(--color-green); }
.job-stat-red    .job-stat-num { color: var(--color-red); }
.job-stat-gray   .job-stat-num { color: var(--text-2); }

.status-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
}
.status-running { background: var(--color-blue-bg);  color: #1d4ed8; }
.status-done    { background: var(--color-green-bg); color: #15803d; }
.status-failed  { background: var(--color-red-bg);   color: #b91c1c; }
.status-pending { background: var(--surface-2);      color: var(--text-2); }

.backup-section { margin-top: 28px; }
.backup-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}

/* ════════════════════════════════════════════════════════════════
   Page: Settings
   ════════════════════════════════════════════════════════════════ */
.settings-layout {
  display: grid; grid-template-columns: 190px 1fr; gap: 20px;
}
.settings-sidenav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  position: sticky; top: calc(var(--header-h) + 20px);
}
.settings-nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.settings-nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 500; }
.settings-nav-item:hover:not(.active) { background: var(--bg); }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.settings-section { margin-bottom: 28px; }
.settings-section-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

.member-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.member-row:last-child { border-bottom: none; }
.member-info { flex: 1; }
.member-name  { font-size: 13.5px; font-weight: 500; }
.member-email { font-size: 12px; color: var(--text-3); margin-top: 1px; }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-info .toggle-label { font-size: 13.5px; font-weight: 500; }
.toggle-info .toggle-desc  { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.toggle-switch {
  width: 38px; height: 22px;
  background: var(--border);
  border-radius: 11px; cursor: pointer;
  position: relative; transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch.on { background: var(--color-blue); }
.toggle-switch::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  top: 3px; left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch.on::after { transform: translateX(16px); }

/* ════════════════════════════════════════════════════════════════
   Responsive – Mobile ( ≤ 768px )
   ════════════════════════════════════════════════════════════════ */

/* Mobile top bar: hamburger + logo */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--sidebar-bg);
  z-index: 200;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.hamburger-btn {
  background: none; border: none;
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; color: #fff;
  cursor: pointer; border-radius: 8px;
  transition: background var(--transition);
  flex-shrink: 0;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.1); }
.hamburger-btn svg { width: 20px; height: 20px; }
.mobile-header-brand {
  display: flex; align-items: center; gap: 8px; flex: 1;
}
.mobile-header-brand .brand-icon { width: 28px; height: 28px; font-size: 11px; }
.mobile-header-brand .brand-name { font-size: 14px; font-weight: 600; color: #fff; }
.mobile-header-right {
  display: flex; align-items: center; gap: 8px;
}
.mobile-header-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: rgba(255,255,255,0.5);
}
.mobile-header-status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-green);
}

/* Sidebar drawer overlay */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.visible {
  display: block;
}
.sidebar-overlay.open {
  opacity: 1;
}

/* Bottom navigation bar (mobile) */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 58px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 200;
  align-items: center;
  justify-content: space-around;
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; padding: 6px 0;
  cursor: pointer; color: var(--text-3);
  transition: color var(--transition);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item svg { width: 20px; height: 20px; }
.bottom-nav-item span { font-size: 10px; font-weight: 500; }
.bottom-nav-item.active { color: var(--color-blue); }
.bottom-nav-item .bottom-badge {
  position: absolute; top: 4px; right: calc(50% - 14px);
  background: var(--color-red); color: #fff;
  font-size: 9px; font-weight: 700;
  width: 14px; height: 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

@media (max-width: 768px) {
  /* Show mobile header, hide desktop top-bar  */
  .mobile-header   { display: flex; }
  .top-bar         { display: none; }

  /* Show bottom nav */
  .bottom-nav      { display: flex; }

  /* Sidebar becomes off-canvas drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 160;
    width: 260px;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Main content fills full width, push down under mobile header */
  .main-wrap {
    margin-left: 0;
    padding-top: var(--header-h);
    padding-bottom: 68px; /* space for bottom nav */
  }

  /* Page content smaller padding */
  .page-content { padding: 16px; }

  /* Login page */
  .login-card {
    width: calc(100vw - 32px);
    padding: 28px 20px;
    border-radius: var(--radius);
  }

  /* Home page: search bar */
  .search-bar-wrap { max-width: 100%; }
  .home-hero { padding: 24px 0 20px; }
  .home-hero h1 { font-size: 20px; }

  /* Category grid: fewer columns on mobile */
  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
  }

  /* Search layout: single column */
  .search-layout {
    grid-template-columns: 1fr;
  }
  .filter-panel {
    position: static;
  }

  /* Document layout: single column */
  .doc-layout {
    grid-template-columns: 1fr;
  }

  /* Upload layout: single column */
  .upload-layout {
    grid-template-columns: 1fr;
  }

  /* Settings layout: single column */
  .settings-layout {
    grid-template-columns: 1fr;
  }
  .settings-sidenav {
    position: static;
    display: flex; gap: 4px; flex-wrap: wrap;
    padding: 8px;
  }
  .settings-nav-item { padding: 7px 10px; font-size: 12.5px; }

  /* Tables: horizontal scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 560px; }

  /* Job stats: 2-col grid on mobile */
  .job-stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Account cards: stack actions */
  .account-card { flex-wrap: wrap; gap: 10px; }
  .account-actions { width: 100%; justify-content: flex-end; }

  /* Toasts: full width at bottom */
  #toast-container {
    bottom: 70px; right: 12px; left: 12px;
  }
  .toast { min-width: unset; max-width: 100%; width: 100%; }

  /* Modal: full-screen on mobile */
  .modal-box {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    position: fixed; bottom: 0; left: 0; right: 0;
    max-height: 90vh;
  }
  .modal-overlay {
    align-items: flex-end;
  }

  /* Result cards: compact */
  .result-footer { flex-wrap: wrap; gap: 6px; }

  /* Doc status row */
  .doc-status-row { gap: 6px; }
  .status-step span { display: none; } /* hide text, show icon only */

  /* Recent items */
  .recent-item-right .btn { display: none; } /* hide view btn on list */
}

@media (max-width: 400px) {
  .home-hero h1 { font-size: 18px; }
  .search-bar { font-size: 13.5px; }
  .category-grid { grid-template-columns: repeat(3, 1fr); }
  .stats-row { gap: 8px; }
  .stat-chip { padding: 5px 10px; font-size: 12px; }
}
