/* ==========================================================================
   Casa Flores · design tokens
   ========================================================================== */

:root {
  --bg: #0b0910;
  --glow-a: #2a1d46;
  --glow-b: #0f2b2a;
  --surface: #141118;
  --surface-2: #1d1924;
  --surface-3: #282132;
  --surface-inset: #0f0c14;
  --text: #efe9f6;
  --text-muted: #ada3bb;
  --text-faint: #7d738c;
  --outline: #322a3d;
  --outline-strong: #4b405b;
  --accent: #d0bcff;
  --accent-2: #b79cff;
  --accent-ink: #2c1a55;
  --accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
  --teal: #8ed8c9;
  --teal-soft: color-mix(in srgb, var(--teal) 12%, transparent);
  --rose: #ffb4a9;
  --rose-soft: color-mix(in srgb, var(--rose) 12%, transparent);
  --amber: #ffd38a;
  --amber-soft: color-mix(in srgb, var(--amber) 12%, transparent);
  --green: #8ee0a8;
  --red: #ff9e9e;
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 26px 70px -38px rgb(0 0 0 / 0.9);
  --sidebar-w: 248px;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f2fb;
  --glow-a: #e8ddff;
  --glow-b: #d8f2ec;
  --surface: #ffffff;
  --surface-2: #f2edfa;
  --surface-3: #e8e0f4;
  --surface-inset: #faf8fe;
  --text: #1d1a22;
  --text-muted: #5f586b;
  --text-faint: #8a8196;
  --outline: #e3daf0;
  --outline-strong: #cfc2e2;
  --accent: #6750a4;
  --accent-2: #7d5fd1;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --teal: #147d6e;
  --teal-soft: color-mix(in srgb, var(--teal) 10%, transparent);
  --rose: #b3261e;
  --rose-soft: color-mix(in srgb, var(--rose) 9%, transparent);
  --amber: #8a5a00;
  --amber-soft: color-mix(in srgb, var(--amber) 12%, transparent);
  --green: #1f7a3a;
  --red: #b3261e;
  --shadow: 0 22px 60px -38px rgb(58 38 96 / 0.25);
  color-scheme: light;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 88% -8%, var(--glow-a) 0%, transparent 62%),
    radial-gradient(800px 480px at -8% 108%, var(--glow-b) 0%, transparent 58%),
    var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

img,
svg {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 8px;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 999px;
  border: 2px solid var(--bg);
}

/* ==========================================================================
   Shell
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 22px 14px;
  border-right: 1px solid var(--outline);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 16px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 15px;
  color: #241541;
  background: linear-gradient(135deg, #e3d6ff 0%, var(--accent) 45%, var(--teal) 120%);
  box-shadow: 0 10px 26px -14px var(--accent);
}

.brand-mark svg {
  width: 26px;
  height: 26px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.brand-text small {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  transition: background 140ms ease, color 140ms ease;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-link svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 4px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--outline);
  border-radius: 14px;
  background: var(--surface-2);
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  color: #23163f;
  font-weight: 800;
  font-size: 0.75rem;
}

.user-meta {
  min-width: 0;
}

.user-meta strong {
  display: block;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta small {
  display: block;
  color: var(--text-muted);
  font-size: 0.68rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--outline);
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: blur(20px);
}

.page-heading {
  min-width: 0;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.2vw, 1.6rem);
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.page-heading p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.view {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 36px) clamp(16px, 3vw, 40px) 110px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.bottom-nav {
  display: none;
}

/* ==========================================================================
   Controls
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 650;
  font-size: 0.86rem;
  line-height: 1;
  transition: background 140ms ease, transform 90ms ease, border-color 140ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:hover {
  background: var(--surface-3);
}

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

.btn svg {
  width: 17px;
  height: 17px;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

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

.btn.ghost {
  background: transparent;
}

.btn.ghost:hover {
  background: var(--surface-2);
}

.btn.danger {
  color: var(--rose);
  border-color: color-mix(in srgb, var(--rose) 35%, var(--outline));
  background: var(--rose-soft);
}

.btn.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.78rem;
}

.btn.icon-only {
  width: 44px;
  padding: 0;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--outline);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  transition: background 140ms ease, color 140ms ease;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 9px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.chip svg {
  width: 13px;
  height: 13px;
}

.chip.accent {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}

.chip.ok {
  color: var(--green);
  background: var(--teal-soft);
  border-color: transparent;
}

.chip.warn {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: transparent;
}

.chip.off {
  color: var(--text-faint);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
}

.dot.on {
  background: var(--green);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 16%, transparent);
}

.dot.off {
  background: var(--red);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 14%, transparent);
}

.dot.warn {
  background: var(--amber);
}

/* ==========================================================================
   Cards / layout
   ========================================================================== */

