:root {
  --bg: #07090e;
  --surface: #10141f;
  --surface-2: #171d2c;
  --border: #232b40;
  --text: #eef2ff;
  --muted: #8b96b0;
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.16);
  --cyan: #22d3ee;
  --cyan-dim: rgba(34, 211, 238, 0.15);
  --violet: #a78bfa;
  --violet-dim: rgba(167, 139, 250, 0.16);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.16);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.16);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  min-height: 100%;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }

/* Lock Screen */
.lock-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lock-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 26px 22px;
  text-align: center;
}

.lock-badge {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--amber);
  background: var(--amber-dim);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.lock-title { margin: 14px 0 4px; font-size: 24px; font-weight: 700; }
.lock-sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 14px;
  margin-bottom: 12px;
}
.pin-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
}

.pin-input {
  width: 100%;
  text-align: center;
  font-size: 20px;
  letter-spacing: 0.25em;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 14px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.keypad button {
  height: 54px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
}
.keypad button:active { transform: scale(0.96); background: #20283d; }
.keypad .key-muted { font-size: 14px; color: var(--muted); }

.error-text { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* App Shell */
.app-shell {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 14px calc(86px + env(safe-area-inset-bottom));
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 10px;
}

.live-clock {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.live-date { color: var(--muted); font-size: 13px; margin-top: 4px; }

.status-pills { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill-pc-on { background: var(--cyan-dim); color: var(--cyan); border-color: rgba(34,211,238,0.35); }
.pill-tv-on { background: var(--violet-dim); color: var(--violet); border-color: rgba(167,139,250,0.35); }
.pill-warn { background: var(--amber-dim); color: var(--amber); border-color: rgba(245,158,11,0.35); }
.pill-off { background: var(--surface); color: var(--muted); }

.next-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 14px;
}
.next-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.section-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 12px;
}
.section-title {
  margin: 14px 0 10px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.section-row .section-title { margin: 0; }

.card-list { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.alarm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.2s, opacity 0.2s;
}
.alarm-card.enabled { border-color: rgba(245, 158, 11, 0.45); }
.alarm-card.disabled { opacity: 0.65; }

.alarm-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.alarm-time {
  font-size: 38px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.alarm-label { font-size: 15px; font-weight: 600; margin-top: 6px; }
.alarm-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag-pc { color: var(--cyan); background: var(--cyan-dim); border-color: transparent; }
.tag-tv { color: var(--violet); background: var(--violet-dim); border-color: transparent; }
.tag-both { color: var(--amber); background: var(--amber-dim); border-color: transparent; }

.alarm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Toggle Switch */
.switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}
.slider-sw::before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  top: 3px;
  background: var(--muted);
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider-sw {
  background: var(--amber-dim);
  border-color: var(--amber);
}
.switch input:checked + .slider-sw::before {
  transform: translateX(22px);
  background: var(--amber);
}

/* Inputs & Buttons */
.field-label {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 6px;
  font-weight: 600;
}
.field-label:first-child { margin-top: 0; }

.input-text, .input-select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  margin-bottom: 10px;
  outline: none;
}
.input-text:focus, .input-select:focus { border-color: var(--amber); }

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 4px;
}
.slider-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.slider-val { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

.range-input {
  width: 100%;
  accent-color: var(--amber);
  height: 28px;
  margin-bottom: 10px;
  cursor: pointer;
}
.range-cyan { accent-color: var(--cyan); }
.range-violet { accent-color: var(--violet); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
}
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn:active { transform: scale(0.97); }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 12px; border-radius: 10px; }
.btn-primary { background: var(--amber); color: #111; }
.btn-amber { background: var(--amber); color: #111; }
.btn-cyan { background: var(--cyan-dim); color: var(--cyan); border-color: rgba(34,211,238,0.35); }
.btn-violet { background: var(--violet-dim); color: var(--violet); border-color: rgba(167,139,250,0.35); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: rgba(239,68,68,0.35); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn-row > .btn { flex: 1; }
.btn-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn-grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 480px) { .btn-grid-4 { grid-template-columns: repeat(4, 1fr); } }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.device-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.device-name { font-size: 16px; font-weight: 700; }
.device-sub { font-size: 12px; color: var(--muted); margin-top: 3px; word-break: break-word; }

.preset-list { display: flex; flex-direction: column; gap: 8px; }
.preset-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.preset-name { font-size: 14px; font-weight: 600; }
.preset-url { font-size: 11px; color: var(--muted); word-break: break-all; }

.divider { height: 1px; background: var(--border); margin: 14px 0; }

.tv-badge {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.tv-badge.ok { background: var(--green-dim); color: var(--green); border-color: rgba(16,185,129,0.35); }
.tv-badge.warn { background: var(--amber-dim); color: var(--amber); border-color: rgba(245,158,11,0.35); }

.guide-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.guide-box ol { margin: 6px 0 0; padding-left: 18px; }

.url-row { margin-bottom: 10px; }
.url-code {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--cyan);
  word-break: break-all;
}

.logs-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.log-entry { font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.log-ts { color: var(--amber); font-variant-numeric: tabular-nums; margin-right: 6px; }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 13, 20, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 18px;
  cursor: pointer;
}
.nav-btn.active { color: var(--amber); }
.nav-icon { font-size: 19px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 600px) { .modal { align-items: center; padding: 16px; } }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72); }
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  padding: 18px;
}
@media (min-width: 600px) { .modal-sheet { border-radius: 22px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  cursor: pointer;
}

.time-picker-wrap { text-align: center; margin-bottom: 10px; }
.time-big-input {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 42px;
  font-weight: 700;
  padding: 10px 18px;
  text-align: center;
  color-scheme: dark;
}
.quick-times { display: flex; justify-content: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.chip:active { color: var(--amber); border-color: var(--amber); }

.seg-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.seg-control button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px;
  font-weight: 600;
  cursor: pointer;
}
.seg-control button.active {
  background: var(--amber-dim);
  color: var(--amber);
  border-color: var(--amber);
}

.days-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 10px; }
.days-row button {
  height: 38px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}
.days-row button.active {
  background: var(--amber-dim);
  color: var(--amber);
  border-color: var(--amber);
}

.modal-actions { display: flex; gap: 10px; margin-top: 12px; }

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2234;
  border: 1px solid var(--amber);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.install-card { border-color: rgba(245,158,11,0.4); background: linear-gradient(135deg, #10141f, #1a1814); }
