/* Optic parent app — builds on the site design system (css/styles.css,
   which imports @optic/ui). Only app-specific layout lives here; every
   button, card, panel, badge, chip, switch, tab, modal, toast, stat,
   bar-list and stepper is the shared primitive, so the dashboard looks and
   moves exactly like optic.fyi. No colors are hardcoded: tokens only. */

.app-body { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); color: var(--text); }
/* The marketing body pins ink-on-paper; the app follows the theme tokens so
   dark mode (prefers-color-scheme) reads correctly everywhere. */
.app-body .brand, .app-body h1, .app-body h2, .app-body h3, .app-body b, .app-body strong { color: var(--text); }

/* ---------- top bar ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 18px;
  padding: 0 clamp(16px, 4vw, 40px); height: 64px;
  background: var(--bg); background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-bar .brand { font-size: 1.05rem; }
.app-bar__spacer { margin-left: auto; }
.app-bar__email { color: var(--muted); font-size: .9rem; }
@media (max-width: 560px) { .app-bar__email { display: none; } }

/* ---------- auth pages ---------- */
.auth-wrap { flex: 1; display: grid; place-items: center; padding: clamp(28px, 6vw, 70px) 16px; }
.auth-card {
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: clamp(24px, 4vw, 40px); box-shadow: var(--shadow-md);
  animation: fadeUp .7s var(--ease-out) both;
}
.auth-card .brand { justify-content: center; margin-bottom: 22px; display: flex; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: .2em; text-align: center; }
.auth-card .sub { color: var(--muted); text-align: center; margin-bottom: 22px; font-size: .95rem; }
.auth-card .stepper { margin-bottom: 22px; }
.auth-alt { text-align: center; margin: 20px 0 0; color: var(--muted); font-size: .9rem; }
.auth-alt a { color: var(--text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: .86rem; color: var(--muted); margin: 4px 0 8px; cursor: pointer; }
.consent input { margin-top: 3px; accent-color: var(--amber); width: 16px; height: 16px; flex: none; }

.form-msg { min-height: 1.2em; font-size: .88rem; margin: 4px 0 14px; }
.form-msg.error { color: var(--error); }
.form-msg.ok { color: var(--ok); }
.field textarea, .field input[type=number], .field input[type=time], .field input[type=email] {
  font: inherit; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
.field .optional { font-weight: 400; color: var(--dim); font-size: .78rem; }
.field-help { color: var(--muted); font-size: .78rem; line-height: 1.45; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }

/* ---------- dashboard layout ---------- */
.dash { flex: 1; padding: clamp(18px, 3vw, 34px) clamp(16px, 4vw, 40px); width: 100%; max-width: 1280px; margin-inline: auto; }
.dash-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.panel h2 { font-size: 1.15rem; margin-bottom: 4px; }
.panel h3 { font-size: .98rem; margin: 18px 0 10px; }
.panel .hint { margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.panel-head h2 { margin: 0; }
.panel-head .hint { margin: 0; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 20px; }
.empty-note { color: var(--muted); font-size: .9rem; padding: 8px 2px; margin: 0; }
.callout-soft { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 15px; font-size: .86rem; color: var(--muted); box-shadow: none; }
.callout-soft b { color: var(--text); }
.callout-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--text); border-radius: var(--radius-sm); padding: 10px 13px; font-size: .86rem; margin: 10px 0; }

/* ---------- child list ---------- */
.device-list { list-style: none; display: grid; gap: 8px; }
.device-item {
  display: grid; gap: 3px; padding: 13px 15px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
  transition: border-color .25s ease, transform .25s var(--ease-out);
}
.device-item:hover { border-color: var(--border-strong); transform: translateX(2px); }
.device-item.is-active { border-color: var(--amber); box-shadow: 0 0 0 2px color-mix(in srgb, var(--amber) 22%, transparent); }
.device-item__name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.device-item__meta { font-size: .8rem; color: var(--muted); }
.dot-status { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.dot-status.online { background: var(--online); box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 22%, transparent); }

/* ---------- child header + tabs ---------- */
.child-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.child-head__who { flex: 1; min-width: 200px; }
.child-head h2 { font-size: 1.5rem; margin-bottom: 2px; }
.tabbar { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 18px; }
.tab-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 7px;
  border-radius: var(--radius-pill); background: var(--amber); color: var(--ink); font-size: .72rem; font-weight: 700;
}
.welcome .stepper { max-width: 420px; }
.welcome h2 { font-size: 1.6rem; }

