/* ==========================================================================
   TicketBulog — "Dispatch Console" design system
   Field-dispatch complaint tracking. One system, two themes.
   ========================================================================== */

/* ---- Design tokens ------------------------------------------------------- */
:root {
  --bg: #edf0f4;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #e9edf2;
  --border: #dce1e8;
  --border-strong: #c6cdd8;
  --text: #131922;
  --text-2: #47515f;
  --muted: #6b7686;

  --brand: #0e5c4a;
  --brand-2: #0b4a3b;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1eb;
  --ring: rgba(14, 92, 74, 0.32);

  --danger: #c62b3f;
  --danger-soft: #fbe7ea;
  --warn: #b7791f;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 18px 44px rgba(13, 22, 38, 0.18);

  /* Rail stays a constant dark "control panel" in both themes. */
  --rail-grad: linear-gradient(178deg, #0c2e28 0%, #0a231f 100%);
  --rail-text: #c8d7d1;
  --rail-dim: #7e948c;
  --rail-hover: rgba(255, 255, 255, 0.06);
  --rail-active: rgba(255, 255, 255, 0.10);
  --rail-accent: #34d6a8;
  --rail-border: rgba(255, 255, 255, 0.07);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Semantic workflow hues — the route warms as the technician nears the site. */
  --st-new: #64748b;
  --st-assigned: #3b82f6;
  --st-received: #6366f1;
  --st-departed: #8b5cf6;
  --st-arrived: #d97706;
  --st-working: #ea8c00;
  --st-completed: #0d9488;
  --st-client_ack: #16a34a;
  --st-reopened: #e11d48;
  --st-cancelled: #6b7280;

  --pr-low: #6b7280;
  --pr-normal: #2563eb;
  --pr-high: #d97706;
  --pr-urgent: #dc2626;
}

:root[data-theme="dark"] {
  --bg: #0a0e15;
  --surface: #121824;
  --surface-2: #0e141e;
  --surface-3: #1a2231;
  --border: #232d3c;
  --border-strong: #34414f;
  --text: #e8edf4;
  --text-2: #aeb9c7;
  --muted: #7d8a9b;

  --brand: #18a184;
  --brand-2: #1fb597;
  --brand-ink: #04150f;
  --brand-soft: rgba(24, 161, 132, 0.14);
  --ring: rgba(24, 161, 132, 0.38);

  --danger: #f2637a;
  --danger-soft: rgba(242, 99, 122, 0.14);
  --warn: #e2b04a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 22px 50px rgba(0, 0, 0, 0.6);

  --st-new: #94a3b8;
  --st-assigned: #60a5fa;
  --st-received: #818cf8;
  --st-departed: #a78bfa;
  --st-arrived: #f59e0b;
  --st-working: #fba615;
  --st-completed: #2dd4bf;
  --st-client_ack: #4ade80;
  --st-reopened: #fb7185;
  --st-cancelled: #94a3b8;

  --pr-low: #94a3b8;
  --pr-normal: #60a5fa;
  --pr-high: #fbbf24;
  --pr-urgent: #f87171;
}

/* ---- Reset / base -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.muted { color: var(--muted); }
::selection { background: var(--brand); color: var(--brand-ink); }

/* ---- App shell ----------------------------------------------------------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
/* The scrim is a mobile-only overlay; off the grid entirely on desktop. */
.scrim { display: none; }

.rail {
  background: var(--rail-grad);
  color: var(--rail-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--rail-border);
  z-index: 40;
}
.rail__brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--rail-border);
}
.rail__mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(150deg, #34d6a8, #0e6f57);
  display: grid; place-items: center; color: #04231a;
  box-shadow: 0 4px 12px rgba(52, 214, 168, 0.28);
}
.rail__mark svg { width: 20px; height: 20px; }
.rail__word { font-family: var(--font-display); font-weight: 700; font-size: 17px; color: #fff; letter-spacing: -0.02em; }
.rail__word b { color: var(--rail-accent); font-weight: 700; }
.rail__tag { display: block; font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--rail-dim); font-family: var(--font-mono); margin-top: 1px; }

