/* =============================================================================
   AI Sales Lead Discovery — Design System
   -----------------------------------------------------------------------------
   ไม่มี build step · ไม่มี CDN · ไม่มี framework
   ออกแบบสำหรับ Sales ที่เปิดจากมือถือเป็นหลัก (ข้อ 32)
   รองรับ light/dark ตาม prefers-color-scheme
   ============================================================================= */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  --bg:            #f6f8fb;
  --bg-elevated:   #ffffff;
  --bg-sunken:     #eef2f7;
  --bg-inset:      #f8fafc;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;

  --text:          #0f172a;
  --text-muted:    #52637a;
  --text-subtle:   #7d8da3;
  --text-inverse:  #ffffff;

  --brand:         #0f172a;
  --brand-accent:  #0369a1;
  --brand-soft:    #e0f2fe;

  --blue:   #0369a1;  --blue-soft:   #e0f2fe;
  --green:  #15803d;  --green-soft:  #dcfce7;
  --amber:  #b45309;  --amber-soft:  #fef3c7;
  --red:    #b91c1c;  --red-soft:    #fee2e2;
  --violet: #6d28d9;  --violet-soft: #ede9fe;
  --indigo: #4338ca;  --indigo-soft: #e0e7ff;
  --teal:   #0f766e;  --teal-soft:   #ccfbf1;
  --slate:  #475569;  --slate-soft:  #f1f5f9;

  --radius:    10px;
  --radius-lg: 14px;
  --radius-sm: 6px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow:    0 1px 3px rgba(15, 23, 42, .08), 0 6px 16px -8px rgba(15, 23, 42, .12);
  --shadow-lg: 0 8px 32px -12px rgba(15, 23, 42, .22);

  --sidebar-w: 236px;
  --header-h:  56px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai",
          "IBM Plex Sans Thai", "Sarabun", Tahoma, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0b1220;
    --bg-elevated:   #131c2e;
    --bg-sunken:     #0a101c;
    --bg-inset:      #182338;
    --border:        #253352;
    --border-strong: #35476b;

    --text:          #e8edf5;
    --text-muted:    #a3b2c7;
    --text-subtle:   #7b8ca5;

    --brand:         #0a101c;
    --brand-accent:  #38bdf8;
    --brand-soft:    #10304a;

    --blue:   #7cc9f5;  --blue-soft:   #10304a;
    --green:  #6ee7a5;  --green-soft:  #0d3222;
    --amber:  #fcd34d;  --amber-soft:  #3a2a08;
    --red:    #fca5a5;  --red-soft:    #3d1414;
    --violet: #c4b5fd;  --violet-soft: #291a4d;
    --indigo: #a5b4fc;  --indigo-soft: #1e2450;
    --teal:   #5eead4;  --teal-soft:   #0a3730;
    --slate:  #94a3b8;  --slate-soft:  #1a2436;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 1px 3px rgba(0, 0, 0, .45), 0 8px 20px -10px rgba(0, 0, 0, .6);
    --shadow-lg: 0 12px 36px -12px rgba(0, 0, 0, .7);
  }
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }

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

img, svg { max-width: 100%; height: auto; vertical-align: middle; }

code, pre, .mono { font-family: var(--mono); font-size: .86em; }
pre {
  margin: 0; padding: .85rem 1rem; overflow-x: auto;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius); line-height: 1.6;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

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

