:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef1f5;
  --text: #191c22;
  --muted: #687080;
  --soft: #8e96a4;
  --border: #dfe3ea;
  --border-strong: #cbd1dc;
  --accent: #e82127;
  --accent-hover: #cb171d;
  --accent-soft: #fff0f0;
  --success: #15803d;
  --success-soft: #eaf8ef;
  --warning: #b45309;
  --warning-soft: #fff7e8;
  --danger: #c1252b;
  --shadow: 0 14px 40px rgba(28, 34, 45, 0.08);
  --shadow-soft: 0 5px 18px rgba(28, 34, 45, 0.07);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --topbar-height: 74px;
  --footer-height: 78px;
}

[data-theme="dark"] {
  --bg: #111318;
  --surface: #191c22;
  --surface-2: #20242c;
  --surface-3: #282d36;
  --text: #f4f6f8;
  --muted: #a8b0be;
  --soft: #808897;
  --border: #303640;
  --border-strong: #414956;
  --accent: #ff3a40;
  --accent-hover: #ff5156;
  --accent-soft: #371d20;
  --success: #53cf7e;
  --success-soft: #1d3426;
  --warning: #f5b85e;
  --warning-soft: #372b1c;
  --danger: #ff656a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

.app-shell { height: 100%; display: grid; grid-template-rows: var(--topbar-height) 1fr; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--accent); color: white; box-shadow: 0 7px 18px rgba(232, 33, 39, .25); flex: 0 0 auto; }
.brand-mark svg { width: 26px; stroke: none; fill: white; }
.brand-mark .play { fill: var(--accent); }
.brand h1 { font-size: 17px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 999px; font-size: 12.5px; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--soft); }
.status-ready { color: var(--success); border-color: color-mix(in srgb, var(--success), transparent 65%); background: var(--success-soft); }
.status-ready .status-dot { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success), transparent 78%); }
.status-missing { color: var(--warning); border-color: color-mix(in srgb, var(--warning), transparent 65%); background: var(--warning-soft); }
.status-missing .status-dot { background: var(--warning); }
.status-error { color: var(--danger); }
.icon-btn, .icon-text-btn, .tool-btn, .small-btn, .secondary-btn, .primary-btn { cursor: pointer; border: 0; transition: .18s ease; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.icon-btn:hover { background: var(--surface-3); transform: translateY(-1px); }
.icon-btn svg { width: 19px; }
.icon-text-btn { height: 40px; display: inline-flex; align-items: center; gap: 7px; padding: 0 13px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 650; font-size: 13px; }
.icon-text-btn svg { width: 17px; }
.icon-text-btn:hover { background: var(--surface-3); }

.workspace { min-height: 0; display: grid; grid-template-columns: minmax(530px, 1.12fr) minmax(420px, .88fr); gap: 14px; padding: 14px; }
.input-pane, .output-pane { min-width: 0; min-height: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); overflow: hidden; }
.input-pane { display: grid; grid-template-rows: 59px minmax(0, 1fr) var(--footer-height); }
.output-pane { display: grid; grid-template-rows: auto auto minmax(0, 1fr) 43px; }

.tabs { display: flex; align-items: end; padding: 0 20px; border-bottom: 1px solid var(--border); gap: 4px; background: var(--surface); }
.tab-btn { height: 59px; padding: 0 15px; display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; color: var(--muted); font-weight: 650; cursor: pointer; position: relative; }
.tab-btn svg { width: 17px; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); }
.tab-btn.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; background: var(--accent); border-radius: 3px 3px 0 0; }

.pane-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.tab-panel { display: none; padding: 26px 28px 34px; }
.tab-panel.active { display: block; }
.section-heading, .card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.section-heading { margin-bottom: 23px; }
.section-heading h2 { margin: 0; font-size: 22px; letter-spacing: -0.025em; }
.section-heading p, .card-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; }
.card-heading h3 { margin: 0; font-size: 16px; }
.help-icon { width: 24px; height: 24px; flex: 0 0 auto; display: inline-grid; place-items: center; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 800; cursor: pointer; font-family: Georgia, serif; }
.help-icon:hover, .help-icon:focus-visible { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); outline: none; }
.help-icon.mini { width: 18px; height: 18px; font-size: 10px; vertical-align: middle; margin-left: 3px; transform: translateY(-1px); }

