/* oklch warm palette — adapted from webb/static/style.css */

:root {
  --hue: 55;

  /* --- Light palette --- */
  --ground-l: oklch(0.96 0.012 var(--hue));
  --surface-l: oklch(0.93 0.010 var(--hue));
  --surface-2-l: oklch(0.90 0.012 var(--hue));
  --text-l: oklch(0.15 0.02 var(--hue));
  --text-2-l: oklch(0.45 0.025 var(--hue));
  --text-3-l: oklch(0.62 0.018 var(--hue));
  --rule-l: oklch(0.84 0.02 var(--hue));
  --gold-l: oklch(0.48 0.16 var(--hue));
  --gold-bright-l: oklch(0.40 0.18 var(--hue));
  --highlight-l: oklch(0.91 0.05 var(--hue) / 0.35);

  /* --- Dark palette --- */
  --ground-d: oklch(0.16 0.025 var(--hue));
  --surface-d: oklch(0.19 0.020 var(--hue));
  --surface-2-d: oklch(0.23 0.018 var(--hue));
  --text-d: oklch(0.82 0.02 var(--hue));
  --text-2-d: oklch(0.50 0.025 var(--hue));
  --text-3-d: oklch(0.38 0.018 var(--hue));
  --rule-d: oklch(0.28 0.02 var(--hue));
  --gold-d: oklch(0.65 0.17 var(--hue));
  --gold-bright-d: oklch(0.75 0.19 var(--hue));
  --highlight-d: oklch(0.20 0.04 var(--hue) / 0.5);

  /* --- Active: dark by default (app context) --- */
  --ground: var(--ground-d);
  --surface: var(--surface-d);
  --surface-2: var(--surface-2-d);
  --text-normal: var(--text-d);
  --text-muted: var(--text-2-d);
  --text-faint: var(--text-3-d);
  --border: var(--rule-d);
  --accent: var(--gold-d);
  --accent-bright: var(--gold-bright-d);
  --highlight: var(--highlight-d);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", monospace;
  --font-size-ui: 13px;

  --radius-s: 4px;
  --radius-m: 6px;
  --sidebar-width: 260px;
  --ribbon-width: 44px;
  --tab-height: 36px;
  --status-bar-height: 24px;

  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --duration: 0.25s;

  color-scheme: dark;
}

/* --- Light mode --- */
@media (prefers-color-scheme: light) {
  :root:not(.force-dark) {
    --ground: var(--ground-l);
    --surface: var(--surface-l);
    --surface-2: var(--surface-2-l);
    --text-normal: var(--text-l);
    --text-muted: var(--text-2-l);
    --text-faint: var(--text-3-l);
    --border: var(--rule-l);
    --accent: var(--gold-l);
    --accent-bright: var(--gold-bright-l);
    --highlight: var(--highlight-l);
    color-scheme: light;
  }
}

