/* ═══════════════════════════════════════════════════════════════
   RayTV — Base Styles
   Target: 600×600 Meta Ray-Ban Display, D-pad navigation
   Theme: OLED black, high-contrast, large text
═══════════════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Design tokens ──────────────────────────────────────────── */
:root {
  /* Palette */
  --bg:           #000000;
  --bg-2:         #0d0d0d;
  --bg-3:         #1a1a1a;
  --bg-4:         #262626;
  --surface:      #111111;
  --surface-2:    #1e1e1e;
  --border:       #2a2a2a;
  --border-hi:    #444444;

  --text:         #f0f0f0;
  --text-2:       #b0b0b0;
  --text-3:       #707070;
  --text-dim:     #505050;

  --accent:       #e50000;       /* TiviMate-style red */
  --accent-2:     #ff3333;
  --accent-dim:   #660000;

  --focus:        #ffffff;
  --focus-ring:   3px solid #ffffff;
  --focus-shadow: 0 0 0 3px rgba(255,255,255,0.9), 0 0 12px rgba(255,255,255,0.4);

  --live:         #00cc44;
  --warn:         #ffaa00;
  --error:        #ff4444;
  --info:         #4488ff;

  /* Typography */
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:    'Cascadia Code', 'Consolas', monospace;

  --text-xs:      12px;
  --text-sm:      14px;
  --text-base:    18px;          /* base — larger than web norm for display glasses */
  --text-lg:      22px;
  --text-xl:      26px;
  --text-2xl:     32px;
  --text-3xl:     40px;

  --weight-normal: 400;
  --weight-med:    500;
  --weight-bold:   700;

  /* Spacing */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;

  /* Radius */
  --r-sm:  4px;
  --r-md:  8px;
  --r-lg:  12px;
  --r-xl:  16px;
  --r-pill: 999px;

  /* Timing */
  --t-fast:   80ms;
  --t-base:   150ms;
  --t-slow:   250ms;

  /* Layout */
  --sidebar-w:    72px;          /* collapsed icon-only sidebar */
  --sidebar-w-open: 200px;       /* expanded sidebar */
  --statusbar-h:  40px;
  --view-pad:     var(--sp-4);
  --min-touch:    48px;          /* minimum focusable target */
}

/* ── Base ───────────────────────────────────────────────────── */
html {
  width: 600px;
  height: 600px;
  overflow: hidden;
  font-size: var(--text-base);
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

/* ── Splash ─────────────────────────────────────────────────── */
#splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);
  z-index: 9999;
  transition: opacity var(--t-slow);
}

#splash.hidden {
  opacity: 0;
  pointer-events: none;
}

.splash-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}

.splash-icon {
  font-size: 64px;
  line-height: 1;
}

.splash-name {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--text);
  letter-spacing: 0.08em;
}

.splash-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-4);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── App shell layout ───────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--statusbar-h) 1fr;
  grid-template-areas:
    "statusbar statusbar"
    "sidebar   main";
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg);
}

#app.sidebar-open {
  --sidebar-w: var(--sidebar-w-open);
}

/* ── Status bar ─────────────────────────────────────────────── */
#statusbar {
  grid-area: statusbar;
  display: flex;
  align-items: center;
  padding: 0 var(--sp-4);
  gap: var(--sp-3);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  height: var(--statusbar-h);
  z-index: 100;
}

.status-title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--accent);
  flex: 0 0 auto;
  letter-spacing: 0.06em;
}

.status-account {
  font-size: var(--text-sm);
  color: var(--text-2);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-clock {
  font-size: var(--text-sm);
  color: var(--text-3);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width var(--t-base);
}

#nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  padding: var(--sp-2) 0;
  height: 100%;
}

.nav-spacer {
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: var(--min-touch);
  padding: 0 var(--sp-3);
  background: none;
  border: none;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}

.nav-btn::before {
  content: attr(data-icon);
  font-size: 20px;
  flex: 0 0 28px;
  text-align: center;
  line-height: 1;
}

.nav-btn:hover,
.nav-btn:focus-visible {
  background: var(--bg-4);
  color: var(--text);
  outline: none;
}

.nav-btn.active {
  color: var(--text);
  background: var(--bg-3);
}

.nav-btn.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* Focus ring for nav items */
.nav-btn.rt-focused {
  background: var(--bg-4);
  color: var(--focus);
  outline: var(--focus-ring);
  outline-offset: -3px;
  box-shadow: var(--focus-shadow);
  z-index: 1;
}

/* ── Main view ──────────────────────────────────────────────── */
#view-root {
  grid-area: main;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ── Generic view scaffold ──────────────────────────────────── */
