/* CloudTV Fitness dashboard */
:root {
  --bg: #f6f5f3; --surface: #ffffff; --surface-2: #f1efec; --line: #e5e1dc; --text: #1d1b19; --muted: #6d6862;
  --primary: #e8553a; --primary-ink: #ffffff; --primary-soft: #fdebe6; --ok: #1f9d6b; --ok-soft: #e3f5ec;
  --danger: #c93a3a; --danger-soft: #fbe9e9; --focus: #e8553a66; --shadow: 0 1px 2px #0000000d, 0 6px 24px #00000010;
  --radius: 14px; --side: 232px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110; --surface: #1c1a19; --surface-2: #262321; --line: #34302d; --text: #f2efeb; --muted: #a39d96;
    --primary: #ff7a5c; --primary-ink: #1b0f0b; --primary-soft: #3a211b; --ok: #4fd29a; --ok-soft: #173327;
    --danger: #ff7b7b; --danger-soft: #3a1c1c; --focus: #ff7a5c66; --shadow: 0 1px 2px #00000040, 0 8px 28px #00000055; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --surface: #1c1a19; --surface-2: #262321; --line: #34302d; --text: #f2efeb; --muted: #a39d96;
  --primary: #ff7a5c; --primary-ink: #1b0f0b; --primary-soft: #3a211b; --ok: #4fd29a; --ok-soft: #173327;
  --danger: #ff7b7b; --danger-soft: #3a1c1c; --focus: #ff7a5c66; --shadow: 0 1px 2px #00000040, 0 8px 28px #00000055; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: Lexend, Inter, system-ui, sans-serif; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--primary); }
.muted { color: var(--muted); }
small { font-size: 12.5px; }
.icon { flex: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid transparent; font: 600 14px/1 Inter, system-ui, sans-serif; cursor: pointer; white-space: nowrap; color: var(--text);
  background: transparent; transition: background .15s, border-color .15s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { border-color: var(--line); background: var(--surface); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.subtle { color: var(--muted); }
.btn.subtle:hover { color: var(--text); background: var(--surface-2); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor;
  border-color: var(--primary-ink) transparent var(--primary-ink) transparent; animation: spin .7s linear infinite; }
.btn.ghost.busy::after { border-color: var(--text) transparent var(--text) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; font: 600 18px/1 Inter, sans-serif; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---- Shell ---- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 20px 14px;
  background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; font: 600 17px Lexend, sans-serif; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); }
.brand small { display: block; color: var(--muted); font: 500 11.5px Inter, sans-serif; letter-spacing: .04em; text-transform: uppercase; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--primary-soft); color: var(--primary); }
.nav a .badge { margin-left: auto; }
.side .me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid var(--line); }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); font-weight: 600; flex: none; }
.me .who { min-width: 0; flex: 1; }
.me .who b, .me .who small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { min-width: 0; padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 13.5px; margin-bottom: 6px; }
.crumb:hover { color: var(--text); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .shell.open .side { transform: none; }
  .shell.open::after { content: ""; position: fixed; inset: 0; background: #0006; z-index: 20; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 10; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--line); font: 600 16px Lexend, sans-serif; }
  .main { padding: 20px 16px 64px; }
  h1 { font-size: 22px; }
}

/* ---- Cards / lists ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 20px; }
.section { margin-top: 28px; }
.section > h2, .section-head { margin-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.accent { background: var(--primary-soft); color: var(--primary); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.stat-row span { display: inline-flex; align-items: center; gap: 5px; }

/* Routine cards */
.routine-card { overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s; }
.routine-card:hover { transform: translateY(-2px); }
.routine-card .cover { position: relative; aspect-ratio: 16 / 8; background: var(--surface-2) center / cover; }
.routine-card .cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 40%, #0009); }
.routine-card .cover .badge { position: absolute; z-index: 1; top: 10px; left: 10px; background: #000a; color: #fff; }
.routine-card .cover h3 { position: absolute; z-index: 1; left: 16px; bottom: 12px; color: #fff; font-size: 19px; }
.routine-card .accent-bar { height: 4px; background: var(--c); }
.routine-card .body { padding: 14px 16px 16px; display: grid; gap: 8px; }
.add-card { display: grid; place-items: center; gap: 8px; min-height: 220px; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted);
  background: transparent; cursor: pointer; font: 600 15px Inter, sans-serif; }
.add-card:hover { border-color: var(--primary); color: var(--primary); }

/* ---- Forms ---- */
.field { display: grid; gap: 6px; }
.field + .field { margin-top: 16px; }
.label { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.label .hint { font-weight: 400; color: var(--muted); }
.req { color: var(--primary); }
input:not([type=checkbox]), select, textarea { width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 15px Inter, system-ui, sans-serif; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.field.invalid input, input.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12.5px; min-height: 0; }
.field-error:empty { display: none; }
.bi-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bi-input { position: relative; display: block; }
.bi-input .lang { position: absolute; left: 10px; top: 11px; font: 700 10.5px/20px Inter, sans-serif; letter-spacing: .05em; color: var(--muted);
  background: var(--surface-2); border-radius: 5px; padding: 0 5px; }
.bi-input input { padding-left: 44px; padding-right: 52px; }
.bi-input .count { position: absolute; right: 10px; top: 12px; font-size: 11px; color: var(--muted); opacity: 0; transition: opacity .15s; }
.bi-input:focus-within .count { opacity: 1; }
@media (max-width: 640px) { .bi-row { grid-template-columns: 1fr; } }

.stepper { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 12px; padding: 3px; background: var(--surface); }
.stepper .icon-btn { width: 36px; height: 36px; font-size: 20px; }
.stepper-value { min-width: 72px; text-align: center; font: 600 15px Lexend, sans-serif; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 500 14px Inter, sans-serif; cursor: pointer; }
.chip small { color: var(--muted); }
.chip:hover { border-color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.on small { color: inherit; opacity: .7; }
.chips.seg { display: inline-flex; gap: 0; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.chips.seg .chip { border: 0; background: transparent; border-radius: 9px; height: 34px; }
.chips.seg .chip.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toggle { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .track { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line); transition: background .15s; flex: none; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px #0003; transition: transform .15s; }
.toggle input:checked + .track { background: var(--primary); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }
.toggle small { display: block; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--c); color: #1d1b19;
  cursor: pointer; box-shadow: inset 0 0 0 1px #0000001a; }
.swatch.on { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--c); }

.move-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
.move-grid.compact { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
.move { position: relative; display: grid; gap: 0; padding: 0; border: 2px solid transparent; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); cursor: pointer; text-align: left; color: var(--text); }
.move img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.move-name { padding: 7px 9px; font: 500 12.5px/1.3 Inter, sans-serif; }
.move:hover { border-color: var(--line); }
.move.on { border-color: var(--primary); }
.move .tick { position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink); }

/* ---- Editor ---- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.editor .preview { position: sticky; top: 24px; }
@media (max-width: 1040px) { .editor { grid-template-columns: 1fr; } .editor .preview { position: static; } }
.form-card { padding: 22px; }
.form-card + .form-card { margin-top: 18px; }
.form-card > h2 { margin-bottom: 4px; }
.form-card > p.muted { margin-bottom: 16px; font-size: 13.5px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .row2 { grid-template-columns: 1fr; } }

.tv-preview { overflow: hidden; }
.tv-preview .screen { position: relative; aspect-ratio: 16 / 9; background: #000 center / cover; }
.tv-preview .screen::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, #000d 10%, #0000 75%); }
.tv-preview .screen > div { position: absolute; z-index: 1; left: 16px; bottom: 14px; right: 30%; color: #fff; }
.tv-preview .eyebrow { font: 600 10px Inter, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--c); }
.tv-preview .title { font: 600 18px/1.2 Lexend, sans-serif; margin: 2px 0 4px; }
.tv-preview .tag { font-size: 11.5px; opacity: .85; }
.tv-preview .meta { padding: 14px 16px; display: grid; gap: 6px; font-size: 13px; }

.ex-list { display: grid; gap: 8px; }
.ex { display: grid; grid-template-columns: auto 88px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px 10px 8px 6px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ex.dragging { opacity: .5; }
.ex.drop-before { box-shadow: 0 -3px 0 var(--primary); }
.ex.drop-after { box-shadow: 0 3px 0 var(--primary); }
.ex .handle { cursor: grab; color: var(--muted); display: grid; place-items: center; width: 22px; height: 40px; }
.ex img { width: 88px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; display: block; }
.ex .info { min-width: 0; }
.ex .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex .info .stat-row { gap: 10px; font-size: 12.5px; }
.ex .tools { display: flex; gap: 2px; }
@media (max-width: 640px) {
  .ex { grid-template-columns: auto 64px minmax(0, 1fr); }
  .ex img { width: 64px; }
  .ex .tools { grid-column: 1 / -1; justify-content: flex-end; }
}

.dropzone { display: grid; place-items: center; gap: 6px; padding: 18px; border: 2px dashed var(--line); border-radius: 12px; text-align: center;
  color: var(--muted); cursor: pointer; }
.dropzone.over, .dropzone:hover { border-color: var(--primary); color: var(--text); }
.clip { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.clip video { width: 120px; aspect-ratio: 16 / 9; border-radius: 8px; background: #000; object-fit: cover; }
.clip .grow { flex: 1; min-width: 0; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.checklist { display: grid; gap: 4px; font-size: 13px; margin-top: 8px; }
.checklist .ok { color: var(--ok); } .checklist .bad { color: var(--danger); }

/* ---- Modal ---- */
.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: 18px; background: var(--surface);
  color: var(--text); box-shadow: 0 20px 60px #0005; display: flex; flex-direction: column; }
.modal:not([open]) { display: none; }
.modal.wide { width: min(860px, calc(100vw - 32px)); }
.modal::backdrop { background: #0008; backdrop-filter: blur(2px); }
.modal header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.modal-body { padding: 10px 20px 20px; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ---- Pickers ---- */
.pick-list { display: grid; gap: 6px; max-height: 320px; overflow: auto; }
.pick { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.pick:hover { background: var(--surface-2); }
.pick .grow { flex: 1; min-width: 0; }
.pick img { width: 64px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; }
.order-list { display: grid; gap: 6px; }
.order-list .pick { cursor: default; }

/* ---- Usage ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi { padding: 16px 18px; }
.kpi .v { font: 600 28px/1.1 Lexend, sans-serif; margin-top: 6px; }
.kpi .l { color: var(--muted); font-size: 13px; }
.usage-tv { padding: 18px 20px; }
.usage-tv + .usage-tv { margin-top: 14px; }
.bars { display: grid; gap: 6px; align-items: end; height: 140px; margin-top: 14px; }
.bar { display: grid; grid-template-rows: auto 1fr auto; height: 100%; text-align: center; gap: 4px; }
.bar .n { font: 600 12px Inter, sans-serif; color: var(--muted); }
.bar .col { display: flex; align-items: flex-end; }
.bar .fill { width: 100%; max-width: 44px; margin: 0 auto; border-radius: 6px 6px 2px 2px; background: var(--primary); min-height: 2px; }
.bar .fill.zero { background: var(--line); }
.bar.now .fill:not(.zero) { background: linear-gradient(var(--primary), color-mix(in srgb, var(--primary) 70%, transparent)); }
.bar .wk { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: visible; width: 0; justify-self: center; display: flex; justify-content: center; }

/* ---- Auth ---- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .hero { position: relative; display: flex; flex-direction: column; justify-content: flex-end; padding: 48px; color: #fff; overflow: hidden;
  background: #111 url(/hero.webp) center / cover; }
.auth .hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, #0002, #000c); }
.auth .hero > * { position: relative; }
.auth .hero h1 { font-size: 34px; max-width: 460px; line-height: 1.15; }
.auth .hero p { opacity: .85; margin-top: 10px; max-width: 420px; }
.auth .panel { display: grid; place-items: center; padding: 32px 16px; }
.auth form { width: min(380px, 100%); display: grid; gap: 14px; }
.auth form .chips.seg { justify-self: start; margin-bottom: 6px; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth .hero { min-height: 220px; padding: 24px; } .auth .hero h1 { font-size: 24px; } }

.empty { display: grid; justify-items: center; gap: 8px; padding: 48px 20px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); margin-bottom: 6px; }
.empty .btn { margin-top: 10px; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

.toasts { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  font-weight: 500; animation: tin .2s ease-out; transition: opacity .3s, transform .3s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok .icon { color: var(--ok); }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.field > .stepper, .field > .chips.seg, .field > .chips { justify-self: start; }
.modal-body > div > .field, .modal-body > div > div > .field { margin-top: 16px; }
.modal-body > div > .field:first-child { margin-top: 0; }
details > summary.label { display: list-item; list-style: disclosure-closed; }
details[open] > summary.label { list-style: disclosure-open; }
.modal-body .helper { margin: 12px 0 0; align-items: center; }
.hbars { display: grid; gap: 12px; margin-top: 14px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 180px) 1fr 130px; align-items: center; gap: 12px; font-size: 14px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.hbar-track { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 6px; min-width: 4px; }
.hbar-n { color: var(--muted); font-size: 13px; white-space: nowrap; text-align: right; }
@media (max-width: 560px) { .hbar { grid-template-columns: 1fr auto; } .hbar-track { grid-column: 1 / -1; grid-row: 2; } }