/* ---------- overview ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.stat.card { padding: 18px 18px 16px; box-shadow: none; background: var(--surface-2); text-align: left; font: inherit; color: inherit; }
button.stat.card { cursor: pointer; }
.stat.card .stat__value { font-size: clamp(1.35rem, 2.6vw, 1.8rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.analogy-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
.analogy.card { display: flex; gap: 14px; align-items: center; padding: 14px 16px; box-shadow: none; }
.analogy__emoji { font-size: 1.8rem; line-height: 1; }
.analogy b { display: block; font-size: .95rem; }
.analogy small { color: var(--muted); font-size: .8rem; }
.day-bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; height: 150px; padding-top: 8px; }
.day-bar { display: grid; grid-template-rows: 1fr auto; gap: 6px; height: 100%; align-items: end; justify-items: center; }
.day-bar__fill {
  display: block; width: min(100%, 38px); min-height: 3px; height: calc(var(--h, 0) * 100%); border-radius: var(--radius-pill);
  background: var(--border-strong); transform-origin: bottom; animation: bar-rise .9s var(--ease-out) both;
}
.day-bar.is-today .day-bar__fill { background: var(--amber); }
.day-bar__label { text-align: center; font-size: .75rem; color: var(--muted); }
.day-bar.is-today .day-bar__label { color: var(--text); font-weight: 600; }
@keyframes bar-rise { from { transform: scaleY(0); } }

/* ---------- assistant ---------- */
.assistant-out { display: grid; gap: 10px; margin-bottom: 14px; }
.assistant-out:empty { display: none; }
.bubble { padding: 13px 16px; border-radius: 16px; font-size: .93rem; line-height: 1.55; animation: fadeUp .5s var(--ease-out) both; }
.bubble--you { background: var(--btn-solid-bg); color: var(--btn-solid-fg); justify-self: end; max-width: 82%; border-bottom-right-radius: 4px; }
.bubble--ai { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble--ai.is-error { border-color: var(--error-border); color: var(--error); }
.bubble.is-thinking { color: var(--muted); font-style: italic; }
.assistant-compose { display: flex; gap: 10px; align-items: flex-end; }
.assistant-input {
  flex: 1; width: 100%; font: inherit; font-size: .95rem; padding: 12px 14px; resize: vertical; min-height: 48px;
  border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
.assistant-input:focus { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--amber); }
@media (max-width: 560px) { .assistant-compose { flex-direction: column; align-items: stretch; } }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }

