:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-muted: #eef3f1;
  --text: #17201d;
  --muted: #60716b;
  --line: #d8e1dd;
  --accent: #0b6e69;
  --accent-strong: #095652;
  --warning: #9f5d16;
  --shadow: 0 14px 28px rgba(23, 32, 29, 0.07);
  --preview-zoom: 1;
  --sidebar-width: 260px;
  --editor-width: 38%;
  --code-height: 58%;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, textarea { font: inherit; }

.app-shell { min-height: 100vh; padding: 12px; }

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-width) 6px minmax(0, 1fr);
  min-height: calc(100vh - 24px);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.template-panel { display: flex; flex-direction: column; gap: 16px; padding: 18px; background: #f9fbfa; min-width: 0; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 800; }
h1, h2, p { margin: 0; }
h1 { font-size: 17px; line-height: 1.2; }
.brand p, .notes p, .template-button small, .eyebrow, .prompt-header small { color: var(--muted); }
.brand p { margin-top: 3px; font-size: 12px; line-height: 1.35; }
.templates { display: grid; gap: 8px; }
.template-button { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); cursor: pointer; text-align: left; }
.template-button:hover, .template-button.is-active { border-color: var(--accent); background: #eaf5f3; }
.template-button span { font-size: 15px; font-weight: 750; }
.template-button small { font-size: 12px; white-space: nowrap; }
.notes { margin-top: auto; padding: 12px; border: 1px solid #e0d3bf; border-radius: 8px; background: #fff8ed; }
.notes strong { display: block; margin-bottom: 6px; color: var(--warning); }
.notes p { font-size: 13px; line-height: 1.38; }

.editor-panel { display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 64px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; margin-bottom: 2px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
h2 { font-size: 20px; line-height: 1.2; }
.actions, .zoom-controls, .orientation-controls, .preview-tools { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.preview-tools { align-items: center; }
.orientation-controls { padding-right: 8px; border-right: 1px solid var(--line); }
.action-button, .mini-button { border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); cursor: pointer; font-weight: 750; }
.action-button { min-height: 34px; padding: 7px 11px; }
.mini-button { min-height: 28px; padding: 5px 9px; font-size: 12px; }
.action-button.primary, .mini-button.is-active { border-color: var(--accent); background: var(--accent); color: #fff; }
.action-button:hover, .mini-button:hover { border-color: var(--accent-strong); }

.split-view { display: grid; grid-template-columns: minmax(280px, var(--editor-width)) 6px minmax(0, 1fr); min-height: 0; flex: 1; }
.left-stack { display: grid; grid-template-rows: minmax(180px, var(--code-height)) 6px minmax(160px, 1fr); min-width: 0; min-height: 0; }
.code-pane, .prompt-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.code-pane > span, .prompt-header { padding: 9px 12px; color: var(--muted); font-size: 12px; font-weight: 800; }
.prompt-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--text); border-top: 1px solid var(--line); }
.prompt-header span { display: block; }
.prompt-header small { display: block; margin-top: 2px; font-weight: 600; }
textarea { flex: 1; width: 100%; min-height: 0; resize: none; padding: 12px; border: 0; border-top: 1px solid var(--line); outline: none; background: #111a18; color: #ecf7f4; line-height: 1.42; font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; }
#promptText { background: #f9fbfa; color: var(--text); font-family: "Segoe UI", Arial, sans-serif; font-size: 13px; }

.preview-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel-muted); }
.preview-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.94); }
.status { color: var(--muted); font-size: 13px; font-weight: 750; }
.status.is-error { color: #a51f1f; }
.preview-scroll { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.diagram-preview { width: max-content; min-width: 640px; padding: 14px; zoom: var(--preview-zoom); }
.diagram-preview svg { display: block; max-width: none; height: auto; border-radius: 8px; background: #fff; box-shadow: 0 8px 22px rgba(23, 32, 29, 0.08); }

.resize-handle { position: relative; background: #edf3f1; min-width: 6px; min-height: 6px; }
.resize-handle::after { content: ""; position: absolute; inset: 0; margin: auto; background: var(--line); }
.sidebar-resizer, .split-resizer { cursor: col-resize; }
.sidebar-resizer::after, .split-resizer::after { width: 2px; height: 44px; }
.stack-resizer { cursor: row-resize; }
.stack-resizer::after { width: 44px; height: 2px; }
body.is-resizing { cursor: col-resize; user-select: none; }
body.is-resizing-vertical { cursor: row-resize; user-select: none; }

@media (max-width: 1100px) {
  .workspace, .split-view { grid-template-columns: 1fr; }
  .resize-handle { display: none; }
  .template-panel { border-bottom: 1px solid var(--line); }
  .templates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .left-stack { grid-template-rows: 360px 6px 260px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 8px; }
  .workspace { min-height: calc(100vh - 16px); }
  .toolbar, .preview-header, .prompt-header { align-items: flex-start; flex-direction: column; }
  .templates { grid-template-columns: 1fr; }
  .diagram-preview { min-width: 520px; }
}