.view {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: view-in var(--t-base) ease-out;
}

@keyframes view-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.view-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  min-height: 48px;
}

.view-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--text);
  flex: 1;
}

.view-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4);
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}

.view-body::-webkit-scrollbar { width: 4px; }
.view-body::-webkit-scrollbar-track { background: transparent; }
.view-body::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: var(--r-pill); }

/* ── Typography helpers ─────────────────────────────────────── */
h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-xl);  font-weight: var(--weight-bold); }
h3 { font-size: var(--text-lg);  font-weight: var(--weight-med);  }
h4 { font-size: var(--text-base);font-weight: var(--weight-med);  }

p  { line-height: 1.5; color: var(--text-2); }

.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-base  { font-size: var(--text-base); }
.text-lg    { font-size: var(--text-lg); }
.text-muted { color: var(--text-3); }
.text-dim   { color: var(--text-dim); }
.text-accent{ color: var(--accent); }
.text-live  { color: var(--live); }
.text-warn  { color: var(--warn); }
.text-error { color: var(--error); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--min-touch);
  padding: 0 var(--sp-5);
  border: none;
  border-radius: var(--r-md);
  font-size: var(--text-base);
  font-family: var(--font);
  font-weight: var(--weight-med);
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover,
.btn-primary.rt-focused {
  background: var(--accent-2);
}

.btn-ghost {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover,
.btn-ghost.rt-focused {
  background: var(--bg-4);
  border-color: var(--border-hi);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}

.btn-danger:hover,
.btn-danger.rt-focused {
  background: rgba(255,68,68,0.12);
}

.btn.rt-focused {
  outline: var(--focus-ring);
  outline-offset: 2px;
  box-shadow: var(--focus-shadow);
}

/* ── Form elements ──────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.field-label {
  font-size: var(--text-sm);
  color: var(--text-2);
  font-weight: var(--weight-med);
}

.field-input {
  width: 100%;
  min-height: var(--min-touch);
  padding: 0 var(--sp-3);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--text-base);
  font-family: var(--font);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.field-input:focus,
.field-input.rt-focused {
  border-color: var(--focus);
  box-shadow: var(--focus-shadow);
}

.field-input::placeholder { color: var(--text-3); }

select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%23707070'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ── Focus ring — universal ─────────────────────────────────── */
.rt-focused {
  outline: var(--focus-ring) !important;
  outline-offset: 2px;
  box-shadow: var(--focus-shadow) !important;
  position: relative;
  z-index: 10;
}

/* Remove browser default focus styles when we handle it */
:focus { outline: none; }
:focus-visible { outline: none; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  z-index: 8888;
  pointer-events: none;
  width: 90%;
}

.toast {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--text-sm);
  text-align: center;
  animation: toast-in var(--t-base) ease-out;
  max-width: 400px;
}

.toast.toast-error   { border-color: var(--error);  color: var(--error); }
.toast.toast-success { border-color: var(--live);   color: var(--live);  }
.toast.toast-warn    { border-color: var(--warn);   color: var(--warn);  }

.toast.toast-out {
  animation: toast-out var(--t-slow) ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ── Section header within views ────────────────────────────── */
.section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--text-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: var(--sp-3);
  margin-top: var(--sp-5);
}

.section-title:first-child { margin-top: 0; }

/* ── Dividers ───────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-4) 0;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  height: 100%;
  min-height: 200px;
  color: var(--text-3);
  text-align: center;
  padding: var(--sp-8);
}

.empty-state-icon {
  font-size: 48px;
  opacity: 0.4;
}

.empty-state-text {
  font-size: var(--text-base);
  color: var(--text-3);
}

/* ── Badge / pill ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-live    { background: var(--live);   color: #000; }
.badge-new     { background: var(--accent); color: #fff; }
.badge-hd      { background: var(--bg-4);  color: var(--text-2); border: 1px solid var(--border-hi); }

/* ── Progress bar ───────────────────────────────────────────── */
.progress-bar {
  height: 3px;
  background: var(--bg-4);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width var(--t-base);
}

/* ── Scrollable row (horizontal strip) ──────────────────────── */
.scroll-row {
  display: flex;
  gap: var(--sp-3);
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: var(--sp-2);
  scrollbar-width: none;
}

.scroll-row::-webkit-scrollbar { display: none; }

/* ── Utility ────────────────────────────────────────────────── */
.hidden       { display: none !important; }
.invisible    { visibility: hidden; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2        { gap: var(--sp-2); }
.gap-3        { gap: var(--sp-3); }
.gap-4        { gap: var(--sp-4); }
.flex-1       { flex: 1; }
.mt-4         { margin-top: var(--sp-4); }
.w-full       { width: 100%; }