/* ---------- modal (on top of @optic/ui .modal) ---------- */
.modal-overlay { overflow-y: auto; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal-overlay--anim { animation: overlay-in .3s ease both; }
.modal-overlay.is-leaving { opacity: 0; transition: opacity .25s ease; }
.modal--anim { animation: fadeUp .45s var(--ease-out) both; }
.modal-overlay.is-leaving .modal { transform: translateY(8px) scale(.98); transition: transform .25s var(--ease-out); }
.modal--wide { max-width: 620px; }
.modal:focus { outline: none; }
.modal-title { font-size: 1.3rem; margin: 0 36px 6px 0; }
.modal-lead { margin-bottom: 18px; }
.modal-body { margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.modal-x {
  position: absolute; top: 18px; right: 18px; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer;
  transition: color .2s ease, background .2s ease, transform .3s var(--ease-out);
}
.modal-x:hover { color: var(--text); background: var(--surface-2); transform: rotate(90deg); }
@keyframes overlay-in { from { opacity: 0; } }
.btn-danger { background: var(--error); border-color: var(--error); color: var(--cream); font-weight: 600; }
.btn-danger:hover { box-shadow: var(--shadow-md); border-color: var(--error); }
.link-btn { background: none; border: 0; padding: 4px 2px; font: inherit; font-size: .84rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.link-btn:hover { color: var(--text); }
.link-btn--danger:hover { color: var(--error); }

.proposal-list { list-style: none; display: grid; gap: 8px; margin: 0 0 12px; }
.proposal-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.proposal-row__mark { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--amber); color: var(--ink); font-size: .75rem; font-weight: 700; flex: none; }
.proposal-row__text { flex: 1; font-size: .93rem; }

/* ---------- toasts (dashboard) ---------- */
.toast-stack { position: fixed; right: 16px; bottom: 16px; z-index: 400; display: grid; gap: 10px; width: min(360px, calc(100vw - 32px)); }
.toast-stack .toast { cursor: pointer; padding: 14px 18px; }
.toast-stack .toast-title { margin: 0; font-weight: 650; }
.toast-stack .toast-message { margin: 0; color: var(--muted); font-size: .88rem; }
.toast--error { border-color: var(--error-border); }
.toast--error .toast-title { color: var(--error); }

/* ---------- setup ---------- */
.setup-steps { display: grid; gap: 10px; margin: 0 0 18px; padding-left: 20px; color: var(--muted); font-size: .92rem; }
.setup-steps b { color: var(--text); }
.setup-steps a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.code-box { text-align: center; padding: 22px; border: 1.5px dashed var(--amber); border-radius: var(--radius-lg); background: var(--surface-2); }
.code-box .code { font-family: var(--font-mono); font-size: clamp(2rem, 7vw, 2.8rem); letter-spacing: .35em; font-weight: 700; color: var(--text); padding-left: .35em; }
.code-box .expiry { color: var(--muted); font-size: .84rem; margin-top: 6px; }
.setup-wait { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: .9rem; margin: 18px 0 0; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--amber); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.setup-done { text-align: center; padding: 10px 0; }
.setup-done__mark { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: var(--amber); color: var(--ink); font-size: 1.5rem; font-weight: 700; }

/* ---------- all controls ---------- */
.control-group { margin: 26px 0 10px; }
.control-group h3 { margin: 0 0 2px; font-size: 1.05rem; }
.control-group > .hint { margin-bottom: 12px; }
.control-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.control-card { display: grid; gap: 6px; align-content: start; text-align: left; padding: 18px; font: inherit; color: inherit; cursor: pointer; }
.control-card b { font-size: .98rem; }
.control-card span { font-size: .84rem; color: var(--muted); line-height: 1.45; }
.control-form select { width: 100%; }
.day-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.day-picker .chip { padding: 6px 11px; }
.chip[aria-pressed="true"] { background: var(--btn-solid-bg); color: var(--btn-solid-fg); border-color: var(--btn-solid-bg); }

/* ---------- rules ---------- */
.rules-group { margin-top: 0 !important; }
.rule-list { list-style: none; display: grid; gap: 0; }
.rule-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.rule-row:last-child { border-bottom: 0; }
.rule-row.is-off { opacity: .6; }
.rule-row__main { flex: 1; min-width: 220px; }
.rule-row__title { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.rule-row__target { font-family: var(--font-mono); font-size: .9rem; font-weight: 600; }
.rule-row__detail { margin: 3px 0 0; font-size: .82rem; color: var(--muted); }
.mode-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; padding: 4px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); }
.mode-opt { border: 0; background: transparent; padding: 9px 12px; border-radius: var(--radius-pill); font: inherit; font-size: .9rem; font-weight: 550; color: var(--muted); cursor: pointer; transition: background .25s ease, color .25s ease, box-shadow .25s ease; }
.mode-opt:hover { color: var(--text); }
.mode-opt.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.mode-help { margin: 8px 0 0; }
.nudge-box:empty { display: none; }
.nudge-box { padding: 14px 14px 0; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 16px; }
.win-list { display: grid; gap: 10px; }
.win-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.win-row input[type=time] { font: inherit; padding: 7px 9px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.win-list .hint { margin: 0; }

/* ---------- requests ---------- */
.req-list { list-style: none; display: grid; gap: 10px; }
.req-row { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); flex-wrap: wrap; }
.req-main { flex: 1; min-width: 220px; }
.req-what { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: .95rem; }
.req-reason { margin: 6px 0 0; font-size: .9rem; }
.req-why { margin: 4px 0 0; font-size: .82rem; color: var(--muted); }
.req-flags { margin: 6px 0 0; font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.req-meta { margin: 4px 0 0; font-size: .76rem; color: var(--dim); }
.req-actions { display: flex; gap: 8px; align-self: center; }
.req-actions .btn { padding: 10px 18px; font-size: .9rem; }

/* ---------- activity ---------- */
.activity { list-style: none; display: grid; gap: 0; max-height: 420px; overflow-y: auto; }
.activity li { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; font-size: .87rem; padding: 9px 0; border-bottom: 1px solid var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity .k { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); padding-top: 2px; }
.activity .v { word-break: break-word; }
.activity .cmd { font-family: var(--font-mono); font-size: .8rem; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
@media (max-width: 560px) { .activity li { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- settings ---------- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .lbl { font-size: .95rem; font-weight: 550; }
.toggle-row .lbl small { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; margin-top: 2px; max-width: 60ch; }
.bedtime-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bedtime-row input[type=time] { width: 140px; font: inherit; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); }
.bedtime-sep { color: var(--muted); font-size: .86rem; }
.chip-editor { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; padding: 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.chip-editor input { flex: 1; min-width: 160px; border: 0 !important; background: transparent !important; padding: 5px 6px !important; outline: none !important; }
.chip--static { display: inline-flex; align-items: center; gap: 6px; cursor: default; color: var(--text); background: var(--surface); }
.chip-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .7rem; padding: 0 0 0 2px; }
.chip-x:hover { color: var(--error); }

/* Consent page (app/consent.html) */
.consent-card { max-width: 520px; }
.consent-points { margin: 0 0 18px; padding-left: 1.1em; display: grid; gap: 8px; color: var(--muted); font-size: .92rem; line-height: 1.5; }
.consent-points b { color: var(--text); font-weight: 600; }
