/* H2O CRM — Iceland-spring inspired theme: deep navy, glacier blue, white, pill buttons, Kanit */
:root {
  --navy: #2f4c90; --navy-d: #1b2c55; --navy-dd: #12203f; --ice: #a5cbed; --ice-l: #eaf3fb; --ice-ll: #f5f9fd;
  --bg: #f4f7fb; --card: #ffffff; --line: #dde6f1; --text: #1a2233; --muted: #6b778c; --red: #fa1414; --red-l: #ffecec;
  --green: #12a150; --green-l: #e6f7ee; --amber: #d98b00; --amber-l: #fff5e0; --radius: 14px; --shadow: 0 2px 10px rgba(27, 44, 85, .07);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Kanit', 'Sarabun', system-ui, sans-serif; font-weight: 300; background: var(--bg); color: var(--text); font-size: 15px; }
b, strong, h1, h2, h3, h4, th { font-weight: 500; }
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; color: var(--navy-d); }
h2 { font-size: 18px; margin: 0 0 10px; color: var(--navy-d); }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--navy); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 30; height: 58px; display: flex; align-items: center; gap: 14px; padding: 0 18px; background: linear-gradient(90deg, var(--navy-d), var(--navy)); color: #fff; box-shadow: 0 2px 12px rgba(18, 32, 63, .25); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 500; letter-spacing: .5px; color: #fff; }
.brand small { font-weight: 300; color: var(--ice); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.topbar .sp { flex: 1; }
.topbar .who { font-size: 13px; color: var(--ice); text-align: right; line-height: 1.2; }
.topbar .burger { display: none; background: none; border: 0; color: #fff; font-size: 24px; cursor: pointer; }
.layout { display: flex; min-height: calc(100vh - 58px); }
.side { width: 220px; flex: none; background: #fff; border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 58px; height: calc(100vh - 58px); overflow: auto; }
.side a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 99px; color: var(--text); margin-bottom: 2px; }
.side a:hover { background: var(--ice-l); text-decoration: none; }
.side a.on { background: var(--navy); color: #fff; }
.side a .ic { width: 20px; text-align: center; }
.side a .badge { margin-left: auto; }
.side .grp { font-size: 11px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; margin: 14px 12px 4px; }
.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
@media (max-width: 860px) {
  .topbar .burger { display: block; }
  .side { position: fixed; left: -240px; top: 58px; z-index: 25; transition: left .2s; box-shadow: 4px 0 20px rgba(0, 0, 0, .1); }
  .side.open { left: 0; }
  .main { padding: 16px 16px 60px; }
  .topbar .who span.nm { display: none; }
}

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flat { box-shadow: none; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.top { align-items: flex-start; }
.grow { flex: 1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); } .g6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 500; color: var(--navy-d); margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi.hl { background: linear-gradient(135deg, var(--navy), var(--navy-d)); color: #fff; border: 0; }
.kpi.hl .l, .kpi.hl .s { color: var(--ice); }
.kpi.hl .v { color: #fff; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--navy); background: var(--navy); color: #fff; padding: 7px 18px; border-radius: 99px; font: inherit; font-weight: 400; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--navy-d); border-color: var(--navy-d); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--navy); }
.btn.ghost:hover { background: var(--ice-l); }
.btn.red { background: var(--red); border-color: var(--red); }
.btn.red.ghost { background: #fff; color: var(--red); }
.btn.green { background: var(--green); border-color: var(--green); }
.btn.sm { padding: 3px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.linkbtn { background: none; border: 0; color: var(--navy); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

input, select, textarea { font: inherit; font-weight: 300; font-size: 14px; border: 1px solid #c9d6e6; border-radius: 10px; padding: 7px 10px; background: #fff; color: var(--text); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ice); border-color: var(--navy); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--navy); }
textarea { min-height: 70px; resize: vertical; }
label.f { display: block; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea, label.f > .ctl { margin-top: 3px; }
label.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; margin-right: 12px; }
.req-star { color: var(--red); }
.lines td:first-child { min-width: 260px; }
.doc-grid { grid-template-columns: minmax(0, 2fr) minmax(290px, 1fr); }
@media (max-width: 1000px) { .doc-grid { grid-template-columns: minmax(0, 1fr); } }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 16px; margin: 0 0 14px; background: #fff; }
legend { padding: 0 8px; color: var(--navy); font-weight: 500; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 400; padding: 8px 10px; border-bottom: 2px solid var(--line); background: var(--ice-ll); white-space: nowrap; }
.t td { padding: 8px 10px; border-bottom: 1px solid #edf2f8; vertical-align: top; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: var(--ice-ll); }
.t tfoot td { font-weight: 500; border-top: 2px solid var(--line); }
.tw { overflow-x: auto; }

.chip { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: 12px; font-weight: 400; background: var(--ice-l); color: var(--navy); white-space: nowrap; }
.chip.green { background: var(--green-l); color: var(--green); }
.chip.red { background: var(--red-l); color: var(--red); }
.chip.amber { background: var(--amber-l); color: var(--amber); }
.chip.gray { background: #eef0f3; color: #5d6676; }
.chip.navy { background: var(--navy); color: #fff; }
.chip.line { background: #06c755; color: #fff; }
.badge { background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; min-width: 18px; text-align: center; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; cursor: pointer; }
.tabs a.on { color: var(--navy); border-color: var(--navy); font-weight: 500; }
.tabs a:hover { text-decoration: none; color: var(--navy); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy-d); color: #fff; padding: 10px 22px; border-radius: 99px; z-index: 100; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: 90vw; }
.toast.err { background: var(--red); }
.modal-bg { position: fixed; inset: 0; background: rgba(18, 32, 63, .45); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow: auto; }
.modal { background: #fff; border-radius: 18px; width: 100%; max-width: 640px; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 920px; }
.modal h2 { display: flex; align-items: center; }
.modal h2 .x { margin-left: auto; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.bars .b { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
.bars .b .lb { width: 130px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .b .tr { flex: 1; background: var(--ice-l); border-radius: 99px; height: 14px; overflow: hidden; }
.bars .b .fl { height: 100%; background: linear-gradient(90deg, var(--ice), var(--navy)); border-radius: 99px; }
.bars .b .vl { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.cols { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.cols .c { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.cols .c .bar { width: 100%; max-width: 46px; background: linear-gradient(180deg, var(--navy), var(--navy-d)); border-radius: 8px 8px 3px 3px; min-height: 2px; }
.cols .c .x { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.cols .c .y { font-size: 10.5px; color: var(--navy); margin-bottom: 2px; white-space: nowrap; }

/* customer header */
.chead { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; background: linear-gradient(120deg, var(--navy-d), var(--navy) 60%, #4e78c4); color: #fff; border-radius: 18px; padding: 18px 22px; margin-bottom: 16px; position: relative; overflow: hidden; }
.chead::after { content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle, rgba(165, 203, 237, .35), transparent 70%); }
.chead .av { width: 60px; height: 60px; border-radius: 50%; background: rgba(255, 255, 255, .15); display: grid; place-items: center; font-size: 26px; overflow: hidden; flex: none; }
.chead .av img { width: 100%; height: 100%; object-fit: cover; }
.chead .nm { font-size: 21px; font-weight: 500; }
.chead .sub { color: var(--ice); font-size: 13px; }
.chead .pts { margin-left: auto; text-align: right; z-index: 1; }
.chead .pts .v { font-size: 30px; font-weight: 500; }
.chead .chip { background: rgba(255, 255, 255, .18); color: #fff; }
.stat { padding: 10px 12px; background: var(--ice-ll); border-radius: 12px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 500; color: var(--navy-d); }
.timeline .it { border-left: 2px solid var(--ice); padding: 0 0 12px 14px; position: relative; }
.timeline .it::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--navy); }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.warnbox { background: var(--amber-l); border: 1px solid #f3d189; color: #7a5200; padding: 10px 14px; border-radius: 12px; margin: 8px 0; }
.errbox { background: var(--red-l); border: 1px solid #f5b5b5; color: #a30d0d; padding: 10px 14px; border-radius: 12px; margin: 8px 0; }
.infobox { background: var(--ice-l); border: 1px solid var(--ice); color: var(--navy-d); padding: 10px 14px; border-radius: 12px; margin: 8px 0; }
.code { font-family: Consolas, monospace; background: var(--ice-ll); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 10%, #4e78c4, transparent), linear-gradient(135deg, var(--navy-dd), var(--navy)); padding: 16px; }
.login .box { background: #fff; border-radius: 22px; padding: 30px 30px 26px; width: 100%; max-width: 380px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.login .logo { display: flex; align-items: center; gap: 10px; color: var(--navy-d); font-size: 22px; font-weight: 500; margin-bottom: 4px; }
.picker { position: relative; }
.picker .dd { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .12); z-index: 20; max-height: 280px; overflow: auto; }
.picker .dd div { padding: 8px 12px; cursor: pointer; }
.picker .dd div:hover { background: var(--ice-l); }
.lines td input, .lines td select { padding: 5px 8px; }
.sum-box { background: var(--ice-ll); border-radius: 14px; padding: 12px 16px; }
.sum-box .r { display: flex; justify-content: space-between; padding: 3px 0; }
.sum-box .r.t { font-size: 18px; font-weight: 500; color: var(--navy-d); border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }

/* ---- collapsible sidebar (icons only) ---- */
.topbar .collapse { background: none; border: 0; color: #fff; font-size: 20px; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.topbar .collapse:hover { background: rgba(255, 255, 255, .12); }
.side a .lb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout.mini .side { width: 62px; padding: 14px 6px; }
.layout.mini .side a { justify-content: center; padding: 9px 0; position: relative; }
.layout.mini .side a .lb { display: none; }
.layout.mini .side a .badge { position: absolute; top: 2px; right: 4px; font-size: 9px; min-width: 14px; padding: 0 4px; }
@media (max-width: 860px) { .topbar .collapse { display: none; } .layout.mini .side { width: 220px; } .layout.mini .side a .lb { display: inline; } }

/* ---- compact filter bars ---- */
.filters { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: flex-end; }
.filters label.f { font-size: 11.5px; }
.filters input, .filters select { font-size: 13px; padding: 4px 8px; border-radius: 8px; height: 30px; }
.filters select { width: auto; max-width: 170px; }
.filters input[type=date] { width: 132px; }
.filters .q { flex: 1; min-width: 180px; }
.filters .btn { padding: 4px 14px; font-size: 13px; height: 30px; }
.card.fbar { padding: 10px 12px; }
.quick { display: flex; gap: 4px; flex-wrap: wrap; }
.quick .btn { padding: 2px 10px; font-size: 12px; height: 26px; }

/* ---- dense tables / editor ---- */
.t.dense { font-size: 13px; }
.t.dense td, .t.dense th { padding: 5px 8px; }
.t th.sort { cursor: pointer; user-select: none; }
.t th.sort:hover { color: var(--navy); }
.t th.sort.on { color: var(--navy); font-weight: 500; }
.t th.sort .ar { font-size: 10px; margin-left: 3px; }
.t thead.stick th { position: sticky; top: 58px; z-index: 2; }
.ell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dense-ed { font-size: 13.5px; }
.dense-ed .card { padding: 10px 12px; margin-bottom: 10px; }
.dense-ed h3 { font-size: 14px; margin-bottom: 6px; }
.dense-ed .grid { gap: 8px; }
.dense-ed label.f { font-size: 11.5px; }
.dense-ed input, .dense-ed select, .dense-ed textarea { font-size: 13px; padding: 4px 8px; border-radius: 8px; }
.dense-ed .t { font-size: 13px; }
.dense-ed .t td, .dense-ed .t th { padding: 4px 6px; }
.dense-ed .lines td:first-child { min-width: 200px; }
.dense-ed .lines td select, .dense-ed .lines td input { padding: 3px 6px; }
.dense-ed .sum-box { padding: 10px 12px; font-size: 13px; }
.dense-ed .sum-box .r.t { font-size: 16px; }
.dense-ed .chk { font-size: 13px; }
.dense-ed .doc-grid { grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1fr); }
@media (max-width: 1000px) { .dense-ed .doc-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---- dashboard overflow ---- */
.kpi { min-width: 0; overflow: hidden; }
.kpi .v { font-size: clamp(17px, 1.55vw, 24px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card { min-width: 0; }
.bars .b .lb { width: auto; flex: 0 0 34%; max-width: 170px; }
.bars .b .vl { width: auto; flex: none; min-width: 80px; }
.cols .c .y { font-size: 10px; }
.t.top10 td { white-space: nowrap; }
.t.top10 td.nm { max-width: 0; width: 60%; overflow: hidden; text-overflow: ellipsis; }

/* ---- vouchers ---- */
tr.used td { color: var(--muted); }
tr.used td.code { text-decoration: line-through; }
.progress { height: 10px; background: var(--ice-l); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--ice), var(--navy)); border-radius: 99px; }
.progress.big { height: 16px; }
.rank1 td { background: #fff8e1; }
.me td { background: var(--ice-l) !important; font-weight: 500; }
.filters label.f > input, .filters label.f > select { display: block; margin-top: 2px; }
