/* CCC Cloud PWA — mobile-first, dark + light, safe-area aware.
 * CSP forbids inline styles; everything lives here. */

:root {
  --bg: #f6f8fa;
  --bg-raised: #ffffff;
  --bg-inset: #eef1f5;
  --text: #1c2430;
  --text-dim: #5c6b7f;
  --line: #d7dee8;
  --accent: #0e7c85;
  --accent-strong: #0a5f66;
  --accent-contrast: #ffffff;
  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #c93c37;
  --danger-strong: #a52f2b;
  --chip-bg: #e8ecf1;
  --shadow: 0 8px 30px rgba(15, 23, 40, .14);
  --radius: 14px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1017;
    --bg-raised: #141a24;
    --bg-inset: #0f141d;
    --text: #e6edf3;
    --text-dim: #8b98a9;
    --line: #232c3a;
    --accent: #4cc2c9;
    --accent-strong: #6ad4da;
    --accent-contrast: #06282b;
    --ok: #4ac26b;
    --warn: #d4a72c;
    --danger: #f47067;
    --danger-strong: #ff8b82;
    --chip-bg: #1d2634;
    --shadow: 0 10px 34px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

/* ---- desktop: centered phone-width column -------------------------------- */
@media (min-width: 640px) {
  #appShell, #authView {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    min-height: 100vh;
  }
  .banner { max-width: 480px; margin-left: auto; margin-right: auto; }
}

