/* whoop-line-notify dashboard — phone-first, light + system dark. No build step. */
:root {
  --bg: #f3f4f6; --card: #fff; --text: #111827; --muted: #6b7280; --border: #e5e7eb; --soft: #f9fafb;
  --primary: #4f46e5; --on-primary: #fff; --green: #16a34a; --yellow: #ca8a04; --red: #dc2626; --blue: #2563eb;
  --info: #374151; --warn: #b45309; --crit: #b91c1c; --gray: #9ca3af;
  --radius: 12px; --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #1e293b; --text: #f1f5f9; --muted: #94a3b8; --border: #334155; --soft: #273449;
    --primary: #818cf8; --on-primary: #0f172a; --green: #4ade80; --yellow: #facc15; --red: #f87171; --blue: #60a5fa;
    --info: #cbd5e1; --warn: #fbbf24; --crit: #fca5a5; --gray: #64748b; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; font-size: 15px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Sarabun", sans-serif;
}
a { color: var(--primary); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: var(--soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 18px; }
h2 { font-size: 17px; margin: 24px 0 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 small { font-size: 12px; font-weight: 400; color: var(--muted); }
h3 { font-size: 15px; margin-bottom: 8px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 60px; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.hidden, [hidden] { display: none !important; }

/* ---- header / nav ---- */
.top { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--border); }
.top .wrap { display: flex; align-items: center; gap: 12px; height: 52px; }
.top h1 { white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 999px; white-space: nowrap; font-size: 13px; }
.nav a:hover, .nav a.active { background: var(--soft); color: var(--text); }
.logout { margin: 0; }

/* ---- cards / grid ---- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 560px) and (max-width: 719px) { .grid.three { grid-template-columns: 1fr 1fr; } }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* key/value rows */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; }
.kv:first-of-type { border-top: 0; }
.kv > span:first-child { color: var(--muted); flex: none; }
.kv > span:last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ---- badges / buttons ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { color: var(--green); border-color: currentColor; }
.badge.warn { color: var(--yellow); border-color: currentColor; }
.badge.bad { color: var(--red); border-color: currentColor; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--card); color: var(--text); font: inherit; font-size: 14px;
  font-weight: 600; cursor: pointer; text-decoration: none; position: relative; transition: background .15s, opacity .15s; -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--soft); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.is-busy { pointer-events: none; opacity: .75; padding-left: 2.2em; }
.btn.is-busy::before {
  content: ""; position: absolute; left: .8em; top: 50%; width: 1em; height: 1em; margin-top: -.5em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chips { display: inline-flex; gap: 4px; background: var(--soft); border-radius: 999px; padding: 3px; }
.chips button { border: 0; background: transparent; color: var(--muted); padding: 4px 12px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; }
.chips button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

/* ---- checklist ---- */
.checklist { border-left: 4px solid var(--yellow); }
.checklist ol { margin: 8px 0 0; padding-left: 22px; }
.checklist li { margin: 8px 0; }
.checklist li.done { color: var(--muted); }
.checklist li.done .t { text-decoration: line-through; }
.checklist li.done::marker { color: var(--green); }
.checklist .step-hint { display: block; font-size: 13px; color: var(--muted); }

/* ---- progress / stage bars ---- */
.progress { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }
.progress > i.warn { background: var(--yellow); }
.progress > i.bad { background: var(--red); }
.stagebar { display: flex; height: 14px; border-radius: 6px; overflow: hidden; background: var(--soft); margin: 8px 0 4px; }
.stagebar > i { display: block; min-width: 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }

/* ---- today ---- */
.big { font-size: 48px; font-weight: 800; line-height: 1; letter-spacing: -1px; }
.big small { font-size: 20px; font-weight: 600; margin-left: 2px; }
.zone { font-weight: 600; margin-top: 4px; }
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 12px; margin-top: 12px; }
@media (min-width: 420px) { .metrics { grid-template-columns: repeat(4, 1fr); } .metrics.cols3 { grid-template-columns: repeat(3, 1fr); } }
.metric { background: var(--soft); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.metric b { display: block; font-size: 18px; }
.metric span { font-size: 12px; color: var(--muted); }
.metric .delta { display: block; font-size: 11px; }
.delta.up { color: var(--green); } .delta.down { color: var(--red); }
.obs { margin: 10px 0 0; padding: 0; list-style: none; }
.obs li { padding: 3px 0 3px 16px; position: relative; font-size: 14px; }
.obs li::before { content: "•"; position: absolute; left: 3px; }
.obs .info { color: var(--info); } .obs .warn { color: var(--warn); } .obs .critical { color: var(--crit); font-weight: 600; }
.wo { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.wo b { display: block; }
.wo .sm { display: block; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }
.wo { flex-wrap: wrap; }
.wo .stagebar { flex-basis: 100%; height: 8px; margin: 2px 0 0; }
.wo-warn { flex-basis: 100%; font-size: 12px; color: var(--warn); }

/* ---- sleep debt (bars grow right = slept less, left = slept more) ---- */
.debt { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 10px; align-items: center; margin-top: 10px; font-size: 13px; }
.debt .bar { position: relative; height: 10px; border-radius: 5px; background: var(--soft); overflow: hidden; }
.debt .bar > i { position: absolute; top: 0; bottom: 0; }
.debt .bar::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--border); }

