:root {
  color-scheme: light;
  --bg: #edf0e6;
  --bg-gradient: radial-gradient(1200px 600px at 15% -10%, #f8fcf1 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #e0e6d8 0%, transparent 55%);
  --panel: #fbfaf5;
  --panel-raised: #ffffff;
  --line: #ddd6c6;
  --line-soft: #e8e3d6;
  --text: #1f2a1f;
  --muted: #6b7468;
  --accent: #2b5d4b;
  --accent-strong: #21503f;
  --accent-soft: #dcebe2;
  --accent-softer: #ecf4ef;
  --warning: #8d4c2f;
  --warning-soft: #f5e1d6;
  --danger: #a33b3b;
  --danger-soft: #f6dcdc;
  --ok: #2f7d4f;
  --ok-soft: #ddefe3;
  --shadow: 0 10px 28px rgba(31, 42, 31, 0.07);
  --shadow-small: 0 2px 8px rgba(31, 42, 31, 0.06);
  --radius: 16px;
  --radius-small: 10px;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161a16;
  --bg-gradient: radial-gradient(1200px 600px at 15% -10%, #1d241d 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #131713 0%, transparent 55%);
  --panel: #1d221d;
  --panel-raised: #242a24;
  --line: #343c34;
  --line-soft: #2b322b;
  --text: #e3e8e0;
  --muted: #8e988b;
  --accent: #7cc3a4;
  --accent-strong: #95d4b8;
  --accent-soft: #2a3d34;
  --accent-softer: #232d28;
  --warning: #e0a37e;
  --warning-soft: #3c2c21;
  --danger: #e08c8c;
  --danger-soft: #3c2424;
  --ok: #8bcaa2;
  --ok-soft: #233529;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-small: 0 2px 8px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg-gradient), var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent-soft);
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 24px 10px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-small);
}

html[data-theme="dark"] .brand-mark {
  color: #16201b;
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.topbar p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.status-pill.ok { color: var(--ok); border-color: var(--ok-soft); background: var(--ok-soft); }
.status-pill.ok .status-dot { background: var(--ok); }
.status-pill.error { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.status-pill.error .status-dot { background: var(--danger); }
.status-pill.warn { color: var(--warning); border-color: var(--warning-soft); background: var(--warning-soft); }
.status-pill.warn .status-dot { background: var(--warning); }

.auth-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-small);
  padding: 6px 8px 6px 12px;
  border-radius: 12px;
}

.auth-icon {
  color: var(--muted);
  flex: none;
}

.auth-box input {
  width: 190px;
  border: 0;
  background: transparent;
  padding: 6px 2px;
  outline: none;
}

.auth-box input::placeholder {
  color: var(--muted);
}

/* ---------- Buttons ---------- */

button {
  border: 1px solid var(--line);
  background: var(--panel-raised);
  border-radius: var(--radius-small);
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
}

button:hover {
  border-color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

html[data-theme="dark"] button.primary {
  color: #16201b;
}

button.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--muted);
}

.icon-button:hover {
  color: var(--accent);
}

#theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] #theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] #theme-toggle .icon-moon { display: block; }

/* ---------- Layout / panels ---------- */

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 330px;
  gap: 14px;
  padding: 8px 24px 20px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.panel-scroll::-webkit-scrollbar {
  width: 8px;
}

.panel-scroll::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.panel h3 {
  margin: 16px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}

.panel section:first-of-type h3 {
  margin-top: 4px;
}

.small {
  font-size: 11.5px;
}

.placeholder {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 4px;
}

/* ---------- Search ---------- */

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}

.search-wrap > svg {
  position: absolute;
  left: 11px;
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-raised);
  border-radius: var(--radius-small);
  padding: 9px 32px 9px 34px;
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent);
  outline: none;
}

.clear-button {
  position: absolute;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  border-radius: 50%;
}

.clear-button:hover {
  color: var(--text);
  background: var(--line-soft);
}

mark {
  background: var(--accent-soft);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------- Shortcuts ---------- */

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shortcut-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  padding: 8px 10px;
}

.shortcut-item:hover {
  border-color: var(--accent);
  background: var(--accent-softer);
}

.shortcut-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
  font-size: 13px;
}

.shortcut-path {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Tree ---------- */

.tree-root,
.search-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.tree-group-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-small);
  user-select: none;
}

.tree-group-summary:hover {
  background: var(--accent-softer);
}

.tree-group-summary::-webkit-details-marker {
  display: none;
}

.tree-caret {
  color: var(--muted);
  flex: none;
  transition: transform 0.15s ease;
  display: grid;
  place-items: center;
}

