:root {
  color-scheme: light;
  --bg: #f8f5f0;
  --panel: #fff;
  --ink: #2c211d;
  --mute: #695750;
  --line: #e9e0d8;
  --brand: #a0381c;
  --brand-ink: #fff8f1;
  --bad: #9f281f;
  --ok: #246143;
  --them: #f2ebe4;
  --sidebar: #2c211d;
  --sidebar-ink: #fff7ee;
  --sidebar-mute: #ded0c6;
  --sidebar-line: #5b463c;
  --shadow: 0 2px 5px rgb(60 35 22 / 5%);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1411;
  --panel: #271d19;
  --ink: #f7eee7;
  --mute: #cfbdb0;
  --line: #493930;
  --brand: #ff9b78;
  --brand-ink: #36190f;
  --bad: #ffaaa2;
  --ok: #94d6af;
  --them: #42332b;
  --sidebar: #241b17;
  --shadow: none;
}
* { box-sizing: border-box; }
body { margin: 0; font: 1rem/1.55 system-ui, "Noto Sans Thai", Tahoma, sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); padding: .45rem .8rem; border-radius: .55rem; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger, .err { color: var(--bad); }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: .55rem; padding: .5rem .7rem; width: 100%; }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.muted { color: var(--mute); }
.ok { color: var(--ok); }
.login { width: min(28rem, calc(100% - 2rem)); margin: 10vh auto; padding: 1.75rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1.1rem; box-shadow: var(--shadow); display: grid; gap: .8rem; }
.login .logo { justify-self: center; border-radius: 1rem; }
.login h1 { margin: 0 0 .45rem; font-size: 1.4rem; text-align: center; }
.phone { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: .55rem; background: var(--panel); overflow: hidden; }
.phone:focus-within { outline: 2px solid var(--brand); outline-offset: -1px; }
.phone .cc { display: flex; align-items: center; gap: .5rem; padding: 0 .75rem; border-right: 1px solid var(--line); color: var(--mute); white-space: nowrap; }
.phone .flag { width: 24px; height: 16px; border-radius: 2px; background: linear-gradient(to bottom,#a51931 0 16.67%,#f4f5f8 16.67% 33.33%,#2d2a4a 33.33% 66.67%,#f4f5f8 66.67% 83.33%,#a51931 83.33% 100%); }
.phone input { border: 0; border-radius: 0; background: transparent; outline: 0; flex: 1; min-width: 0; }

.workspace { display: grid; grid-template-columns: clamp(13rem, 18vw, 17.5rem) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100dvh; overflow: auto; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; padding: 1.25rem .95rem; }
.sidebar-head, .brand { display: flex; align-items: center; gap: .7rem; }
.sidebar-head { justify-content: space-between; padding: .2rem .2rem 1.15rem; }
.brand-logo { width: clamp(2.75rem, 4.25vw, 4rem); height: auto; border-radius: .8rem; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 1.35rem; line-height: 1.15; }
.brand span { font-size: .875rem; color: var(--sidebar-mute); margin-top: .1rem; }
.sidebar-content { display: flex; flex-direction: column; flex: 1; }
.tabs { flex: 1; }
.nav-group { display: grid; gap: .23rem; padding: .85rem 0; border-top: 1px solid var(--sidebar-line); }
.nav-group p { color: var(--sidebar-mute); font-size: .875rem; margin: 0 .65rem .3rem; font-weight: 650; }
.tabs button, .nav-toggle { border: 0; background: transparent; color: var(--sidebar-ink); text-align: left; }
.icon { display: inline-block; width: 1.35rem; height: 1.35rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button { display: flex; align-items: center; gap: .75rem; padding: .65rem .75rem; }
.tabs button:hover { background: #4c372e; }
.tabs button.on { background: #a0381c; font-weight: 650; }
.sidebar :focus-visible { outline-color: #ffb695; }
.nav-toggle { display: none; border: 1px solid var(--sidebar-line); }
.account { display: grid; justify-items: start; padding-top: .75rem; border-top: 1px solid var(--sidebar-line); gap: .4rem; }
.account button:not(.primary) { background: transparent; color: var(--sidebar-ink); border-color: var(--sidebar-line); }
.name-edit { display: flex; flex-wrap: wrap; gap: .4rem; max-width: 100%; }
.name-edit input { color: var(--ink); }
.name-edit button { font-size: .875rem; }
#logout { color: var(--sidebar-mute); font-size: .875rem; }

.page-heading, .wrap { max-width: 100rem; margin: 0 auto; padding-inline: clamp(1rem, 2.3vw, 2.4rem); }
.page-heading { padding-top: 1.8rem; padding-bottom: 1.2rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem; }
.page-heading h1 { margin: 0; font-size: clamp(1.65rem, 3vw, 3.15rem); line-height: 1.25; letter-spacing: -.025em; }
.page-heading h1:focus { outline: none; }
.theme-toggle { flex: none; min-height: 2.6rem; color: var(--mute); font-size: .875rem; }
.theme-toggle[aria-pressed="true"] { color: var(--ink); background: var(--them); }
.login .theme-toggle { justify-self: end; }
.wrap { padding-bottom: 2rem; }
.overview { display: grid; gap: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10.5rem), 1fr)); gap: .85rem; margin-bottom: 1rem; }
.overview .cards { margin-bottom: 0; }
.overview-primary, .overview-trends { display: grid; gap: 1rem; align-items: stretch; }
.overview-primary { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.overview-trends { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.overview .panel { margin-bottom: 0; }
.card, .panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: .95rem; padding: clamp(.85rem, 1.45vw, 1.4rem); box-shadow: var(--shadow); }
.panel { margin-bottom: 1rem; }
.card .k { color: var(--mute); font-weight: 650; font-size: .9rem; }
.card .v { font-size: clamp(1.38rem, 2.15vw, 2.05rem); font-weight: 750; letter-spacing: -.025em; margin: .2rem 0; overflow-wrap: anywhere; }
.card .s { color: var(--mute); font-size: .82rem; }
.card.metric { display: grid; grid-template-columns: auto minmax(0, 1fr); align-content: start; align-items: center; gap: .35rem .65rem; container-type: inline-size; }
.metric-icon { display: grid; place-items: center; align-self: start; width: clamp(2.35rem, 3.5vw, 3.5rem); aspect-ratio: 1; border-radius: .85rem; color: var(--brand); background: var(--them); }
.metric-icon .icon { width: 62%; height: 62%; }
.metric .s { grid-column: 1 / -1; }
@container (max-width: 10rem) {
  .metric-text { display: contents; }
  .metric .v { grid-column: 1 / -1; }
}
.panel h2 { margin: 0 0 .6rem; font-size: clamp(1.05rem, 1.4vw, 1.38rem); line-height: 1.3; }
.table-scroll { max-width: 100%; overflow: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { text-align: left; padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--mute); font-weight: 650; white-space: nowrap; }
.panel table.t { min-width: max-content; }
.status-list { margin: 0; }
.status-list > div { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .62rem .15rem; border-bottom: 1px solid var(--line); }
.status-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.status-list dd { margin: 0; font-weight: 750; font-variant-numeric: tabular-nums; }
.chart p { margin: -.3rem 0 .8rem; font-size: .875rem; }
.overview-primary .chart { display: flex; flex-direction: column; }
.chart-plot { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .55rem; min-height: 11.5rem; }
.overview-primary .chart-plot { flex: 1; }
.chart-axis { display: flex; flex-direction: column; align-items: end; justify-content: space-between; padding-bottom: 1.3rem; color: var(--mute); font-size: .75rem; font-variant-numeric: tabular-nums; }
.bar { position: relative; display: flex; gap: clamp(.12rem, .52vw, .5rem); }
.bar::before { content: ""; position: absolute; inset: .35rem 0 1.3rem; border-top: 1px solid var(--line); border-inline-start: 1px solid var(--line); background: repeating-linear-gradient(to top, var(--line) 0 1px, transparent 1px 25%); pointer-events: none; }
.bar .col { flex: 1; min-width: 0; height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) 1.3rem; text-align: center; }
.bar-track { position: relative; display: flex; align-items: end; padding-top: .35rem; }
.bar .fill { width: 100%; background: var(--brand); border-radius: .2rem .2rem 0 0; min-height: 2px; }
.bar .fill.zero { opacity: .28; }
.bar .lb { align-self: end; font-size: .75rem; color: var(--mute); white-space: nowrap; }
.trend canvas { position: absolute; inset: 0 0 auto; width: 100%; height: calc(100% - 1.3rem); pointer-events: none; }
@media (max-width: 1400px) {
  .chart .col:nth-child(even):not(:last-child) .lb { visibility: hidden; }
}
.toolbar, .pager, .row-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.toolbar { margin-bottom: .85rem; }
.toolbar input { max-width: 19rem; }
.toolbar select { width: auto; max-width: 100%; }
.pager { align-items: center; justify-content: flex-end; margin-top: .85rem; font-size: .9rem; }
.pill { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .875rem; background: var(--them); white-space: nowrap; }
.pill.good { color: #225a3d; background: #e3f0e5; }
.pill.bad { color: #86251e; background: #f8e6e2; }
.pill.info { color: #26526a; background: #e1eef4; }
.pill.waiting { color: #77500d; background: #faedcc; }
.toast { position: fixed; right: 1rem; bottom: 1rem; max-width: calc(100% - 2rem); background: var(--ink); color: var(--bg); padding: .65rem .95rem; border-radius: .6rem; z-index: 5; }
.toast.err { background: #8f2419; color: #fff; }
.form { display: grid; align-items: start; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem 1.2rem; max-width: 69rem; margin: 1rem 0; }
.line-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sms-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-full { grid-column: 1 / -1; }
.span-two { grid-column: span 2; }
.fld { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.fld > :is(input, select, .phone) { min-height: 2.75rem; }
.fld .lb2 { font-size: .9rem; font-weight: 650; }
.fld .hint { font-size: .875rem; overflow-wrap: anywhere; }
.checkline { display: flex; align-items: center; gap: .4rem; width: fit-content; min-height: 2.75rem; color: var(--ink); }
.checkline input { accent-color: var(--brand); }
.form .row-actions { align-self: end; }
#line-panel, #sms-panel, #test-panel { max-width: 74rem; }
#line-guide { margin-block: 1rem; overflow-wrap: anywhere; }
#l-result:empty { display: none; }
#t-result { margin-top: .6rem; min-height: 1.4em; }

@media (max-width: 1060px) {
  .overview-primary { grid-template-columns: minmax(0, 1fr); }
  .sms-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .workspace { display: block; }
  .sidebar { position: static; height: auto; padding: .7rem 1rem; }
  .sidebar-head { padding: 0; }
  .nav-toggle { display: block; }
  .sidebar-content { display: none; }
  .sidebar.expanded .sidebar-content { display: flex; margin-top: .85rem; }
  .overview-trends { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 580px) {
  .line-form, .sms-form { grid-template-columns: minmax(0, 1fr); }
  .span-two { grid-column: auto; }
}
details.guide{background:var(--them);border:1px solid var(--line);border-radius:10px;padding:8px 14px;margin:10px 0}
details.guide summary{cursor:pointer;font-weight:600}
details.guide ol{margin:8px 0 4px;padding-left:20px}
details.guide li{margin:4px 0}
.fld textarea{width:100%}


input[type=checkbox]{width:auto;margin-right:6px;vertical-align:middle}