/* ---- banners -------------------------------------------------------------- */
.banner {
  position: sticky;
  top: 0;
  z-index: 60;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.banner-offline { background: var(--warn); color: #fff; }
.banner-error { background: var(--danger); color: #fff; }

/* ---- buttons --------------------------------------------------------------- */
.btn {
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(.985); }
/* Visible keyboard focus (both color schemes via the adaptive accent). */
.btn:focus-visible,
.card.tappable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger.armed {
  background: var(--danger);
  color: #fff;
}
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-block { display: block; width: 100%; }
/* Compact styling, but keep a >=44px tap target (padding grows the hit area
 * without inflating the visual weight much). */
.btn-small { min-height: var(--tap); padding: 6px 12px; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
  * { animation: none !important; transition: none !important; }
}

/* ---- auth ------------------------------------------------------------------ */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.auth-card { width: 100%; max-width: 360px; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.brand-mark { width: 72px; height: 72px; border-radius: 18px; }
.brand-bg { fill: #0c1017; }
.brand-chevron { stroke: #4cc2c9; }
.brand-cursor { fill: #e6edf3; }
.auth-brand h1 { font-size: 22px; margin: 14px 0 2px; }
.auth-tagline { color: var(--text-dim); margin: 0; font-size: 14px; }
.auth-consent { text-align: center; color: var(--text-dim); font-size: 12px; margin: 4px 0 0; }
.auth-consent a { color: var(--accent, #4aa8ff); }

.auth-step label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.auth-step input[type="email"] {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  margin-bottom: 14px;
  font-size: 17px;
}
.auth-code-hint { text-align: center; color: var(--text-dim); font-size: 14px; }
.code-boxes {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 18px 0 10px;
}
.code-boxes input {
  width: 46px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  caret-color: var(--accent);
}
.code-boxes input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.field-error { color: var(--danger); font-size: 14px; text-align: center; }

/* ---- shell ------------------------------------------------------------------ */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-freshness { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.live-badge {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--chip-bg); color: var(--text-dim);
}
.live-badge.is-live { color: var(--ok); }
.live-badge.is-live::before {
  content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok); margin-right: 5px; vertical-align: 1px;
}
.live-badge.is-degraded { color: var(--warn); }
.turns-live-note { font-size: 12px; color: var(--text-dim); margin: 4px 0 8px; }

.view {
  flex: 1;
  padding: 14px 14px calc(86px + env(safe-area-inset-bottom));
}

/* ---- tab bar ------------------------------------------------------------------ */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) {
  .tabbar { max-width: 480px; margin: 0 auto; }
}
.tab {
  position: relative;
  flex: 1;
  min-height: calc(var(--tap) + 6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  padding-top: 6px;
}
.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tab .icon-detail { stroke-width: 1.6; }
.tab.active { color: var(--accent); }
.tab-badge {
  position: absolute;
  top: 3px;
  right: calc(50% - 20px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

/* ---- cards + lists ------------------------------------------------------------- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.card.tappable { cursor: pointer; }
.card.tappable:active { background: var(--bg-inset); }

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-main { flex: 1; min-width: 0; }
.card-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-sub {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 2px 8px;
}
.group-head:first-child { margin-top: 4px; }
.group-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin: 0; }
.group-head .freshness { font-size: 12px; color: var(--text-dim); }

/* ---- chips ------------------------------------------------------------------------ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.chip.no-dot::before { display: none; }
.chip-working, .chip-ok, .chip-online { color: var(--ok); }
.chip-waiting, .chip-backlog, .chip-question, .chip-approval { color: var(--warn); }
.chip-idle, .chip-ended, .chip-draining, .chip-none { color: var(--text-dim); }
.chip-stuck, .chip-failed, .chip-error, .chip-offline, .chip-fail { color: var(--danger); }
.chip-completed, .chip-done { color: var(--accent); }

.engine-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--accent);
  text-transform: none;
}

/* ---- freshness / staleness --------------------------------------------------------- */
.freshness { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.stale-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  white-space: nowrap;
}
.is-stale {
  filter: saturate(.25);
  opacity: .72;
}
.is-stale .stale-badge {
  /* the badge itself must stay loud even inside a desaturated card */
  filter: none;
  opacity: 1;
}

/* ---- context bar ---------------------------------------------------------------------- */
.ctx-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--bg-inset);
  overflow: hidden;
  flex: 0 0 64px;
}
.ctx-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.ctx-fill.ctx-low { background: var(--warn); }
.ctx-fill.ctx-critical { background: var(--danger); }

/* ---- skeleton / empty / error ------------------------------------------------------------ */
.skeleton { border-radius: var(--radius); overflow: hidden; }
.skel-line {
  height: 64px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: linear-gradient(100deg, var(--bg-raised) 40%, var(--bg-inset) 50%, var(--bg-raised) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer {
  from { background-position: 130% 0; }
  to { background-position: -30% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skel-line { animation: none; background: var(--bg-inset); }
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 56px 24px;
}
.empty h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.empty p { margin: 0; font-size: 14px; }

.view-error {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-dim);
}

/* ---- sheet -------------------------------------------------------------------------------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 8, 14, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-raised);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  box-shadow: var(--shadow);
  padding: 6px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-in .22s ease-out;
}
@keyframes sheet-in {
  from { transform: translateY(24px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 6px auto 4px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.sheet-head h2 { font-size: 17px; margin: 0; overflow-wrap: anywhere; }
.sheet-body .meta-list { margin: 0 0 14px; }
.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 14px;
}
.meta-list dt { color: var(--text-dim); }
.meta-list dd { margin: 0; overflow-wrap: anywhere; }

.sheet-section { margin-top: 18px; }
.sheet-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin: 0 0 8px;
}

.question-text {
  font-size: 16px;
  background: var(--bg-inset);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  font-size: 15px;
  overflow-wrap: anywhere;
}

textarea.input-text {
  width: 100%;
  min-height: 88px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 10px 12px;
  resize: vertical;
  margin-bottom: 8px;
}

.cmd-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  min-height: 20px;
  margin-left: 10px;
}
.cmd-status.st-sending { color: var(--warn); }
.cmd-status.st-delivered { color: var(--accent); }
.cmd-status.st-done { color: var(--ok); }
.cmd-status.st-error { color: var(--danger); }

.privacy-notice {
  font-size: 12px;
  color: var(--warn);
  margin: 8px 0;
}

.turns { margin-top: 10px; }
.turn {
  border-left: 3px solid var(--line);
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.turn-role {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-dim);
  display: block;
  margin-bottom: 2px;
}
.turn-user { border-left-color: var(--accent); }

/* ---- pairing ------------------------------------------------------------------------------ */
.pair-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .14em;
  text-align: center;
  margin: 14px 0 4px;
  user-select: all;
  -webkit-user-select: all;
}
.pair-expiry { text-align: center; font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
.pair-expiry.expiring { color: var(--danger); font-weight: 700; }
.qr-holder { display: flex; justify-content: center; margin: 10px 0; }
.qr-holder canvas {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  border-radius: 10px;
}
.pair-hint { font-size: 13px; color: var(--text-dim); text-align: center; }
.pair-code.pair-install {
  font-size: 13px; font-weight: 500; letter-spacing: 0; text-align: left;
  word-break: break-all; line-height: 1.4;
}

/* ---- account ------------------------------------------------------------------------------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  padding: 6px 0;
}
.setting-row label { flex: 1; font-size: 15px; }
.setting-sub { font-size: 12px; color: var(--text-dim); display: block; }

/* switch — 30px visual track, but a full 44px tap target (the input overlays
 * the whole box so the clickable area meets the a11y minimum). */
.switch {
  position: relative;
  width: 50px;
  height: var(--tap);
  flex: 0 0 50px;
}
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .knob {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 30px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--line);
  transition: background .15s ease;
  pointer-events: none;
}
.switch .knob::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-raised);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .15s ease;
}
.switch input:checked + .knob { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(20px); }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }

.quiet-hours { display: flex; align-items: center; gap: 8px; }
.quiet-hours input[type="time"] {
  min-height: var(--tap);
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 4px 8px;
}

/* Quiet-hours row: at narrow widths the label + two 130px time inputs no
 * longer fit on one line (the label crushed to ~48px). Stack the inputs
 * below the label instead of letting them overflow. */
.setting-row.quiet-hours-row { flex-wrap: wrap; }
.quiet-hours-row .quiet-hours { flex-wrap: wrap; }
@media (max-width: 480px) {
  .setting-row.quiet-hours-row {
    flex-direction: column;
    align-items: stretch;
  }
  .quiet-hours-row .quiet-hours { width: 100%; }
  .quiet-hours-row .quiet-hours input[type="time"] { flex: 1 1 0; min-width: 0; }
}

.privacy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.privacy-table th, .privacy-table td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.privacy-table th { color: var(--text-dim); font-weight: 600; white-space: nowrap; }

.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.confirm-input {
  width: 100%;
  min-height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 8px 12px;
  margin: 8px 0;
}

.section-note { font-size: 13px; color: var(--text-dim); margin: 4px 0 10px; }

.kv-inline { font-size: 13px; color: var(--text-dim); }

.oldest-age { font-variant-numeric: tabular-nums; }

.wide-btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.wide-btn-row .btn { flex: 1; min-width: 130px; }

/* ---- Queues + tickets ------------------------------------------------------- */
.policy-card { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.policy-card .section-note { margin-bottom: 12px; }
.queue-card .card-title { white-space: normal; }
.ticket-card .card-title { white-space: normal; overflow-wrap: anywhere; }
.back-btn { margin: 0 0 6px -8px; }
.owner-note { margin-top: 0; }
#newTicketBtn { margin-bottom: 12px; }
.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  margin: 4px 0 12px;
  border-radius: 12px;
  background: var(--bg-inset);
}
.seg-btn {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
}
.seg-btn.active { background: var(--bg-raised); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.keep-local { margin-top: 24px; }
input.input-line {
  width: 100%;
  min-height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 16px;
}
.ticket-text, .hist-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.hist { padding: 8px 0; border-top: 1px solid var(--line); }
.hist:first-of-type { border-top: 0; }
.hist-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 13px; }
.hist-event { font-weight: 600; }
.hist-comment .hist-text {
  margin-top: 4px;
  background: var(--bg-inset);
  border-radius: 10px;
  padding: 8px 10px;
}
.ticket-notice { display: block; margin: 8px 0 0; }
.consent-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
  margin: 4px 0 14px;
  text-align: left;
}
.consent-check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
