/* Oriel web app: Apple-style (Human Interface look, no Apple assets). Shared by /app/ and /app/playback/.
   System fonts, light and dark via prefers-color-scheme, iOS-style switches and segments, sheets. */

:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --hairline: rgba(0, 0, 0, 0.08);
  --fill: rgba(120, 120, 128, 0.16);
  --segment: rgba(118, 118, 128, 0.12);
  --segment-on: #ffffff;
  --accent: #0071e3;
  --danger: #ff3b30;
  --green: #34c759;
  --bar: rgba(245, 245, 247, 0.72);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --muted: #98989d;
    --hairline: rgba(255, 255, 255, 0.12);
    --fill: rgba(120, 120, 128, 0.36);
    --segment: rgba(118, 118, 128, 0.24);
    --segment-on: #636366;
    --accent: #0a84ff;
    --bar: rgba(28, 28, 30, 0.72);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  }
}

/* hidden must win over any class that sets display (.btn, .card, .skeleton). */
[hidden] {
  display: none !important;
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.47 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p,
ul,
figure {
  margin: 0;
}

a {
  color: var(--accent);
}

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

:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- Top bar ---------- */

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

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.brand img {
  display: block;
  width: 104px;
  height: auto;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  max-width: 100%;
  gap: 2px;
  padding: 3px;
  background: var(--segment);
  border-radius: 999px;
}

.tabs a {
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.tabs a[aria-current="page"] {
  background: var(--segment-on);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* ---------- Page and titles ---------- */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

.large-title {
  font-size: 34px;
  line-height: 41px;
  font-weight: 700;
  letter-spacing: -0.022em;
  margin: 4px 4px 0;
  outline: none;
}

.lead {
  color: var(--muted);
  font-size: 17px;
  margin: 8px 4px 0;
  max-width: 60ch;
}

.section {
  margin-top: 28px;
}

.section-title {
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 0 16px 8px;
}

.note {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
  margin: 8px 16px 0;
}

.section .note {
  margin: 0 16px 8px;
}

.fine {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 32px 4px 0;
}

.fine a {
  color: inherit;
}

/* ---------- Cards and grouped lists ---------- */

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

.card h2 {
  font-size: 20px;
  line-height: 25px;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.card p {
  color: var(--muted);
  font-size: 15px;
  margin-top: 6px;
}

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.account-label {
  font-size: 13px;
  color: var(--muted);
}

.account-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  overflow-wrap: anywhere;
}

.account-mail {
  font-size: 15px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.group {
  list-style: none;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 12px;
}

.group > li + li,
.group > .setting + .setting {
  border-top: 1px solid var(--hairline);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  position: relative;
}

.row-main {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.row-title {
  display: block;
  font-size: 17px;
}

.row-meta {
  display: block;
  font-size: 15px;
  color: var(--muted);
  margin-top: 2px;
}

.row-btn {
  width: 100%;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
}

.row-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

.row-btn:not(:disabled):hover {
  background: var(--segment);
}

.row-link {
  color: inherit;
  text-decoration: none;
}

.row-link:hover {
  background: var(--segment);
}

.row-link .chevron {
  color: var(--muted);
}

.row-action .row-title {
  color: var(--accent);
}

.tv-icon {
  color: var(--muted);
  display: inline-flex;
  flex: none;
}

.check,
.accent {
  color: var(--accent);
}

.check {
  display: inline-flex;
  flex: none;
}

/* ---------- Source rows and menu ---------- */

.row-more {
  position: relative;
  flex: none;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.icon-btn:not(:disabled):hover {
  background: var(--segment);
}

.icon-btn:disabled {
  color: var(--muted);
  opacity: 0.4;
  cursor: default;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 10;
  min-width: 200px;
  display: grid;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.menu button {
  font: inherit;
  font-size: 17px;
  text-align: left;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

.menu button:hover,
.menu button:focus-visible {
  background: var(--segment);
}

.menu button.danger {
  color: var(--danger);
}

/* ---------- Switch (51 x 31) ---------- */

.switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.switch[aria-checked="true"] {
  background: var(--green);
}

.switch:disabled {
  opacity: 0.5;
  cursor: default;
}

.switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2), 0 0 1px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.switch[aria-checked="true"] .knob {
  transform: translateX(20px);
}

/* ---------- Segmented control ---------- */

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

legend {
  padding: 0;
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 4px;
}

.setting {
  padding: 16px;
}

.setting-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.setting-desc {
  color: var(--muted);
  font-size: 15px;
  margin-top: 2px;
}

.setting .segmented {
  margin-top: 12px;
}

.segmented {
  display: flex;
  padding: 2px;
  background: var(--segment);
  border-radius: 9px;
}

.segmented label {
  flex: 1 1 0;
  position: relative;
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  text-align: center;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.segmented input:checked + span {
  background: var(--segment-on);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16), 0 3px 8px rgba(0, 0, 0, 0.1);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.segmented input:disabled + span {
  opacity: 0.4;
  cursor: default;
}

.setting-status {
  margin-top: 8px;
}

.setting-status:empty {
  display: none;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: var(--fill);
  color: var(--accent);
}

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

.btn-secondary {
  background: var(--fill);
  color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

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

.btn-block {
  width: 100%;
  margin-top: 16px;
}

/* ---------- Form fields ---------- */

.field {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.field > label {
  font-size: 15px;
  color: var(--muted);
}

input[type="text"],
input[type="url"],
input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--segment);
  border: 1px solid var(--hairline);
  border-radius: 10px;
}

input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.field-set {
  margin-top: 16px;
}

.field-set legend {
  font-size: 15px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 8px;
}

/* ---------- Status and banners ---------- */

.status {
  min-height: 1.4em;
  margin: 10px 4px 0;
  font-size: 15px;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

/* Sync state of one source row: waiting for the TV, or not applied by it. */
.chip {
  width: fit-content;
  margin-top: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.chip[data-state="refused"] {
  color: var(--danger);
}

/* Visually hidden, still read by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
}

/* Loading placeholder: grey bars in place of the TV list, so the layout does not jump when it loads. */
.skeleton {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.skeleton[hidden] {
  display: none;
}

.skel-line {
  display: block;
  height: 14px;
  border-radius: 7px;
  background: var(--fill);
  animation: skel-pulse 1.4s ease-in-out infinite;
}

.skel-line.w60 {
  width: 60%;
}

.skel-line.w80 {
  width: 80%;
}

@keyframes skel-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Account menu in the top bar: an avatar that opens the account and sign-out. */
.account-menu {
  position: relative;
  margin-left: auto;
}

.account-menu > summary {
  list-style: none;
  cursor: pointer;
}

.account-menu > summary::-webkit-details-marker {
  display: none;
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 10;
  width: 240px;
  padding: 14px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}

/* A message under a form field. Hidden until the field is refused. */
.field-error {
  margin: 6px 4px 0;
  font-size: 14px;
  color: var(--danger);
}

.field-error[hidden] {
  display: none;
}

.status.done {
  color: var(--text);
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  font-size: 15px;
  color: var(--muted);
}

.banner strong {
  color: var(--text);
  font-weight: 600;
}

.banner::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- Sheets: bottom on phones, centred on wide screens ---------- */

dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 14px 14px 0 0;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

dialog.sheet::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog.sheet[open] {
  animation: sheet-up 0.28s ease-out;
}

.sheet-form {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.grabber {
  width: 36px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 3px;
  background: var(--fill);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 0 20px;
}

.sheet-head h2,
.sheet-title {
  font-size: 20px;
  line-height: 25px;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.sheet-body {
  padding: 8px 20px 0;
}

.sheet-body .note {
  margin: 8px 0 0;
}

.sheet-body .field:first-child,
.sheet-body .field-set:first-child {
  margin-top: 4px;
}

.sheet-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 10px;
  padding: 20px;
}

@keyframes sheet-up {
  from {
    transform: translateY(32px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@media (min-width: 700px) {
  .page {
    padding: 32px 24px 72px;
  }

  .topbar-inner {
    padding: 12px 24px;
  }

  dialog.sheet {
    inset: 0;
    margin: auto;
    width: 460px;
    max-width: calc(100% - 32px);
    max-height: 85vh;
    border-radius: 14px;
  }

  dialog.sheet .grabber {
    display: none;
  }

  .sheet-head {
    padding-top: 18px;
  }
}

/* ---------- Motion and small details ---------- */

@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;
  }
}

@media (hover: none) {
  .row-btn:not(:disabled):hover,
  .row-link:hover,
  .icon-btn:not(:disabled):hover {
    background: none;
  }
}

noscript {
  display: block;
  margin-top: 16px;
  color: var(--danger);
}

/* ---------- Small layout helpers ---------- */

.icon-inline,
.chevron {
  display: inline-flex;
  flex: none;
}

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

.mt-12 {
  margin-top: 12px;
}

.footer-page {
  padding-top: 0;
}

.fine.flush {
  margin-top: 0;
}

/* Notes that follow a list get a little space above them. */
.group ~ .note {
  margin-top: 10px;
}

/* Google's sign-in button, rendered by Google Identity Services. */
.google-signin {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin-top: 4px;
}