::selection {
  background: var(--accent);
  color: var(--ground);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%; overflow: hidden;
  background: var(--ground); color: var(--text-normal);
  font-family: var(--font-ui); font-size: var(--font-size-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}

/* ── App Container ── */
.app-container { display: flex; flex-direction: column; height: 100vh; }
.workspace { display: flex; flex: 1; overflow: hidden; }

/* ── Ribbon (left icon bar) ── */
.workspace-ribbon {
  width: var(--ribbon-width); background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  align-items: center; padding: 8px 0; gap: 2px; flex-shrink: 0;
}
.workspace-ribbon .side-dock-ribbon-action {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-s); color: var(--text-faint); cursor: pointer;
  font-size: 16px; transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.workspace-ribbon .side-dock-ribbon-action:hover { background: var(--surface-2); color: var(--text-normal); }
.workspace-ribbon .side-dock-ribbon-action.is-active { color: var(--accent); }
.workspace-ribbon .side-dock-actions { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.workspace-ribbon .side-dock-settings { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }

/* ── Sidebars ── */
.mod-left-split, .mod-right-split {
  background: var(--surface); display: flex; flex-direction: column; overflow: hidden;
  flex-shrink: 0; transition: width var(--duration) var(--ease);
}
.mod-left-split { border-right: 1px solid var(--border); }
.mod-right-split { border-left: 1px solid var(--border); }
.mod-left-split.is-collapsed, .mod-right-split.is-collapsed { width: 0 !important; overflow: hidden; border: none; }

/* ── Resize Handles ── */
.workspace-leaf-resize-handle {
  width: 4px; cursor: col-resize; flex-shrink: 0;
  background: transparent; transition: background 0.15s;
}
.workspace-leaf-resize-handle:hover, .workspace-leaf-resize-handle.is-dragging {
  background: var(--accent);
}

/* ── Root (main content) ── */
.mod-root { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 200px; }

/* ── Tab Headers ── */
.workspace-tab-header-container {
  display: flex; align-items: center; height: var(--tab-height);
  background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden; flex-shrink: 0;
  padding: 0 4px; gap: 1px;
}
.workspace-tab-header-container::-webkit-scrollbar { height: 0; }
.workspace-tab-header {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; height: 28px; border-radius: var(--radius-s);
  color: var(--text-muted); cursor: pointer; white-space: nowrap;
  font-family: var(--font-mono); font-size: 11px;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
  max-width: 200px; flex-shrink: 0; user-select: none;
}
.workspace-tab-header:hover { background: var(--surface-2); color: var(--text-normal); }
.workspace-tab-header.is-active { background: var(--surface-2); color: var(--text-normal); }
.workspace-tab-header .tab-title { overflow: hidden; text-overflow: ellipsis; }
.workspace-tab-header .tab-close {
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  border-radius: 3px; color: var(--text-faint); font-size: 14px; line-height: 1;
  opacity: 0; transition: opacity 0.1s, color 0.1s;
}
.workspace-tab-header:hover .tab-close { opacity: 1; }
.workspace-tab-header .tab-close:hover { color: var(--accent); }
.workspace-tab-header.is-dirty .tab-title::after { content: " \2022"; color: var(--accent); }

/* Sidebar tab headers */
.mod-left-split .workspace-tab-header-container,
.mod-right-split .workspace-tab-header-container {
  padding: 6px 8px; gap: 4px;
}
.mod-left-split .workspace-tab-header,
.mod-right-split .workspace-tab-header {
  padding: 4px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
}

/* ── Tab Container (leaves area) ── */
.workspace-tab-container { flex: 1; position: relative; overflow: hidden; }
.workspace-tab-container > .workspace-leaf { position: absolute; inset: 0; display: none; overflow: auto; }
.workspace-tab-container > .workspace-leaf.is-active { display: flex; flex-direction: column; }

/* ── Leaf / View ── */
.workspace-leaf { display: flex; flex-direction: column; }
.view-header {
  display: flex; align-items: center; padding: 4px 12px; height: 32px;
  border-bottom: 1px solid var(--border); gap: 8px; flex-shrink: 0;
  background: var(--ground);
}
.view-header-title {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.view-header-nav-buttons { display: flex; gap: 2px; }
.view-content { flex: 1; overflow: auto; }

/* ── File Explorer ── */
.nav-files-container { flex: 1; overflow-y: auto; padding: 4px 0; }
.nav-folder { user-select: none; }
.nav-folder-title {
  display: flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px;
  cursor: pointer; color: var(--text-muted); font-size: 13px;
  border-radius: var(--radius-s); margin: 0 4px;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.nav-folder-title:hover { background: var(--surface-2); color: var(--text-normal); }
.nav-folder-title .collapse-icon {
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s; font-size: 10px; flex-shrink: 0;
}
.nav-folder.is-collapsed > .nav-folder-children { display: none; }
.nav-folder.is-collapsed > .nav-folder-title .collapse-icon { transform: rotate(-90deg); }
.nav-folder-children { padding-left: 8px; }
.nav-file {
  display: flex; align-items: center; padding: 3px 8px 3px 24px;
  cursor: pointer; color: var(--text-normal); font-size: 13px;
  border-radius: var(--radius-s); margin: 0 4px;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-file:hover { background: var(--surface-2); }
.nav-file.is-active { background: var(--surface-2); color: var(--accent); }
.tree-item-icon { width: 16px; flex-shrink: 0; text-align: center; font-size: 11px; color: var(--text-faint); margin-right: 4px; }

/* ── Context Menu ── */
.menu {
  position: fixed; z-index: 1000; min-width: 180px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-m); padding: 4px;
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.3);
}
.menu-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-radius: var(--radius-s); cursor: pointer; color: var(--text-normal);
  font-size: 12px;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.menu-item:hover { background: var(--accent); color: var(--ground); }
.menu-item.is-disabled { opacity: 0.4; pointer-events: none; }
.menu-separator { height: 1px; background: var(--border); margin: 4px 8px; }

/* ── Status Bar ── */
.status-bar {
  height: var(--status-bar-height); display: flex; align-items: center;
  padding: 0 12px; gap: 12px; background: var(--surface);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.status-bar-item { display: flex; align-items: center; gap: 4px; }

/* ── Empty state ── */
.empty-state {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-faint);
  font-size: 15px; font-style: italic;
}

/* ── CM6 overrides ── */
.cm-editor {
  height: 100% !important;
  font-family: var(--font-mono); font-size: var(--editor-font-size, 15px);
  background: var(--ground) !important;
}
.cm-editor .cm-scroller { overflow: auto !important; padding: 16px 0; }
.cm-editor .cm-content { padding: 0 24px; max-width: 65ch; line-height: 1.7; color: var(--text-normal); }
.cm-editor .cm-line { line-height: 1.7; }
.cm-editor .cm-gutters { background: var(--ground); border-right: 1px solid var(--border); color: var(--text-faint); }
.cm-editor .cm-activeLineGutter { background: var(--surface); }
.cm-editor .cm-activeLine { background: var(--highlight); }
.cm-editor .cm-cursor { border-left-color: var(--accent); }
.cm-editor .cm-selectionBackground { background: oklch(from var(--accent) l c h / 0.2) !important; }
.cm-editor.cm-focused .cm-selectionBackground { background: oklch(from var(--accent) l c h / 0.25) !important; }
.cm-editor.cm-focused { outline: none !important; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: oklch(from var(--text-faint) l c h / 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: oklch(from var(--text-faint) l c h / 0.5); }

/* ── Input prompts (rename, new file) ── */
.prompt-container {
  position: fixed; inset: 0; z-index: 2000; display: flex;
  align-items: flex-start; justify-content: center; padding-top: 20vh;
  background: oklch(0 0 0 / 0.4);
}
.prompt {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-m); padding: 16px; min-width: 400px;
  box-shadow: 0 12px 40px oklch(0 0 0 / 0.4);
}
.prompt-title {
  font-size: 15px; font-weight: 600;
  margin-bottom: 12px; color: var(--text-normal);
}
.prompt-input {
  width: 100%; padding: 8px 12px; background: var(--ground);
  border: 1px solid var(--border); border-radius: var(--radius-s);
  color: var(--text-normal); font-size: 14px; font-family: var(--font-mono);
  outline: none; transition: border-color var(--duration) var(--ease);
}
.prompt-input:focus { border-color: var(--accent); }

/* ── Modal / Suggest Modal ── */
.modal-container {
  position: fixed; inset: 0; z-index: 2000; display: flex;
  align-items: flex-start; justify-content: center; padding-top: 12vh;
  background: oklch(0 0 0 / 0.4);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-m); min-width: 500px; max-width: 700px; width: 60vw;
  box-shadow: 0 12px 40px oklch(0 0 0 / 0.4); overflow: hidden;
}
.modal-title {
  padding: 12px 16px; font-size: 15px;
  font-weight: 600; color: var(--text-normal);
}
.modal-content { padding: 0 16px 16px; }
.modal .prompt-input {
  margin-bottom: 0; border-radius: 0; border: none;
  border-bottom: 1px solid var(--border); padding: 12px 16px; font-size: 15px;
}
.prompt-results { max-height: 400px; overflow-y: auto; padding: 4px 0; }
.suggestion-item {
  padding: 8px 16px; cursor: pointer; color: var(--text-normal);
  font-size: 14px;
  transition: background 0.08s var(--ease); display: flex;
  flex-direction: column; gap: 2px;
}
.suggestion-item:hover, .suggestion-item.is-selected { background: var(--highlight); }
.suggestion-item .suggestion-note {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-faint);
}
.suggestion-item .suggestion-hotkey {
  font-size: 10px; color: var(--text-muted); margin-left: auto;
  font-family: var(--font-mono); padding: 1px 6px;
  background: var(--ground); border-radius: 3px;
}
.suggestion-item .suggestion-flair { display: flex; justify-content: space-between; align-items: center; }
.suggestion-item .suggestion-title { flex: 1; }

/* ── Live Preview ── */
.cm-heading { color: var(--text-normal); }
.cm-heading-1 { font-size: 2em; }
.cm-heading-2 { font-size: 1.7em; }
.cm-heading-3 { font-size: 1.4em; }
.cm-heading-4 { font-size: 1.2em; }
.cm-heading-5 { font-size: 1.05em; }
.cm-heading-6 { font-size: 1em; color: var(--text-muted); }
.cm-strong { font-weight: 700; }
.cm-em { font-style: italic; }
.cm-inline-code {
  font-family: var(--font-mono); font-size: 0.88em;
  background: color-mix(in oklch, var(--ground), var(--text-normal) 6%);
  padding: 0.15em 0.35em; border-radius: 3px;
}
.cm-strikethrough { text-decoration: line-through; opacity: 0.5; }
.cm-link { color: var(--accent); text-decoration: underline; text-underline-offset: 0.15em; text-decoration-thickness: 1px; cursor: pointer; }
.cm-link:hover { color: var(--accent-bright); }
.cm-tag { color: var(--accent); opacity: 0.8; }

/* ── Settings Modal ── */
.modal input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 1px; background: var(--border);
  border-radius: 1px; outline: none;
}
.modal input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 10px; height: 10px;
  background: var(--accent); border-radius: 50%; cursor: pointer;
  border: none;
}
.modal input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; background: var(--accent);
  border-radius: 50%; border: none;
}

