/* ============================================================
   KEN OCR - Cổng gửi hồ sơ
   Design tokens: 1 accent (teal), nền trung tính, light + dark.
   Khóa bo góc: card 12px / control 8px / badge pill.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: light;

  /* Bề mặt */
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --border: #e1e6e4;
  --border-strong: #c9d2ce;

  /* Chữ */
  --text: #1d2725;
  --muted: #5d6c67;
  --faint: #8a9792;

  /* Accent duy nhất: teal */
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --accent-soft: #e0f0ee;
  --accent-soft-border: #b5dbd5;
  --on-accent: #f5faf9;

  /* Trạng thái (semantic) */
  --ok: #1a7f43;
  --ok-soft: #ddefe2;
  --danger: #b42318;
  --danger-soft: #fbe5e2;
  --warn: #9a5b0b;
  --warn-soft: #f9eed8;

  /* Bo góc: card / control / pill */
  --r-card: 12px;
  --r-ctl: 8px;

  --shadow-1: 0 1px 2px rgba(23, 46, 41, 0.05);
  --shadow-2: 0 4px 16px rgba(23, 46, 41, 0.08);
  --shadow-3: 0 20px 50px rgba(15, 32, 28, 0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #111514;
    --surface: #191e1d;
    --surface-2: #212827;
    --border: #2b3331;
    --border-strong: #3d4744;

    --text: #e6ebe9;
    --muted: #9aa8a3;
    --faint: #6d7a76;

    --accent: #2fbdad;
    --accent-strong: #4fd3c4;
    --accent-soft: rgba(47, 189, 173, 0.14);
    --accent-soft-border: rgba(47, 189, 173, 0.35);
    --on-accent: #07211d;

    --ok: #4cc472;
    --ok-soft: rgba(76, 196, 114, 0.15);
    --danger: #f0705f;
    --danger-soft: rgba(240, 112, 95, 0.14);
    --warn: #e3a94c;
    --warn-soft: rgba(227, 169, 76, 0.14);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-3: 0 20px 50px rgba(0, 0, 0, 0.55);
  }
}

html { height: 100%; }

body {
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 36px 20px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft-border); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-ctl);
}

/* ---------- Layout 2 cột ---------- */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  gap: 28px;
  align-items: flex-start;
}
.main-col { flex: 1; min-width: 0; }

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}
.logo {
  font-size: 26px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--r-card);
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.subtitle {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 3px;
  max-width: 52ch;
}

/* ---------- Dropzone ---------- */
.dropzone {
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-card);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: border-color 0.18s ease, background-color 0.18s ease;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
}
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-icon {
  font-size: 24px;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: 999px;
}
.dropzone-title {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.dropzone-title .link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.dropzone-hint {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 6px;
}
.dropzone-hint b { color: var(--text); font-weight: 600; }
.dropzone-hint + .dropzone-hint { margin-top: 2px; }

/* ---------- Sections ---------- */
.section { margin-top: 28px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}
.section-head h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--r-ctl);
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.1s ease, opacity 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 15px; line-height: 1; }

/* ---------- File list (chờ upload) ---------- */
.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.file-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-1);
}
.file-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--r-ctl);
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.file-thumb.icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.file-remove {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 15px;
  cursor: pointer;
  padding: 7px;
  border-radius: var(--r-ctl);
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.file-remove:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Progress ---------- */
.progress {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  margin-top: 10px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 330px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 18px;
  position: sticky;
  top: 28px;
  max-height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-1);
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sidebar-head h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  margin-right: -6px;
  padding-right: 6px;
}
.group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 12px 0 8px;
}
.doc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-item {
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  padding: 11px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.doc-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}

/* Thumbnail bấm được để xem file gốc */
.doc-thumb-wrap {
  flex-shrink: 0;
  cursor: zoom-in;
  border-radius: var(--r-ctl);
}
.doc-thumb {
  width: 46px;
  height: 46px;
  border-radius: var(--r-ctl);
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: block;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.doc-thumb.icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
}
.doc-thumb-wrap:hover .doc-thumb {
  border-color: var(--accent);
  transform: scale(1.04);
}

