/* ServiceBOE — design tokens first, then shell, then components. */
:root {
  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --surface-2: #F8F9FA;
  --line: #E3E6EA;
  --line-2: #CFD4DB;
  --ink: #15191E;
  --ink-2: #4A525D;
  --ink-3: #7A838F;
  --brand: #0B6B73;
  --brand-hover: #09575E;
  --brand-soft: #E2F0F1;
  --brand-ink: #FFFFFF;
  --focus: rgba(11, 107, 115, .28);
  --nav-bg: #0F1D21;
  --nav-line: rgba(255, 255, 255, .08);
  --nav-ink: #A7B6B9;
  --nav-ink-hi: #FFFFFF;
  --nav-hover: rgba(255, 255, 255, .06);
  --nav-active: rgba(94, 196, 203, .15);
  --nav-accent: #5EC4CB;
  --red: #BF3A2F;   --red-soft: #FCECEA;
  --amber: #A95F09; --amber-soft: #FCF1E1;
  --green: #1C7A4B; --green-soft: #E4F3EB;
  --blue: #2863AA;  --blue-soft: #E7EFF9;
  --gray-soft: #EDEFF2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 32, .05);
  --shadow-md: 0 12px 32px rgba(16, 24, 32, .14), 0 2px 6px rgba(16, 24, 32, .06);
  --radius: 8px;
  --sans: "IBM Plex Sans Thai", "Noto Sans Thai", "Thonburi", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C0F12; --surface: #13171C; --surface-2: #181D23; --line: #232A32; --line-2: #313A44;
    --ink: #E6E9ED; --ink-2: #A9B1BB; --ink-3: #7B8490;
    --brand: #4DB6BE; --brand-hover: #6AC5CC; --brand-soft: #11302F; --brand-ink: #061314; --focus: rgba(77, 182, 190, .35);
    --nav-bg: #0A1417;
    --red: #EF8277; --red-soft: #38191A; --amber: #E6A451; --amber-soft: #33250F;
    --green: #5BBF8D; --green-soft: #112E1F; --blue: #82AFEA; --blue-soft: #15263C; --gray-soft: #1D232A;
    --shadow-sm: none; --shadow-md: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }
ul { margin: 0; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); border-radius: 6px; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }
.code { font-family: var(--mono); font-size: 12.5px; letter-spacing: -.01em; }
.muted { color: var(--ink-2); }
.subtle { color: var(--ink-3); }
.small { font-size: 12.5px; color: var(--ink-3); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: var(--nav-ink); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 14px 12px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: var(--nav-ink-hi); }
.brand:hover { text-decoration: none; }
.brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--nav-accent); color: var(--nav-bg); display: grid; place-items: center; }
.brand .mark .ic { width: 19px; height: 19px; stroke-width: 2; }
.brand b { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.brand small { display: block; font-size: 11.5px; color: var(--nav-ink); }
.menu { display: grid; gap: 2px; }
.menu-label { font-size: 11.5px; color: rgba(167, 182, 185, .6); padding: 16px 10px 6px; }
.menu a { display: flex; align-items: center; gap: 11px; padding: 7px 10px; border-radius: 6px; color: var(--nav-ink); font-size: 14px; }
.menu a:hover { background: var(--nav-hover); color: var(--nav-ink-hi); text-decoration: none; }
.menu a.on { background: var(--nav-active); color: var(--nav-ink-hi); font-weight: 500; }
.menu a.on .ic { color: var(--nav-accent); }
.sidebar-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--nav-line); font-size: 11.5px; color: rgba(167, 182, 185, .55); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 0 1 400px; }
.search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.search input { height: 34px; padding-left: 34px; background: var(--surface-2); border-color: var(--line); }
.topbar .spacer { flex: 1; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: 9px; padding: 4px 8px 4px 4px; border-radius: 8px; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface-2); }
.usermenu .chev { width: 14px; height: 14px; color: var(--ink-3); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }
.who { display: grid; line-height: 1.25; }
.who b { font-size: 13.5px; font-weight: 500; }
.who span { font-size: 12px; color: var(--ink-3); }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); width: 248px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-md); padding: 6px; z-index: 30; }
.dropdown .head { padding: 8px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.dropdown .head span { font-size: 12.5px; color: var(--ink-3); overflow-wrap: anywhere; }
.dropdown a, .dropdown button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--ink); font: inherit; font-size: 13.5px; text-align: left; cursor: pointer; }
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown .ic { width: 16px; height: 16px; color: var(--ink-3); }
.content { width: 100%; max-width: 1320px; padding: 24px 28px 72px; display: grid; gap: 20px; align-content: start; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand small, .menu-label, .sidebar-foot { display: none; }
  .menu { display: flex; }
  .menu a { white-space: nowrap; }
  .topbar { padding: 0 16px; }
  .who { display: none; }
  .content { padding: 18px 16px 56px; }
}
@media (max-width: 640px) {
  .search { display: none; } /* the Tickets page has its own search box */
  .page-head h1 { font-size: 19px; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12.5px; color: var(--ink-3); }
.crumbs a { color: var(--ink-3); }
.crumbs a:hover { color: var(--ink); }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-sub { margin-top: 4px; color: var(--ink-2); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Surfaces & layout ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); min-height: 52px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.count { font-size: 12px; font-weight: 500; color: var(--ink-2); background: var(--gray-soft); padding: 0 7px; border-radius: 10px; line-height: 20px; }
.card-body { padding: 16px 18px; display: grid; gap: 14px; }
.card-foot { padding: 16px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; align-content: start; min-width: 0; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* Stat strip: 1px gaps over a line-coloured ground draw the dividers at any wrap. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.stat { background: var(--surface); padding: 15px 18px; display: grid; gap: 3px; color: inherit; }
a.stat:hover { background: var(--surface-2); text-decoration: none; }
.stat .label { font-size: 12.5px; color: var(--ink-2); }
.stat .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .value.alert { color: var(--red); }
.stat .hint { font-size: 12px; color: var(--ink-3); }

/* Meta bar under a detail page title */
.meta { display: flex; flex-wrap: wrap; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.meta > div { padding: 11px 18px; border-right: 1px solid var(--line); min-width: 0; }
.meta > div:last-child { border-right: 0; }
.meta dt { font-size: 12px; color: var(--ink-3); }
.meta dd { margin: 2px 0 0; font-weight: 500; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.kv.left dd { text-align: left; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-3); background: var(--surface-2); padding: 9px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 500; color: var(--ink); }
a.cell-title:hover { color: var(--brand); text-decoration: none; }
.cell-sub { margin-top: 1px; font-size: 12.5px; color: var(--ink-3); }
td.min { width: 1%; white-space: nowrap; }
td.namecol { min-width: 220px; }
td.ticketcol { min-width: 260px; }

/* ---------- Badges, status, meters ---------- */
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11.5px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; vertical-align: 1px; background: var(--gray-soft); color: var(--ink-2); }
.badge.P1, .badge.overage, .badge.bad { background: var(--red-soft); color: var(--red); }
.badge.P2, .badge.expire, .badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.P3, .badge.info { background: var(--blue-soft); color: var(--blue); }
.badge.grant, .badge.ok { background: var(--green-soft); color: var(--green); }
.badge.consume { background: var(--brand-soft); color: var(--brand); }
.badge.wrap { height: auto; padding: 3px 7px; line-height: 1.4; white-space: normal; font-weight: 500; }
.signals { display: grid; gap: 4px; min-width: 190px; }
.status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 13px; color: var(--ink-2); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.status.open::before { background: var(--blue); }
.status.in_progress::before { background: var(--brand); }
.status.awaiting_approval::before, .status.pending::before { background: var(--amber); }
.status.resolved::before, .status.approved::before, .status.active::before { background: var(--green); }
.status.closed::before, .status.ended::before { background: var(--line-2); }
.status.rejected::before { background: var(--red); }
.meter { height: 6px; border-radius: 99px; background: var(--gray-soft); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.meter.warn > i { background: var(--amber); }
.meter.bad > i { background: var(--red); }
.w-after_hours { color: var(--amber); }
.w-weekend, .w-holiday { color: var(--red); }
.neg { color: var(--red); }

/* ---------- Forms ---------- */
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 6px; height: 36px; padding: 0 11px; width: 100%; min-width: 0; transition: border-color .12s, box-shadow .12s; }
textarea { height: auto; min-height: 84px; padding: 8px 11px; line-height: 1.5; resize: vertical; }
select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237A838F' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: .8; }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > span { font-size: 13px; font-weight: 500; }
.field > small { font-size: 12px; color: var(--ink-3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 16px; align-items: start; }
.form-stack { display: grid; gap: 14px; }
.form-section { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 28px; padding: 22px; border-bottom: 1px solid var(--line); }
.form-section > header p { margin-top: 4px; font-size: 13px; color: var(--ink-3); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
@media (max-width: 900px) { .form-section { grid-template-columns: 1fr; gap: 12px; } }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 500; white-space: nowrap; cursor: pointer; box-shadow: var(--shadow-sm); transition: background .12s, border-color .12s, color .12s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--gray-soft); color: var(--ink); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- Feedback ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: var(--radius); font-size: 13.5px; }
.alert .ic { width: 17px; height: 17px; margin-top: 1px; }
.alert-success { background: var(--green-soft); color: var(--green); }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-warn { background: var(--amber-soft); color: var(--amber); }
.alert code { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--ink); background: var(--surface); padding: 1px 6px; border-radius: 4px; user-select: all; }
.empty { display: grid; justify-items: center; gap: 6px; padding: 36px 20px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.empty .ic { width: 28px; height: 28px; color: var(--line-2); }

/* ---------- Toolbar & segmented filter ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.toolbar select, .toolbar input { width: auto; min-width: 170px; height: 32px; font-size: 13px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--gray-soft); border-radius: 8px; }
.segmented a { padding: 4px 12px; border-radius: 6px; color: var(--ink-2); font-size: 13px; font-weight: 500; white-space: nowrap; }
.segmented a:hover { color: var(--ink); text-decoration: none; }
.segmented a.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(16, 24, 32, .1); }

/* ---------- Ticket page pieces ---------- */
.usage { display: grid; gap: 10px; }
.usage .big { display: flex; align-items: baseline; gap: 6px; }
.usage .big b { font-size: 30px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.usage .big span { color: var(--ink-3); }
.preview { font-size: 13px; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line-2); border-radius: 6px; padding: 8px 12px; }
.preview.over { background: var(--red-soft); border-color: transparent; color: var(--red); }
.mailtext { margin: 0; max-height: 280px; overflow: auto; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--ink-2); white-space: pre-wrap; }
.est { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.est:first-child { padding-top: 0; border-top: 0; }
.est-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.segs { display: grid; gap: 2px; font-size: 12.5px; }
.segs span { white-space: nowrap; }

/* ---------- Sign-in screens ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-md); padding: 30px 28px 26px; display: grid; gap: 20px; }
.auth-brand { display: flex; align-items: center; gap: 11px; }
.auth-brand .mark { width: 38px; height: 38px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.auth-brand .mark .ic { width: 22px; height: 22px; stroke-width: 2; }
.auth-brand b { display: block; font-size: 16px; }
.auth-brand small { color: var(--ink-3); font-size: 12.5px; }
.auth h1 { font-size: 19px; }
.auth .foot { font-size: 12.5px; color: var(--ink-3); text-align: center; }

/* ---------- Statement: a paper document in either theme ---------- */
.doc { --ink: #15191E; --ink-2: #4A525D; --ink-3: #7A838F; --line: #E3E6EA; --surface-2: #F6F7F9; --gray-soft: #EDEFF2;
  --red: #BF3A2F; --red-soft: #FCECEA; --amber: #A95F09; --amber-soft: #FCF1E1; --blue: #2863AA; --blue-soft: #E7EFF9;
  background: #fff; color: var(--ink); max-width: 860px; padding: 40px 44px; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); display: grid; gap: 26px; }
.doc thead th { background: var(--surface-2); }
.doc tbody tr:hover td { background: transparent; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.doc-head .issuer { display: flex; gap: 10px; align-items: center; }
.doc-head .issuer .mark { width: 34px; height: 34px; border-radius: 8px; background: #0B6B73; color: #fff; display: grid; place-items: center; }
.doc-title { font-size: 18px; font-weight: 600; }
.lines { list-style: none; padding: 0; }
.lines li { display: grid; grid-template-columns: 118px 1fr auto; gap: 16px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.lines .k { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.lines .v { min-width: 90px; text-align: right; font-variant-numeric: tabular-nums; }
.lines li.total { font-weight: 600; border-top: 1.5px solid var(--ink); }
.lines li.sub .v::before { content: "− "; color: var(--ink-3); }
.lines li.muted-row { color: var(--ink-3); }

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .noprint, .alert { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .doc { border: 0; box-shadow: none; padding: 0; max-width: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