.card {
  min-width: 0;
  padding: clamp(16px, 2.2vw, 24px);
  border: 1px solid var(--outline);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card.flat {
  box-shadow: none;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.card-subtitle {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-head h2 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: -0.015em;
}

.section-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.muted {
  color: var(--text-muted);
}

.faint {
  color: var(--text-faint);
}

.tiny {
  font-size: 0.72rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ==========================================================================
   Home
   ========================================================================== */

.hero {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(220px, 0.7fr);
  gap: 24px;
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--outline));
  border-radius: var(--radius-xl);
  background:
    radial-gradient(700px 320px at 90% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 65%),
    linear-gradient(135deg, color-mix(in srgb, var(--surface) 92%, var(--accent)), var(--surface));
  box-shadow: var(--shadow);
}

.hero > * {
  position: relative;
  z-index: 1;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.hero h2 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 3.4vw, 2.5rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.hero p {
  margin: 0;
  max-width: 58ch;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.hero-side {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface-2) 76%, transparent);
  backdrop-filter: blur(10px);
}

.hero-side-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hero-side-top strong {
  display: block;
  font-size: 0.9rem;
}

.hero-side-top small {
  display: block;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat {
  flex: 1 1 90px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--outline);
}

.stat strong {
  display: block;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.stat span {
  color: var(--text-muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.scene {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.scene-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.scene-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--accent-soft);
  color: var(--accent);
}

.scene-icon svg {
  width: 22px;
  height: 22px;
}

.scene h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.scene p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.scene-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 4px;
}

.rooms {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--outline);
}

.room-head h3 {
  margin: 0;
  font-size: 0.96rem;
  letter-spacing: -0.01em;
}

.room-head span {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.device-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  transition: border-color 140ms ease, transform 140ms ease;
  min-width: 0;
}

.device-card:hover {
  border-color: var(--outline-strong);
  transform: translateY(-1px);
}

.device-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.device-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--outline);
}

.device-icon svg {
  width: 20px;
  height: 20px;
}

.device-name {
  min-width: 0;
}

.device-name strong {
  display: block;
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-name small {
  display: block;
  color: var(--text-muted);
  font-size: 0.68rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-caps {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.device-caps .chip {
  font-size: 0.64rem;
  padding: 3px 7px;
}

.device-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

.device-actions .btn {
  flex: 1;
  min-height: 36px;
  font-size: 0.72rem;
  padding: 0 10px;
}

.list {
  display: flex;
  flex-direction: column;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--outline);
}

.list-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.list-row:first-child {
  padding-top: 0;
}

.list-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--outline);
}

.list-icon svg {
  width: 17px;
  height: 17px;
}

.list-main {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-size: 0.84rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-sub {
  color: var(--text-muted);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-end {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 0.7rem;
  white-space: nowrap;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 30px 16px;
  text-align: center;
  color: var(--text-muted);
}

.empty svg {
  width: 34px;
  height: 34px;
  color: var(--text-faint);
}

.empty strong {
  color: var(--text);
  font-size: 0.9rem;
}

.empty p {
  margin: 0;
  font-size: 0.8rem;
  max-width: 40ch;
}

/* ==========================================================================
   Automations
   ========================================================================== */

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

.auto-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.auto-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent);
}

.auto-icon svg {
  width: 20px;
  height: 20px;
}

.auto-name {
  margin: 0;
  font-size: 0.94rem;
}

.auto-trigger {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.auto-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.auto-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--outline);
}

.auto-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface-3);
  transition: background 160ms ease, border-color 160ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1), background 160ms ease;
}

.switch[aria-checked="true"] {
  background: var(--accent);
  border-color: transparent;
}

.switch[aria-checked="true"]::after {
  transform: translateX(20px);
  background: var(--accent-ink);
}

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.filter-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

/* ==========================================================================
   TV
   ========================================================================== */

.tv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 16px;
  align-items: start;
}

.tv-left,
.tv-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.now-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.now-art {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: linear-gradient(135deg, var(--accent-soft), var(--teal-soft));
  color: var(--accent);
  border: 1px solid var(--outline);
}

.now-art svg {
  width: 26px;
  height: 26px;
}

.now-main {
  flex: 1;
  min-width: 0;
}

.now-title {
  font-size: 1rem;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.now-sub {
  color: var(--text-muted);
  font-size: 0.76rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remote-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 70px);
  grid-template-rows: repeat(3, 70px);
  gap: 8px;
  justify-content: center;
}

.pad {
  display: grid;
  place-items: center;
  border: 1px solid var(--outline);
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  transition: background 120ms ease, transform 90ms ease;
}

