:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-subtle: #f5f5f7;
  --surface-hover: #f9f9fb;
  --glass: rgba(255, 255, 255, 0.78);
  --hairline: rgba(0, 0, 0, 0.08);
  --hairline-strong: rgba(0, 0, 0, 0.14);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --blue-tint: rgba(0, 113, 227, 0.1);
  --green: #248a3d;
  --green-tint: rgba(52, 199, 89, 0.14);
  --red: #d70015;
  --red-tint: rgba(255, 59, 48, 0.12);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 24px 60px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.08);
  --focus-ring: 0 0 0 4px rgba(0, 113, 227, 0.2);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-subtle: #2c2c2e;
    --surface-hover: #252528;
    --glass: rgba(28, 28, 30, 0.78);
    --hairline: rgba(255, 255, 255, 0.1);
    --hairline-strong: rgba(255, 255, 255, 0.18);
    --text: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #8e8e93;
    --blue: #0a84ff;
    --blue-hover: #409cff;
    --blue-tint: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --green-tint: rgba(48, 209, 88, 0.18);
    --red: #ff453a;
    --red-tint: rgba(255, 69, 58, 0.18);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-sheet: 0 24px 60px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* Sticky frosted navigation bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}

.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand-svg {
  width: 24px;
  height: 24px;
}

.segmented-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
}

.seg-link {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.seg-link:hover {
  color: var(--text);
}

.seg-link.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.nav-count {
  background: var(--blue);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

.text-btn:hover {
  background: var(--blue-tint);
}

/* Floating toast */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--shadow-sheet);
  font-size: 0.88rem;
  font-weight: 500;
  max-width: min(92vw, 480px);
  text-align: center;
}

.toast.error {
  color: var(--red);
  border-color: var(--red-tint);
}

.toast.success {
  color: var(--green);
}

/* Main page container */
.page-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 36px 24px 80px;
}

