/* Cream & white minimal. One accent (ink navy), one secondary (sand), status colors kept apart. */
:root {
  --bg: #F7F3EC;
  --panel: #FFFDF9;
  --fg: #2B2622;
  --muted: #857B70;
  --line: #E9E1D4;
  --soft: #F3EDE3;
  --accent: #26384F;
  --sand: #C9A77C;
  --ok: #3F7D5A;
  --warn: #A86E12;
  --bad: #B4432F;
  --grid: #EEE7DC;
  --bar-muted: #DDD3C4;
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  --num: "Newsreader", "Georgia", serif;
  --r: 16px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; -webkit-text-size-adjust: 100%; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--bg); z-index: 20; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { max-width: 1200px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 64px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: clamp(20px, 3vw, 32px); }

/* login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(100%, 360px); display: flex; flex-direction: column; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px; }
.login h1 { margin: 0; font-family: var(--num); font-weight: 400; font-size: 28px; }
.login p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login .err { color: var(--bad); min-height: 1.2em; }

/* header */
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.head-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; flex: 1 1 30rem; }
.eyebrow { font-size: 11px; letter-spacing: .12em; color: var(--muted); }
.title { margin: 0; font-family: var(--num); font-weight: 400; font-size: clamp(28px, 4vw, 40px); line-height: 1.1; letter-spacing: -.01em; text-wrap: balance; }
.sub { margin: 0; color: var(--muted); line-height: 1.75; max-width: 68ch; }
.sub b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; color: var(--muted); white-space: nowrap; }
.chip.on { color: var(--ok); }
.chip.on::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; justify-content: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
select, input.in { font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; min-height: 40px; }
input.in { border-radius: 10px; font-size: 18px; font-variant-numeric: tabular-nums; width: 100%; }
select:focus-visible, input.in:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 9px 16px; min-height: 40px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; transition: border-color .3s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #FFFDF9; border-color: var(--accent); justify-content: center; }
.btn.refresh::before { content: "↻"; font-size: 16px; line-height: 1; display: inline-block; }
.btn.refresh.spin::before { animation: spin .9s var(--ease); }
.updated { flex-basis: 100%; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.updated::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; animation: pulse 2.4s ease-in-out infinite; }
.updated.stale::before { background: var(--warn); }
.banner { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.banner.bad { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); color: var(--bad); }

/* tabs */
.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; background: var(--bg); border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tab { appearance: none; border: 0; background: none; padding: 12px 14px; cursor: pointer; color: var(--muted); white-space: nowrap; position: relative; transition: color .3s; }
.tab:hover { color: var(--fg); }
.tab::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); transform: scaleX(0); transition: transform .35s var(--ease); }
.tab.active { color: var(--fg); font-weight: 500; }
.tab.active::after { transform: scaleX(1); }
.panel { display: flex; flex-direction: column; gap: clamp(16px, 2.5vw, 24px); }

