:root {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202a;
  background: #edf1f5;
  --panel: #fff;
  --line: #d9e0e7;
  --muted: #66727f;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(20, 32, 50, .08);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button, .button-like { border: 1px solid var(--line); background: #fff; color: inherit; border-radius: 8px; padding: 7px 10px; cursor: pointer; }
button:hover, .button-like:hover { background: #f5f8fb; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: inherit; }
label { display: grid; gap: 5px; font-size: 13px; }
code { font-family: "Cascadia Code", Consolas, monospace; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top left, #dbeafe, #edf1f5 48%); }
.login-card { width: min(420px, 100%); padding: 28px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); display: grid; gap: 15px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-card output { color: var(--danger); min-height: 1.3em; }
.studio { min-height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.topbar { height: 56px; display: flex; justify-content: space-between; align-items: center; padding: 0 14px; background: #17202a; color: #fff; }
.topbar a { color: #dbeafe; text-decoration: none; }
.top-actions, .topbar > div { display: flex; align-items: center; gap: 10px; }
.badge { background: #334155; border-radius: 999px; padding: 3px 9px; font-size: 12px; }
.workspace { min-height: 0; display: grid; grid-template-columns: 285px minmax(380px, 1fr) minmax(340px, 38vw); gap: 10px; padding: 10px; }
.panel { min-width: 0; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 2px 10px rgba(20, 32, 50, .04); }
.sidebar { padding: 10px; display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); gap: 9px; overflow: hidden; }
.panel-title { min-height: 34px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel-title h2 { margin: 0; font-size: 16px; }
.pathbar, .row { display: flex; align-items: center; gap: 7px; }
.pathbar input { min-width: 0; }
.file-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.button-like { text-align: center; font-size: 13px; }
.file-list { overflow: auto; border-top: 1px solid var(--line); }
.file-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px; padding: 5px 0; border-bottom: 1px solid #eef2f6; }
.file-entry .file-open { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-color: transparent; background: transparent; }
.file-menu { display: flex; gap: 3px; }
.file-menu button { padding: 5px 7px; }
.main-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; }
.tabs { min-height: 40px; display: flex; align-items: end; gap: 2px; overflow-x: auto; padding: 5px 6px 0; border-bottom: 1px solid var(--line); background: #f7f9fb; }
.tab { max-width: 230px; border-radius: 8px 8px 0 0; border-bottom: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.active { background: #fff; border-color: var(--line); font-weight: 600; }
.tab.dirty::after { content: " ●"; color: #e07a00; }
.editor-toolbar { min-height: 44px; display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.editor-toolbar label { display: flex; align-items: center; gap: 5px; }
.editor-toolbar select { width: auto; padding: 5px; }
.editor-host { min-height: 0; position: relative; overflow: hidden; }
.editor-host > .cm-editor, .editor-host > .fallback-editor { height: 100%; }
.empty-state { height: 100%; display: grid; place-items: center; color: var(--muted); }
.fallback-editor { display: grid; grid-template-columns: auto minmax(0, 1fr); height: 100%; background: #fff; }
.fallback-gutter { margin: 0; padding: 10px 8px; overflow: hidden; user-select: none; text-align: right; background: #f3f5f7; color: #89929c; border-right: 1px solid var(--line); line-height: 1.45; font: inherit; }
.fallback-textarea { resize: none; border: 0; border-radius: 0; outline: none; padding: 10px; line-height: 1.45; font: inherit; font-family: "Cascadia Code", Consolas, monospace; white-space: pre; overflow: auto; }
.fallback-editor[data-theme="dark"] { background: #1e1e1e; color: #ddd; }
.fallback-editor[data-theme="dark"] .fallback-textarea { background: #1e1e1e; color: #ddd; }
.fallback-editor[data-theme="dark"] .fallback-gutter { background: #252526; color: #888; border-color: #3a3a3a; }
.rightbar { min-height: 0; display: grid; grid-template-rows: minmax(280px, 52%) minmax(260px, 48%); gap: 10px; }
.preview-panel { padding: 9px; display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 5px; }
.preview-panel iframe { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.tool-panel { display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.tool-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.tool-tabs button { border: 0; border-radius: 0; background: #f7f9fb; }
.tool-tabs button.active { background: #fff; color: var(--accent); font-weight: 700; border-bottom: 2px solid var(--accent); }
.tool-content { min-height: 0; overflow: auto; padding: 10px; display: grid; align-content: start; gap: 9px; }
.history-list { display: grid; gap: 7px; }
.history-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; gap: 5px; }
.history-item .meta { font-size: 11px; color: var(--muted); }
.assistant-messages { min-height: 120px; max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #f9fafb; }
.chat-message { margin: 0 0 8px; padding: 7px 9px; border-radius: 8px; white-space: pre-wrap; }
.chat-message.user { background: #e8f0ff; margin-left: 20px; }
.chat-message.assistant { background: #fff; border: 1px solid var(--line); margin-right: 20px; }
.statusbar { min-height: 28px; padding: 5px 12px; display: flex; justify-content: space-between; gap: 10px; background: #17202a; color: #cbd5e1; font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
dialog { border: 0; border-radius: 14px; box-shadow: var(--shadow); width: min(680px, calc(100vw - 30px)); }
dialog::backdrop { background: rgba(15, 23, 42, .55); }
.dialog-card { display: grid; gap: 12px; }
.dialog-card h2, .dialog-card p { margin: 0; }
.dialog-card textarea { font-family: monospace; }
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 250px minmax(0, 1fr); }
  .rightbar { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; grid-template-rows: 420px; }
}
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { min-height: 360px; }
  .main-panel { min-height: 620px; }
  .rightbar { grid-template-columns: 1fr; grid-template-rows: 420px 420px; }
  .topbar { height: auto; min-height: 56px; flex-wrap: wrap; padding: 8px; }
}
