/* ── Reset & Variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --radius: 8px;
  --transition: 0.2s ease;
}

/* ── Dark Theme (default) ────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2d3148;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --accent: #6c8ef7;
  --accent-hover: #8aa3ff;
  --ok: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --btn-bg: #242736;
  --btn-hover: #2d3148;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --editor-bg: #12141e;
  --scrollbar: #2d3148;
  --scrollbar-thumb: #4a5280;
}

/* ── Light Theme ─────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f0f2f8;
  --surface: #ffffff;
  --surface2: #f8f9fc;
  --border: #d1d9e6;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --accent: #3b5bdb;
  --accent-hover: #2f4ac7;
  --ok: #16a34a;
  --error: #dc2626;
  --warning: #d97706;
  --btn-bg: #f0f2f8;
  --btn-hover: #e2e6f0;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --editor-bg: #fafbfe;
  --scrollbar: #e2e6f0;
  --scrollbar-thumb: #b0b8cc;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover {
  background: var(--btn-hover);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.btn-icon {
  padding: 5px 9px;
  font-size: 15px;
  line-height: 1;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* ── Examples Dropdown ───────────────────────────────────────────────────── */
.examples-wrapper {
  position: relative;
}

.example-menu {
  display: none;
  flex-direction: column;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

.example-menu.open {
  display: flex;
}

.example-btn {
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}

.example-btn:last-child { border-bottom: none; }

.example-btn:hover {
  background: var(--surface2);
  color: var(--accent);
}

/* ── Split Pane ──────────────────────────────────────────────────────────── */
.panes {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.pane + .pane {
  border-left: 2px solid var(--border);
}

/* ── Pane Header ─────────────────────────────────────────────────────────── */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.pane-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.pane-actions {
  display: flex;
  gap: 4px;
}

/* ── Editor ──────────────────────────────────────────────────────────────── */
.editor-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.editor {
  width: 100%;
  height: 100%;
  padding: 14px;
  background: var(--editor-bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  overflow: auto;
}

.editor::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

/* Custom scrollbars */
.editor::-webkit-scrollbar { width: 8px; height: 8px; }
.editor::-webkit-scrollbar-track { background: var(--scrollbar); }
.editor::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

/* ── Status Bar ──────────────────────────────────────────────────────────── */
.status-bar {
  padding: 4px 12px;
  font-size: 12px;
  font-family: var(--mono);
  min-height: 24px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition), color var(--transition);
}

.status-idle {
  background: var(--surface);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.status-ok {
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  color: var(--ok);
  border-top: 1px solid color-mix(in srgb, var(--ok) 25%, transparent);
}

.status-error {
  background: color-mix(in srgb, var(--error) 12%, transparent);
  color: var(--error);
  border-top: 1px solid color-mix(in srgb, var(--error) 25%, transparent);
}

/* ── Divider icon ────────────────────────────────────────────────────────── */
.pane-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  flex-shrink: 0;
  background: var(--surface2);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 16px;
  user-select: none;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100vh; overflow: auto; }
  .panes { flex-direction: column; overflow: visible; }
  .pane + .pane { border-left: none; border-top: 2px solid var(--border); }
  .pane-divider { display: none; }
  .editor-wrap { height: 40vh; }
  .editor { height: 100%; }
  .header { gap: 8px; }
  .logo { font-size: 1rem; }
}

@media (max-width: 400px) {
  .btn { padding: 4px 8px; font-size: 12px; }
  .pane-label { font-size: 11px; }
}