.rail__nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.rail__section { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--rail-dim); padding: 14px 12px 6px; font-weight: 600; }
.navlink {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--rail-text); font-weight: 500; font-size: 13.5px;
  position: relative; transition: background 0.14s, color 0.14s;
}
.navlink svg { width: 18px; height: 18px; opacity: 0.85; flex: none; }
.navlink:hover { background: var(--rail-hover); color: #fff; }
.navlink.is-active { background: var(--rail-active); color: #fff; }
.navlink.is-active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--rail-accent);
}
.navlink.is-active svg { opacity: 1; color: var(--rail-accent); }

.rail__foot { padding: 12px; border-top: 1px solid var(--rail-border); }
.rail__user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.rail__user .avatar { flex: none; }
.rail__user .nm { font-size: 13px; font-weight: 600; color: #fff; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail__user .rl { font-size: 11px; color: var(--rail-dim); text-transform: capitalize; }

.main { display: flex; flex-direction: column; min-width: 0; }

/* ---- Topbar -------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px; height: 62px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { min-width: 0; }
.topbar__title h1 { font-size: 18px; }
.topbar__crumb { font-size: 12px; color: var(--muted); font-family: var(--font-mono); letter-spacing: 0.02em; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

.iconbtn {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--text-2);
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}
.iconbtn:hover { background: var(--surface-3); color: var(--text); }
.iconbtn svg { width: 19px; height: 19px; }

/* theme toggle shows the icon for the theme you'd switch TO */
.themebtn .i-sun { display: none; }
.themebtn .i-moon { display: block; }
:root[data-theme="dark"] .themebtn .i-sun { display: block; }
:root[data-theme="dark"] .themebtn .i-moon { display: none; }

/* user menu */
.usermenu { position: relative; }
.usermenu__btn { display: flex; align-items: center; gap: 9px; padding: 5px 8px 5px 5px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: border-color 0.14s, box-shadow 0.14s; }
.usermenu__btn:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.usermenu__btn .nm { font-size: 13px; font-weight: 600; }
.usermenu__btn .cx { color: var(--muted); }
.usermenu__pop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: none; z-index: 50;
}
.usermenu.open .usermenu__pop { display: block; animation: pop 0.14s ease; }
.usermenu__head { padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.usermenu__head .nm { font-weight: 600; }
.usermenu__head .em { font-size: 12px; color: var(--muted); }
.menuitem { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 8px; background: none; border: none; cursor: pointer; font-size: 13.5px; text-align: left; color: var(--text-2); }
.menuitem:hover { background: var(--surface-3); color: var(--text); }
.menuitem svg { width: 16px; height: 16px; }
.menuitem.danger { color: var(--danger); }
.menuitem.danger:hover { background: var(--danger-soft); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: 13px;
  background: linear-gradient(145deg, #17a184, #0c5c49); color: #fff; flex: none;
  letter-spacing: 0.02em;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

/* ---- Content ------------------------------------------------------------- */
.content { padding: 26px 22px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.pagehead h2 { font-size: 22px; }
.pagehead p { color: var(--muted); font-size: 13.5px; margin-top: 3px; }

/* ---- Cards --------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card__head h3 { font-size: 15px; }
.card__body { padding: 18px; }
.card__body.flush { padding: 0; }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 15px; height: 38px; border-radius: 10px; cursor: pointer;
  font-weight: 600; font-size: 13.5px; border: 1px solid transparent;
  transition: background 0.14s, border-color 0.14s, box-shadow 0.14s, transform 0.06s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn--primary { background: var(--brand); color: var(--brand-ink); }
.btn--primary:hover { background: var(--brand-2); }
.btn--ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.btn--soft { background: var(--brand-soft); color: var(--brand); }
.btn--soft:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(1.06); }
.btn--sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

/* ---- Badges -------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  line-height: 1.4; white-space: nowrap;
  color: var(--c, var(--muted));
  background: color-mix(in srgb, var(--c, var(--muted)) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c, var(--muted)) 26%, transparent);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge--plain { background: var(--surface-3); border-color: var(--border); color: var(--text-2); }

.st-new { --c: var(--st-new); }
.st-assigned { --c: var(--st-assigned); }
.st-received { --c: var(--st-received); }
.st-departed { --c: var(--st-departed); }
.st-arrived { --c: var(--st-arrived); }
.st-working { --c: var(--st-working); }
.st-completed { --c: var(--st-completed); }
.st-client_ack { --c: var(--st-client_ack); }
.st-reopened { --c: var(--st-reopened); }
.st-cancelled { --c: var(--st-cancelled); }
.pr-low { --c: var(--pr-low); }
.pr-normal { --c: var(--pr-normal); }
.pr-high { --c: var(--pr-high); }
.pr-urgent { --c: var(--pr-urgent); }

/* ---- Stats --------------------------------------------------------------- */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { position: relative; overflow: hidden; padding: 17px 18px; }
.stat__label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; display: flex; align-items: center; gap: 8px; }
.stat__num { font-family: var(--font-display); font-size: 34px; font-weight: 600; margin-top: 8px; line-height: 1; letter-spacing: -0.02em; }
.stat__foot { font-size: 12px; color: var(--muted); margin-top: 8px; }
.stat__chip { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: var(--c, var(--brand)); background: color-mix(in srgb, var(--c, var(--brand)) 14%, transparent); }
.stat__chip svg { width: 17px; height: 17px; }
.stat__accent { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, var(--brand)); }

/* ---- Tables -------------------------------------------------------------- */
.tablewrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 600; padding: 11px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
table.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr { transition: background 0.12s; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl tbody tr:last-child td { border-bottom: none; }
.cellstack { display: flex; flex-direction: column; gap: 2px; }
.cellstack .sub { font-size: 12px; color: var(--muted); }

/* ---- Forms --------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .req { color: var(--danger); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  transition: border-color 0.14s, box-shadow 0.14s; font-size: 13.5px;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.textarea { resize: vertical; min-height: 90px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7686' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 34px; }
.formrow { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---- Custom dropdown (replaces native <select> chrome) --------------------
   app.js progressively wraps every <select class="select"> in a .dd: the
   native select stays in the DOM (invisible) as the single source of truth
   for value/name/required/validation, while a styled .dd__trigger button +
   one shared, body-portaled .ddpanel handle the actual picking UI. Portaling
   the panel to <body> keeps it from being clipped by a modal's or table's
   overflow — the same freedom a native select's OS-rendered popup has. */
.dd { position: relative; display: block; }
.dd__native {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; opacity: 0; pointer-events: none;
}
.dd__trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 10px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font: inherit; font-size: 13.5px; cursor: pointer;
  transition: border-color 0.14s, box-shadow 0.14s;
}
.dd__trigger:hover { border-color: var(--border-strong); }
.dd__trigger:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.dd.open .dd__trigger { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.dd__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd__label--ph { color: var(--muted); }
.dd__chev { width: 16px; height: 16px; flex: none; color: var(--muted); transition: transform 0.16s ease; }
.dd.open .dd__chev { transform: rotate(180deg); }
.dd.is-disabled .dd__trigger { opacity: 0.55; cursor: default; pointer-events: none; }

/* shared portal: one panel + scrim reused by every .dd (only one open at a time) */
.ddpanel {
  position: fixed; z-index: 120; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; max-height: 280px; overflow-y: auto;
}
.ddpanel.open { display: block; animation: pop 0.14s ease; }
.ddpanel__opt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 11px; border-radius: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer;
}
.ddpanel__opt:hover, .ddpanel__opt.is-active { background: var(--surface-3); color: var(--text); }
.ddpanel__opt.is-selected { color: var(--brand); font-weight: 600; background: var(--brand-soft); }
.ddpanel__opt.is-selected.is-active, .ddpanel__opt.is-selected:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.ddpanel__opt.is-disabled { opacity: 0.5; pointer-events: none; }
.ddpanel__chk { width: 15px; height: 15px; flex: none; color: var(--brand); visibility: hidden; }
.ddpanel__opt.is-selected .ddpanel__chk { visibility: visible; }
.ddpanel__empty { padding: 16px 11px; color: var(--muted); font-size: 13px; text-align: center; }

.ddscrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 119; display: none; }
.ddscrim.open { display: block; animation: fade 0.16s ease; }

/* ---- Filter bar ---------------------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.search input { padding-left: 38px; }
.toolbar .dd { width: auto; min-width: 130px; }

/* ---- Timeline (signature: dispatch route) -------------------------------- */
.route { position: relative; padding-left: 6px; }
.route__item { position: relative; padding: 0 0 22px 34px; }
.route__item::before {
  content: ""; position: absolute; left: 9px; top: 20px; bottom: -2px; width: 2px;
  background: var(--border-strong);
}
.route__item:last-child::before { display: none; }
.route__node {
  position: absolute; left: 0; top: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--c, var(--muted));
  display: grid; place-items: center;
}
.route__node::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--muted)); }
.route__item.is-current .route__node { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent); }
.route__item.is-current .route__node::after { animation: pulse 1.6s ease-in-out infinite; }
.route__stage { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.route__meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.route__meta .mono { color: var(--text-2); }
.route__note { font-size: 13px; color: var(--text-2); margin-top: 7px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; }

/* ---- Modal --------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: rgba(9, 14, 22, 0.55); backdrop-filter: blur(3px);
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal-overlay.open { display: flex; animation: fade 0.16s ease; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; margin: auto 0; animation: rise 0.2s cubic-bezier(0.2,0.8,0.2,1);
}
.modal.lg { max-width: 720px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal__head h3 { font-size: 16px; }
.modal__body { padding: 20px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ---- Tabs ---------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 15px; font-weight: 600; font-size: 13.5px; color: var(--muted); cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---- Toast --------------------------------------------------------------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 11px; padding: 12px 15px; min-width: 260px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: 11px; box-shadow: var(--shadow-lg); font-size: 13.5px; animation: slidein 0.22s ease;
}
.toast.ok { border-left-color: var(--st-client_ack); }
.toast.err { border-left-color: var(--danger); }
.toast svg { width: 19px; height: 19px; flex: none; }
.toast.ok svg { color: var(--st-client_ack); }
.toast.err svg { color: var(--danger); }

/* ---- Empty / loading ----------------------------------------------------- */
.empty { text-align: center; padding: 52px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 12px; opacity: 0.5; }
.empty h4 { font-size: 15px; color: var(--text-2); margin-bottom: 5px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.7s linear infinite; }

/* ---- Auth split screen --------------------------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth__aside {
  background: var(--rail-grad); color: #fff; padding: 48px 52px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth__aside::after {
  content: ""; position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%;
  background: radial-gradient(circle, rgba(52,214,168,0.22), transparent 70%);
}
.auth__brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.auth__pitch { position: relative; z-index: 1; }
.auth__pitch h1 { color: #fff; font-size: 34px; line-height: 1.12; letter-spacing: -0.02em; }
.auth__pitch h1 b { color: var(--rail-accent); }
.auth__pitch p { color: #a9c2ba; margin-top: 14px; font-size: 15px; max-width: 40ch; }
.auth__steps { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 14px; }
.auth__step { display: flex; align-items: center; gap: 13px; color: #cbdbd5; font-size: 13.5px; }
.auth__step .n { width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,0.08); display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; color: var(--rail-accent); flex: none; }
.auth__panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 40px 24px; background: var(--bg); }
.auth__card { width: 100%; max-width: 388px; }
.auth__card h2 { font-size: 24px; }
.auth__card .lede { color: var(--muted); margin: 6px 0 24px; font-size: 14px; }
.authswitch { text-align: center; margin-top: 20px; font-size: 13.5px; color: var(--muted); }
.authswitch a { color: var(--brand); font-weight: 600; }
.auth__foot { width: 100%; max-width: 388px; text-align: center; }
.auth__build { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); opacity: 0.65; }
.sig { margin-top: 5px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.22em; color: var(--muted); opacity: 0.35; -webkit-user-select: none; user-select: none; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }
.gbtn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 13.5px; cursor: pointer; }
.gbtn:hover { background: var(--surface-3); }
.formerr { display: none; padding: 11px 13px; border-radius: 10px; background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); font-size: 13px; margin-bottom: 16px; }
.formerr.show { display: block; }
.formnotice { padding: 11px 13px; border-radius: 10px; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); color: var(--brand); font-size: 13px; margin-bottom: 16px; }
.ginfo { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 20px; }

/* ---- Detail layout ------------------------------------------------------- */
.detailgrid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.detailcol { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.detailcol--side { position: sticky; top: 78px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { color: var(--text); font-weight: 500; }
.desc { font-size: 14px; color: var(--text-2); line-height: 1.65; white-space: pre-wrap; }
.actionbar { display: flex; flex-direction: column; gap: 9px; }

/* ---- Matrix (RBAC) ------------------------------------------------------- */
.matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix th, .matrix td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.matrix thead th { background: var(--surface-2); text-transform: capitalize; font-family: var(--font-display); }
.matrix .modrow td { background: var(--surface-2); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.06em; color: var(--muted); text-align: left; }
.matrix .permlabel { text-align: left; }
.matrix .permlabel .pc { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); display: block; }
.chk { width: 19px; height: 19px; accent-color: var(--brand); cursor: pointer; }

/* ---- Dashboard breakdowns ------------------------------------------------ */
.dashcols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar { display: grid; grid-template-columns: 128px 1fr 36px; align-items: center; gap: 12px; font-size: 13px; }
.bar__l { color: var(--text-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar__t { height: 9px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.bar__t span { display: block; height: 100%; border-radius: 6px; transition: width 0.5s cubic-bezier(0.2,0.8,0.2,1); }
.bar__v { text-align: right; font-family: var(--font-mono); font-weight: 500; color: var(--text); }
.barchart { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 8px; }
.barchart__col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; min-width: 0; }
.barchart__bar { width: 100%; max-width: 42px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 55%, transparent)); min-height: 6px; transition: height 0.5s cubic-bezier(0.2,0.8,0.2,1); }
.barchart__v { font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: var(--text-2); }
.barchart__x { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---- Bottom nav (phone tab bar) ------------------------------------------ */
.bottomnav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}
.bottomnav__item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 5px 2px 4px; border-radius: 9px;
  font-size: 10.5px; font-weight: 600; line-height: 1.1; color: var(--muted);
  white-space: nowrap; overflow: hidden;
}
.bottomnav__item svg { width: 20px; height: 20px; flex: none; }
.bottomnav__item.is-active { color: var(--brand); background: var(--brand-soft); }

/* ---- FAB (phone-only primary action, e.g. "Lapor komplain") --------------- */
.fab { display: none; }

/* ---- Misc ---------------------------------------------------------------- */
.pager { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.pager .grp { display: flex; gap: 8px; }
.hstack { display: flex; align-items: center; gap: 10px; }
.hstack.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.mt { margin-top: 18px; }
.hidden { display: none !important; }
.mobile-only { display: none; }
.railtoggle { display: none; }
.noscroll { overflow: hidden; }

/* ---- Animations ---------------------------------------------------------- */
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: 0.6; } }