.doc-info { flex: 1; min-width: 0; }
.doc-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.doc-meta2 {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Nút xem nội dung */
.doc-actions { margin-top: 8px; }
.btn-view {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--r-ctl);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.btn-view:hover { background: var(--accent-soft-border); }
.btn-view:active { transform: scale(0.98); }
.btn-view-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.btn-view-error:hover { background: var(--danger-soft); filter: brightness(0.96); }
.doc-waiting { font-size: 11px; color: var(--warn); }

/* Cột phải: badge + xoá */
.doc-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }

.doc-delete {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 13px;
  cursor: pointer;
  padding: 5px;
  border-radius: var(--r-ctl);
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.doc-delete:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 18, 16, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 700px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-3);
  animation: modal-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.preview-modal { max-width: 860px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--faint);
  cursor: pointer;
  padding: 7px 11px;
  border-radius: var(--r-ctl);
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-meta {
  padding: 10px 20px 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.modal-body {
  flex: 1;
  overflow: auto;
  margin: 12px 20px;
  min-height: 120px;
  font-size: 13px;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.modal-body.error-text {
  color: var(--danger);
  white-space: pre-wrap;
  padding: 16px;
  background: var(--danger-soft);
  border-radius: var(--r-card);
}
.modal-foot {
  display: flex;
  gap: 10px;
  padding: 0 20px 18px;
}

/* ---------- Thẻ phân tích AI ---------- */
.ai-card {
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--r-card);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.ai-card.ai-error {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}
.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.ai-doctype { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.ai-score {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
}
.score-high { background: var(--ok-soft); color: var(--ok); }
.score-mid { background: var(--warn-soft); color: var(--warn); }
.score-low { background: var(--danger-soft); color: var(--danger); }

.profile-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  background: var(--surface);
  border-radius: var(--r-ctl);
  overflow: hidden;
  border: 1px solid var(--border);
}
.profile-table th,
.profile-table td {
  text-align: left;
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.profile-table tr:last-child th,
.profile-table tr:last-child td { border-bottom: none; }
.profile-table th {
  width: 122px;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
  white-space: nowrap;
}

.ai-para { margin: 8px 0 0; font-size: 13px; }
.ai-notes { margin: 6px 0 0 20px; }
.ai-notes li { margin-bottom: 3px; }

/* ---------- Highlight độ tin cậy OCR ---------- */
.ai-legend {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}
.legend-chip {
  padding: 1px 7px;
  border-radius: 4px;
  font-weight: 600;
}
.conf-mid {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 4px;
  padding: 0 3px;
  cursor: help;
}
.conf-low {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  border-radius: 4px;
  padding: 0 3px;
  cursor: help;
}
.ocr-text {
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12.5px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}
.ocr-note {
  margin-top: 12px;
  color: var(--warn);
  font-family: "Segoe UI", system-ui, sans-serif;
}

/* ---------- Bộ hồ sơ: trạng thái + xung đột + chips ---------- */
.batch-status {
  font-size: 14px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--r-ctl);
  margin-bottom: 10px;
}
.batch-ok { background: var(--ok-soft); color: var(--ok); }
.batch-conflict { background: var(--danger-soft); color: var(--danger); }

.conflict-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-ctl);
  padding: 9px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.conflict-item b { color: var(--danger); }

.chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  margin: 2px 4px 2px 0;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-missing { background: var(--danger-soft); color: var(--danger); }

/* ---------- Preview file gốc ---------- */
.preview-body {
  padding: 16px 20px 20px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.preview-img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--r-ctl);
  border: 1px solid var(--border);
}
.preview-frame {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
  background: var(--surface-2);
}
.preview-note {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 2.2;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: var(--r-card);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-3);
  z-index: 200;
  max-width: 90vw;
  animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.toast.success { background: var(--ok); color: #f4faf5; }
.toast.error { background: var(--danger); color: #fdf3f2; }

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 14px 10px;
  line-height: 1.7;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--r-card);
}
.hidden { display: none !important; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body { padding: 20px 14px; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }
  .file-thumb { width: 42px; height: 42px; }
  .section-head { flex-direction: column; align-items: flex-start; }
}