details.tree-group[open] > .tree-group-summary .tree-caret {
  transform: rotate(90deg);
}

.tree-group-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--dot-color, var(--muted));
}

.tree-children {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-left: 1px solid var(--line-soft);
  margin-left: 14px;
}

.tree-file,
.search-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}

.tree-file:hover,
.search-result-item:hover {
  background: var(--accent-softer);
  border-color: transparent;
}

.tree-file.active,
.search-result-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 500;
}

.tree-file .file-icon,
.search-result-item .file-icon {
  color: var(--muted);
  flex: none;
}

.tree-file.active .file-icon {
  color: var(--accent-strong);
}

.tree-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.search-result-text {
  min-width: 0;
  flex: 1;
}

.search-result-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.search-result-path {
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 8px;
  background: var(--accent-softer);
  color: var(--muted);
  font-size: 11px;
  flex: none;
}

/* ---------- Viewer ---------- */

.viewer-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.viewer-header {
  flex-wrap: wrap;
}

.viewer-title-block {
  min-width: 0;
}

#viewer-title {
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

#viewer-meta {
  font-size: 12px;
  margin-top: 2px;
}

.tab-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  overflow: hidden;
  background: var(--panel-raised);
}

.segmented .tab-button {
  border: 0;
  border-radius: 0;
  padding: 6px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.segmented .tab-button:hover {
  color: var(--text);
}

.segmented .tab-button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

html[data-theme="dark"] .segmented .tab-button.active {
  color: #16201b;
}

.icon-button.toggled {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.viewer-surface {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

#viewer-raw.viewer-surface {
  white-space: pre;
  word-break: normal;
}

#viewer-raw.viewer-surface.wrap {
  white-space: pre-wrap;
  word-break: break-word;
}

.markdown-preview {
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  white-space: normal;
  word-break: break-word;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 {
  margin: 1.2em 0 0.4em;
  line-height: 1.3;
}

.markdown-preview h1:first-child,
.markdown-preview h2:first-child,
.markdown-preview h3:first-child {
  margin-top: 0;
}

.markdown-preview h1 { font-size: 1.5em; border-bottom: 1px solid var(--line-soft); padding-bottom: 0.3em; }
.markdown-preview h2 { font-size: 1.25em; }
.markdown-preview h3 { font-size: 1.1em; }

.markdown-preview p {
  margin: 0.5em 0;
}

.markdown-preview ul,
.markdown-preview ol {
  margin: 0.5em 0;
  padding-left: 1.6em;
}

.markdown-preview li {
  margin: 0.2em 0;
}

.markdown-preview blockquote {
  margin: 0.6em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-softer);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}

.markdown-preview hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.2em 0;
}

.markdown-preview code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--accent-softer);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.markdown-preview pre {
  background: var(--accent-softer);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 12px 14px;
  overflow: auto;
  margin: 0.6em 0;
}

.markdown-preview pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

.markdown-preview a {
  color: var(--accent);
}

.viewer-warning {
  margin-bottom: 10px;
  border: 1px solid var(--warning);
  background: var(--warning-soft);
  color: var(--warning);
  border-radius: var(--radius-small);
  padding: 9px 12px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* ---------- Right panel ---------- */

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

.card {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  padding: 10px 12px;
}

.card .card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.card strong {
  display: block;
  font-size: 20px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.status-list,
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-item {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  padding: 8px 10px;
  font-size: 12.5px;
}

.kv {
  display: grid;
  grid-template-columns: 105px 1fr;
  gap: 4px 10px;
  align-items: baseline;
}

.kv strong {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.kv span {
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12px;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-family: var(--mono);
}

.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }

.recent-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  padding: 8px 10px;
}

.recent-item:hover {
  border-color: var(--accent);
  background: var(--accent-softer);
}

.recent-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.recent-path {
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
}

.muted {
  color: var(--muted);
}

/* ---------- Toasts ---------- */

.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 13px;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.2s ease;
}

.toast.success { border-color: var(--ok); color: var(--ok); }
.toast.error { border-color: var(--danger); color: var(--danger); }

.toast.leaving {
  animation: toast-out 0.2s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(8px); }
}

/* ---------- Responsive ---------- */

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    max-height: 320px;
  }
}

@media (max-width: 860px) {
  html,
  body,
  #app {
    height: auto;
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .panel {
    max-height: none;
  }

  .right-panel {
    max-height: none;
  }

  .center-panel {
    min-height: 60vh;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .auth-box {
    flex: 1;
  }

  .auth-box input {
    flex: 1;
    width: auto;
  }

  .panel-scroll {
    overflow: visible;
  }
}
