:root {
  --bg: #f3f5f7; --card: #fff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #0f766e; --brand-2: #14b8a6; --brand-soft: #ccfbf1;
  --side: #0b1f2a; --side-ink: #cbd5e1;
  --ok: #16a34a; --ok-soft: #dcfce7; --warn: #d97706; --warn-soft: #fef3c7;
  --bad: #dc2626; --bad-soft: #fee2e2; --info: #2563eb; --info-soft: #dbeafe; --gray-soft: #f1f5f9;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 15px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 19px; padding: 0 8px 20px; }
.logo b { background: var(--brand-2); color: var(--side); border-radius: 9px; padding: 2px 8px; }
.nav a { display: flex; gap: 10px; align-items: center; color: var(--side-ink); padding: 10px 12px; border-radius: 10px; margin-bottom: 2px; }
.nav a:hover { background: #ffffff12; text-decoration: none; }
.nav a.on { background: var(--brand); color: #fff; }
.nav .ico { width: 20px; text-align: center; }
.side .foot { margin-top: auto; font-size: 12px; color: #64748b; padding: 0 8px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-nav { display: none; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.brand { background: linear-gradient(135deg, #0f766e, #0d9488); color: #fff; border: 0; }
.kpi.brand .label, .kpi.brand .sub { color: #ccfbf1; }
.kpi.bad .value { color: var(--bad); }
.kpi.ok .value { color: var(--ok); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafc; }
tr.row-overdue td { background: #fff7f7; }
tr.row-paid td { color: #94a3b8; }
tfoot td { font-weight: 700; background: #f8fafc; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-active { background: var(--info-soft); color: var(--info); }
.b-overdue { background: var(--bad-soft); color: var(--bad); }
.b-closed, .b-paid { background: var(--ok-soft); color: var(--ok); }
.b-pending { background: var(--gray-soft); color: var(--muted); }
.b-due_today { background: var(--warn-soft); color: var(--warn); }
.b-bad_debt { background: #1e293b; color: #fff; }
.b-cancelled { background: var(--gray-soft); color: #94a3b8; text-decoration: line-through; }
.b-repossessed { background: #ede9fe; color: #7c3aed; }
.b-loan { background: var(--brand-soft); color: var(--brand); }
.b-hp { background: #fae8ff; color: #a21caf; }
.b-discount { background: var(--warn-soft); color: var(--warn); }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 10px; font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.inline { display: flex; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #115e59; }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; font: inherit; font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { max-width: 320px; }
.err { color: var(--bad); font-size: 13px; margin-top: 6px; min-height: 18px; }
.hint { background: var(--brand-soft); color: #134e4a; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.6; }
.hint.warn { background: var(--warn-soft); color: #78350f; }

/* key-values */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* chart */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 180px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-stack { width: 100%; max-width: 54px; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 0 0; overflow: hidden; }
.bar-stack div { width: 100%; }
.c-int { background: var(--brand); } .c-prin { background: #5eead4; } .c-hp { background: #c026d3; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: #0f172a80; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 14px; z-index: 50; overflow-y: auto; }
.modal-box { background: #fff; border-radius: 16px; padding: 22px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px #0004; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; font-size: 14px; }
.toast.bad { background: var(--bad); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 20%, #134e4a, #0b1f2a 60%); padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .logo { color: var(--ink); justify-content: center; padding-bottom: 6px; font-size: 24px; }

/* receipt */
.receipt { max-width: 560px; margin: 0 auto; background: #fff; padding: 28px; border: 1px solid var(--line); border-radius: 12px; }
.receipt h1 { text-align: center; font-size: 20px; }
.receipt .line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.receipt .total { font-size: 20px; font-weight: 700; }
.sign { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 50px; text-align: center; font-size: 13px; }
.sign div { border-top: 1px solid #94a3b8; padding-top: 6px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: none; }
  .mobile-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--side); z-index: 40; justify-content: space-around; padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav a { color: var(--side-ink); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 8px; border-radius: 8px; }
  .mobile-nav a.on { color: #fff; background: var(--brand); text-decoration: none; }
  .main { padding: 16px 14px 90px; }
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3, .g2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 20px; }
  .kv { grid-template-columns: 110px 1fr; }
}
@media print {
  .side, .mobile-nav, .topbar .actions, .no-print { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .receipt { border: 0; }
}

/* credit grades */
.grade { display: inline-flex; align-items: baseline; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.grade small { font-weight: 500; font-size: 11.5px; }
.g-A { background: var(--ok-soft); color: #15803d; }
.g-B { background: #e0f2fe; color: #0369a1; }
.g-C { background: var(--warn-soft); color: #b45309; }
.g-D { background: var(--bad-soft); color: var(--bad); }
.g-F { background: #1e293b; color: #fff; }
.g-N { background: var(--gray-soft); color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grade-sum { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
tr.row-today td { background: #fffbeb; }
.credit-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--gray-soft); margin: 8px 0; }
.credit-bar div { height: 100%; }
.kpi-inline { display: flex; gap: 22px; flex-wrap: wrap; }
.kpi-inline div { display: flex; flex-direction: column; }
.kpi-inline b { font-size: 20px; font-variant-numeric: tabular-nums; }

/* multi-tenant */
.shop { color: #fff; font-weight: 600; padding: 0 8px 16px; font-size: 14px; line-height: 1.4; }
.shop span { display: block; color: var(--brand-2); font-size: 12px; font-weight: 500; }
.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.info { background: var(--brand-soft); color: #134e4a; }
.banner.warn { background: var(--warn-soft); color: #78350f; }
.banner.bad { background: var(--bad-soft); color: #7f1d1d; }
.banner .btn { margin-left: auto; }
.pair { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pair-step { display: flex; gap: 10px; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-size: 14px; }
.pair-step > b { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; }
.pair .code { font-size: 28px; font-weight: 700; letter-spacing: 6px; color: var(--brand); margin: 4px 0; user-select: all; }
.btn.line { background: #06c755; border-color: #06c755; color: #fff; }
.btn.block { width: 100%; justify-content: center; }
.plan-card { border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; }
.plan-card.hot { border: 2px solid var(--brand); }
.plan-card h3 { margin: 0; font-size: 18px; }
.plan-card .price { font-size: 28px; font-weight: 700; margin-top: 8px; }
.plan-card .price small { font-size: 14px; color: var(--muted); font-weight: 500; }
.plan-card ul { padding: 0 0 0 18px; margin: 12px 0 16px; flex: 1; font-size: 14px; color: var(--ink-2, #334155); }
@media (max-width: 900px) { .pair { grid-template-columns: 1fr; } }

/* LINE: ตัวอย่างหน้าจอมือถือข้างการตั้งค่า */
.line-split { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 24px; align-items: start; }
.line-split .pair { grid-template-columns: 1fr; }
.line-side { position: sticky; top: 16px; }
@media (max-width: 1100px) { .line-split { grid-template-columns: 1fr; } .line-split .pair { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .line-split .pair { grid-template-columns: 1fr; } }
.modal-box.wide { max-width: 860px; }
.send-split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
@media (max-width: 820px) { .send-split { grid-template-columns: 1fr; } }
