:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #20242d;
  --surface-3: #292e39;
  --text: #f4f7fb;
  --muted: #9da8b8;
  --line: #313846;
  --accent: #5eead4;
  --accent-2: #facc15;
  --danger: #fb7185;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

:root.light {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #e1e7ef;
  --text: #151923;
  --muted: #5f6876;
  --line: #d7dde7;
  --accent: #0f9f8c;
  --accent-2: #b98500;
  --danger: #c02643;
  --shadow: 0 18px 45px rgba(34, 42, 53, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 82%, var(--bg));
  padding: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 800;
}

.brand span,
.muted,
.eyebrow {
  color: var(--muted);
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  font-size: 12px;
  margin-top: 2px;
}

.nav-group,
.sidebar-section {
  margin-top: 26px;
}

.nav-item,
.folder-item,
.primary-action,
.secondary-action,
.theme-toggle,
.icon-button,
.link-button,
.segment {
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  margin-bottom: 6px;
  padding: 0 10px;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active,
.folder-item:hover,
.folder-item.active {
  background: var(--surface-2);
  border-color: var(--line);
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  color: var(--accent);
}

.section-head,
.panel-head,
.editor-toolbar,
.form-actions,
.inline-filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  min-height: 32px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.icon-button,
.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--surface-2);
  border-color: var(--line);
}

.folder-tree {
  display: grid;
  gap: 6px;
}

.folder-item {
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  text-align: left;
}

.folder-item.child {
  padding-left: 24px;
  color: var(--muted);
}

.category-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.token {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(18px);
}

.mobile-menu {
  display: none;
}

.command-search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.command-search input,
.ai-box input,
.palette-panel input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

kbd {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 6px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
}

.primary-action,
.secondary-action {
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}

.primary-action {
  background: var(--accent);
  color: #06201d;
  border-color: transparent;
  font-weight: 750;
}

.secondary-action,
.link-button,
.segment {
  background: var(--surface-2);
  border-color: var(--line);
}

.link-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--accent);
}

.view {
  display: none;
  padding: 26px;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 22px;
}

.compact-heading {
  align-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 56px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
}

.stat-card,
.panel,
.prompt-card,
.clipboard-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 16px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.dashboard-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.wide {
  grid-column: 1 / -1;
}

.snippet-list,
.clipboard-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.snippet-card {
  display: grid;
  gap: 9px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.snippet-card.selected {
  border-color: var(--accent);
}

.snippet-title-row,
.snippet-meta,
.snippet-actions,
.token-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.snippet-title-row {
  justify-content: space-between;
}

.snippet-title-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.snippet-meta {
  color: var(--muted);
  font-size: 12px;
}

.snippet-code {
  max-height: 96px;
  overflow: hidden;
  margin: 0;
  border-radius: 6px;
  padding: 10px;
  background: #0b0d11;
  color: #d7fbe8;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 12px;
}

:root.light .snippet-code {
  background: #17202b;
}

.tiny-button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
}

.ai-box {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.ai-box input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 0 12px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(290px, 420px) minmax(0, 1fr);
  gap: 16px;
}

.list-panel {
  align-self: start;
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segment {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.segment.active {
  background: var(--accent);
  color: #06201d;
}

.inline-filters {
  margin-top: 16px;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}

.inline-filters select {
  width: 50%;
  min-height: 38px;
  padding: 0 10px;
}

form {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label input,
label textarea,
label select {
  width: 100%;
  padding: 11px;
  outline: 0;
}

textarea {
  resize: vertical;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.toggle span {
  margin: 0;
}

.code-editor {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  min-height: 390px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0b0d11;
}

#lineNumbers {
  margin: 0;
  padding: 14px 10px;
  border-right: 1px solid #26303d;
  color: #607085;
  text-align: right;
  user-select: none;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

#codeInput {
  width: 100%;
  min-height: 390px;
  padding: 14px;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: #e8f5ff;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.prompt-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.prompt-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.clipboard-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
}

.clipboard-item pre {
  max-height: 110px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.button-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.schema-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.settings-grid code {
  display: block;
  margin: 10px 0;
  padding: 10px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--accent);
}

.command-palette,
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  padding: 7vh 20px;
  background: rgba(0, 0, 0, 0.5);
}

.command-palette.open,
.modal.open {
  display: block;
}

.palette-panel,
.modal-panel {
  width: min(760px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.palette-panel input {
  min-height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.palette-results {
  max-height: 55vh;
  overflow: auto;
  padding: 10px;
}

.palette-result {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.palette-result:hover,
.palette-result.active {
  background: var(--surface-2);
  border-color: var(--line);
}

.modal-panel {
  padding: 18px;
}

.markdown-preview {
  max-height: 68vh;
  overflow: auto;
  margin-top: 14px;
  line-height: 1.65;
}

.markdown-preview pre {
  padding: 14px;
  overflow: auto;
  border-radius: var(--radius);
  background: #0b0d11;
  color: #d7fbe8;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  transform: translateY(90px);
  opacity: 0;
  transition: 180ms ease;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    transform: translateX(-105%);
    transition: 200ms ease;
    width: min(320px, 86vw);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: grid;
    place-items: center;
    width: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
  }

  .split-layout,
  .dashboard-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .list-panel {
    position: static;
    max-height: none;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .primary-action {
    grid-column: 1 / -1;
  }

  kbd {
    display: none;
  }

  .view {
    padding: 18px;
  }

  .view-heading,
  .panel-head,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 32px;
  }
}
