/* Slave Clock Control — UI stylesheet */

:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242e;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #8b919a;
  --accent: #f5a623;
  --accent-dim: #8a5a12;
  --danger: #e5484d;
  --success: #30a46c;
  --warn: #f5a623;
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 560px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 10px;
}
.topbar-title { font-size: 18px; font-weight: 600; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #555;
  box-shadow: 0 0 0 2px var(--surface);
}
.conn-dot[data-state="connected"]    { background: var(--success); }
.conn-dot[data-state="disconnected"] { background: #555; }
.conn-dot[data-state="auth-error"]   { background: var(--danger); }

.chip {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip-ble[data-state="on-secured"] { color: var(--success); border-color: var(--success); }
.chip-ble[data-state="on-open"]    { color: var(--warn); border-color: var(--warn); }
.chip-ble[data-state="off"]        { color: var(--muted); }

/* ── Screens ────────────────────────────────────────────── */
.screen {
  flex: 1 0 auto;
  /* Leave room for the fixed bottom nav (≈56px + safe area + gap). */
  padding: 8px 14px calc(72px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.screen.hidden { display: none; }

.screen-head { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.screen-head h2 { margin: 0; font-size: 22px; font-weight: 600; }

/* ── Watch (SVG) ────────────────────────────────────────── */
.watch-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0 4px; }
.watch { width: min(72vw, 260px); height: min(72vw, 260px); display: block; }
.watch-rim { fill: var(--surface); stroke: var(--border); stroke-width: 3; }
.dial-tick { stroke: var(--muted); stroke-width: 1; }
.dial-tick.major { stroke: var(--text); stroke-width: 2; }
.dial-numeral { fill: var(--text); font-size: 12px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.hand line { stroke: var(--accent); stroke-width: 4; stroke-linecap: round; }
.minute-hand line { stroke-width: 3; }
.hour-hand { will-change: transform; }
.minute-hand { will-change: transform; }
.hour-hand.animatable, .minute-hand.animatable { transition: transform 0.45s ease-out; }
.hand-cap { fill: var(--accent); }

.watch-readout { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.watch-readout #displayed-time { font-size: 20px; font-weight: 600; }
.state-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 7px; border-radius: 20px;
}
.state-badge[data-state="on"]  { background: var(--success); color: #04160c; }
.state-badge[data-state="off"] { background: var(--surface-2); color: var(--muted); }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; color: var(--muted); }
.field .value { font-size: 15px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Two-column label/value grid used by the diagnostics card. */
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 13px;
}
.kv > span:nth-child(odd) { color: var(--muted); }
.kv > span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-height: 44px;
  font-size: 14px;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:active { background: var(--border); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 8px 12px; min-height: 38px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a1100; font-weight: 600; }
.btn-primary:active { background: #d88f1a; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-danger:active { background: #c93d42; }
.btn.ghost { background: transparent; }
.icon-btn { min-height: 38px; min-width: 38px; padding: 0 10px; font-size: 18px; }

/* ── Power button ───────────────────────────────────────── */
.power-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  min-height: 76px;
}
.power-btn-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.power-btn-state { font-size: 18px; }
.power-btn[data-state="on"] { border-color: var(--success); background: rgba(48,164,108,.12); color: var(--success); }

/* ── Segmented control ──────────────────────────────────── */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn { background: transparent; border: none; padding: 9px 16px; min-height: 40px; color: var(--muted); }
.seg-btn.active { background: var(--accent); color: #1a1100; font-weight: 600; }

.mode-group { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.mode-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.mode-help { font-size: 12px; color: var(--muted); text-align: center; max-width: 320px; }

.controls-card { gap: 18px; align-items: center; }

/* ── Switch ─────────────────────────────────────────────── */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; border-radius: 14px;
  background: var(--border); transition: background .15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--success); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }

/* ── Inputs ─────────────────────────────────────────────── */
input[type="text"], input[type="password"], input[type="number"],
input[type="datetime-local"], input[type="date"], select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-height: 40px;
  font-size: 14px;
  color: var(--text);
}
select { min-width: 64px; }
input:disabled { opacity: .5; }

/* ── Schedules ──────────────────────────────────────────── */
.banner {
  background: rgba(245,166,35,.12);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.schedule-list { display: flex; flex-direction: column; gap: 8px; }
.sched-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.sched-time { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 60px; }
.sched-state {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 8px; border-radius: 20px;
}
.sched-state[data-state="on"]  { background: rgba(48,164,108,.2); color: var(--success); }
.sched-state[data-state="off"] { background: rgba(229,72,77,.18); color: var(--danger); }
.sched-meta { flex: 1; font-size: 13px; color: var(--muted); }
.sched-del {
  background: transparent; border: none; color: var(--muted);
  min-width: 38px; min-height: 38px; font-size: 18px; border-radius: 8px;
}
.sched-del:active { background: var(--surface-2); color: var(--danger); }
.loading, .empty { color: var(--muted); padding: 16px; text-align: center; }

/* ── Day picker ─────────────────────────────────────────── */
.day-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.day-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.day-btn.active { background: var(--accent); border-color: var(--accent); color: #1a1100; }

/* ── Users ──────────────────────────────────────────────── */
.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 9px 12px;
}
.user-row span { font-weight: 500; }
.user-del { background: transparent; border: none; color: var(--muted); min-height: 32px; }
.user-del:active { color: var(--danger); }

/* ── Firmware progress ──────────────────────────────────── */
.progress { display: flex; align-items: center; gap: 10px; }
.progress-bar { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); width: 0%; transition: width .2s; }
.badge {
  font-size: 11px; padding: 1px 7px; border-radius: 20px;
  background: rgba(245,166,35,.2); color: var(--warn);
  text-transform: uppercase; letter-spacing: .5px;
}

.error { color: var(--danger); font-size: 13px; }

.danger-card { border-color: rgba(229,72,77,.4); }

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-bottom: var(--safe-bottom);
  max-width: var(--maxw);
  margin: 0 auto;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: none; color: var(--muted);
  padding: 8px 0 10px; min-height: 56px; font-size: 11px;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { width: 24px; height: 24px; }

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(76px + var(--safe-bottom));
  z-index: 150;
  max-width: min(92vw, var(--maxw));
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.toast[data-kind="error"] { border-color: var(--danger); color: var(--danger); }
.toast[data-kind="ok"]    { border-color: var(--success); color: var(--success); }

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; padding: 0;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: var(--maxw);
  padding: 16px; padding-bottom: calc(20px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px;
  max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; }

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-card { border-radius: var(--radius); }
}

/* ── Auth lock ──────────────────────────────────────────── */
.auth-locked { opacity: .55; pointer-events: none; }
.auth-locked.unlocked { opacity: 1; pointer-events: auto; }

/* ── Mock panel ─────────────────────────────────────────── */
/* Deliberately below the modal (100) and the toast (150): the panel sits
   over the bottom sheet otherwise and swallows its taps. */
#mock-panel {
  position: fixed; left: 8px; bottom: calc(64px + var(--safe-bottom));
  background: #1a1300; border: 1px solid var(--warn); color: var(--warn);
  border-radius: 10px; padding: 8px; z-index: 90;
  font-size: 12px; max-width: 240px; display: flex; flex-direction: column; gap: 6px;
}
#mock-panel .mp-title { font-weight: 700; margin-bottom: 2px; }
#mock-panel button { background: transparent; border: 1px solid var(--warn); color: var(--warn); border-radius: 6px; padding: 6px 8px; font-size: 12px; }
#mock-panel label { display: flex; align-items: center; gap: 6px; }
/* Hosted connection controls share the existing card and form styles. */
.device-panel { margin: 12px 16px; }
.device-panel label { display: block; margin-bottom: 8px; }
.device-panel .form-row { flex-wrap: wrap; }
.device-panel input { flex: 1; min-width: 160px; }