.form-grid { display: grid; gap: 17px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.full-width { grid-column: 1 / -1; }
.field { display: grid; gap: 7px; min-width: 0; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.field-label { color: var(--text); font-size: 13px; font-weight: 700; }
.optional { font-weight: 500; color: var(--soft); margin-left: 4px; }
.counter { color: var(--soft); font-size: 12px; white-space: nowrap; }
input, select, textarea {
  width: 100%;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input, select { height: 43px; padding: 0 12px; }
textarea { padding: 12px 13px; resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: var(--soft); }
input:focus, select:focus, textarea:focus { border-color: color-mix(in srgb, var(--accent), transparent 35%); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 87%); background: var(--surface); }
.transcript-field { margin-top: 20px; }
#transcriptInput { min-height: 250px; height: clamp(250px, 34vh, 480px); }
.medium-textarea { min-height: 96px; }
.small-textarea { min-height: 115px; }

.blocks-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.block-card { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; min-height: 91px; padding: 15px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); transition: .18s ease; }
.block-card:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.block-card.enabled { background: color-mix(in srgb, var(--accent-soft), var(--surface) 35%); border-color: color-mix(in srgb, var(--accent), transparent 65%); }
.block-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.enabled .block-icon { color: var(--accent); border-color: color-mix(in srgb, var(--accent), transparent 70%); }
.block-icon svg { width: 20px; }
.block-card h3 { margin: 0; font-size: 14px; }
.block-card p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.35; }
.block-actions { display: flex; align-items: center; gap: 8px; }
.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; cursor: pointer; transition: .2s; }
.switch-track::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 5px rgba(0,0,0,.22); transition: .2s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }

.advanced-card, .list-editor-card { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); padding: 19px; }
.compact { margin-top: 18px; gap: 14px; }
.timestamp-settings { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--border); }
.segmented, .view-switch { display: inline-flex; background: var(--surface-3); padding: 3px; border-radius: 10px; }
.segment, .view-btn { border: 0; background: transparent; padding: 7px 11px; border-radius: 8px; color: var(--muted); cursor: pointer; font-weight: 650; font-size: 12.5px; }
.segment.active, .view-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(20, 25, 35, .08); }
.inline-note { color: var(--muted); font-size: 12.5px; margin: 10px 0 14px; }

.repeatable-list { display: grid; gap: 9px; margin-top: 15px; }
.resource-row { display: grid; grid-template-columns: .7fr 1.3fr 36px; gap: 8px; align-items: center; }
.resource-row input { height: 40px; background: var(--surface); }
.remove-resource-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; }
.remove-resource-btn:hover { color: var(--danger); background: color-mix(in srgb, var(--danger), transparent 90%); }
.remove-resource-btn svg { width: 17px; }
.small-btn { padding: 7px 10px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border); font-size: 12px; font-weight: 700; }
.small-btn:hover { border-color: var(--accent); color: var(--accent); }
.profile-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 19px; }
.secondary-btn { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); font-size: 12.5px; font-weight: 700; }
.secondary-btn svg { width: 16px; }
.secondary-btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.danger-text { color: var(--danger); }
.file-btn { cursor: pointer; }

