:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #edf2f5;
  --text: #13202d;
  --muted: #667484;
  --border: #dfe6ec;
  --nav: #08111f;
  --nav-2: #0d1a2a;
  --nav-text: #f5f8fb;
  --nav-muted: #91a2b5;
  --accent: #2db7a3;
  --accent-strong: #138b7b;
  --accent-soft: #dff7f2;
  --blue: #3a77d2;
  --warning: #d48b20;
  --danger: #c84a4a;
  --success: #23866d;
  --shadow: 0 18px 50px rgba(17, 33, 50, .09);
  --radius: 18px;
  --radius-sm: 12px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09111c;
  --surface: #101b29;
  --surface-2: #142131;
  --surface-3: #1b2a3c;
  --text: #edf4f8;
  --muted: #9badbd;
  --border: #243449;
  --nav: #050b13;
  --nav-2: #0b1521;
  --nav-text: #f5f8fb;
  --nav-muted: #90a2b4;
  --accent-soft: #13362f;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 276px minmax(0, 1fr); }
.sidebar { background: var(--nav); color: var(--nav-text); padding: 22px 16px; display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; height: 100vh; z-index: 30; }
.brand-row { display: flex; align-items: center; gap: 12px; padding: 2px 8px 22px; }
.brand-mark { width: 35px; height: 35px; position: relative; display: grid; place-items: center; }
.brand-mark span { position: absolute; width: 9px; height: 23px; border-radius: 7px; background: var(--accent); transform: rotate(34deg); }
.brand-mark span:nth-child(1) { left: 5px; top: 8px; }
.brand-mark span:nth-child(2) { left: 14px; top: 2px; height: 30px; }
.brand-mark span:nth-child(3) { right: 3px; bottom: 4px; height: 19px; }
.brand-name { font-size: 13px; font-weight: 800; letter-spacing: .14em; }
.brand-sub { color: var(--nav-muted); font-size: 10px; letter-spacing: .3em; margin-top: 2px; }
.new-work { border: 1px solid rgba(255,255,255,.11); background: linear-gradient(135deg, rgba(45,183,163,.22), rgba(45,183,163,.08)); color: #f7fffd; border-radius: 13px; padding: 12px 14px; display: flex; gap: 9px; align-items: center; justify-content: center; font-weight: 700; margin-bottom: 18px; }
.new-work:hover { border-color: rgba(45,183,163,.6); }
.workspace-nav { overflow-y: auto; padding-right: 3px; }
.nav-group { margin-bottom: 14px; }
.nav-group-title { width: 100%; color: var(--nav-muted); background: transparent; border: 0; display: flex; justify-content: space-between; align-items: center; padding: 7px 9px; text-align: left; font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.nav-group-title i { font-style: normal; font-size: 13px; }
.nav-app { width: 100%; display: flex; gap: 10px; align-items: center; border: 0; background: transparent; color: #becbd8; padding: 9px 10px; border-radius: 10px; text-align: left; font-size: 13px; margin: 2px 0; }
.nav-app:hover { background: rgba(255,255,255,.055); color: #fff; }
.nav-app.active { color: #fff; background: rgba(45,183,163,.14); box-shadow: inset 3px 0 0 var(--accent); }
.nav-icon { width: 24px; height: 24px; border: 1px solid rgba(255,255,255,.1); border-radius: 7px; display: grid; place-items: center; font-size: 11px; flex: 0 0 auto; }
.nav-app.active .nav-icon { border-color: rgba(45,183,163,.4); color: #72dbc9; }
.sidebar-bottom { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.utility-link { width: 100%; border: 0; color: #aebdcb; background: transparent; padding: 9px 8px; display: flex; gap: 10px; align-items: center; border-radius: 9px; text-align: left; font-size: 12px; }
.utility-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.utility-link b { margin-left: auto; background: #274052; color: #d9f7f1; border-radius: 99px; min-width: 21px; padding: 2px 6px; text-align: center; font-size: 10px; }
.connection-card { margin-top: 12px; background: rgba(255,255,255,.045); border: 1px solid rgba(255,255,255,.07); border-radius: 12px; padding: 10px; display: flex; gap: 9px; align-items: flex-start; }
.status-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; margin-top: 4px; box-shadow: 0 0 0 4px rgba(45,183,163,.12); }
.connection-card strong, .connection-card small { display: block; }
.connection-card strong { font-size: 11px; }
.connection-card small { color: var(--nav-muted); margin-top: 3px; font-size: 9px; line-height: 1.35; }

.workspace { min-width: 0; height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.workspace-header { height: 78px; flex: 0 0 auto; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; display: flex; justify-content: space-between; align-items: center; }
.header-title { display: flex; align-items: center; gap: 12px; }
.eyebrow { display: block; font-size: 10px; font-weight: 800; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
.header-title h1 { margin: 3px 0 0; font-size: 22px; letter-spacing: -.02em; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.icon-button, .avatar, .mobile-menu { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.icon-button { width: 38px; height: 38px; border-radius: 11px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--nav); color: #fff; font-weight: 800; font-size: 11px; }
.mobile-menu { display: none; width: 38px; height: 38px; border-radius: 10px; }

.studio-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(390px, .92fr) minmax(430px, 1.08fr); gap: 1px; background: var(--border); }
.chat-pane, .preview-pane { background: var(--surface); min-width: 0; min-height: 0; }
.chat-pane { display: flex; flex-direction: column; }
.chat-scroll { overflow-y: auto; flex: 1; padding: 28px 30px 20px; }
.welcome-card { max-width: 690px; padding: 4px 0 20px; }
.assistant-orb { width: 39px; height: 39px; display: inline-block; border-radius: 14px; background: linear-gradient(145deg, var(--accent), #236fae); margin-bottom: 14px; position: relative; box-shadow: 0 8px 25px rgba(45,183,163,.18); }
.assistant-orb::before, .assistant-orb::after { content: ""; position: absolute; background: rgba(255,255,255,.85); border-radius: 99px; transform: rotate(35deg); }
.assistant-orb::before { width: 7px; height: 21px; left: 11px; top: 10px; }
.assistant-orb::after { width: 7px; height: 15px; right: 10px; top: 13px; }
.welcome-card h2 { font-size: clamp(25px, 3vw, 38px); letter-spacing: -.04em; line-height: 1.06; max-width: 600px; margin: 8px 0 12px; }
.welcome-card > p:last-child { color: var(--muted); line-height: 1.7; max-width: 650px; font-size: 14px; }
.quick-section { padding-top: 12px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 11px; }
.section-heading span { font-weight: 750; font-size: 12px; }
.section-heading small { color: var(--muted); font-size: 10px; }
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.quick-card { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 13px; padding: 13px; text-align: left; min-height: 78px; display: flex; justify-content: space-between; gap: 8px; line-height: 1.45; font-size: 12px; }
.quick-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.quick-card span:last-child { color: var(--accent-strong); font-size: 17px; }
.messages { padding-top: 22px; display: grid; gap: 16px; }
.message { display: flex; gap: 10px; max-width: 90%; }
.message.user { margin-left: auto; flex-direction: row-reverse; }
.message-bubble { border: 1px solid var(--border); border-radius: 15px; padding: 12px 14px; line-height: 1.55; font-size: 13px; background: var(--surface-2); white-space: pre-wrap; }
.message.user .message-bubble { background: var(--nav); color: #f8fbfd; border-color: var(--nav); border-bottom-right-radius: 5px; }
.message.assistant .message-bubble { border-bottom-left-radius: 5px; }
.message-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); flex: 0 0 auto; font-size: 12px; font-weight: 800; }
.message.user .message-icon { background: var(--surface-3); color: var(--text); }
.composer { flex: 0 0 auto; margin: 0 22px 20px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface); box-shadow: var(--shadow); padding: 10px 12px 10px; }
.context-pill { display: inline-flex; align-items: center; gap: 7px; background: var(--surface-3); border-radius: 99px; padding: 5px 7px 5px 9px; font-size: 10px; color: var(--muted); }
.context-pill > span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.context-pill b { color: var(--text); }
.context-pill button { width: 18px; height: 18px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.composer textarea { width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); padding: 12px 3px 8px; min-height: 60px; line-height: 1.45; }
.composer textarea::placeholder { color: #8d99a6; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; }
.composer-tools { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 9px; }
.composer-tools button { border: 0; background: var(--surface-3); color: var(--text); width: 26px; height: 26px; border-radius: 8px; }
.send-button { border: 0; background: var(--accent); color: #06251f; border-radius: 10px; padding: 8px 9px 8px 13px; display: flex; align-items: center; gap: 9px; font-size: 11px; font-weight: 800; }
.send-button b { background: rgba(255,255,255,.48); width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; }
.send-button:disabled { opacity: .55; cursor: wait; }

.preview-pane { display: flex; flex-direction: column; position: relative; background: var(--surface-2); }
.preview-header { height: 78px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
.preview-header h2 { margin: 4px 0 0; font-size: 16px; }
.preview-status { border: 1px solid var(--border); border-radius: 99px; padding: 5px 9px; font-size: 9px; color: var(--muted); background: var(--surface-2); }
.preview-empty { margin: auto; text-align: center; max-width: 360px; padding: 30px; color: var(--muted); }
.preview-empty h3 { color: var(--text); margin-bottom: 8px; }
.preview-empty p { font-size: 12px; line-height: 1.65; }
.empty-illustration { width: 150px; height: 105px; margin: 0 auto 22px; position: relative; }
.empty-illustration span { position: absolute; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; box-shadow: 0 8px 20px rgba(20,40,60,.05); }
.empty-illustration span:nth-child(1) { width: 90px; height: 65px; left: 30px; top: 10px; transform: rotate(-6deg); }
.empty-illustration span:nth-child(2) { width: 96px; height: 70px; left: 31px; top: 21px; transform: rotate(4deg); }
.empty-illustration span:nth-child(3) { width: 88px; height: 63px; left: 32px; top: 32px; background: linear-gradient(140deg, var(--surface), var(--accent-soft)); }
.preview-content { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 24px 110px; }
.preview-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.preview-meta span { color: var(--accent-strong); background: var(--accent-soft); border-radius: 99px; padding: 5px 8px; font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.preview-meta small { color: var(--muted); font-size: 9px; }
.structured-preview { display: grid; gap: 10px; }
.field-card[data-key="missing_information"] { border-color: rgba(245,158,11,.42); background: rgba(245,158,11,.06); }
.field-card[data-key="draft"] { border-color: rgba(99,102,241,.35); }
.field-card[data-key="next_step"] { border-color: rgba(34,197,94,.35); background: rgba(34,197,94,.05); }
.field-card[data-key="ai_runtime"] { opacity: .78; }
.structured-item { display: grid !important; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; }
.item-index { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-strong); font-size: 9px; font-weight: 800; }
.bullet-dot { color: var(--accent-strong); margin-right: 7px; }
.object-item { display: block !important; }
.object-item > strong { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.nested-value, .nested-content { min-width: 0; }
.muted-value { color: var(--muted); font-style: italic; }
.depth-1, .depth-2, .depth-3 { margin-top: 4px; }
.field-card { border: 1px solid var(--border); background: var(--surface); border-radius: 13px; padding: 13px; }
.field-label { display: block; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; margin-bottom: 7px; }
.field-value { font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.field-list { display: grid; gap: 7px; }
.list-item { border-left: 2px solid var(--accent); padding: 8px 10px; background: var(--surface-2); border-radius: 0 9px 9px 0; font-size: 11px; line-height: 1.5; }
.list-item strong { display: block; margin-bottom: 2px; }
.json-editor-wrap { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.json-editor-wrap summary { padding: 11px 13px; font-size: 11px; cursor: pointer; color: var(--muted); }
.json-editor-wrap textarea { width: calc(100% - 22px); margin: 0 11px 10px; min-height: 220px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); padding: 10px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; line-height: 1.55; }
.json-editor-wrap .secondary-button { margin: 0 11px 11px; }
.approval-bar { position: absolute; left: 18px; right: 18px; bottom: 18px; border: 1px solid var(--border); border-radius: 15px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(15px); padding: 12px 13px; display: flex; justify-content: space-between; gap: 15px; align-items: center; box-shadow: var(--shadow); }
.approval-copy strong, .approval-copy span { display: block; }
.approval-copy strong { font-size: 11px; margin-bottom: 3px; }
.approval-copy span { font-size: 9px; color: var(--muted); }
.approval-actions { display: flex; gap: 7px; }
.primary-button, .secondary-button, .danger-button { border-radius: 9px; padding: 9px 12px; font-size: 10px; font-weight: 800; }
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #05261f; }
.secondary-button { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.danger-button { border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border)); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--danger); }

.full-view { flex: 1; overflow-y: auto; padding: 28px; }
.full-view-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.full-view-head h2 { font-size: 26px; margin-bottom: 7px; }
.full-view-head p { color: var(--muted); max-width: 650px; line-height: 1.6; font-size: 13px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-bottom: 20px; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.summary-card span { color: var(--muted); font-size: 10px; }
.summary-card strong { display: block; font-size: 26px; margin-top: 7px; }
.catalog-section { margin: 25px 0; }
.catalog-section h3 { margin-bottom: 4px; }
.catalog-section > p { color: var(--muted); font-size: 12px; }
.catalog-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 11px; margin-top: 12px; }
.app-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 15px; }
.app-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.app-card h4 { margin: 0; font-size: 14px; }
.app-card p { color: var(--muted); font-size: 11px; line-height: 1.55; min-height: 52px; margin: 9px 0 13px; }
.app-card button { border: 0; background: transparent; color: var(--accent-strong); font-size: 10px; font-weight: 800; padding: 0; }
.status-chip { font-size: 8px; text-transform: uppercase; font-weight: 800; padding: 4px 6px; border-radius: 99px; background: var(--surface-3); color: var(--muted); }
.status-chip.ready { background: var(--accent-soft); color: var(--accent-strong); }
.list-panel { border: 1px solid var(--border); background: var(--surface); border-radius: 15px; overflow: hidden; }
.list-row { padding: 14px 16px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.list-row:last-child { border-bottom: 0; }
.list-row strong { display: block; font-size: 12px; }
.list-row small { color: var(--muted); font-size: 10px; }
.list-actions { display: flex; gap: 7px; align-items: center; }
.badge { border-radius: 99px; padding: 4px 7px; font-size: 8px; font-weight: 800; text-transform: uppercase; background: var(--surface-3); color: var(--muted); }
.badge.pending { background: #fff2db; color: #9a620c; }
[data-theme="dark"] .badge.pending { background: #3a2a13; color: #ffc96f; }
.badge.executed_demo, .badge.executed { background: var(--accent-soft); color: var(--accent-strong); }
.badge.rejected { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.mobile-tabs { display: none; }
.mobile-overlay { display: none; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; }
.toast { width: min(340px, calc(100vw - 36px)); background: var(--nav); color: #fff; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 11px 13px; box-shadow: var(--shadow); font-size: 11px; line-height: 1.5; animation: toast-in .2s ease; }
.toast.error { border-color: rgba(225,100,100,.55); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 238px minmax(0,1fr); }
  .studio-grid { grid-template-columns: minmax(350px,.9fr) minmax(390px,1.1fr); }
  .catalog-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 880px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: -286px; width: 276px; transition: left .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.28); }
  .sidebar.open { left: 0; }
  .mobile-overlay { position: fixed; inset: 0; background: rgba(1,8,16,.55); z-index: 20; }
  .mobile-overlay.visible { display: block; }
  .workspace { height: 100vh; }
  .mobile-menu { display: inline-grid; place-items: center; }
  .workspace-header { padding: 0 15px; height: 68px; }
  .studio-grid { grid-template-columns: 1fr; }
  .chat-pane, .preview-pane { display: none; }
  .chat-pane.pane-visible, .preview-pane.pane-visible { display: flex; }
  .mobile-tabs { height: 44px; flex: 0 0 auto; display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-bottom: 1px solid var(--border); padding: 5px 9px; gap: 7px; }
  .mobile-tab { border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
  .mobile-tab.active { background: var(--surface-3); color: var(--text); }
  .preview-header { height: 65px; }
  .summary-grid { grid-template-columns: 1fr; }
  .catalog-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .workspace-header { height: 62px; }
  .header-title h1 { font-size: 17px; }
  .header-title .eyebrow { font-size: 8px; }
  .icon-button { display: none; }
  .chat-scroll { padding: 20px 16px 14px; }
  .welcome-card h2 { font-size: 28px; }
  .quick-grid { grid-template-columns: 1fr; }
  .composer { margin: 0 10px 10px; }
  .composer-tools span { display: none; }
  .preview-content { padding: 16px 14px 120px; }
  .preview-header { padding: 0 14px; }
  .approval-bar { left: 9px; right: 9px; bottom: 9px; flex-direction: column; align-items: stretch; }
  .approval-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .full-view { padding: 19px 14px; }
}