/* ── Focus ── */
a:focus-visible, button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Mobile / Touch ── */
@media (max-width: 768px) {
  /* Ribbon becomes a bottom tab bar */
  .workspace-ribbon {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: auto !important; height: 52px;
    flex-direction: row; justify-content: space-around;
    padding: 0 8px; gap: 0;
    border-right: none; border-top: 1px solid var(--border);
    z-index: 300;
  }
  .workspace-ribbon .side-dock-actions {
    flex-direction: row; flex: 1;
    justify-content: space-around; align-items: center; gap: 0;
  }
  .workspace-ribbon .side-dock-settings {
    flex-direction: row; margin-top: 0; align-items: center;
  }
  .workspace-ribbon .side-dock-ribbon-action {
    width: 44px; height: 44px; font-size: 18px;
  }

  /* Workspace: leave room for fixed ribbon; hide status bar */
  .workspace { padding-bottom: 52px; }
  .status-bar { display: none; }

  /* Left sidebar: slide-in drawer from left */
  .mod-left-split {
    position: fixed !important;
    top: 0; left: 0; bottom: 52px;
    width: 82% !important; max-width: 320px;
    z-index: 200;
    transform: translateX(0);
    transition: transform var(--duration) var(--ease);
    border-right: 1px solid var(--border);
  }
  .mod-left-split.is-collapsed {
    width: 82% !important; max-width: 320px !important;
    transform: translateX(-110%);
    border: none;
  }

  /* Right sidebar: slide-in drawer from right */
  .mod-right-split {
    position: fixed !important;
    top: 0; right: 0; bottom: 52px;
    width: 82% !important; max-width: 320px;
    z-index: 200;
    transform: translateX(0);
    transition: transform var(--duration) var(--ease);
    border-left: 1px solid var(--border);
  }
  .mod-right-split.is-collapsed {
    width: 82% !important; max-width: 320px !important;
    transform: translateX(110%);
    border: none;
  }

  /* Dim backdrop behind open drawers */
  .workspace:has(.mod-left-split:not(.is-collapsed))::after,
  .workspace:has(.mod-right-split:not(.is-collapsed))::after {
    content: "";
    position: fixed; inset: 0; bottom: 52px;
    background: oklch(0 0 0 / 0.4);
    z-index: 190;
    pointer-events: none;
  }

  /* Resize handles: unusable on touch */
  .workspace-leaf-resize-handle { display: none; }

  /* Modals / Prompts: near full-width */
  .modal { min-width: unset; max-width: none; width: 92vw; }
  .prompt { min-width: unset; width: 92vw; }
  .modal-container, .prompt-container { padding-top: 6vh; }
  .prompt-results { max-height: 60vh; }

  /* Tab close always visible (can't hover on touch) */
  .workspace-tab-header .tab-close { opacity: 1; }

  /* Editor: no prose max-width, tighter padding */
  .cm-editor .cm-content { max-width: none; padding: 0 16px; }
  .cm-editor .cm-scroller { padding: 10px 0; }

  /* Touch-friendly tap targets */
  .nav-folder-title, .nav-file { min-height: 40px; }
  .suggestion-item { padding: 10px 16px; }
}
