:root {
  --bg: #ffffff;
  --bg-muted: #f5f5f5;
  --fg: #1f2328;
  --fg-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --topbar-height: 48px;
  --sidebar-width: 320px;
  --font: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a1f;
    --bg-muted: #20242b;
    --fg: #e6e8eb;
    --fg-muted: #9aa1ab;
    --border: #2c323a;
    --accent: #3b82f6;
    --accent-fg: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-height);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  position: relative;
  z-index: 30;
}

.app-title {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.current-path {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--bg-muted);
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  max-width: 85vw;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 40;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}

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

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--topbar-height);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-muted);
  color: var(--fg-muted);
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
}

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

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
  font-size: 14px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 35;
}

.sidebar-message {
  padding: 24px 16px;
  color: var(--fg-muted);
  text-align: center;
  font-size: 14px;
}

.sidebar-message p {
  margin: 4px 0;
}

.text-button {
  margin-top: 8px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--fg);
  border-radius: 6px;
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
}

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

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

.tree-node {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--fg);
  line-height: 1.4;
}

.tree-row:hover {
  background: var(--bg-muted);
}

.tree-row.file {
  cursor: pointer;
}

.tree-row.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.tree-arrow {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-muted);
  transition: transform 0.15s ease;
}

.tree-arrow.collapsed {
  transform: rotate(-90deg);
}

.tree-arrow.leaf {
  visibility: hidden;
}

.tree-icon {
  flex-shrink: 0;
  color: var(--fg-muted);
}

.tree-row.active .tree-icon,
.tree-row.active .tree-arrow {
  color: inherit;
}

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

.tree-children {
  margin-left: 18px;
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.tree-children[hidden] {
  display: none;
}

.tree-result {
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
}

.tree-result:hover {
  background: var(--bg-muted);
}

.tree-result.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.tree-result-path {
  display: block;
  font-size: 12px;
  color: var(--fg-muted);
}

.tree-result.active .tree-result-path {
  color: inherit;
  opacity: 0.85;
}

/* ---------- Main ---------- */

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--fg-muted);
  text-align: center;
  padding: 24px;
}

.empty-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
}

.empty-hint {
  margin: 0;
  font-size: 14px;
}

.reader {
  flex: 1;
  width: 100%;
  border: none;
  background: #ffffff;
}

/* ---------- Footer navigation ---------- */

.nav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 48px;
  padding: 0 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 110px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
}

.nav-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.nav-button:not(:disabled):hover {
  border-color: var(--accent);
}

.nav-arrow {
  font-size: 15px;
}

.nav-position {
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
}