/* ---- Responsive ---------------------------------------------------------- */
/* Tablet (≤960px): the rail becomes a drawer behind the hamburger. */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: fixed; left: 0; top: 0; width: 250px; transform: translateX(-100%);
    transition: transform 0.22s ease; box-shadow: var(--shadow-lg);
  }
  .rail.open { transform: translateX(0); }
  .railtoggle { display: grid; }
  .mobile-only { display: block; }
  .dashcols { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 39; display: none; }
  .scrim.open { display: block; }

  /* Ticket detail flows as one column; Aksi jumps right below the info card
     so field technicians reach their action without scrolling the timeline. */
  .detailgrid { display: flex; flex-direction: column; }
  .detailcol { display: contents; }
  .dg-info { order: 1; }
  .dg-actions { order: 2; }
  .dg-route { order: 3; }
  .dg-assign { order: 4; }
}

/* Phone (≤760px): tab bar navigation, tables become stacked labeled cards. */
@media (max-width: 760px) {
  /* chrome: the bottom tab bar replaces the drawer */
  .railtoggle { display: none; }
  .bottomnav { display: grid; }
  .content { padding: 18px 14px calc(78px + env(safe-area-inset-bottom, 0px)); }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar__title h1 { font-size: 16px; }
  .usermenu__btn .nm { display: none; }

  .pagehead { flex-direction: column; align-items: stretch; gap: 12px; }
  .pagehead h2 { font-size: 19px; }
  .pagehead .btn { width: 100%; }
  /* the FAB below takes over this action on phone */
  .pagehead [data-open-create] { display: none; }

  /* floating "+" action, centered above the bottom tab bar */
  .fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom, 0px) + 16px);
    transform: translateX(-50%);
    width: 56px; height: 56px; border-radius: 50%; z-index: 65;
    background: var(--brand); color: var(--brand-ink); border: none; cursor: pointer;
    box-shadow: 0 10px 22px color-mix(in srgb, var(--brand) 40%, transparent), var(--shadow-md);
    transition: transform 0.14s, box-shadow 0.14s;
  }
  .fab:active { transform: translateX(-50%) scale(0.92); }
  .fab svg { width: 26px; height: 26px; }

  /* filters: search takes its own row, dropdowns share the next one */
  .toolbar { gap: 8px; }
  .search { flex-basis: 100%; }
  .toolbar .dd { flex: 1; min-width: 0; }
  .toolbar .field { flex: 1 1 100%; }
  .toolbar .btn--primary { flex: 1; }

  /* 16px inputs stop iOS from zooming the page on focus (buttons — .dd__trigger
     included — never trigger that zoom, so the custom dropdown is exempt) */
  .input, .textarea { font-size: 16px; }
  .formrow { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 108px 1fr; }

  /* dropdown panel becomes a bottom sheet instead of an anchored popover */
  .ddpanel {
    left: 0 !important; right: 0 !important; bottom: 0 !important; top: auto !important; width: auto !important;
    max-height: 70vh !important; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .ddpanel.open { animation: rise 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .ddpanel::before {
    content: ""; display: block; width: 36px; height: 4px; border-radius: 3px;
    background: var(--border-strong); margin: 3px auto 10px;
  }
  .ddpanel__opt { padding: 13px 12px; font-size: 15px; }

  /* tables flow as stacked cards; data-th paints each cell's column label */
  table.tbl thead { display: none; }
  table.tbl, table.tbl tbody, table.tbl tr, table.tbl td { display: block; }
  table.tbl tr { padding: 13px 16px; border-bottom: 1px solid var(--border); }
  table.tbl tbody tr:last-child { border-bottom: none; }
  table.tbl td { padding: 4px 0; border-bottom: none; }
  table.tbl td[data-th] { display: flex; align-items: center; justify-content: space-between; gap: 14px; text-align: right; }
  table.tbl td[data-th]::before {
    content: attr(data-th); flex: none; text-align: left;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  }
  table.tbl td[data-th] .cellstack { align-items: flex-end; }
  table.tbl td.t-main { padding: 0 0 7px; }
  table.tbl td.t-actions { display: flex; justify-content: flex-end; margin-top: 9px; padding: 9px 0 0; border-top: 1px dashed var(--border); }
  table.tbl tr.clickable { padding-right: 34px; position: relative; }
  table.tbl tr.clickable::after {
    content: "›"; position: absolute; right: 15px; top: 13px;
    font-size: 20px; line-height: 1; color: var(--muted);
  }

  /* stats & charts */
  .statgrid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .stat__num { font-size: 26px; }
  .bar { grid-template-columns: 96px 1fr 32px; gap: 9px; }

  /* modals: near full-width sheets with easy-to-tap buttons */
  .modal-overlay { padding: 14px 10px; }
  .modal__head { padding: 14px 16px; }
  .modal__body { padding: 16px; }
  .modal__foot { padding: 14px 16px; }
  .modal__foot .btn { flex: 1; }

  /* toasts sit above the tab bar, full width */
  .toasts { left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  .toast { min-width: 0; max-width: none; }

  .pager { flex-wrap: wrap; gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