.input-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 13px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.model-control { display: flex; align-items: center; gap: 9px; min-width: 0; }
.model-control label { color: var(--muted); font-size: 12px; font-weight: 700; }
.model-control select { width: 205px; height: 39px; font-size: 12.5px; }
.primary-btn { min-width: 205px; height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 20px; border-radius: 12px; background: var(--accent); color: white; font-weight: 800; box-shadow: 0 9px 22px color-mix(in srgb, var(--accent), transparent 70%); }
.primary-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { cursor: not-allowed; opacity: .7; transform: none; }
.btn-icon svg { width: 20px; }
.spinner { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.45); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.primary-btn.loading .btn-icon { display: none; }
.primary-btn.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.output-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 25px 18px; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 850; }
.output-header h2 { margin: 3px 0 0; font-size: 22px; letter-spacing: -0.025em; }
.output-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 20px 13px; border-bottom: 1px solid var(--border); }
.toolbar-actions { display: flex; align-items: center; gap: 5px; }
.tool-btn { height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 9px; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.tool-btn svg { width: 15px; }
.tool-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.tool-btn:disabled { opacity: .35; cursor: default; }
.output-body { min-height: 0; position: relative; background: var(--surface-2); }
.empty-state, .loading-state { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; padding: 35px; }
.empty-state h3, .loading-state h3 { margin: 12px 0 5px; font-size: 17px; }
.empty-state p, .loading-state p { max-width: 360px; margin: 0; color: var(--muted); font-size: 13px; }
.empty-illustration svg { width: 130px; color: var(--border-strong); }
.empty-illustration .spark { color: var(--accent); }
.large-spinner { width: 38px; height: 38px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.output-editor { position: absolute; inset: 0; height: 100%; resize: none; border: 0; border-radius: 0; background: var(--surface); padding: 25px 27px 45px; font-family: inherit; font-size: 14.5px; line-height: 1.65; box-shadow: none !important; }
.output-preview { position: absolute; inset: 0; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: 25px 27px 45px; background: var(--surface); color: var(--text); font-family: inherit; font-size: 14.5px; line-height: 1.65; }
.output-footer { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 0 20px; border-top: 1px solid var(--border); color: var(--soft); font-size: 11.5px; }

.help-popover { position: fixed; z-index: 100; width: min(330px, calc(100vw - 28px)); padding: 15px 37px 15px 16px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); box-shadow: 0 16px 50px rgba(0,0,0,.18); color: var(--text); }
.help-popover p { margin: 0; font-size: 13px; line-height: 1.5; }
.help-popover button { position: absolute; top: 7px; right: 8px; width: 25px; height: 25px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; }
.help-popover button:hover { background: var(--surface-2); }
.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: grid; gap: 9px; }
.toast { min-width: 250px; max-width: 420px; padding: 12px 14px; border-radius: 11px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); font-size: 13px; animation: toastIn .22s ease-out; }
.toast.error { background: #b4232a; color: white; }
.toast.success { background: #18733a; color: white; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(470px, 1.05fr) minmax(370px, .95fr); }
  .blocks-grid { grid-template-columns: 1fr; }
  .status-text { display: none; }
}

@media (max-width: 850px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100%; grid-template-rows: auto auto; }
  .topbar { min-height: var(--topbar-height); padding: 11px 15px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(720px, auto) minmax(650px, 80vh); padding: 10px; }
  .input-pane, .output-pane { min-height: 650px; }
  .status-pill { display: none; }
}

@media (max-width: 600px) {
  .brand p, .icon-text-btn { display: none; }
  .brand h1 { font-size: 15px; }
  .topbar { gap: 10px; }
  .workspace { padding: 0; gap: 8px; }
  .input-pane, .output-pane { border-radius: 0; border-left: 0; border-right: 0; }
  .tab-panel { padding: 21px 16px 28px; }
  .tabs { padding: 0 7px; justify-content: space-around; }
  .tab-btn { flex: 1; justify-content: center; padding: 0 6px; font-size: 12px; }
  .two-columns { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .input-footer { align-items: stretch; flex-direction: column; height: auto; }
  .input-pane { grid-template-rows: 59px minmax(0,1fr) auto; }
  .model-control { justify-content: space-between; }
  .model-control select { flex: 1; }
  .primary-btn { width: 100%; }
  .resource-row { grid-template-columns: 1fr 36px; }
  .resource-value { grid-column: 1; }
  .remove-resource-btn { grid-column: 2; grid-row: 1 / span 2; }
  .output-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; justify-content: flex-end; }
  .output-footer { flex-direction: column; justify-content: center; gap: 1px; text-align: center; }
}
