/* Phone first: one column, big tap targets. Light and dark follow the device setting. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #5d6877;
  --line: #dde2e8;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --good: #137a3f;
  --good-bg: #e3f5ea;
  --ok: #1d5fa8;
  --ok-bg: #e4eefb;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --alert: #ffffff;
  --alert-bg: #d92d20;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --text: #e8edf3;
    --muted: #9aa6b4;
    --line: #2a3542;
    --primary: #4c8dff;
    --good: #5fd28c;
    --good-bg: #133222;
    --ok: #8bb8f5;
    --ok-bg: #16283d;
    --warn: #f2c14e;
    --warn-bg: #3a2d0c;
    --bad: #ff8a80;
    --bad-bg: #3d1714;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must always win. Without this, a rule like .login { display: grid }
   overrides the browser's built-in "hidden = display: none" and hidden things stay visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
p { margin: 0.4rem 0; }

.page { max-width: 760px; margin: 0 auto; padding: 12px 16px 48px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--bad); }
.warning { color: var(--warn); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }
.needs-you { color: var(--alert); background: var(--alert-bg); padding: 8px 12px; border-radius: 8px; font-weight: 600; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.top p { margin: 0.1rem 0 0; font-size: 0.875rem; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  border: none; background: none; border-radius: 8px 8px 0 0; padding: 10px 14px; color: var(--muted);
  border-bottom: 3px solid transparent; min-height: 44px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}
.card.off { opacity: 0.7; }
.card.empty { color: var(--muted); text-align: center; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.session.tone-alert { border: 2px solid var(--alert-bg); }
.session.tone-good { border-left: 5px solid var(--good); }

/* Status pills */
.pill { font-size: 0.8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.ok, .pill.info { color: var(--ok); background: var(--ok-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.muted { color: var(--muted); background: var(--bg); }
.pill.alert { color: var(--alert); background: var(--alert-bg); }

/* Notice under the tabs */
.notice { padding: 10px 12px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); }
.notice.ok { background: var(--good-bg); color: var(--good); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.error { background: var(--bad-bg); color: var(--bad); }

/* Buttons and fields */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: progress; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
button.big { font-size: 1.05rem; padding: 10px 18px; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.alert { background: var(--alert-bg); color: var(--alert); border-color: var(--alert-bg); font-weight: 600; }
button.quiet { border-color: transparent; background: none; color: var(--muted); }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
textarea { resize: vertical; }
label { display: block; margin: 10px 0; font-size: 0.9rem; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; min-height: auto; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 8px 10px; }
legend { font-size: 0.9rem; padding: 0 4px; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.row > select, .row > input { flex: 1; min-width: 0; }
.controls { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 2px; }

.days { display: flex; flex-wrap: wrap; gap: 6px; }
.day { display: flex; align-items: center; gap: 4px; margin: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; }
.day input { width: auto; min-height: auto; margin: 0; }

.grid-2, .grid-3 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}

.problems { color: var(--bad); padding-left: 1.2rem; }
.problems:empty { display: none; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; }
.login button { width: 100%; }

/* Dialogs */
dialog {
  width: min(760px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 14px;
}
dialog::backdrop { background: rgb(0 0 0 / 55%); }
.dialog-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Live view */
.live-screen { background: #000; border-radius: 8px; overflow: hidden; margin-top: 8px; }
.live-screen img { display: block; width: 100%; height: auto; cursor: crosshair; }

/* History */
.history summary { display: flex; justify-content: space-between; gap: 8px; cursor: pointer; flex-wrap: wrap; }
.events { padding-left: 1.2rem; font-size: 0.875rem; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; }
