:root {
  --bg: #0a0a0c;
  --bg-2: #131318;
  --bg-3: #1a1a21;
  --border: #2a2a33;
  --border-strong: #3a3a44;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --text-faint: #6b7280;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --radius: 8px;
  --radius-sm: 4px;
  --gap: 1rem;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  background: var(--accent);
  color: white;
  border: 0;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { background: var(--border); color: var(--text-faint); cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: var(--bg-3); }
button.danger { background: var(--red); }
button.danger:hover:not(:disabled) { background: #dc2626; }
button.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }

input, textarea, select {
  font: inherit;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 4rem; font-family: inherit; }
label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.35rem; }
.field { margin-bottom: 1rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ============ Login ============ */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
}
.login-mark { color: var(--accent); margin: 0 auto 1rem; display: inline-block; }
.login-card h1 { font-size: 1.4rem; margin: 0 0 0.5rem; font-weight: 500; }
.login-sub { color: var(--text-dim); margin: 0 0 1.5rem; font-size: 0.9rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-error { color: var(--red); margin-top: 0.75rem; font-size: 0.85rem; min-height: 1.2em; }

/* ============ App shell ============ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0.75rem;
  display: flex; flex-direction: column;
}
.sidebar-mark { color: var(--accent); padding: 0 0.75rem 1.5rem; display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; font-weight: 500; }
.sidebar-mark svg { display: block; }
.nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer; user-select: none;
}
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-link:hover { background: var(--bg-3); color: var(--text); }
.nav-link.active { background: var(--bg-3); color: var(--text); }
.sidebar-foot { padding: 0.75rem; color: var(--text-faint); font-size: 0.8rem; }
.sidebar-foot button { width: 100%; background: transparent; color: var(--text-dim); border: 1px solid var(--border); padding: 0.45rem; }
.sidebar-foot button:hover { color: var(--text); border-color: var(--border-strong); }

.main { padding: 2rem 2.5rem; overflow-x: hidden; }
.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 1.4rem; font-weight: 500; }
.page-sub { color: var(--text-dim); font-size: 0.9rem; margin: 0.2rem 0 0; }

.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }

/* ============ Script Generator ============ */
.gen-wrap { max-width: 760px; }
.gen-wrap textarea { min-height: 8rem; }
.gen-actions { display: flex; gap: 0.75rem; align-items: center; }

.script-options { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.script-option { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; cursor: pointer; transition: border-color 0.15s; }
.script-option:hover { border-color: var(--border-strong); }
.script-option h3 { margin: 0 0 0.5rem; font-size: 1rem; font-weight: 500; }
.script-option p { color: var(--text-dim); white-space: pre-wrap; max-height: 12rem; overflow: hidden; font-size: 0.9rem; margin: 0; }
.script-option .meta { color: var(--text-faint); font-size: 0.8rem; margin-top: 0.5rem; }

/* ============ Script Editor ============ */
.editor-grid { display: grid; grid-template-columns: 240px 1fr 320px; gap: 1rem; height: calc(100vh - 8rem); }
.lib-panel, .compliance-panel { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.lib-panel header, .compliance-panel header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.lib-panel header h3, .compliance-panel header h3 { margin: 0; font-size: 0.9rem; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.lib-panel .lib-search { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.lib-panel .lib-list { flex: 1; overflow-y: auto; padding: 0.25rem; }
.lib-item { padding: 0.55rem 0.75rem; border-radius: var(--radius-sm); cursor: pointer; }
.lib-item:hover { background: var(--bg-3); }
.lib-item.active { background: var(--bg-3); }
.lib-item .title { font-size: 0.9rem; }
.lib-item .meta { color: var(--text-faint); font-size: 0.75rem; margin-top: 0.15rem; display: flex; gap: 0.5rem; }
.lib-item .status { color: var(--text-dim); font-size: 0.7rem; padding: 0 0.4rem; border: 1px solid var(--border); border-radius: 99px; }
.lib-item .status.draft { color: var(--text-dim); }
.lib-item .status.approved { color: var(--green); border-color: var(--green); }
.lib-item .status.video-generated { color: var(--accent-hover); border-color: var(--accent); }

.editor-panel { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.editor-title { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.editor-title input { background: transparent; border: 0; padding: 0; font-size: 1rem; color: var(--text); }
.editor-meta { padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); display: flex; gap: 1.5rem; color: var(--text-dim); font-size: 0.8rem; }
.editor-body { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.editor-body .ql-container { background: var(--bg-2); color: var(--text); border: 0; flex: 1; font-size: 0.95rem; }
.editor-body .ql-toolbar { background: var(--bg-3); border: 0; border-bottom: 1px solid var(--border); }
.editor-body .ql-snow .ql-stroke { stroke: var(--text-dim); }
.editor-body .ql-snow .ql-fill { fill: var(--text-dim); }
.editor-body .ql-snow .ql-picker-label { color: var(--text-dim); }
.editor-body .ql-snow .ql-active .ql-stroke { stroke: var(--text); }
.editor-body .ql-snow .ql-active .ql-fill { fill: var(--text); }
.editor-body .ql-editor { color: var(--text); font-family: inherit; }
.editor-body textarea.fallback-editor { flex: 1; border: 0; background: var(--bg-2); color: var(--text); padding: 1rem; resize: none; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.95rem; line-height: 1.6; }
.editor-foot { padding: 0.75rem 1rem; border-top: 1px solid var(--border); display: flex; gap: 0.75rem; align-items: center; }
.editor-foot .save-status { color: var(--text-faint); font-size: 0.8rem; margin-left: auto; }

.compliance-panel .comp-content { flex: 1; overflow-y: auto; padding: 0.75rem; }
.comp-summary { display: flex; gap: 0.5rem; padding-bottom: 0.5rem; }
.comp-pill { padding: 0.2rem 0.5rem; border-radius: 99px; font-size: 0.75rem; border: 1px solid var(--border); color: var(--text-dim); }
.comp-pill.high { color: var(--red); border-color: var(--red); }
.comp-pill.moderate { color: var(--yellow); border-color: var(--yellow); }
.comp-pill.clear { color: var(--green); border-color: var(--green); }
.comp-flag { padding: 0.65rem; background: var(--bg-3); border-radius: var(--radius-sm); margin-bottom: 0.5rem; font-size: 0.85rem; border-left: 3px solid var(--text-faint); }
.comp-flag.high { border-left-color: var(--red); }
.comp-flag.moderate { border-left-color: var(--yellow); }
.comp-flag .phrase { font-weight: 500; color: var(--text); }
.comp-flag .issue { color: var(--text-dim); margin-top: 0.25rem; }
.comp-flag .reg { color: var(--text-faint); font-size: 0.75rem; margin-top: 0.25rem; }
.comp-flag .suggestion { color: var(--accent-hover); margin-top: 0.4rem; font-size: 0.8rem; }

/* ============ Generate Video ============ */
.gen-video-grid { display: grid; grid-template-columns: 1fr 380px; gap: 1.5rem; align-items: start; }
.video-preview { background: var(--bg-2); border-radius: var(--radius); border: 1px solid var(--border); aspect-ratio: 9/16; display: flex; align-items: center; justify-content: center; color: var(--text-faint); overflow: hidden; max-width: 360px; }
.video-preview video { width: 100%; height: 100%; object-fit: contain; background: black; }
.progress-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.progress-step { display: flex; align-items: center; gap: 0.65rem; padding: 0.5rem 0.75rem; background: var(--bg-3); border-radius: var(--radius-sm); font-size: 0.9rem; color: var(--text-dim); }
.progress-step .icon { width: 1rem; text-align: center; }
.progress-step.done { color: var(--green); }
.progress-step.running { color: var(--accent-hover); }
.progress-step.failed { color: var(--red); }

.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.75rem; }
.export-grid button { padding: 0.4rem; font-size: 0.85rem; }

/* ============ Archive ============ */
.archive-toolbar { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.archive-toolbar input, .archive-toolbar select { width: auto; min-width: 200px; }
.archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.archive-item { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color 0.15s; }
.archive-item:hover { border-color: var(--border-strong); }
.archive-item .thumb { aspect-ratio: 9/16; background: var(--bg-3); display: flex; align-items: center; justify-content: center; color: var(--text-faint); overflow: hidden; }
.archive-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.archive-item .info { padding: 0.75rem; }
.archive-item .info .title { font-size: 0.9rem; }
.archive-item .info .meta { color: var(--text-faint); font-size: 0.75rem; margin-top: 0.25rem; }

/* ============ Profiles ============ */
.profiles-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.profile-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.profile-card h3 { margin: 0 0 0.25rem; font-size: 1rem; font-weight: 500; display: flex; align-items: center; gap: 0.5rem; }
.profile-card .badge { font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 99px; background: var(--accent); color: white; }
.profile-card .row { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.25rem; }
.profile-card .row .lbl { color: var(--text-faint); }
.profile-card .actions { margin-top: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 2rem; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; max-width: 600px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 1rem; font-size: 1.2rem; font-weight: 500; }
.modal-foot { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ============ Settings ============ */
.settings-wrap { max-width: 560px; }

/* ============ Util ============ */
.row { display: flex; gap: 0.5rem; align-items: center; }
.gap-sm { gap: 0.5rem; }
.gap { gap: 1rem; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.empty { padding: 3rem 1rem; text-align: center; color: var(--text-faint); }
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; max-width: 360px; z-index: 200; }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }
