/* SMART WEALTH SOLUTION 15 & CO — FA Team Tracker.
   Design system per DESIGN.md: "an AIA Prestige private-client lounge after dark —
   deep navy walls, brass fittings, gold light raking across them."
   Structural + token styles live here; dynamic per-item styles stay inline in app.js. */

:root {
  color-scheme: dark;              /* native selects, scrollbars and inputs render dark */

  /* ground + surfaces */
  --bg:           #0f1e36;
  --bg-deep:      #0A1628;         /* the rail, sunk below the page */
  --surface:      #1E3A5F;
  --surface-2:    #2A4E7D;
  --line:         #5C86BC;
  --line-strong:  #7099CE;

  /* ink */
  --ink:          #FFFFFF;
  --ink-2:        #EAF2FC;
  --ink-muted:    #C2D5EA;
  --ink-faint:    #A2B8D2;

  /* gold — scarce by rule: brand, seal, active nav, focus, one hero number */
  --gold:         #E3B341;
  --gold-bright:  #F7D97A;
  --gold-deep:    #A87B1E;
  --gold-tint:    rgba(227,179,65,0.18);
  --gold-glow:    rgba(227,179,65,0.45);
  --on-gold:      #12203A;

  /* status — desaturated so none of them competes with the gold */
  --jade:         #3FD18C;  --jade-tint:    rgba(63,209,140,0.18);
  --copper:       #FFA53D;  --copper-tint:  rgba(255,165,61,0.18);
  --crimson:      #FF6B72;  --crimson-tint: rgba(255,107,114,0.18);
  --steel:        #74A6FF;  --steel-tint:   rgba(116,166,255,0.18);

  --track:        #2A4E7D;         /* progress troughs */
  --shadow:       0 10px 30px rgba(3,9,20,0.62);

  --r-panel: 14px;                 /* graded radii — hierarchy must stay legible */
  --r-ctl:   10px;
  --r-pill:  999px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;                /* the app owns the viewport; .main scrolls, not the page */
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', 'IBM Plex Sans Thai', system-ui, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-bright); }

input, select, button, textarea { font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--ink-faint); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

/* numerals line up in columns */
.tnum, table, .agent-row { font-variant-numeric: tabular-nums; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .seal__arc { stroke-dasharray: none !important; }
}

/* ---- app shell: fixed-height viewport, rail static, main pane scrolls ---- */
.app { height: 100vh; height: 100dvh; background: var(--bg); display: flex; align-items: stretch; }
.main { flex: 1; min-width: 0; height: 100%; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }

/* ---- the rail (desktop): 240px, collapses to a 64px icon rail ---- */
.sidebar {
  width: 240px; flex: none;
  background: var(--bg-deep);
  border-right: 1px solid var(--line);
  color: var(--ink-2);
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px;
  height: 100%; overflow-y: auto; overflow-x: hidden;
  transition: width 180ms ease-out;
}
.app.mini .sidebar { width: 64px; padding-left: 8px; padding-right: 8px; }

.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; margin-bottom: 16px; min-height: 40px; }
.sidebar__spacer { flex: 1; }
.sidebar__user { display: flex; align-items: center; gap: 10px; padding: 12px 6px 2px; border-top: 1px solid var(--line); }
.sidebar__menu { display: contents; }

/* label/text collapses away in mini; the icon stays put */
.app.mini .rail-hide { display: none !important; }
.app.mini .sidebar__brand { justify-content: center; padding: 0; }
.app.mini .menu-item { justify-content: center; padding-left: 0; padding-right: 0; }
.app.mini .sidebar__user { justify-content: center; }

.menu-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; border: 1px solid transparent; background: transparent;
  text-align: left; border-radius: var(--r-ctl);
  padding: 10px 11px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  color: var(--ink-muted);
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}
.menu-item:hover { background: var(--surface); color: var(--ink); }
.menu-item .ico { flex: none; width: 18px; height: 18px; display: block; }
/* the gold light-edge: active nav is the only nav item that catches the gold */
.menu-item.is-on {
  background: linear-gradient(90deg, var(--gold-tint), transparent 72%);
  border-color: var(--gold);
  color: var(--gold-bright);
}

.rail-toggle {
  display: flex; align-items: center; justify-content: center;
  margin-top: 6px; width: 100%;
  background: transparent; border: 1px solid var(--line); color: var(--ink-faint);
  border-radius: var(--r-ctl); padding: 7px; cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.rail-toggle:hover { color: var(--gold); border-color: var(--gold-deep); }

.nav-toggle {
  display: none; margin-left: auto;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-ctl); padding: 8px 12px; font-size: 17px; line-height: 1; cursor: pointer;
}

/* ---- panels + rows ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }
.agent-row { cursor: pointer; transition: background 120ms ease; }
.agent-row:hover { background: var(--surface-2) !important; }
.top3-card { cursor: pointer; transition: background 150ms ease, border-color 150ms ease; }
.top3-card:hover { background: var(--surface-2) !important; border-color: var(--gold-deep) !important; }

.btn-primary { transition: background 140ms ease, box-shadow 140ms ease; }
.btn-primary:hover { background: var(--gold-bright) !important; box-shadow: 0 0 0 3px var(--gold-tint); }

/* ---- จัดการทีม roster: one dense row per agent, click through to their detail ---- */
.team-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.team-row {
  display: flex; align-items: center; gap: 12px; min-height: 34px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); cursor: pointer; transition: background 120ms ease;
}
.team-row:last-child { border-bottom: none; }
.team-row:hover { background: var(--surface-2); }
.team-row:focus-visible { outline-offset: -2px; border-radius: 0; }
.team-row.is-off { opacity: 0.6; }
.team-row__who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.team-row__name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-row__meta { font-size: 12px; color: var(--ink-faint); }
.team-row__chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.team-row__go { font-size: 20px; line-height: 1; color: var(--ink-faint); flex: none; }
.team-row:hover .team-row__go { color: var(--gold); }
@media (max-width: 600px) {
  .team-row { flex-wrap: wrap; }
  .team-row__who { flex-basis: calc(100% - 80px); }
  .team-row__chips { order: 3; width: 100%; justify-content: flex-start; padding-left: 46px; }
}

/* ---- breadcrumb: quiet wayfinding; gold only on hover / focus ---- */
.page-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.page-top .breadcrumb { margin-bottom: 0; flex: 1 1 240px; }
.breadcrumb { margin-bottom: 14px; min-width: 0; }
.breadcrumb ol { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; flex-wrap: wrap; row-gap: 4px; font-size: 13px; }
.crumb { display: flex; align-items: center; min-width: 0; }
.crumb + .crumb::before { content: "›"; color: var(--ink-faint); margin: 0 8px; font-size: 15px; line-height: 1; }
.crumb__link {
  border: none; background: none; padding: 2px 0; font: inherit; color: var(--ink-muted); cursor: pointer;
  border-bottom: 1px solid transparent; transition: color 120ms ease, border-color 120ms ease;
}
.crumb__link:hover { color: var(--gold); border-bottom-color: var(--gold-deep); }
.crumb__current { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42ch; }
.crumb--more { display: none; color: var(--ink-faint); }
@media (max-width: 600px) {
  .crumb--far { display: none; }
  .crumb--more { display: flex; }
  .crumb--more::before { display: none; }   /* "…" leads the trail once earlier items are hidden */
  .crumb__current { max-width: 22ch; }
}

/* leader-only entry to the edit panel on a detail page */
.btn-edit {
  border: 1px solid var(--gold-deep); background: var(--surface); color: var(--gold);
  border-radius: var(--r-ctl); padding: 8px 16px; font-size: 13.5px; font-weight: 700; cursor: pointer;
  transition: background 120ms ease, box-shadow 120ms ease;
}
.btn-edit:hover, .btn-edit[aria-expanded="true"] { background: var(--gold-tint); box-shadow: 0 0 0 3px var(--gold-tint); }

/* ---- edit panel: fixed to the right edge over a dimmed detail page ----
   The panel is the one active element on screen, so it carries the gold light-edge (DESIGN.md §6). */
body.drawer-open { overflow: hidden; }
.edit-scrim { position: fixed; inset: 0; background: rgba(5,12,24,0.62); z-index: 40; }
.edit-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(460px, 100vw); display: flex; flex-direction: column;
  background: var(--bg); box-shadow: var(--shadow);
}
.edit-drawer::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg, transparent, var(--gold) 18%, var(--gold-bright) 50%, var(--gold) 82%, transparent);
}
.edit-drawer__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line); flex: none;
}
.edit-drawer__close {
  flex: none; width: 36px; height: 36px; border-radius: var(--r-ctl);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  font-size: 15px; cursor: pointer;
}
.edit-drawer__close:hover { color: var(--gold); border-color: var(--gold-deep); }
.edit-drawer__body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 18px 28px; display: flex; flex-direction: column; gap: 14px;
}
@media (max-width: 480px) {
  .edit-drawer::before { display: none; }
  .edit-drawer__head, .edit-drawer__body { padding-left: 16px; padding-right: 16px; }
}

/* ---- the gold seal: struck-medallion progress primitive (DESIGN.md §8) ---- */
.seal { display: block; }
.seal__arc { transition: stroke-dashoffset 600ms ease-out; }
.seal--lit .seal__glow { opacity: 1; }          /* glow only when the metric is on target */
.seal__glow { opacity: 0; transition: opacity 300ms ease; }

/* ---- bento: a grid of unequal widgets, not a uniform column set ---- */
.bento { display: grid; grid-template-columns: minmax(0,1.7fr) minmax(0,1fr); gap: 14px; align-items: start; }
.bento__col { display: grid; gap: 14px; }
@media (max-width: 1040px) { .bento { grid-template-columns: 1fr; } }

/* ---- team dashboard KPI row: hero (wider) + 3 metric cards ---- */
.kpi-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 1040px) { .kpi-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .kpi-row { grid-template-columns: 1fr; } }

