/*
 * Doc Timeline AI — design system (Sprint 9).
 * Tokens sampled from FromBasic's real logo.png, not guessed — see
 * docs/sprints/SPRINT-09.md for the full rationale.
 */

:root {
  --color-accent: #0060a8;
  --color-accent-hover: #004d87;
  --color-ink: #384048;
  --color-ink-soft: #5b6570;
  --color-cyan: #00a0c8;

  --color-bg: #f7f9fb;
  --color-bg-alt: #eef2f6;
  --color-card-bg: #ffffff;
  --color-border: #dbe3ea;

  --color-confirmed: #1e8f4e;
  --color-confirmed-bg: #e3f6ea;
  --color-suggested: #a3690a;
  --color-suggested-bg: #fdecd2;
  --color-error: #c0392b;
  --color-error-bg: #fbe4e0;
  --color-processing: #00879f;
  --color-processing-bg: #e0f6fb;

  --shadow-card: 0 1px 3px rgba(56, 64, 72, 0.08), 0 1px 2px rgba(56, 64, 72, 0.06);
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-accent: #4da3d9;
    --color-accent-hover: #6fb6e3;
    --color-ink: #e8edf1;
    --color-ink-soft: #aab4bd;
    --color-cyan: #33c1e0;

    --color-bg: #1b2126;
    --color-bg-alt: #232b31;
    --color-card-bg: #262f36;
    --color-border: #3a444c;

    --color-confirmed: #4fbf7f;
    --color-confirmed-bg: #17301f;
    --color-suggested: #e0a94a;
    --color-suggested-bg: #3a2d15;
    --color-error: #e2685a;
    --color-error-bg: #3a1e1a;
    --color-processing: #33c1e0;
    --color-processing-bg: #123138;

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-weight: 700;
  color: var(--color-ink);
  line-height: 1.25;
}

h1 { font-size: 1.75rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

em {
  color: var(--color-ink-soft);
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* ── Layout ─────────────────────────────────────────────────────── */

.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.container-narrow {
  max-width: 420px;
  margin: 0 auto;
  padding: 2.5rem 1rem;
}

/* ── Topbar ─────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  background: var(--color-card-bg);
  border-bottom: 1px solid var(--color-border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-ink);
  font-weight: 700;
  font-size: 1.05rem;
}
.topbar-brand:hover {
  text-decoration: none;
}
.topbar-brand strong {
  color: var(--color-accent);
}
.topbar-logo {
  height: 28px;
  width: auto;
}

.topbar-tagline {
  margin: 0;
  color: var(--color-ink-soft);
  font-size: 0.85rem;
  flex: 1;
}

.topbar-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  margin-left: auto;
}
.topbar-user {
  color: var(--color-ink-soft);
}

@media (max-width: 900px) {
  .topbar-tagline {
    display: none;
  }
}

/* ── Buttons ────────────────────────────────────────────────────── */

.btn, button, input[type="submit"] {
  display: inline-block;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: 1px solid var(--color-accent);
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.btn:hover, button:hover, input[type="submit"]:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.btn-secondary, button.btn-secondary {
  background: transparent;
  color: var(--color-ink);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-bg-alt);
  color: var(--color-ink);
}

.btn-danger, button.btn-danger {
  background: transparent;
  color: var(--color-error);
  border-color: var(--color-error);
}
.btn-danger:hover {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.btn-link, button.btn-link {
  background: none;
  border: none;
  color: var(--color-error);
  padding: 0.2rem 0.4rem;
  font-weight: 600;
}
.btn-link:hover {
  background: var(--color-error-bg);
}

/* ── Forms ──────────────────────────────────────────────────────── */

.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-ink-soft);
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="file"],
textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--color-ink);
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 20%, transparent);
}

.error-text {
  color: var(--color-error);
  background: var(--color-error-bg);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
}
.success-text {
  color: var(--color-confirmed);
  background: var(--color-confirmed-bg);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
}

/* ── Cards ──────────────────────────────────────────────────────── */

.card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
}

.auth-card {
  text-align: center;
}
.auth-card .brand-block {
  margin-bottom: 1.5rem;
}
.auth-card .brand-logo {
  height: 40px;
  margin-bottom: 0.5rem;
}
.auth-card .brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}
.auth-card .brand-title strong {
  color: var(--color-accent);
}
.auth-card .brand-tagline {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--color-ink-soft);
}
.auth-card h1 {
  font-size: 1.15rem;
  text-align: left;
}
.auth-card form {
  text-align: left;
}
.auth-card .divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--color-ink-soft);
  font-size: 0.85rem;
  margin: 1rem 0;
}
.auth-card .divider::before,
.auth-card .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}
.auth-card .auth-footer {
  margin-top: 1rem;
  font-size: 0.9rem;
}