/* Auth Stage */
.auth-stage {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.auth-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.auth-emblem {
  width: 52px;
  height: 52px;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.auth-subtitle {
  margin: 0;
  font-size: 0.94rem;
  color: var(--text-secondary);
  max-width: 320px;
}

.notice-pill {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--blue-tint);
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: center;
}

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

/* Apple-style connected grouped input stack */
.grouped-inputs {
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.grouped-field {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--hairline);
}

.grouped-field:last-child {
  border-bottom: 0;
}

.grouped-field input,
.grouped-field select {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.96rem;
  padding: 14px 16px;
  outline: none;
}

.grouped-field input:focus,
.grouped-field select:focus {
  background: var(--blue-tint);
}

.grouped-field-labeled {
  padding-left: 16px;
}

.field-prefix {
  color: var(--text-secondary);
  font-size: 0.92rem;
  min-width: 72px;
}

.field-caption {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
}

.auth-switch {
  margin-top: 4px;
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-weight: 500;
  padding: 0;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

/* Buttons */
.btn {
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 500;
  padding: 11px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.08s ease;
}

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

.btn-block {
  width: 100%;
  padding: 13px 18px;
  border-radius: 12px;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.84rem;
  border-radius: 999px;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: 999px;
}

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

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

.btn-subtle {
  background: var(--surface-subtle);
  color: var(--text);
  border: 1px solid var(--hairline);
}

.btn-subtle:hover {
  background: var(--hairline);
}

.btn-danger-text {
  background: var(--red-tint);
  color: var(--red);
}

.btn-danger-text:hover {
  opacity: 0.86;
}

/* Account Layout */
.account-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 44px;
  align-items: start;
}

.account-sidebar {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.identity-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.avatar-lg {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--shadow-card);
  color: var(--text);
  font-size: 1.75rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}

.identity-name {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.identity-email {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
  word-break: break-word;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.chip-blue {
  background: var(--blue-tint);
  border-color: transparent;
  color: var(--blue);
}

.chip-green {
  background: var(--green-tint);
  border-color: transparent;
  color: var(--green);
}

.side-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-item {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: 10px;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.side-item:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.side-item.active {
  color: var(--blue);
  background: var(--blue-tint);
}

.account-main {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

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

.section-head h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-head p {
  margin: 3px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.section-head-compact h3 {
  margin: 0 0 0 4px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

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

.form-hint {
  margin: 10px 4px 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* iOS/macOS Inset Grouped Card */
.inset-group {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.inset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hairline);
}

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

.inset-footer {
  padding: 12px 18px;
  display: flex;
  justify-content: flex-end;
  background: var(--surface-hover);
}

.row-label {
  font-size: 0.93rem;
  font-weight: 500;
  color: var(--text);
}

.row-sub {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.row-value {
  font-size: 0.92rem;
  color: var(--text-secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-control {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.row-control-inline {
  gap: 8px;
}

.inline-input,
.inline-select {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  text-align: right;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.inline-input:hover,
.inline-select:hover {
  background: var(--surface-subtle);
}

.inline-input:focus,
.inline-select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--blue);
  box-shadow: var(--focus-ring);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

/* Homes View */
.homes-stage,
.admin-stage {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.view-header h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.view-subtitle {
  margin: 3px 0 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.homes-workspace {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 28px;
  align-items: start;
}

.homes-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 0 6px;
}

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

.home-nav-item {
  width: 100%;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--text);
  border-radius: 13px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.home-nav-item:hover {
  background: var(--surface-hover);
}

.home-nav-item.active {
  border-color: var(--blue);
  background: var(--blue-tint);
}

.home-nav-title {
  font-size: 0.94rem;
  font-weight: 600;
}

.home-nav-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.home-detail-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.home-banner {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.home-banner-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

.home-glyph {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--blue-tint);
  color: var(--blue);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.home-glyph svg {
  width: 22px;
  height: 22px;
}

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

.home-title-row h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.home-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--hairline);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

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

.empty-state {
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-icon {
  width: 44px;
  height: 44px;
  color: var(--text-tertiary);
}

.empty-state h3 {
  margin: 4px 0 0;
  font-size: 1.08rem;
  font-weight: 600;
}

.empty-state p {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  max-width: 320px;
}

/* Admin Table */
.search-field {
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 999px;
  min-width: 240px;
}

.search-field:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: var(--focus-ring);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
}

th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.8rem;
}

tr:last-child td {
  border-bottom: 0;
}

/* Modal Sheets */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-sheet {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 20px;
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.icon-close {
  border: 0;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 999px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.modal-body {
  padding: 10px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.invite-share-box {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.invite-share-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--green);
}

.invite-share-code {
  word-break: break-all;
  color: var(--text);
}

/* Admin Stats & Access Controls */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-tile {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.chip-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.permission-banner {
  border-color: var(--hairline-strong);
}

.modal-sheet-wide {
  max-width: 480px;
}

.modal-actions-split {
  justify-content: space-between;
  align-items: center;
}

.admin-user-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px;
}

.admin-services-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-service-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ios-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  cursor: pointer;
}

.ios-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-switch-track {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--hairline-strong);
  position: relative;
  transition: background-color 0.2s ease;
}

.ios-switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.ios-switch input:checked + .ios-switch-track {
  background: var(--green);
}

.ios-switch input:checked + .ios-switch-track::after {
  transform: translateX(18px);
}

.ios-switch input:disabled + .ios-switch-track {
  opacity: 0.55;
  cursor: not-allowed;
}

.ios-switch input:focus-visible + .ios-switch-track {
  box-shadow: var(--focus-ring);
}

@media (max-width: 780px) {
  .account-layout,
  .homes-workspace {
    grid-template-columns: 1fr;
    gap: 24px;
  }

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

  .account-sidebar {
    position: static;
  }

  .topbar-inner {
    padding: 0 16px;
  }

  .page-wrap {
    padding: 24px 16px 64px;
  }
}

[hidden] {
  display: none !important;
}

.pair-tv-stage {
  min-height: calc(100vh - 160px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pair-tv-card {
  width: 100%;
  max-width: 460px;
}

.pin-input {
  width: 90px;
  text-align: center;
  letter-spacing: 0.25em;
  font-variant-numeric: tabular-nums;
}

.notice-error {
  background: rgba(255, 59, 48, 0.12);
  color: #c9342b;
}
