:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --line: #e2e8f0;
  --line-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-sub: #0b1120;
  --sidebar-hover: #1e293b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-ink: #ffffff;
  --danger: #e11d48;
  --ok: #059669;
  --ok-dot: #10b981;
  --warn: #ea580c;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, .05), 0 2px 4px -2px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-family: 'Inter', -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
.sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono, code { font-family: var(--mono); }
.muted { color: var(--muted); }
.num { text-align: end; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.error, .login-error { color: var(--danger); }
.warn-text { color: var(--warn); font-weight: 600; }
.danger-text { color: var(--danger); }
[lang="my"] { line-height: 1.8; }

/* ---------- TSMS Slip System Sidebar + Main Shell ---------- */
.tsms-layout { display: flex; min-block-size: 100dvh; }
.sidebar {
  inline-size: 260px; background-color: var(--sidebar-bg); color: #fff;
  min-block-size: 100dvh; position: fixed; inset-block-start: 0; inset-inline-start: 0; z-index: 100;
  display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.sidebar-brand {
  padding: 1.4rem 1.25rem 1.4rem 1.5rem; border-block-end: 1px solid #1e293b;
  display: flex; align-items: center; gap: 1rem;
}
.sidebar-close-btn {
  margin-inline-start: auto; background: rgba(255, 255, 255, .07); color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, .1); border-radius: 6px;
  inline-size: 30px; block-size: 30px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .15s;
}
.sidebar-close-btn:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.sidebar-brand .logo-placeholder {
  min-inline-size: 40px; block-size: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-brand .logo-placeholder img { inline-size: 40px; block-size: 40px; object-fit: contain; }
.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.sidebar-brand .brand-tsms { font-size: 1.4rem; font-weight: 800; letter-spacing: 1px; color: #fff; }
.sidebar-brand .brand-command { font-size: 0.85rem; font-weight: 700; letter-spacing: 2px; color: #94a3b8; }

.sidebar-selector {
  padding: 1rem 1.5rem; background-color: var(--sidebar-sub);
  border-block-end: 1px solid rgba(148, 163, 184, .18);
  display: grid; gap: 6px;
}
.selector-label {
  color: #94a3b8; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; margin-block-start: 4px;
}
.sidebar-selector select {
  inline-size: 100%; background-color: #1e293b; color: #fff;
  border: 1px solid #334155; border-radius: 6px; padding: 6px 10px;
  font-size: 0.85rem; font-weight: 500; cursor: pointer;
}
.sidebar-selector select option { background-color: #0f172a; color: #fff; }
.plat-row { display: flex; align-items: center; gap: 8px; }
.plat-row select { flex: 1; }

.menu-label {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: #64748b; margin: 1.4rem 1.5rem 0.45rem; font-weight: 600;
}
.sidebar-nav { display: flex; flex-direction: column; }
.menu-item {
  display: flex; align-items: center; gap: 10px; inline-size: 100%;
  padding: 0.75rem 1.5rem; color: #cbd5e1; background: none; border: 0;
  border-inline-start: 4px solid transparent; text-align: start;
  font: inherit; font-weight: 500; cursor: pointer; transition: 0.2s;
}
.menu-item i { inline-size: 22px; text-align: center; font-size: 0.95rem; }
.menu-item:hover, .menu-item.active {
  background-color: var(--sidebar-hover); color: #fff;
  border-inline-start-color: var(--primary);
}
.badge {
  background: #f59e0b; color: #fff; border-radius: 999px;
  padding: 1px 7px; font-size: 11px; font-weight: 700; margin-inline-start: auto;
}

.main-shell {
  margin-inline-start: 260px; flex: 1; display: flex; flex-direction: column; min-block-size: 100dvh;
  max-inline-size: calc(100vw - 260px);
  transition: margin-inline-start .22s ease, max-inline-size .22s ease;
}
.sidebar-collapsed .main-shell {
  margin-inline-start: 0;
  max-inline-size: 100vw;
}
.topbar {
  position: sticky; inset-block-start: 0; z-index: 50;
  background-color: rgba(255, 255, 255, 0.95); backdrop-filter: blur(5px);
  padding: 1rem 2rem; border-block-end: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; min-block-size: 70px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.btn-sidebar-toggle {
  background: #f8fafc; border: 1px solid var(--line); color: var(--text);
  inline-size: 36px; block-size: 36px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .15s;
}
.btn-sidebar-toggle:hover { background: var(--panel-2); color: var(--primary); }
.topbar-title { margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--text); }
.plat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(59, 130, 246, .1); color: var(--primary);
  padding: 3px 10px; border-radius: 8px; font-size: 0.82rem; font-weight: 700;
}
.topbar-plat-select {
  background: transparent; border: 0; color: var(--primary);
  font: inherit; font-weight: 700; padding: 2px 4px; cursor: pointer;
}
.topbar-plat-select option { color: var(--text); background: #fff; }
@keyframes tsms-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.dot { inline-size: 9px; block-size: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-on { background: var(--ok-dot); box-shadow: 0 0 0 3px rgba(16, 185, 129, .25); animation: tsms-pulse 2s infinite; }
.dot-off { background: var(--danger); }

.userbox { display: flex; align-items: center; gap: 10px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; font-weight: 600; color: var(--text); font-size: 13px;
}
.role {
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: rgba(59, 130, 246, .12); color: var(--primary);
}
.btn-logout {
  background: #fff; border: 1px solid var(--line); color: var(--danger);
  font-weight: 600; padding: 6px 12px; border-radius: 8px;
}
.btn-logout:hover { background: #ffe4e6; border-color: #fecdd3; }

main { padding: 1.75rem 2rem; flex: 1; }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid #cbd5e1;
  border-radius: 8px; padding: 7px 11px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, .table-wrapper:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
textarea { inline-size: 100%; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: #334155; text-decoration: none;
  font-size: 13px; transition: 0.15s;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary, .filters button[type="submit"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled), .filters button[type="submit"]:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #be123c; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { display: flex; inline-size: 100%; }
.btn-row { display: flex; gap: 5px; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.inline { display: inline-flex; align-items: center; gap: 6px; color: #475569; font-size: 13px; font-weight: 500; }

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-block-end: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; box-shadow: var(--shadow);
}
.filters input[type="search"] { min-inline-size: 270px; }
.bulkbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; margin-block-end: 12px;
  background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}
.banner { padding: 12px 2rem; }
.banner-block { background: #ffe4e6; color: #be123c; border-block-end: 1px solid #fecdd3; font-weight: 600; }
.banner-warn { background: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; border-radius: var(--radius); margin-block-start: 8px; }

/* ---------- TSMS KPI Scorecards ---------- */
.stats { display: flex; gap: 12px; margin-block-end: 16px; flex-wrap: wrap; }
.stats div, .stat-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 18px; display: grid; gap: 2px; text-align: start; font: inherit; color: inherit;
  box-shadow: var(--shadow); min-inline-size: 145px;
}
.stats span, .stat-btn span { font-size: 12px; font-weight: 600; color: var(--muted); }
.stats b, .stat-btn b { font-size: 1.45rem; font-weight: 700; color: var(--text); }
.stat-btn { cursor: pointer; transition: border-color .15s, background .15s, transform .1s; }
.stat-btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.stat-btn.active { border-color: var(--primary); background: #eff6ff; box-shadow: 0 0 0 1px var(--primary); }
.stat-btn.active b { color: var(--primary); }

/* ---------- tables (TSMS rounded-4 card + sticky headers) ---------- */
.table-wrapper {
  overflow: auto; max-inline-size: 100%; max-block-size: calc(100dvh - 250px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow);
  container-type: inline-size;
}
table { border-collapse: separate; border-spacing: 0; inline-size: 100%; font-size: 13.5px; }
caption { text-align: start; padding: 12px 18px; color: var(--text); font-weight: 700; font-size: 14px; border-block-end: 1px solid var(--line); }
th, td { padding: 11px 14px; border-block-end: 1px solid var(--line-soft); text-align: start; vertical-align: middle; }
thead { position: sticky; inset-block-start: 0; z-index: 1; }
thead th {
  background: #f8fafc; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); border-block-end: 2px solid var(--line); white-space: nowrap;
}
tbody th { font-weight: 600; }
tbody tr:hover td, tbody tr:hover th { background: #f8fafc; }
tr.selected td, tr.selected th { background: #eff6ff; }
td.actions { white-space: nowrap; }
td.msg { max-inline-size: 420px; }
td.msg small { display: block; }
td.reason { max-inline-size: 320px; min-inline-size: 200px; }
td.reason b { font-size: 12px; display: block; color: var(--text); }
.mm-short { margin: 2px 0; font-size: 12px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.empty { text-align: center; color: var(--muted); padding: 40px 24px; }
table.mini { font-size: 13px; border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- TSMS status pills ---------- */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: #f8fafc; border: 1px solid var(--line); color: #475569; white-space: nowrap;
}
.btn-pill { cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }
.btn-pill:hover { filter: brightness(0.95); }
.tag { font-size: 11px; color: var(--muted); margin-inline-start: 4px; }
.st-pending { color: #ea580c; background-color: #ffedd5; border-color: #fed7aa; }
.st-success, .st-on, .ts-success { color: #059669; background-color: #d1fae5; border-color: #a7f3d0; }
.st-refuse, .ts-failed, .ts-error, .ts-rejected { color: #e11d48; background-color: #ffe4e6; border-color: #fecdd3; }
.st-warn, .ts-uncertain, .ts-unknown { color: #8b5cf6; background-color: #f3e8ff; border-color: #e9d5ff; }
.st-off { color: #64748b; background-color: #f8fafc; border-color: #e2e8f0; }
.ts-queued, .ts-processing { color: #0284c7; background-color: #e0f2fe; border-color: #bae6fd; }

.meter { inline-size: 120px; block-size: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.meter span { display: block; block-size: 100%; background: var(--primary); }
.meter span.hot { background: var(--danger); }

/* ---------- dialogs ---------- */
dialog.dlg {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text);
  inline-size: min(560px, 94vw); max-block-size: 90dvh;
}
dialog.dlg-wide { inline-size: min(900px, 96vw); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dlg-body { padding: 16px 20px; display: grid; gap: 12px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-foot {
  display: flex; align-items: center; gap: 8px; position: sticky; inset-block-end: 0;
  background: var(--panel); padding-block: 10px 0; border-block-start: 1px solid var(--line);
}
.field { display: grid; gap: 4px; font-weight: 600; }
.field input, .field select, .field textarea { font-weight: 400; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.hint { color: var(--warn); margin: 0; }
.confirm { color: var(--warn); font-weight: 600; }
h3 { margin: 4px 0; font-size: 14px; }

.verdicts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-block-size: 40dvh; overflow: auto; }
.verdicts > li { border: 1px solid var(--line); border-inline-start-width: 4px; border-radius: 6px; padding: 6px 10px; }
.verdicts ul { margin: 4px 0 0; padding-inline-start: 18px; }
.verdicts .lv { font-size: 11px; font-weight: 700; margin-inline-end: 6px; }
li.lv-ok { border-inline-start-color: var(--ok); }
li.lv-info { border-inline-start-color: var(--primary); }
li.lv-warn { border-inline-start-color: var(--warn); }
li.lv-block { border-inline-start-color: var(--danger); }
.verdicts ul li.lv-warn { color: var(--warn); }
.verdicts ul li.lv-block { color: var(--danger); }
.verdicts ul li.lv-info { color: var(--muted); }

.tpl-preview { background: var(--panel-2); border-radius: var(--radius); padding: 8px 12px; font-weight: 400; }
.tpl-preview p { margin: 4px 0; }
.paid-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; background: var(--panel-2); padding: 10px; border-radius: var(--radius); font-weight: 400; }
.paid-summary span { display: block; font-size: 12px; color: var(--muted); }
.seg { display: flex; gap: 16px; font-weight: 400; }
.pay-row { display: flex; gap: 6px; }
.pay-row input:first-child { flex: 2; }
.pay-row input + input { flex: 1; }
.split-total { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.diff ul { margin: 0; padding-inline-start: 18px; }
.diff .before { text-decoration: line-through; color: var(--muted); }
.diff .after { color: var(--primary); font-weight: 600; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 16px; margin: 0; }
.kv div { display: grid; }
.kv dt { font-size: 12px; color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- system users ---------- */
.users-grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
@media (max-width: 960px) { .users-grid { grid-template-columns: 1fr; } }
.users-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}
.users-card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.users-form { display: grid; gap: 12px; margin-block-start: 14px; }
.plat-badges { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- templates ---------- */
.tpl-list { display: grid; gap: 8px; padding-inline-start: 24px; }
.tpl-list li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.tpl-list li.inactive { opacity: .55; }
.tpl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tpl-list p { margin: 4px 0; }
.en { color: var(--muted); }
.mm { font-size: 15px; }
.note { font-size: 12px; color: var(--warn); }

/* ---------- toasts ---------- */
.toasts { position: fixed; inset-block-end: 16px; inset-inline-end: 16px; display: grid; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 20px rgb(0 0 0 / .15); max-inline-size: 380px; }
.toast-ok { border-inline-start: 4px solid var(--ok); }
.toast-warn { border-inline-start: 4px solid var(--warn); }
.toast-error { border-inline-start: 4px solid var(--danger); }

/* ---------- login (TSMS Slip System style) ---------- */
.login-body { min-block-size: 100dvh; display: flex; align-items: center; justify-content: center; background: #f8f9fa; }
.login-card {
  background: var(--panel); border-radius: 1rem; inline-size: min(400px, 92vw);
  overflow: hidden; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}
.login-header {
  background: linear-gradient(135deg, #0d6efd, #0dcaf0);
  padding: 2rem; color: #fff; display: grid; gap: 10px; justify-items: center;
}
.login-header h3 { margin: 0; font-size: 1.4rem; font-weight: 700; }
.login-content { padding: 2rem 1.75rem; display: grid; gap: 14px; }
.dev-login { display: grid; gap: 8px; border-block-start: 1px dashed var(--line); padding-block-start: 12px; }

/* ---------- narrow containers: stacked rows ---------- */
@container (width < 700px) {
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tbody tr { border-block-end: 2px solid var(--line); padding-block: 6px; }
  th, td { border: 0; padding: 3px 10px; }
}