/* ---- charts ---- */
.chart { min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chart-head b { font-size: 22px; }
.chart svg { display: block; width: 100%; height: auto; margin-top: 6px; overflow: visible; }
.chart text { font-size: 10px; fill: var(--muted); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .ref { stroke-dasharray: 4 3; stroke-width: 1.5; }
.chart-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 8px; border-top: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; border-top: 0; white-space: nowrap; }
td.err { color: var(--red); max-width: 260px; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  table thead { display: none; }
  table, tbody, tr, td { display: block; }
  tr { border-top: 1px solid var(--border); padding: 8px 0; }
  td { border: 0; padding: 2px 0; }
  td[data-l]::before { content: attr(data-l) " "; color: var(--muted); }
  td.act { padding-top: 6px; }
}

/* ---- settings form ---- */
fieldset { border: 0; padding: 0; margin: 0 0 18px; }
legend { font-weight: 700; font-size: 15px; padding: 0; margin-bottom: 4px; }
.note { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.field:first-of-type { border-top: 0; }
.field label { flex: 1; min-width: 0; }
.field label small { display: block; color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea, textarea, input[type=password] {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 38px;
}
.field input[type=number] { width: 96px; text-align: right; }
.field input[type=time] { width: 116px; }
.field input[type=text] { width: 100%; max-width: 360px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.field.wide { flex-direction: column; align-items: stretch; }
.field.invalid input, .field.invalid select { border-color: var(--red); outline: 1px solid var(--red); }
.field .unit { color: var(--muted); font-size: 13px; margin-left: 6px; }
.ctl { display: flex; align-items: center; flex: none; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--gray); border-radius: 24px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
textarea { width: 100%; min-height: 84px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
details summary { cursor: pointer; color: var(--primary); font-size: 14px; margin-top: 10px; }
.sticky-save { position: sticky; bottom: 0; background: var(--card); padding: 10px 0 0; margin-top: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- modal ---- */
dialog { border: 0; border-radius: 16px; padding: 0; background: var(--card); color: var(--text); width: min(96vw, 560px); max-height: 92vh; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 14px 16px; overflow-y: auto; max-height: calc(92vh - 60px); background: #e8ecf1; }
@media (prefers-color-scheme: dark) { .modal-body { background: #0b1220; } }
.modal-foot { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ---- Flex approximation (LINE chat look: explicit colors, independent of theme) ---- */
.fx-msg { max-width: 340px; margin: 0 auto 12px; }
.fx-text { background: #fff; color: #111; border-radius: 14px; padding: 10px 14px; white-space: pre-wrap; font-size: 14px; display: inline-block; max-width: 100%; }
.fx-bubble { background: #fff; color: #111; border-radius: 14px; overflow: hidden; font-size: 14px; line-height: 1.4; }
.fx-carousel { display: flex; gap: 8px; overflow-x: auto; }
.fx-carousel .fx-bubble { flex: none; width: 280px; }
.fx-sec { padding: 12px 16px; }
.fx-box { display: flex; min-width: 0; }
.fx-vertical { flex-direction: column; }
.fx-horizontal, .fx-baseline { flex-direction: row; }
.fx-baseline { align-items: baseline; }
.fx-t { min-width: 0; overflow-wrap: anywhere; }
.fx-t.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-sep { border: 0; border-top: 1px solid #e5e7eb; margin: 0; width: 100%; }
.fx-btn { display: block; text-align: center; padding: 8px 12px; border-radius: 8px; text-decoration: none; font-weight: 600; font-size: 14px; }
.fx-btn.link { color: #4f46e5; }
.fx-btn.primary { background: #4f46e5; color: #fff; }
.fx-btn.secondary { background: #f3f4f6; color: #111; }
.fx-img { display: block; max-width: 100%; }

/* ---- toasts ---- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); animation: pop .2s ease-out; pointer-events: auto; overflow-wrap: anywhere; }
.toast.ok { background: #166534; } .toast.err { background: #991b1b; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ---- login ---- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login input[type=password] { width: 100%; margin: 12px 0; }
.login .error { color: var(--red); font-size: 14px; margin: 0 0 8px; }