.pad:hover {
  background: var(--surface-3);
}

.pad:active {
  transform: scale(0.95);
}

.pad svg {
  width: 22px;
  height: 22px;
}

.pad.up { grid-area: 1 / 2; }
.pad.left { grid-area: 2 / 1; }
.pad.ok {
  grid-area: 2 / 2;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-size: 0.9rem;
}
.pad.right { grid-area: 2 / 3; }
.pad.down { grid-area: 3 / 2; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.volume-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.volume-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.volume-label output {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 34px;
  accent-color: var(--accent);
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.app-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: left;
  min-width: 0;
  transition: background 120ms ease, transform 90ms ease;
}

.app-btn:hover {
  background: var(--surface-3);
}

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

.app-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: -0.03em;
}

.app-name {
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.15;
}

.search-row {
  display: flex;
  gap: 8px;
}

.input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.86rem;
}

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

.screen-frame {
  display: grid;
  place-items: center;
  min-height: 180px;
  overflow: hidden;
  border: 1px dashed var(--outline);
  border-radius: var(--radius-md);
  background: #000;
}

.screen-frame img {
  width: 100%;
  height: auto;
}

.screen-frame .empty {
  color: #8d8799;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--amber) 35%, var(--outline));
  border-radius: var(--radius-md);
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 0.8rem;
}

.banner svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 1px;
}

.banner strong {
  display: block;
  color: var(--text);
}

/* ==========================================================================
   Settings
   ========================================================================== */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--outline);
}

.setting-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.setting-copy {
  min-width: 0;
}

.setting-copy strong {
  display: block;
  font-size: 0.85rem;
}

.setting-copy small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface-2);
  gap: 2px;
}

.segmented button {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.segmented button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.kv {
  display: grid;
  grid-template-columns: minmax(100px, 0.4fr) minmax(0, 1fr);
  gap: 8px 14px;
  font-size: 0.8rem;
}

.kv dt {
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.security-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.security-list li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.security-list svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--green);
}

/* ==========================================================================
   Skeleton / toast / modal / auth
   ========================================================================== */

.skeleton {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 45%, var(--surface-2) 65%);
  background-size: 220% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-title {
  width: 42%;
  height: 24px;
  margin-bottom: 14px;
}

.skeleton-line {
  width: 100%;
  margin-bottom: 9px;
}

.skeleton-line.short {
  width: 62%;
}

.loading-card {
  max-width: 720px;
}

@keyframes shimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -40% 0; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 100;
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 11px 18px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 20px 50px -22px rgb(0 0 0 / 0.7);
  font-size: 0.82rem;
  text-align: center;
}

.toast.error {
  color: var(--rose);
  border-color: color-mix(in srgb, var(--rose) 40%, var(--outline));
}

.modal {
  width: min(760px, 92vw);
  max-width: 760px;
  max-height: 88dvh;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.62);
  backdrop-filter: blur(6px);
}

.modal-card {
  max-height: 88dvh;
  overflow: auto;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--outline);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: 0 40px 100px -40px rgb(0 0 0 / 0.9);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-head p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.yaml {
  margin: 0;
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  line-height: 1.55;
  white-space: pre;
}

body.auth-locked .sidebar,
body.auth-locked .bottom-nav,
body.auth-locked .topbar {
  display: none;
}

body.auth-locked .shell {
  grid-template-columns: minmax(0, 1fr);
}

body.auth-locked .view {
  max-width: 760px;
  padding-top: 8vh;
}

.auth-card {
  max-width: 620px;
  margin: 6vh auto 0;
  text-align: center;
}

.auth-card .scene-icon {
  margin: 0 auto 14px;
}

.auth-card h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.auth-card p {
  margin: 0 auto 16px;
  max-width: 52ch;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1200px) {
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tv-layout { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-side { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .hero-stats { flex: 1; }
}

@media (max-width: 1024px) {
  :root { --sidebar-w: 76px; }
  .brand { justify-content: center; padding: 6px; }
  .brand-text,
  .nav-label,
  .sidebar-foot .user-meta,
  .sidebar-foot .btn span {
    display: none;
  }
  .nav-link { justify-content: center; padding: 12px; }
  .sidebar-foot { align-items: center; }
  .user-chip { padding: 4px; border: 0; background: transparent; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { padding: 14px 16px; }
  .view { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); gap: 18px; }
  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    justify-content: space-around;
    gap: 2px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--outline);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(22px);
  }
  .bottom-nav .nav-link {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    min-height: 50px;
    padding: 6px 4px;
    font-size: 0.62rem;
    border-radius: 12px;
  }
  .bottom-nav .nav-link svg { width: 21px; height: 21px; }
  .bottom-nav .nav-label { display: block; }
  .grid.two,
  .grid.three,
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dpad { grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); }
  .app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .now-card { align-items: flex-start; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 42px; padding: 0; border-radius: 50%; }
}