/* ── Case list ──────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.page-header .subtitle {
  color: var(--color-ink-soft);
  font-size: 0.9rem;
  margin: 0.15rem 0 0;
}

.case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.case-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.case-card h2 {
  margin: 0;
  font-size: 1.05rem;
}
.case-card .case-note {
  color: var(--color-ink-soft);
  font-size: 0.9rem;
  font-style: italic;
}
.case-card .case-meta {
  display: flex;
  justify-content: space-between;
  color: var(--color-ink-soft);
  font-size: 0.82rem;
  margin-top: auto;
  padding-top: 0.5rem;
}
.case-card .case-doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-ink-soft);
}
.case-card form {
  margin-top: 0.25rem;
}

/* ── Badges (status chips) ─────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-confirmed { color: var(--color-confirmed); background: var(--color-confirmed-bg); }
.badge-suggested { color: var(--color-suggested); background: var(--color-suggested-bg); }
.badge-error     { color: var(--color-error); background: var(--color-error-bg); }
.badge-processing{ color: var(--color-processing); background: var(--color-processing-bg); }
.badge-violation { color: #fff; background: var(--color-error); }

/* ── Processing status banner ──────────────────────────────────── */

.processing-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--color-processing-bg);
  border: 1px solid var(--color-processing);
  color: var(--color-ink);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.processing-banner small {
  display: block;
  color: var(--color-ink-soft);
  margin-top: 0.25rem;
}

@keyframes dtai-spin { to { transform: rotate(360deg); } }
.dtai-spinner {
  display: inline-block;
  flex-shrink: 0;
  width: 1.1em;
  height: 1.1em;
  margin-top: 0.15em;
  border: 2px solid var(--color-processing-bg);
  border-top-color: var(--color-processing);
  border-radius: 50%;
  animation: dtai-spin 0.8s linear infinite;
}

/* ── Timeline ───────────────────────────────────────────────────── */

.timeline-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  margin-bottom: 0.75rem;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: var(--color-border);
}

.timeline-item {
  position: relative;
  padding-left: 2rem;
  margin-bottom: 1rem;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-card-bg);
  border: 2px solid var(--color-accent);
}
.timeline-item.is-unprocessed::before {
  border-color: var(--color-border);
}
.timeline-item.is-failed::before {
  border-color: var(--color-error);
}
.timeline-item.is-violation::before {
  border-color: var(--color-error);
  background: var(--color-error);
}

.timeline-item-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.1rem;
}
.timeline-item[draggable="true"] .timeline-item-card {
  cursor: move;
}
.timeline-item[draggable="true"] .drag-handle {
  cursor: move;
  color: var(--color-ink-soft);
}

.timeline-item-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.timeline-item-date {
  color: var(--color-ink-soft);
  font-size: 0.85rem;
}
.timeline-item-name {
  font-weight: 600;
  flex: 1;
}

.timeline-summary {
  background: var(--color-bg-alt);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  margin-top: 0.6rem;
  font-size: 0.92rem;
}
.timeline-summary textarea {
  background: transparent;
  border: none;
  padding: 0;
  resize: vertical;
  width: 100%;
}
.timeline-summary textarea:focus {
  box-shadow: none;
  outline: 1px dashed var(--color-border);
}
.timeline-hint {
  font-size: 0.78rem;
  color: var(--color-ink-soft);
  margin-top: 0.3rem;
}

/* ── Relationships & key-notes lists ────────────────────────────── */

.rel-list, .notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.rel-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.rel-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}
.rel-card-names {
  font-weight: 600;
}
.rel-card-desc {
  color: var(--color-ink-soft);
  font-size: 0.92rem;
}

.notes-list li {
  background: var(--color-suggested-bg);
  color: var(--color-ink);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
}

/* ── Dashboard ──────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.1rem 1.25rem;
}
.stat-card .stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  margin-bottom: 0.4rem;
}
.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--color-ink);
}
.stat-card .stat-sub {
  font-size: 0.82rem;
  color: var(--color-ink-soft);
  margin-top: 0.2rem;
}

.filter-form {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.filter-form .field {
  margin-bottom: 0;
}
.filter-form input, .filter-form select {
  width: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.88rem;
}
.data-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-ink-soft);
  background: var(--color-bg-alt);
}
.data-table tr:last-child td {
  border-bottom: none;
}
.data-table .num {
  text-align: right;
}
.table-scroll {
  overflow-x: auto;
}

/* ── Announcement banner (FR-15, all users) ───────────────────────── */