/* ---- mobile: the rail becomes a top bar with a drawer ---- */
@media (max-width: 820px) {
  .app { flex-direction: column; align-items: stretch; }
  .app.mini .sidebar { width: auto; padding: 10px 14px; }
  .sidebar {
    width: auto; height: auto; flex: none; overflow: visible; z-index: 20;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 12px; padding: 10px 14px;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .main { height: auto; flex: 1 1 auto; min-height: 0; }
  .sidebar__brand { margin-bottom: 0; padding: 0; flex: 1 1 auto; min-height: 0; }
  .app.mini .sidebar__brand { justify-content: flex-start; }
  .app.mini .rail-hide { display: block !important; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .rail-toggle { display: none; }
  .sidebar__spacer, .sidebar__user { display: none; }
  .sidebar__menu { display: none; width: 100%; flex-direction: column; gap: 6px; }
  .sidebar.open .sidebar__menu { display: flex; }
  .app.mini .menu-item { justify-content: flex-start; padding: 10px 11px; }
}

@media (max-width: 760px) {
  .products-grid { grid-template-columns: 1fr !important; }
  .products-grid > div:first-child { position: static !important; }
}

@media (max-width: 480px) {
  h1 { font-size: 19px !important; }
}

/* ---- เส้นทางอาชีพ (career track master data) ---- */
.ct-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--copper); border-radius: var(--r-panel);
  padding: 14px 16px; margin-bottom: 14px; font-size: 13.5px;
}
.ct-stages { display: flex; flex-direction: column; }
.ct-stage {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.ct-stage:last-child { border-bottom: none; }
.ct-stage.is-off { opacity: 0.6; }
/* the row being edited is the one active element: it takes the gold edge */
.ct-stage.is-editing { box-shadow: inset 2px 0 0 var(--gold); padding-left: 12px; background: var(--gold-tint); border-radius: var(--r-ctl); }
.ct-stage__num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line-strong); color: var(--ink-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.ct-stage__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ct-stage__acts { display: flex; gap: 6px; flex: none; }
.ct-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.ct-chip { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.ct-chip--muted { color: var(--ink-faint); }
.ct-chip--off { background: var(--crimson-tint); color: var(--crimson); }
.ct-btn {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: var(--r-ctl); padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.ct-btn:hover { border-color: var(--gold-deep); color: var(--gold); }
.ct-btn--danger { border-color: var(--crimson); color: var(--crimson); }
.ct-btn--gold { border-color: var(--gold-deep); color: var(--gold); padding: 10px 14px; font-size: 13.5px; }
.ct-form { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.ct-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; }
.ct-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ct-seg {
  flex: 1; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: var(--r-ctl); padding: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ct-seg.is-on { border-color: var(--gold); background: var(--gold-tint); color: var(--gold); }
.ct-err { background: var(--gold-tint); color: var(--gold); border-radius: var(--r-ctl); padding: 10px 14px; font-size: 12.5px; font-weight: 600; }
.ct-tiers { display: flex; flex-wrap: wrap; gap: 8px; }
.ct-tier {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 13px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.ct-tier__x {
  border: none; background: none; color: var(--ink-faint); cursor: pointer; font-size: 11px;
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
}
.ct-tier__x:hover { color: var(--crimson); background: var(--crimson-tint); }
.ct-tier__x--confirm { width: auto; padding: 0 8px; border-radius: 999px; color: var(--crimson); background: var(--crimson-tint); font-weight: 700; }
.ct-tier__use { font-size: 11px; font-weight: 600; color: var(--ink-faint); padding-right: 4px; }
@media (max-width: 600px) {
  .ct-grid, .ct-grid--3 { grid-template-columns: 1fr; }
  .ct-stage { flex-wrap: wrap; }
  .ct-stage__acts { width: 100%; padding-left: 42px; }
}

/* ---- page header with the primary action at top right ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head__cta {
  flex: none; border: none; background: var(--gold); color: var(--on-gold);
  border-radius: var(--r-ctl); padding: 11px 18px; font-size: 14px; font-weight: 700; cursor: pointer;
}

/* ---- ผลิตภัณฑ์: grouped dense list ---- */
.page-head__tools { display: flex; align-items: center; gap: 10px; flex: 0 1 auto; min-width: 0; }
.prod-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.prod-pill { flex: none; border-radius: 999px; padding: 7px 13px; font-size: 12.5px; }
.prod-pill span { color: var(--ink-faint); font-weight: 500; margin-left: 2px; }
.prod-pill.is-on span { color: var(--gold); }
.prod-search {
  flex: 0 1 240px; width: 240px; min-width: 0; padding: 9px 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; outline: none; color: var(--ink);
}
.prod-note { background: var(--jade-tint); color: var(--jade); border-radius: var(--r-ctl); padding: 10px 14px; font-size: 12.5px; font-weight: 600; margin-bottom: 12px; }
.prod-group + .prod-group { border-top: 1px solid var(--line-strong); }
.prod-group__head {
  position: sticky; top: 0; z-index: 1; padding: 10px 16px; background: var(--surface-2);
  font-size: 12.5px; font-weight: 700; color: var(--ink-2);
}
.prod-group__head span { color: var(--ink-faint); font-weight: 500; margin-left: 4px; }
.prod-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 96px auto; align-items: center; gap: 14px;
  min-height: 34px; padding: 9px 16px; border-bottom: 1px solid var(--line);
}
.prod-group .prod-row:last-child { border-bottom: none; }
.prod-row:hover { background: var(--surface-2); }
.prod-row.is-off { opacity: 0.6; }
.prod-row.is-editing { box-shadow: inset 2px 0 0 var(--gold); background: var(--gold-tint); }
.prod-row__main { min-width: 0; }
.prod-row__name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.prod-row__code { font-size: 11.5px; font-weight: 500; color: var(--ink-faint); }
.prod-row__note { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.prod-row__comm { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.prod-row__comm span { font-size: 15px; font-weight: 700; }
.prod-row__comm small { font-size: 11px; color: var(--ink-faint); }
.prod-row__acts { display: flex; gap: 6px; }
@media (max-width: 600px) {
  .prod-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 8px; }
  .prod-row__acts { grid-column: 1 / -1; }
  .page-head__tools { width: 100%; flex-direction: column; align-items: stretch; }
  .prod-search { width: 100%; flex: none; }
  /* one swipeable row instead of four wrapped lines */
  .prod-pills { flex-wrap: nowrap; overflow-x: auto; margin: 0 -20px 14px; padding: 0 20px 2px; scrollbar-width: none; }
  .prod-pills::-webkit-scrollbar { display: none; }
}
