:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6ea;
  --text: #0f1419;
  --muted: #6b7280;
  --accent: #ff0033;
  --accent-dark: #d90029;
  --accent-soft: #ffe5ea;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --sidebar: #0f0f0f;
  --sidebar-text: #d1d5db;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 700; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
p { margin: 0; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: 0 0 240px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px 18px; color: #fff; font-weight: 700; font-size: 15px; }
.brand-mark { display: inline-block; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: 0 0 26px; }
.brand-mark::after { content: ""; position: absolute; left: 10px; top: 7px; border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 6px 12px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: none; border: 0; border-radius: 10px; color: var(--sidebar-text); cursor: pointer; text-align: left; font-weight: 500; position: relative; }
.nav-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: #1f1f1f; color: #fff; }
.nav-item.active { background: #262626; color: #fff; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.sidebar-footer { margin-top: auto; padding: 14px; border-top: 1px solid #222; }
.channel-loading { font-size: 12px; color: #888; }
.channel { display: flex; align-items: center; gap: 10px; }
.channel img, .channel .avatar { width: 38px; height: 38px; border-radius: 50%; background: #333; flex: 0 0 38px; object-fit: cover; }
.channel .avatar { display: grid; place-items: center; color: #fff; font-weight: 700; }
.channel-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-sub { font-size: 11px; color: #9ca3af; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-disconnect { background: none; border: 0; color: #9ca3af; font-size: 11px; cursor: pointer; padding: 0; margin-top: 4px; text-decoration: underline; }
.channel-disconnect:hover { color: #fff; }
.main { flex: 1; min-width: 0; padding: 28px 36px 60px; }
.page { display: none; max-width: 1180px; margin: 0 auto; }
.page.active { display: block; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; margin: 30px 0 12px; }
.section-title-row h2 { margin: 0; }
.empty { padding: 26px; text-align: center; }

/* ---------- cards & controls ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; background: var(--surface-2); cursor: pointer; font-weight: 600; white-space: nowrap; transition: background .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: #fff; border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: rgba(0,0,0,.05); }
.btn-danger { background: #fff; border-color: var(--border); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; text-decoration: underline; }
.select, input[type=text], input[type=password], input[type=number], textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; outline: none; }
.select { width: auto; }
input:focus, textarea:focus, .select:focus { border-color: #9ca3af; box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; gap: 10px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); margin-bottom: 12px; cursor: pointer; }
.counter { font-weight: 500; color: var(--muted); font-size: 12px; }
.counter.over { color: var(--red); }
.form-error { color: var(--red); margin-top: 10px; font-size: 13px; }

/* switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: 0 0 44px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.toggle-card { display: flex; align-items: center; gap: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; cursor: pointer; box-shadow: var(--shadow); }
.toggle-title { font-weight: 700; }
.toggle-sub { font-size: 12px; color: var(--muted); }

/* ---------- dropzone ---------- */
.dropzone { border: 2px dashed #c7ccd3; border-radius: 16px; padding: 44px 20px; text-align: center; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: #fff7f8; }
.dropzone-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; }
.dropzone-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dropzone-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }

/* ---------- activity / video cards ---------- */
.vcard { display: grid; grid-template-columns: 148px 1fr auto; gap: 16px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.vcard .thumb { width: 148px; aspect-ratio: 16/9; border-radius: 8px; background: #111 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 8l6 4-6 4z' fill='%23444'/%3E%3C/svg%3E") center/40px no-repeat; object-fit: cover; display: block; }
.vcard-title { font-weight: 700; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vcard-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.vcard-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.progress { height: 6px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ff6a00); border-radius: 999px; transition: width .4s; }
.progress.indeterminate > span { width: 40% !important; animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.progress-label { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; }

/* status badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.uploaded { background: var(--green-soft); color: #15803d; }
.badge.ready_for_review { background: var(--amber-soft); color: #b45309; }
.badge.failed { background: var(--red-soft); color: #b91c1c; }
.badge.queued, .badge.analyzing, .badge.generating_thumbnails, .badge.uploading { background: var(--blue-soft); color: #1d4ed8; }
.badge.analyzing::before, .badge.generating_thumbnails::before, .badge.uploading::before, .badge.queued::before { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.error-text { color: var(--red); font-size: 12px; margin-top: 6px; }

/* ---------- alerts ---------- */
.alert { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; display: flex; gap: 12px; align-items: flex-start; border: 1px solid; }
.alert strong { display: block; margin-bottom: 2px; }
.alert.warn { background: var(--amber-soft); border-color: #fcd34d; color: #92400e; }
.alert.error { background: var(--red-soft); border-color: #fca5a5; color: #991b1b; }
.alert.info { background: var(--blue-soft); border-color: #93c5fd; color: #1e40af; }
.alert.success { background: var(--green-soft); border-color: #86efac; color: #166534; }
.alert .btn { margin-left: auto; }

/* ---------- review page ---------- */
.review-grid { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.review-grid video { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 16/9; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12px; margin-top: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details { margin-top: 12px; }
details summary { cursor: pointer; font-weight: 600; }
.transcript { max-height: 280px; overflow: auto; white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 8px; margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip button { background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; }
.chip.suggest { cursor: pointer; }
.chip.suggest:hover { border-color: var(--accent); color: var(--accent); }
.tag-editor { border: 1px solid var(--border); border-radius: 10px; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; background: #fff; }
.tag-editor input { flex: 1; min-width: 160px; border: 0; padding: 4px 6px; }
.tag-editor input:focus { box-shadow: none; }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.thumb-option { position: relative; border: 3px solid transparent; border-radius: 12px; overflow: hidden; cursor: pointer; background: #000; aspect-ratio: 16/9; }
.thumb-option img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-option.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.thumb-option .tag { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.thumb-option .check { position: absolute; right: 8px; top: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: none; place-items: center; font-size: 13px; }
.thumb-option.selected .check { display: grid; }
.thumb-gen { border: 1px dashed var(--border); border-radius: 12px; padding: 12px; margin-top: 12px; background: var(--surface-2); }
.thumb-gen .row { flex-wrap: wrap; }
.thumb-gen input[type=text] { flex: 1; min-width: 180px; }
.alt-titles { margin-top: 8px; }
.ai-box { background: var(--surface-2); border-radius: 10px; padding: 12px; font-size: 13px; margin-top: 12px; }
.ai-box h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.yt-result { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.stat-inline { display: inline-flex; gap: 14px; font-size: 13px; }
.stat-inline b { font-size: 15px; }

/* ---------- reports ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fafbfc; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .vcell { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.table .vcell img { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #111; flex: 0 0 96px; }
.table .vcell .t { font-weight: 600; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table .vcell .s { font-size: 12px; color: var(--muted); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- settings ---------- */
.info-list { display: flex; flex-direction: column; gap: 10px; }
.info-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; font-size: 13px; align-items: center; }
.info-item .k { color: var(--muted); }
.info-item .v { font-weight: 600; text-align: right; word-break: break-all; }
.ok { color: var(--green); }
.bad { color: var(--red); }
.copy-btn { margin-left: 8px; }

/* ---------- connect / VNC ---------- */
.connect-steps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.step { display: flex; align-items: baseline; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); }
.step-n { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; }
.vnc-frame { padding: 0; overflow: hidden; }
.vnc-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.vnc-status { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.vnc-status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; }
.vnc-status.on::before { background: var(--green); }
.vnc-status.off::before { background: var(--amber); }
.vnc-status.err::before { background: var(--red); }
.vnc-viewport { position: relative; width: 100%; aspect-ratio: 1280/800; background: #0b0b0b; }
.vnc-viewport iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #0b0b0b; }
.vnc-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #9ca3af; font-size: 14px; text-align: center; padding: 20px; }

/* ---------- overlay & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 15, 15, .96); z-index: 50; display: grid; place-items: center; }
.login-card { background: #fff; border-radius: 16px; padding: 32px; width: 360px; text-align: center; }
.login-card .brand-mark { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px; }
.login-card .brand-mark::after { left: 17px; top: 13px; border-left-width: 14px; border-top-width: 9px; border-bottom-width: 9px; }
.login-card p { margin: 6px 0 18px; color: var(--muted); }
.login-card input { margin-bottom: 10px; }
#toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #111; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 13px; max-width: 360px; animation: fadein .2s; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 980px) {
  .review-grid, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-basis: auto; height: auto; position: static; }
  .nav { flex-direction: row; }
  .nav-item span:not(.nav-badge) { display: none; }
  .sidebar-footer { display: none; }
  .main { padding: 18px; }
  .vcard { grid-template-columns: 1fr; }
  .vcard .thumb { width: 100%; }
}