.announcement-banner {
  background: var(--color-suggested-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-suggested);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

/* ── Sidebar shell (Sprint 7 admin panel; also used by the user-facing
   account settings pages — same visual language, different nav items) ── */

.sidebar-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar-panel {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-card-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.5rem;
}
.sidebar-brand {
  padding: 0 0.25rem;
}
/* The FromBasic wordmark logo is a wide horizontal lockup (~4.8:1) — at the
   topbar's usual 28px height it alone eats ~135px, leaving too little of the
   240px sidebar for a label like "Tài khoản" to fit on one line. */
.sidebar-brand .topbar-logo {
  height: 22px;
}
.sidebar-brand span {
  font-size: 0.95rem;
  white-space: nowrap;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.sidebar-nav a {
  color: var(--color-ink);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
}
.sidebar-nav a:hover {
  background: var(--color-bg-alt);
  text-decoration: none;
}
.sidebar-nav a.is-active {
  background: var(--color-accent);
  color: #fff;
}

.sidebar-footer {
  /* A fixed gap, not margin-top:auto — pinning this to the very bottom of a
     min-height:100vh column left a jarring empty void under a short nav
     list (the account settings sidebar has only 3 items, vs. admin's 7). */
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.sidebar-content {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem 3rem;
}

.badge-cancelled { color: var(--color-ink-soft); background: var(--color-bg-alt); }

.alert-banner {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  color: var(--color-error);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

/* 1024px, not the usual 900px tablet breakpoint — a resized/narrow desktop
   window (not just phones) should also get the compact horizontal nav
   instead of a full-height 220px sidebar dominating the view. */
@media (max-width: 1024px) {
  .sidebar-shell {
    flex-direction: column;
  }
  .sidebar-panel {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    flex-direction: row;
    border-top: none;
    padding-top: 0;
  }
  .sidebar-content {
    padding: 1.25rem 1rem 2rem;
  }
}

/* ── Misc ───────────────────────────────────────────────────────── */

.muted {
  color: var(--color-ink-soft);
}

hr.sep {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1.5rem 0;
}

/* ── Intro popup (one-time, App\Controllers\OnboardingController::acknowledgeIntro) ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal-card {
  background: var(--color-card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.75rem;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-card h2 {
  margin-top: 0;
}

.modal-card ul {
  padding-left: 1.25rem;
  margin: 0.5rem 0 1rem;
}

.modal-card li {
  margin-bottom: 0.4rem;
}

.modal-card form {
  text-align: right;
  margin-top: 0.5rem;
}

/* ── Admin dashboard trend charts (FR-11.4, App\Core\Chart) ──────── */

.trend-filter {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}
.trend-filter a {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  color: var(--color-ink-soft);
}
.trend-filter a:hover {
  text-decoration: none;
  background: var(--color-bg-alt);
}
.trend-filter a.is-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.trend-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.1rem 1.25rem;
  position: relative;
}
.trend-card .stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  margin-bottom: 0.1rem;
}
.trend-card .trend-total {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-ink);
  margin-bottom: 0.5rem;
}

.trend-chart-wrap {
  position: relative;
}
.trend-chart-svg {
  width: 100%;
  height: 72px;
  display: block;
  cursor: crosshair;
}

.trend-axis-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--color-ink-soft);
  margin-top: 0.3rem;
}

.trend-crosshair {
  position: absolute;
  top: 0;
  bottom: 18px;
  width: 1px;
  background: var(--color-border);
  pointer-events: none;
  display: none;
}

.trend-tooltip {
  position: absolute;
  top: -6px;
  transform: translate(-50%, -100%);
  background: var(--color-ink);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  display: none;
  z-index: 5;
}
.trend-tooltip strong {
  font-weight: 700;
}
.trend-tooltip .trend-tooltip-date {
  display: block;
  color: var(--color-ink-soft);
  font-size: 0.72rem;
  margin-top: 0.1rem;
}

@media (prefers-color-scheme: dark) {
  .trend-tooltip {
    background: var(--color-bg-alt);
    color: var(--color-ink);
    border: 1px solid var(--color-border);
  }
}

/* ── Language switcher (App\Core\View::langSwitcher) ─────────────── */

.lang-switch {
  font-size: 0.85rem;
  color: var(--color-ink-soft);
}
.lang-switch a {
  color: var(--color-ink-soft);
}
.lang-switch a:hover {
  color: var(--color-accent);
}
.lang-switch-current {
  font-weight: 700;
  color: var(--color-accent);
}

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .page {
    padding: 1rem 0.85rem 2rem;
  }
  .case-grid {
    grid-template-columns: 1fr;
  }
  h1 { font-size: 1.4rem; }
}