/* cards */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 14px; }
.kpi, .card, .ad, .tip, .strip { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.kpi { padding: 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-family: var(--num); font-size: clamp(28px, 3.2vw, 40px); line-height: 1.1; font-variant-numeric: tabular-nums; min-height: 1.1em; }
.kpi.main .v { color: var(--accent); }
.kpi .h { font-size: 12px; color: var(--muted); line-height: 1.5; }
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); overflow: hidden; }
.stat { padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); gap: 14px; }
.card { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.card.flat { background: transparent; border-color: transparent; padding: 0; }
.card h3, .h2 { margin: 0; font-size: 17px; font-weight: 500; }
.note { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.link { appearance: none; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: 13px; }
.link:hover { text-decoration: underline; }
.tag { font-size: 12px; color: var(--muted); margin: 0; }

/* charts */
.chart { position: relative; min-height: 220px; }
.chart svg { display: block; overflow: visible; }
.tick { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.val { fill: var(--fg); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.gl { stroke: var(--grid); }
.ax { stroke: var(--line); }
.tip-pop { position: absolute; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px -14px rgba(60, 45, 30, .28); padding: 8px 10px; font-size: 12px; pointer-events: none; white-space: nowrap; line-height: 1.6; font-variant-numeric: tabular-nums; }
.tip-pop div:first-child { color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.empty { display: flex; align-items: center; justify-content: center; min-height: inherit; color: var(--muted); font-size: 13px; }

.funnel { display: flex; flex-direction: column; gap: 14px; }
.fstep { display: grid; grid-template-columns: minmax(6.5rem, 8rem) 1fr; gap: 4px 10px; align-items: center; }
.fname { font-size: 12px; color: var(--muted); }
.fbar { position: relative; height: 30px; background: var(--soft); border-radius: 8px; overflow: hidden; display: flex; align-items: center; }
.fbar i { display: block; height: 100%; border-radius: 8px; min-width: 4px; width: 0; transition: width .9s var(--ease); }
.fbar b { position: absolute; left: 10px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.frate { grid-column: 2; font-size: 12px; color: var(--muted); }
.frate.low { color: var(--bad); }

.ads { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: 14px; }
.ad { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.ad-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ad h3 { margin: 0; font-size: 16px; font-weight: 500; line-height: 1.35; }
.ad .set { font-size: 12px; color: var(--muted); }
.ad .big { font-family: var(--num); font-size: clamp(26px, 2.6vw, 32px); font-variant-numeric: tabular-nums; }
.ad-m { display: grid; grid-template-columns: 7rem 1fr auto; gap: 10px; align-items: center; font-size: 12px; }
.ad-m > span:first-child { color: var(--muted); }
.ad-m .bar { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.ad-m .bar i { display: block; height: 100%; border-radius: 3px; width: 0; transition: width .9s var(--ease); }
.ad-m .v { text-align: right; min-width: 5.5rem; font-variant-numeric: tabular-nums; }
.best { color: var(--ok); font-size: 11px; margin-left: 4px; }
.pill { font-size: 12px; border-radius: 999px; padding: 2px 9px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.on { color: var(--ok); }

.split { display: flex; flex-direction: column; gap: 14px; }
.split .l { font-size: 12px; color: var(--muted); }
.sbar { display: flex; height: 34px; border-radius: 10px; overflow: hidden; background: var(--soft); margin-top: 6px; }
.sbar i { display: flex; align-items: center; justify-content: center; font-style: normal; font-size: 12px; font-weight: 600; color: #FFFDF9; white-space: nowrap; overflow: hidden; flex: 0 0 0; transition: flex-basis .9s var(--ease); }

/* tables */
.tw { overflow: auto; max-height: 28rem; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: var(--bg); text-align: right; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td:first-child { white-space: normal; min-width: 9rem; }
th.l, td.l { text-align: left; }
tbody tr:hover { background: var(--soft); }
details.more > summary { cursor: pointer; color: var(--accent); list-style: none; padding: 6px 0; font-size: 13px; }
details.more > summary::-webkit-details-marker { display: none; }

/* insights + playbook */
.tips { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); gap: 14px; }
.tip { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.tip h4 { margin: 0; font-size: 15px; font-weight: 500; display: flex; gap: 8px; align-items: baseline; }
.tip h4::before { content: ""; flex: 0 0 8px; height: 8px; border-radius: 50%; background: var(--bar-muted); transform: translateY(-1px); }
.tip.good h4::before { background: var(--ok); }
.tip.warn h4::before { background: var(--warn); }
.tip.bad h4::before { background: var(--bad); }
.tip p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.7; }
.tip p.do { color: var(--fg); }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: 14px; }
.be { display: flex; flex-direction: column; gap: 10px; }
.be-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.be .n { font-family: var(--num); font-size: clamp(24px, 2.6vw, 32px); font-variant-numeric: tabular-nums; }
.be .l { font-size: 12px; color: var(--muted); }
.gauge { position: relative; height: 12px; border-radius: 6px; margin-top: 8px; background: linear-gradient(90deg, color-mix(in srgb, var(--ok) 50%, var(--panel)) 0 66.7%, color-mix(in srgb, var(--bad) 40%, var(--panel)) 66.7% 100%); }
.gauge i { position: absolute; top: -5px; left: 0; width: 4px; height: 22px; border-radius: 2px; background: var(--fg); transition: left .9s var(--ease); }
.gscale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.verdict { margin: 0; line-height: 1.6; }
.check { display: grid; grid-template-columns: 1fr auto; gap: 2px 14px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.check:last-child { border-bottom: 0; }
.check .do { grid-column: 1 / -1; font-size: 12px; color: var(--muted); line-height: 1.5; }
.check .v { display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.st { font-size: 11px; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.st.good { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.st.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.st.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
table.rules { min-width: 640px; font-size: 13px; line-height: 1.6; }
.rules th, .rules td { text-align: left; vertical-align: top; white-space: normal; }
.rules td { color: var(--muted); }
.rules td:first-child { color: var(--fg); font-weight: 500; white-space: nowrap; }
.rules td:last-child { color: var(--fg); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bar-muted); margin-right: 8px; }
.dot.good { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.list { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.list b { color: var(--fg); font-weight: 500; }
.plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 14px; }
.week { border-top: 2px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; transition: border-color .3s; }
.week:hover { border-top-color: var(--accent); }
.week span { font-size: 12px; color: var(--muted); }
.week h4, .routine h4 { margin: 0; font-size: 15px; font-weight: 500; }
.week p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.routine { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 20px; }
.routine > div { display: flex; flex-direction: column; gap: 8px; }
dl { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: 8px 16px; margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
dt { color: var(--fg); } dd { margin: 0; }
.skel { color: transparent !important; background: linear-gradient(90deg, var(--soft), var(--line), var(--soft)); background-size: 200% 100%; border-radius: 6px; animation: shimmer 1.2s linear infinite; }

@media (max-width: 560px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 16px; }
  .controls { justify-content: flex-start; width: 100%; }
  .updated { text-align: left; }
  .ad-m { grid-template-columns: 6rem 1fr auto; }
  dl { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .panel.enter > * { animation: rise .45s var(--ease) both; }
  .panel.enter > *:nth-child(2) { animation-delay: 60ms; }
  .panel.enter > *:nth-child(3) { animation-delay: 120ms; }
  .panel.enter > *:nth-child(n+4) { animation-delay: 180ms; }
  .panel.enter .hero > .kpi { animation: rise .5s var(--ease) both; }
  .panel.enter .hero > .kpi:nth-child(2) { animation-delay: 70ms; }
  .panel.enter .hero > .kpi:nth-child(3) { animation-delay: 140ms; }
  .panel.enter .hero > .kpi:nth-child(4) { animation-delay: 210ms; }
  .ad.in, .tip.in, .check.in { animation: rise .5s var(--ease) both; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; animation: none !important; }
}
@keyframes rise { from { opacity: .001; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes shimmer { to { background-position: -200% 0; } }
