:root {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #17233d;
  --border: #253455;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --sun: #f59e0b;
  --moon: #818cf8;
  --sleep-bar: #6366f1;
  --sleep-bar-live: #a855f7;
  --accent: #38bdf8;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 0.75rem 1rem 1rem;
}

.top-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.65rem;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.lang-switch:hover {
  color: var(--text);
  border-color: var(--accent);
  text-decoration: none;
}

.lang-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--accent);
}

.lang-current {
  color: var(--text);
}

.lang-sep {
  opacity: 0.45;
}

.lang-target {
  color: var(--muted);
}

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

/* Hero status */
.hero {
  text-align: center;
  padding: 2rem 1.25rem 2.25rem;
}

.status-icon {
  width: 240px;
  height: 240px;
  margin: 0 auto 0.5rem;
  display: block;
}

.status-icon.is-awake {
  filter: drop-shadow(0 0 32px rgba(245, 158, 11, 0.28));
}

.status-icon.is-asleep {
  filter: drop-shadow(0 0 32px rgba(129, 140, 248, 0.3));
}

.status-title {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-since {
  margin: 0.4rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.98rem;
}

.status-duration {
  margin: 0.25rem 0 0;
  font-size: 1.65rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.admin-action-wrap {
  margin-top: 1.5rem;
}

.btn-primary-giant {
  display: inline-block;
  width: 100%;
  max-width: 340px;
  padding: 1rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  color: #0b1120;
  background: var(--sun);
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn-primary-giant.is-wake {
  background: var(--moon);
  color: #0b1120;
}

.btn-primary-giant:active {
  transform: scale(0.98);
}

.admin-sublinks {
  margin-top: 0.85rem;
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Controls & Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.toolbar h2 {
  margin: 0;
  font-size: 1.15rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

select,
input[type="text"],
input[type="password"],
input[type="datetime-local"],
input[type="file"],
button,
.btn {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
}

button,
.btn {
  cursor: pointer;
  font-weight: 600;
}

.btn-accent {
  background: var(--accent);
  color: #0b1120;
  border-color: transparent;
}

.btn-danger {
  background: transparent;
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.5);
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

.tz-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.85rem;
}

.tz-switch a {
  padding: 0.35rem 0.65rem;
  color: var(--muted);
  text-decoration: none;
}

.tz-switch a.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

/* Stats strip */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 24h Day Timeline */
.timeline-ruler,
.day-row {
  display: grid;
  grid-template-columns: 92px 1fr 64px;
  gap: 0.5rem;
  align-items: center;
}

.timeline-ruler {
  font-size: 0.75rem;
  color: var(--muted);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}

.ruler-scale {
  display: flex;
  justify-content: space-between;
}

.day-row {
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(37, 52, 85, 0.45);
  font-size: 0.85rem;
}

.day-row.is-empty .day-date {
  color: var(--muted);
}

.day-date {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.day-track {
  position: relative;
  height: 18px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.day-slice {
  position: absolute;
  top: 2px;
  bottom: 2px;
  background: var(--sleep-bar);
  border-radius: 3px;
  min-width: 2px;
}

.day-slice.is-live {
  background: var(--sleep-bar-live);
}

.day-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.82rem;
}

.day-row:not(.is-empty) .day-total {
  color: var(--text);
  font-weight: 600;
}

.day-detail {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.25rem 0 0.25rem 0.25rem;
}

/* Alerts & Forms */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

.alert-ok {
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.5);
  color: #bbf7d0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.field input,
.field select {
  width: 100%;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.inline-form {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}

.site-footer {
  text-align: center;
  padding: 1rem 0 2rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--text);
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.tab-link {
  flex: 1;
  text-align: center;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tab-link:hover {
  color: var(--text);
  border-color: var(--accent);
  text-decoration: none;
}

.tab-link.active {
  background: var(--surface-2);
  color: var(--accent);
  border-color: var(--accent);
}

/* Prediction controls & plot */
.pred-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 0.9rem;
  padding: 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1.1rem;
}

.slider-pair {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.slider-pair input[type="range"] {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}

.pct-input-wrap,
.duration-pair {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.pct-input-wrap span,
.duration-pair span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.duration-pair input[type="number"] {
  width: 100%;
  min-width: 0;
  text-align: center;
}

.pred-chart-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 1.1rem;
}

.pred-chart-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.pred-chart-title {
  font-size: 0.92rem;
  font-weight: 600;
}

.pred-legend {
  display: flex;
  gap: 0.9rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.pred-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 10px;
  border-radius: 2px;
}

.legend-swatch.is-expected {
  background: var(--sleep-bar);
}

.legend-swatch.is-range {
  background: rgba(129, 140, 248, 0.38);
  border: 1px solid rgba(129, 140, 248, 0.65);
}

.pred-chart-svg-wrap {
  width: 100%;
  overflow-x: auto;
}

.pred-svg {
  width: 100%;
  height: auto;
  display: block;
  min-width: 460px;
}

.pred-table {
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
}

.pred-table th,
.pred-table td {
  white-space: nowrap;
}

.pred-cell-bed {
  color: #a5b4fc;
  font-weight: 600;
}

.pred-cell-wake {
  color: #fcd34d;
  font-weight: 600;
}

.pred-cell-bound {
  color: var(--muted);
}

@media (max-width: 640px) {
  .pred-table thead {
    display: none;
  }
  .pred-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem 0.6rem;
    padding: 0.65rem 0.55rem;
    margin-bottom: 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  .pred-table tbody td {
    border: 0;
    padding: 0;
    white-space: normal;
    font-size: 0.82rem;
  }
  .pred-table tbody td.pred-cell-cycle {
    grid-column: 1 / -1;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.25rem;
    margin-bottom: 0.1rem;
  }
  .pred-table tbody td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-weight: 400;
    font-size: 0.76rem;
  }
}

@media (max-width: 540px) {
  .timeline-ruler,
  .day-row {
    grid-template-columns: 74px 1fr 54px;
    gap: 0.35rem;
  }
  .day-date {
    font-size: 0.78rem;
  }
  .status-icon {
    width: 190px;
    height: 190px;
  }
}