@media (max-width: 620px) {
  body { font-size: 14px; }
  .page-heading p { max-width: 64vw; }
  .topbar-actions .chip { display: none; }
  .topbar-actions a[href="#/settings"] { display: none; }
  .grid.two,
  .grid.three,
  .grid.four,
  .device-grid,
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { padding: 20px; }
  .hero-side { flex-direction: column; align-items: stretch; }
  .hero-stats { width: 100%; }
  .stat { flex: 1 1 40%; }
  .scene-actions .btn { flex: 1; }
  .modal { width: 94vw; }
  .modal-card { border-radius: 22px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .search-row { flex-direction: column; }
  .search-row .btn { width: 100%; }
  .tv-layout { gap: 12px; }
  .dpad { grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 60px); }
  .pad { border-radius: 17px; }
  .media-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
  .app-grid { grid-template-columns: minmax(0, 1fr); }
  .dpad { grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 54px); }
  .topbar-actions { gap: 4px; }
  .icon-btn { width: 38px; height: 38px; }
}

/* ==========================================================================
   TV mode · 10-foot UI
   ========================================================================== */

body.tv-mode {
  font-size: 18px;
}

body.tv-mode .shell {
  grid-template-columns: 300px minmax(0, 1fr);
}

body.tv-mode .sidebar {
  padding: 30px 20px;
  gap: 34px;
}

body.tv-mode .brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
}

body.tv-mode .brand-mark svg {
  width: 32px;
  height: 32px;
}

body.tv-mode .brand-text strong {
  font-size: 1.15rem;
}

body.tv-mode .nav-link {
  min-height: 62px;
  font-size: 1rem;
  padding: 14px 16px;
  border-radius: 18px;
}

body.tv-mode .nav-link svg {
  width: 26px;
  height: 26px;
}

body.tv-mode .topbar {
  padding: 22px 40px;
}

body.tv-mode .page-heading h1 {
  font-size: 2rem;
}

body.tv-mode .page-heading p {
  font-size: 0.95rem;
}

body.tv-mode .view {
  max-width: 1800px;
  padding: 32px 40px 80px;
  gap: 30px;
}

body.tv-mode .card {
  padding: 28px;
  border-radius: 32px;
}

body.tv-mode .btn {
  min-height: 58px;
  padding: 0 22px;
  font-size: 1rem;
}

body.tv-mode .icon-btn {
  width: 54px;
  height: 54px;
}

body.tv-mode .hero h2 {
  font-size: 3rem;
}

body.tv-mode .hero p {
  font-size: 1.05rem;
}

body.tv-mode .scene h3,
body.tv-mode .auto-name,
body.tv-mode .device-name strong {
  font-size: 1.1rem;
}

body.tv-mode .scene p,
body.tv-mode .auto-desc,
body.tv-mode .device-name small {
  font-size: 0.92rem;
}

body.tv-mode .dpad {
  grid-template-columns: repeat(3, 86px);
  grid-template-rows: repeat(3, 86px);
  gap: 10px;
}

body.tv-mode .pad {
  border-radius: 24px;
}

body.tv-mode .pad svg {
  width: 28px;
  height: 28px;
}

body.tv-mode .app-btn {
  min-height: 68px;
}

body.tv-mode .app-logo {
  width: 42px;
  height: 42px;
  font-size: 0.8rem;
}

body.tv-mode .app-name {
  font-size: 0.95rem;
}

body.tv-mode .bottom-nav {
  display: none;
}

body.tv-mode :focus-visible {
  outline: 4px solid var(--accent);
  outline-offset: 4px;
}

body.tv-mode .hero {
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
}

@media (max-width: 1200px) {
  body.tv-mode .shell { grid-template-columns: 200px minmax(0, 1fr); }
  body.tv-mode .view { padding: 24px 24px 60px; }
  body.tv-mode .hero { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  body.tv-mode .shell { grid-template-columns: minmax(0, 1fr); }
  body.tv-mode .sidebar { display: none; }
  body.tv-mode .bottom-nav { display: flex; }
  body.tv-mode .view { padding: 20px 20px 110px; }
  body.tv-mode .dpad { grid-template-columns: repeat(3, 78px); grid-template-rows: repeat(3, 78px); }
}

/* ==========================================================================
   Motion / misc
   ========================================================================== */

.fade-in {
  animation: fade-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