/* ── App shell ───────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--brand); color: #cdd8e8;
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, .07);
  z-index: 40;
}

.sidebar__brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1rem 1.1rem; border-bottom: 1px solid rgba(255, 255, 255, .08);
  color: #fff; text-decoration: none;
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__logo {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px;
  background: linear-gradient(140deg, #38bdf8, #0369a1);
  display: grid; place-items: center; font-size: 15px; font-weight: 800; color: #041b2c;
}
.sidebar__name { font-size: .84rem; font-weight: 700; line-height: 1.3; }
.sidebar__tag {
  font-size: .62rem; letter-spacing: .12em; text-transform: uppercase;
  color: #7dd3fc; font-weight: 700;
}

.sidebar__nav { flex: 1; overflow-y: auto; padding: .7rem .55rem 1.2rem; }
.sidebar__section {
  padding: .9rem .6rem .35rem; font-size: .63rem; font-weight: 700;
  letter-spacing: .13em; text-transform: uppercase; color: #64748b;
}
.sidebar__link {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .65rem; margin-bottom: 1px; border-radius: 8px;
  color: #cdd8e8; font-size: .875rem; text-decoration: none;
  transition: background .12s, color .12s;
}
.sidebar__link:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.sidebar__link.is-active { background: rgba(56, 189, 248, .16); color: #fff; font-weight: 600; }
.sidebar__icon { flex: 0 0 18px; text-align: center; font-size: .95rem; opacity: .9; }
.sidebar__badge {
  margin-left: auto; min-width: 19px; padding: 0 5px; border-radius: 9px;
  background: #dc2626; color: #fff; font-size: .66rem; font-weight: 700;
  text-align: center; line-height: 19px;
}
.sidebar__footer {
  padding: .7rem .9rem; border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: .74rem; color: #7d8da3;
}

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--header-h); padding: .5rem 1.25rem;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: .98rem; font-weight: 700; margin-right: auto; }
.topbar__actions { display: flex; align-items: center; gap: .4rem; }

.menu-toggle {
  display: none; width: 36px; height: 36px; padding: 0;
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 1.1rem; cursor: pointer;
}

.content { flex: 1; padding: 1.25rem; max-width: 1500px; width: 100%; }
.content > * + * { margin-top: 1.1rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .8rem; }
.page-head__text { flex: 1 1 260px; min-width: 0; }
.page-head__sub { color: var(--text-muted); font-size: .875rem; margin-top: .2rem; }
.page-head__actions { display: flex; flex-wrap: wrap; gap: .45rem; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 35;
  }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 1rem .85rem 4.5rem; }
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  padding: .85rem 1.05rem; border-bottom: 1px solid var(--border);
}
.card__title { font-size: .95rem; font-weight: 700; margin-right: auto; }
.card__sub { font-size: .8rem; color: var(--text-muted); font-weight: 400; }
.card__body { padding: 1.05rem; }
.card__body--tight { padding: .7rem; }
.card__body--flush { padding: 0; }
.card__foot {
  padding: .7rem 1.05rem; border-top: 1px solid var(--border);
  background: var(--bg-inset); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  font-size: .84rem;
}

/* ── Grid ────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid--stat { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: .7rem; }
.grid--split { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
@media (max-width: 1080px) { .grid--split { grid-template-columns: 1fr; } }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack--sm { gap: .5rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ── Stat tiles ──────────────────────────────────────────────────────────── */
.stat {
  padding: .85rem .95rem; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); display: block; color: inherit; text-decoration: none;
}
.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat__label {
  font-size: .72rem; font-weight: 600; color: var(--text-subtle);
  letter-spacing: .04em; text-transform: uppercase;
  display: flex; align-items: center; gap: .3rem;
}
.stat__value {
  font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em;
  line-height: 1.15; margin-top: .25rem; font-variant-numeric: tabular-nums;
}
.stat__hint { font-size: .76rem; color: var(--text-muted); margin-top: .1rem; }
.stat--accent { border-left: 3px solid var(--brand-accent); }
.stat--danger { border-left: 3px solid var(--red); }
.stat--warn   { border-left: 3px solid var(--amber); }
.stat--good   { border-left: 3px solid var(--green); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-elevated); color: var(--text);
  font-family: inherit; font-size: .875rem; font-weight: 600; line-height: 1.4;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { text-decoration: none; background: var(--bg-inset); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn--primary {
  background: var(--brand-accent); border-color: var(--brand-accent); color: #fff;
}
.btn--primary:hover { background: color-mix(in srgb, var(--brand-accent) 86%, #000); }
.btn--danger { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn--danger:hover { background: var(--red); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--bg-inset); }
.btn--sm { padding: .32rem .6rem; font-size: .8rem; }
.btn--xs { padding: .2rem .45rem; font-size: .74rem; }
.btn--block { width: 100%; }
.btn--icon { padding: .4rem; width: 32px; height: 32px; }

.btn-group { display: inline-flex; flex-wrap: wrap; gap: .35rem; }

/* ── Badges & pills ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .16rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 700; line-height: 1.5; white-space: nowrap;
  background: var(--slate-soft); color: var(--slate);
}
.badge--blue { background: var(--blue-soft); color: var(--blue); }
.badge--green { background: var(--green-soft); color: var(--green); }
.badge--amber { background: var(--amber-soft); color: var(--amber); }
.badge--red { background: var(--red-soft); color: var(--red); }
.badge--violet { background: var(--violet-soft); color: var(--violet); }
.badge--indigo { background: var(--indigo-soft); color: var(--indigo); }
.badge--teal { background: var(--teal-soft); color: var(--teal); }
.badge--slate { background: var(--slate-soft); color: var(--slate); }
.badge--outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .22rem .6rem; border-radius: 999px;
  background: var(--bg-inset); border: 1px solid var(--border);
  font-size: .78rem; color: var(--text-muted);
}
.chip__key { font-weight: 700; color: var(--text-subtle); font-size: .72rem; }
.chip a { color: var(--text-subtle); font-weight: 700; }

/* ── Score badge (ข้อ 8) ─────────────────────────────────────────────────── */
.score {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 52px; padding: .3rem .45rem; border-radius: var(--radius);
  font-variant-numeric: tabular-nums; line-height: 1.1;
  border: 1px solid transparent;
}
.score__value { font-size: 1.22rem; font-weight: 800; letter-spacing: -.02em; }
.score__label { font-size: .6rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.score--very_hot { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.score--hot      { background: var(--amber-soft); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.score--warm     { background: var(--blue-soft); color: var(--blue); }
.score--cold     { background: var(--slate-soft); color: var(--slate); }
.score--low      { background: var(--bg-inset); color: var(--text-subtle); }

.score-inline {
  display: inline-flex; align-items: baseline; gap: .2rem;
  font-variant-numeric: tabular-nums; font-weight: 800;
}

/* ── Lead card (ข้อ 32) ──────────────────────────────────────────────────── */
.lead-card {
  display: block; padding: .9rem 1rem; background: var(--bg-elevated);
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius);
  box-shadow: var(--shadow-sm); color: inherit; text-decoration: none;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.lead-card:hover {
  text-decoration: none; box-shadow: var(--shadow); transform: translateY(-1px);
  border-color: var(--border-strong);
}
.lead-card--very_hot { border-left-color: var(--red); }
.lead-card--hot      { border-left-color: var(--amber); }
.lead-card--warm     { border-left-color: var(--blue); }
.lead-card--cold     { border-left-color: var(--slate); }
.lead-card--low      { border-left-color: var(--border-strong); }

.lead-card__top { display: flex; gap: .8rem; align-items: flex-start; }
.lead-card__main { flex: 1; min-width: 0; }
.lead-card__company {
  font-weight: 700; font-size: .96rem; display: flex; align-items: center;
  gap: .35rem; flex-wrap: wrap;
}
.lead-card__title {
  color: var(--text-muted); font-size: .875rem; margin-top: .15rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lead-card__meta {
  display: flex; flex-wrap: wrap; gap: .35rem .55rem; margin-top: .5rem;
  font-size: .76rem; color: var(--text-subtle);
}
.lead-card__meta > span { display: inline-flex; align-items: center; gap: .22rem; }
.lead-card__why {
  margin-top: .6rem; padding: .55rem .7rem; border-radius: var(--radius-sm);
  background: var(--bg-inset); font-size: .82rem; color: var(--text-muted);
  border-left: 2px solid var(--brand-accent);
}
.lead-card__action {
  margin-top: .5rem; font-size: .82rem; font-weight: 600;
  color: var(--brand-accent); display: flex; align-items: flex-start; gap: .35rem;
}
.lead-card__rank {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 7px;
  background: var(--brand); color: #fff; font-size: .78rem; font-weight: 800;
  display: grid; place-items: center;
}

/* ── Reason list (Why this lead / score reasons) ──────────────────────────── */
.reasons { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.reasons li {
  display: flex; gap: .5rem; align-items: flex-start;
  font-size: .85rem; line-height: 1.6;
}
.reasons__icon { flex: 0 0 1.1rem; text-align: center; }
.reasons--impact li { padding: .3rem .5rem; border-radius: var(--radius-sm); }
.reasons li.is-high     { background: var(--green-soft); color: var(--green); }
.reasons li.is-medium   { background: var(--bg-inset); }
.reasons li.is-negative { background: var(--red-soft); color: var(--red); }
.reasons li.is-neutral  { background: var(--bg-inset); color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%; border-collapse: collapse; font-size: .86rem;
}
table.data th, table.data td {
  padding: .55rem .7rem; text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data th {
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-subtle); background: var(--bg-inset); position: sticky; top: 0;
}
table.data tbody tr:hover { background: var(--bg-inset); }
table.data td.wrap { white-space: normal; min-width: 200px; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; background: var(--bg-inset); }
table.data--compact th, table.data--compact td { padding: .38rem .55rem; font-size: .82rem; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field { display: block; margin-bottom: .8rem; }
.field__label {
  display: block; font-size: .8rem; font-weight: 600;
  margin-bottom: .28rem; color: var(--text);
}
.field__label .req { color: var(--red); }
.field__hint { font-size: .76rem; color: var(--text-subtle); margin-top: .25rem; line-height: 1.55; }
.field__error { font-size: .78rem; color: var(--red); margin-top: .25rem; font-weight: 600; }

input[type="text"], input[type="email"], input[type="url"], input[type="number"],
input[type="password"], input[type="date"], input[type="datetime-local"],
input[type="tel"], input[type="search"], input[type="file"], select, textarea {
  width: 100%; padding: .5rem .65rem;
  font-family: inherit; font-size: .9rem; color: var(--text);
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 8px; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 18%, transparent);
}
input[type="checkbox"], input[type="radio"] {
  width: 15px; height: 15px; margin: 0; accent-color: var(--brand-accent);
  flex: 0 0 auto;
}
textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
select[multiple] { min-height: 110px; }
input:disabled, select:disabled, textarea:disabled {
  background: var(--bg-sunken); color: var(--text-subtle); cursor: not-allowed;
}

.check { display: flex; align-items: flex-start; gap: .5rem; font-size: .86rem; cursor: pointer; }
.check input { margin-top: .28rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .35rem .8rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 .85rem; }
.form-grid--wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.field--full { grid-column: 1 / -1; }

.otp-input {
  font-family: var(--mono); font-size: 1.7rem; font-weight: 700;
  letter-spacing: .5em; text-align: center; padding: .7rem .5rem .7rem 1.1rem;
}

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 1rem; }
legend { font-size: .82rem; font-weight: 700; padding: 0 .4rem; color: var(--text-muted); }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: .55rem; align-items: end;
}
.filters .field { margin-bottom: 0; }
.filters__actions { display: flex; gap: .4rem; align-items: end; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  display: flex; gap: .65rem; align-items: flex-start;
  padding: .7rem .9rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-inset);
  font-size: .875rem; line-height: 1.6;
}
.alert__icon { flex: 0 0 1.15rem; font-size: 1rem; line-height: 1.4; }
.alert__body { flex: 1; min-width: 0; }
.alert--success { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 26%, transparent); color: var(--green); }
.alert--error   { background: var(--red-soft);   border-color: color-mix(in srgb, var(--red) 26%, transparent);   color: var(--red); }
.alert--warning { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 26%, transparent); color: var(--amber); }
.alert--info    { background: var(--blue-soft);  border-color: color-mix(in srgb, var(--blue) 26%, transparent);  color: var(--blue); }
.alert--critical { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 600; }

.flash-stack {
  position: sticky; top: calc(var(--header-h) + .5rem); z-index: 25;
  display: grid; gap: .5rem;
}

/* ── Timeline (ข้อ 12) ───────────────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ''; position: absolute; left: 11px; top: .6rem; bottom: .6rem;
  width: 2px; background: var(--border);
}
.timeline__item { position: relative; padding: 0 0 1rem 2.1rem; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot {
  position: absolute; left: 0; top: .18rem;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg-elevated); border: 2px solid var(--border);
  display: grid; place-items: center; font-size: .72rem;
}
.timeline__item.is-system .timeline__dot { border-color: var(--border); color: var(--text-subtle); }
.timeline__item.is-call .timeline__dot { border-color: var(--green); color: var(--green); }
.timeline__item.is-meeting .timeline__dot { border-color: var(--violet); color: var(--violet); }
.timeline__item.is-quotation .timeline__dot { border-color: var(--amber); color: var(--amber); }
.timeline__item.is-follow_up .timeline__dot { border-color: var(--blue); color: var(--blue); }
.timeline__head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem;
  font-size: .875rem; font-weight: 600;
}
.timeline__time { font-size: .76rem; color: var(--text-subtle); font-weight: 400; }
.timeline__body {
  font-size: .85rem; color: var(--text-muted); margin-top: .2rem;
  white-space: pre-wrap; word-break: break-word;
}

/* ── Evidence / source list (ข้อ 7, 9) ───────────────────────────────────── */
.evidence {
  padding: .7rem .85rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-inset);
}
.evidence + .evidence { margin-top: .5rem; }
.evidence__quote {
  font-size: .85rem; line-height: 1.7; color: var(--text);
  border-left: 3px solid var(--brand-accent); padding-left: .7rem;
  white-space: pre-wrap; word-break: break-word;
}
.evidence__meta {
  display: flex; flex-wrap: wrap; gap: .3rem .6rem; margin-top: .5rem;
  font-size: .76rem; color: var(--text-subtle);
}
.evidence__url { word-break: break-all; }

/* ── Charts (inline SVG, server-rendered) ────────────────────────────────── */
.bars { display: grid; gap: .5rem; }
.bar { display: grid; grid-template-columns: minmax(88px, 30%) 1fr auto; gap: .6rem; align-items: center; }
.bar__label { font-size: .82rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar__track { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.bar__fill { height: 100%; border-radius: 999px; background: var(--brand-accent); }
.bar__value { font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 2.4rem; text-align: right; }

.sparkline { display: flex; align-items: flex-end; gap: 2px; height: 52px; }
.sparkline__bar {
  flex: 1; min-width: 3px; border-radius: 2px 2px 0 0;
  background: var(--brand-accent); opacity: .8; min-height: 2px;
}
.sparkline__bar:hover { opacity: 1; }

.meter { height: 7px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.meter__fill { height: 100%; border-radius: 999px; background: var(--brand-accent); }
.meter__fill--warn { background: var(--amber); }
.meter__fill--danger { background: var(--red); }

/* ── Pipeline columns ────────────────────────────────────────────────────── */
.pipeline { display: flex; gap: .7rem; overflow-x: auto; padding-bottom: .6rem; }
.pipeline__col {
  flex: 0 0 258px; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem;
}
.pipeline__head {
  display: flex; align-items: center; gap: .4rem; margin-bottom: .55rem;
  font-size: .82rem; font-weight: 700;
}
.pipeline__count {
  margin-left: auto; padding: 0 .4rem; border-radius: 999px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  font-size: .72rem; font-variant-numeric: tabular-nums;
}
.pipeline__items { display: grid; gap: .45rem; }
.pipeline__card {
  display: block; padding: .55rem .65rem; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--border);
  font-size: .82rem; color: inherit; text-decoration: none;
}
.pipeline__card:hover { text-decoration: none; border-color: var(--border-strong); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.pagination__info { margin-right: auto; font-size: .82rem; color: var(--text-muted); }
.pagination a, .pagination span {
  min-width: 32px; padding: .3rem .5rem; border-radius: 7px;
  border: 1px solid var(--border); background: var(--bg-elevated);
  font-size: .84rem; text-align: center; color: var(--text); text-decoration: none;
}
.pagination a:hover { text-decoration: none; background: var(--bg-inset); }
.pagination .is-current {
  background: var(--brand-accent); border-color: var(--brand-accent);
  color: #fff; font-weight: 700;
}
.pagination .is-disabled { opacity: .45; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty { padding: 2.2rem 1.2rem; text-align: center; color: var(--text-muted); }
.empty__icon { font-size: 2rem; opacity: .5; }
.empty__title { font-weight: 700; color: var(--text); margin: .5rem 0 .3rem; }
.empty__text { font-size: .875rem; max-width: 42ch; margin: 0 auto; line-height: 1.7; }
.empty__actions { margin-top: 1rem; display: flex; justify-content: center; gap: .4rem; flex-wrap: wrap; }

/* ── Definition list ─────────────────────────────────────────────────────── */
.dl { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: .35rem .9rem; font-size: .86rem; }
.dl dt { color: var(--text-subtle); font-weight: 600; }
.dl dd { margin: 0; word-break: break-word; }
.dl--stack { grid-template-columns: 1fr; gap: .1rem; }
.dl--stack dt { font-size: .76rem; }
.dl--stack dd { margin-bottom: .55rem; }

/* ── Details / accordion ─────────────────────────────────────────────────── */
details.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elevated); }
details.panel + details.panel { margin-top: .5rem; }
details.panel > summary {
  padding: .6rem .85rem; cursor: pointer; font-size: .875rem; font-weight: 600;
  display: flex; align-items: center; gap: .45rem; list-style: none;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: '▸'; color: var(--text-subtle); font-size: .8rem; }
details.panel[open] > summary::before { content: '▾'; }
details.panel[open] > summary { border-bottom: 1px solid var(--border); }
details.panel > .panel__body { padding: .85rem; }

/* ── Auth pages ──────────────────────────────────────────────────────────── */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem;
  background:
    radial-gradient(1000px 500px at 15% -10%, color-mix(in srgb, var(--brand-accent) 12%, transparent), transparent),
    var(--bg);
}
.auth__box { width: 100%; max-width: 420px; }
.auth__brand { text-align: center; margin-bottom: 1.3rem; }
.auth__logo {
  width: 50px; height: 50px; margin: 0 auto .65rem; border-radius: 13px;
  background: linear-gradient(140deg, #38bdf8, #0369a1);
  display: grid; place-items: center; font-size: 1.4rem; font-weight: 800; color: #041b2c;
  box-shadow: var(--shadow);
}
.auth__name { font-size: 1.18rem; font-weight: 800; letter-spacing: -.02em; }
.auth__tag { font-size: .82rem; color: var(--text-muted); margin-top: .2rem; }
.auth__card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 1.4rem;
}
.auth__foot { text-align: center; margin-top: 1.1rem; font-size: .78rem; color: var(--text-subtle); line-height: 1.7; }

/* ── Install wizard ──────────────────────────────────────────────────────── */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.steps li {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .7rem; border-radius: var(--radius-sm);
  background: var(--bg-inset); font-size: .875rem;
}
.steps li.is-done { background: var(--green-soft); color: var(--green); }
.steps__mark { flex: 0 0 1.2rem; text-align: center; font-weight: 800; }

.check-row {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .45rem .6rem; border-radius: var(--radius-sm); font-size: .85rem;
}
.check-row.is-ok { background: var(--green-soft); color: var(--green); }
.check-row.is-fail { background: var(--red-soft); color: var(--red); }
.check-row.is-optional { background: var(--amber-soft); color: var(--amber); }
.check-row__mark { flex: 0 0 1.1rem; font-weight: 800; }
.check-row__text { flex: 1; }
.check-row__detail { font-size: .8rem; opacity: .85; margin-top: .1rem; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.tiny { font-size: .76rem; }
.small { font-size: .84rem; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.tabular { font-variant-numeric: tabular-nums; }
.break { word-break: break-word; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hide { display: none !important; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-blue { color: var(--blue); }

@media (max-width: 640px) {
  h1 { font-size: 1.28rem; }
  .content { font-size: 14.5px; }
  .stat__value { font-size: 1.45rem; }
  .dl { grid-template-columns: 1fr; gap: .1rem; }
  .dl dt { font-size: .76rem; margin-top: .4rem; }
  .grid--split { gap: .8rem; }
}

@media print {
  .sidebar, .topbar, .page-head__actions, .btn, form { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
