:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --text: #18212f;
  --muted: #617186;
  --border: #d7dfeb;
  --link: #2a5bd7;
  --accent: #dbe8ff;
  --hover: #f1f5fb;
  --shadow: 0 8px 24px rgba(27, 39, 63, 0.08);
}

:root[data-theme='dark'] {
  --bg: #0f141d;
  --panel: #171d28;
  --panel-2: #1e2531;
  --text: #edf2fb;
  --muted: #9ca9bb;
  --border: #2b3545;
  --link: #8fb3ff;
  --accent: #24314a;
  --hover: #1d2633;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--link); }
button, input, select { font: inherit; }
button { color: inherit; }

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

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  overflow: auto;
}

.sidebar-header, .viewer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.toolbar-buttons,
.viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-nav-button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.muted, .generated-at, .content-meta { color: var(--muted); }
.search-wrap { display: block; margin: 16px 0 12px; }
.search-wrap input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
}

.search-results {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  max-height: 220px;
  overflow: auto;
}
.search-results.hidden { display: none; }
.search-result {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--hover); }
.search-result-title { font-weight: 600; }
.search-result-path { font-size: 0.85rem; color: var(--muted); }

.tree details { margin-left: 10px; }
.tree details > summary {
  list-style: none;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 8px;
}
.tree details > summary:hover, .tree-file:hover { background: var(--hover); }
.tree details > summary::-webkit-details-marker { display: none; }
.tree-file {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 6px 8px 6px 28px;
  border-radius: 8px;
}
.tree-file.active, .tree details > summary.active { background: var(--accent); }
.file-label { display: inline-flex; align-items: center; gap: 8px; }
.file-icon { width: 18px; text-align: center; }
.folder-icon-wrap {
  position: relative;
  width: 18px;
  height: 1em;
  display: inline-block;
}
.folder-icon {
  position: absolute;
  left: 0;
  top: 0;
}
.folder-icon--expanded { display: none; }
.tree details[open] > summary .folder-icon--collapsed { display: none; }
.tree details[open] > summary .folder-icon--expanded { display: inline; }

.viewer-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}
.viewer-topbar {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 2;
}
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.95rem;
}
.breadcrumb button {
  border: 0;
  background: transparent;
  color: var(--link);
  cursor: pointer;
  padding: 0;
}
.viewer-title {
  padding: 16px 20px 0;
  font-size: 1.15rem;
  font-weight: 700;
}
.viewer {
  flex: 1;
  min-height: 0;
  padding: 16px 20px 20px;
  overflow: auto;
}
.viewer-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: auto;
}
.viewer-card--document {
  height: calc(100vh - 150px);
  min-height: 520px;
}
.viewer-card--content {
  overflow-x: auto;
  overflow-y: visible;
}
.viewer-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}
.viewer-frame--autoheight {
  display: block;
  min-height: 720px;
}
.viewer-empty {
  padding: 24px;
  color: var(--muted);
}
.inline-actions {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.inline-actions a { text-decoration: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  #app {
    display: block;
    min-height: 100vh;
  }

  .sidebar,
  .viewer-shell {
    min-height: 100vh;
  }

  #app[data-mobile-mode='tree'] .sidebar {
    display: block;
    border-right: 0;
  }

  #app[data-mobile-mode='tree'] .viewer-shell {
    display: none;
  }

  #app[data-mobile-mode='viewer'] .sidebar {
    display: none;
  }

  #app[data-mobile-mode='viewer'] .viewer-shell {
    display: flex;
  }

  .sidebar {
    max-height: none;
    overflow: visible;
    border-right: 0;
    border-bottom: 0;
    padding: 16px 14px 32px;
  }

  .sidebar-header {
    align-items: flex-start;
  }

  .viewer-shell {
    min-height: 100vh;
    background: var(--bg);
  }

  .viewer-topbar {
    position: sticky;
    top: 0;
    z-index: 4;
    padding: 10px 14px;
    align-items: center;
  }

  .viewer-actions {
    flex-shrink: 0;
    margin-left: auto;
    align-self: center;
  }

  .mobile-nav-button {
    padding: 7px 10px;
    line-height: 1.2;
  }

  .generated-at {
    display: none;
  }

  .breadcrumb {
    min-width: 0;
    overflow-x: auto;
    flex-wrap: nowrap;
    white-space: nowrap;
    scrollbar-width: thin;
  }

  .viewer-title {
    padding: 12px 14px 0;
  }

  .viewer {
    flex: none;
    min-height: 0;
    padding: 12px 0 0;
    overflow: visible;
  }

  .viewer-card {
    height: auto;
    min-height: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-radius: 0;
    box-shadow: none;
    overflow-x: auto;
    overflow-y: visible;
  }

  .viewer-card--document {
    min-height: calc(100vh - 70px);
  }

  .viewer-frame {
    display: block;
    width: 100%;
    min-width: 100%;
  }

  .viewer-card--fixed-frame .viewer-frame {
    height: calc(100vh - 120px);
  }

  .viewer-frame--autoheight {
    min-height: 0;
  }

  .inline-actions {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 14px;
    overflow-x: auto;
    white-space: nowrap;
  }
}
