/* FamilyTube Studio — no framework, no build step. */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --line: #e6e3dd;
  --text: #1f1d1a;
  --muted: #6d6a64;
  --accent: #e8553d;
  --accent-ink: #ffffff;
  --accent-soft: #fdebe7;
  --blue: #2f6fdf;
  --blue-soft: #e7effd;
  --green: #1f8f5a;
  --green-soft: #e3f4ea;
  --amber: #b7791f;
  --amber-soft: #fbf1df;
  --red: #c93a3a;
  --red-soft: #fbe6e6;
  --violet: #7650d8;
  --violet-soft: #efe9fc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 18, 15, .06), 0 2px 8px rgba(20, 18, 15, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1d1a;
    --surface-2: #24221f;
    --line: #34312c;
    --text: #efece6;
    --muted: #a19c93;
    --accent: #f06a52;
    --accent-soft: #3a2420;
    --blue: #6d9cf0;
    --blue-soft: #1e2a40;
    --green: #4cc28a;
    --green-soft: #1a3328;
    --amber: #e0a84a;
    --amber-soft: #3a2f1c;
    --red: #ef7070;
    --red-soft: #3d2020;
    --violet: #a68af0;
    --violet-soft: #2c2440;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: 12px; background: var(--accent); color: #fff; border-radius: 99px; padding: 0 7px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; font-size: 13px; }
.cron-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 6px; }
.cron-dot.bad { background: var(--red); }

.main { padding: 26px 32px 60px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 2px; }

.topbar-mobile { display: none; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.stack > * + * { margin-top: 16px; }

.stat { padding: 16px 18px; }
.stat .n { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 500 14px var(--font);
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-link { border: 0; background: none; padding: 0; color: var(--blue); cursor: pointer; font: inherit; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 550; font-size: 13.5px; margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: 14px var(--font);
}
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 450; }
.check input { margin-top: 3px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.counter { float: right; font-weight: 400; font-size: 12px; color: var(--muted); }
.counter.over { color: var(--red); }
.inline-form { display: inline; }

/* tag input */
.tags-box { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-height: 42px; cursor: text; }
.tags-box:focus-within { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.tags-box input { border: 0 !important; outline: 0 !important; flex: 1; min-width: 140px; padding: 4px; background: transparent; }
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--blue-soft); color: var(--blue); padding: 3px 4px 3px 9px; border-radius: 99px; font-size: 13px; }
.tag button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th a { color: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.thumb { width: 54px; height: 54px; border-radius: 7px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); display: block; }
.thumb.empty { display: grid; place-items: center; color: var(--muted); }
.thumb.empty svg { width: 20px; height: 20px; }
.title-cell { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.title-cell a { color: var(--text); font-weight: 550; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.s-queued, .badge.s-generating { background: var(--violet-soft); color: var(--violet); }
.badge.s-review { background: var(--amber-soft); color: var(--amber); }
.badge.s-scheduled { background: var(--blue-soft); color: var(--blue); }
.badge.s-uploading { background: var(--blue-soft); color: var(--blue); }
.badge.s-published { background: var(--green-soft); color: var(--green); }
.badge.s-failed { background: var(--red-soft); color: var(--red); }
.badge.s-generating::before, .badge.s-uploading::before { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }

/* ---------- alerts ---------- */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.alert-success { background: var(--green-soft); color: var(--green); }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-warn { background: var(--amber-soft); color: var(--amber); }
.alert-info { background: var(--blue-soft); color: var(--blue); }
.alert ul { margin: 0; padding-left: 18px; }

/* ---------- tabs / filters ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .n { font-size: 12px; color: var(--muted); margin-left: 4px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }

/* ---------- video page ---------- */
.player { width: 100%; max-height: 70vh; background: #000; border-radius: var(--radius); display: block; }
.player.vertical { max-width: 380px; margin: 0 auto; }
.placeholder-media { aspect-ratio: 16/9; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--line); display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
.placeholder-media.vertical { aspect-ratio: 9/16; max-width: 320px; margin: 0 auto; }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.events { list-style: none; padding: 0; margin: 0; font-size: 13.5px; max-height: 360px; overflow-y: auto; }
.events li { padding: 7px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 112px 1fr; gap: 10px; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-size: 12.5px; }
.events .error { color: var(--red); }
.events .warning { color: var(--amber); }
.desc-preview { white-space: pre-wrap; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-size: 14px; max-height: 220px; overflow-y: auto; }

.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* scene editor */
.scene { border: 1px solid var(--line); border-radius: 9px; padding: 12px; background: var(--surface-2); margin-bottom: 10px; }
.scene-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; font-size: 13px; }
.scene textarea { min-height: 54px; }
.scene .row { grid-template-columns: 1fr 1fr; }

.source-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 16px; }
.source-picker label { margin: 0; border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; cursor: pointer; background: var(--surface); font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.source-picker label small { display: block; font-weight: 400; }
.source-picker input { margin-top: 4px; }
.source-picker label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.assistant { background: linear-gradient(135deg, var(--violet-soft), var(--blue-soft)); border: 0; }
.assistant h2 { display: flex; align-items: center; gap: 8px; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal-dow { background: var(--surface-2); padding: 7px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.cal-day { background: var(--surface); min-height: 112px; padding: 6px; display: flex; flex-direction: column; gap: 4px; transition: background .12s; }
.cal-day.other { background: var(--surface-2); }
.cal-day.other .d { opacity: .45; }
.cal-day.today .d { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 7px; }
.cal-day.drop { background: var(--accent-soft); }
.cal-day .d { font-size: 12.5px; font-weight: 600; align-self: flex-start; }
.cal-item { display: block; font-size: 12px; padding: 4px 6px; border-radius: 6px; background: var(--blue-soft); color: var(--blue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: grab; border-left: 3px solid currentColor; }
.cal-item:hover { text-decoration: none; filter: brightness(.97); }
.cal-item.s-published { background: var(--green-soft); color: var(--green); cursor: pointer; }
.cal-item.s-failed { background: var(--red-soft); color: var(--red); }
.cal-item.s-uploading { background: var(--violet-soft); color: var(--violet); }
.cal-item.s-review { background: var(--amber-soft); color: var(--amber); }
.cal-item b { font-weight: 600; margin-right: 3px; }
.dragging { opacity: .4; }
.side-list { display: grid; gap: 8px; }
.side-item { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: grab; font-size: 13.5px; }
.side-item .thumb { width: 40px; height: 40px; }

/* ---------- keywords ---------- */
.score { display: inline-flex; align-items: center; gap: 8px; min-width: 110px; }
.bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 50px; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.bar.opp > i { background: var(--green); }
.bar.comp > i { background: var(--amber); }
.score span { font-variant-numeric: tabular-nums; font-size: 13px; width: 26px; text-align: right; }
.star { border: 0; background: none; cursor: pointer; font-size: 18px; color: var(--line); padding: 0 4px; line-height: 1; }
.star.on { color: #f2b01e; }
.kw-actions { display: flex; gap: 6px; justify-content: flex-end; }
.seed-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.seed-chips a { font-size: 13px; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.top-videos { font-size: 13px; margin: 6px 0 0; padding-left: 18px; }
.picker { position: relative; }
.picker-results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; display: none; }
.picker-results div { padding: 7px 11px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.picker-results div:hover { background: var(--surface-2); }

/* ---------- settings ---------- */
.settings-nav { position: sticky; top: 20px; display: grid; gap: 2px; }
.settings-nav a { padding: 7px 10px; border-radius: 7px; color: var(--text); font-size: 14px; }
.settings-nav a:hover { background: var(--surface); text-decoration: none; }
.settings-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 24px; align-items: start; }
.secret-state { font-size: 12px; color: var(--green); font-weight: 500; }
.test-result { font-size: 13px; margin-left: 6px; }
.test-result.ok { color: var(--green); }
.test-result.bad { color: var(--red); }
.cmd { display: flex; gap: 8px; align-items: center; }
.cmd code { flex: 1; padding: 8px 10px; display: block; }
section.card { scroll-margin-top: 20px; }

/* ---------- guest ---------- */
.guest { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.guest .card { width: 100%; max-width: 400px; padding: 28px; }
.guest .brand { padding: 0 0 18px; justify-content: center; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }

.toast { white-space: pre-line; position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 100; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; max-width: 420px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); color: #fff; }

.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.nav-open .sidebar { transform: none; }
  .topbar-mobile { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .main { padding: 18px 16px 50px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { display: none; }
  .cal-day { min-height: 74px; padding: 4px; }
  .cal-item { font-size: 11px; padding: 2px 4px; }
  .cal-item b { display: none; }
  .events li { grid-template-columns: 1fr; gap: 0; }
}
.dropzone > svg { width: 28px; height: 28px; } .dropzone small svg { width: 14px; height: 14px; vertical-align: -2px; }
h1 svg, h2 svg, h3 svg { width: 20px; height: 20px; flex: none; }
.grid > .card + .card, .split > .card + .card { margin-top: 0; }
.hint { font-size: 12.5px; color: var(--muted); }
.card img[alt=""][style*="width:100%"] { max-height: 260px; object-fit: contain; background: var(--surface-2); }
.cal-item { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
@media (max-width: 1100px) { .split[style] { grid-template-columns: 1fr !important; } }
.toolbar input[type=search] { width: 240px; }
