/* ===================== RESET & BASE ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none; }

:root {
  --sidebar-w: 240px;
  --header-h: 52px;
  --accent: #4f86f7;
  --accent-hover: #3a6fd6;
  --bg: #f5f6fa;
  --sidebar-bg: #1e2130;
  --sidebar-text: #c8cce0;
  --sidebar-hover: #2a2f45;
  --sidebar-active: #4f86f7;
  --sidebar-active-text: #fff;
  --header-bg: #1a1d2e;
  --header-text: #e8eaf0;
  --card-bg: #fff;
  --border: #e0e3ef;
  --muted: #8890a8;
  --disabled: #4a4f68;
  --overlay-bg: rgba(245, 246, 250, 0.85);
  --text: #222;
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --bg: #12141f;
  --card-bg: #1a1d2e;
  --border: #2a2f45;
  --muted: #6a7090;
  --overlay-bg: rgba(18, 20, 31, 0.88);
  --text: #d0d4e8;
}
[data-theme="dark"] .btn {
  background: #252a3d;
  color: #c8cce0;
  border-color: #3a3f5a;
}
[data-theme="dark"] .btn:hover { background: #2e3449; border-color: #4a5070; }
[data-theme="dark"] .btn:active { background: #252a3d; }
[data-theme="dark"] .current-title span { color: #d0d4e8; }
[data-theme="dark"] .toolbar { border-bottom-color: #2a2f45; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===================== HEADER ===================== */
header {
  height: var(--header-h);
  background: var(--header-bg);
  color: var(--header-text);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  z-index: 10;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hamburger — hidden on desktop */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--header-text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.12s;
}
.hamburger-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* Theme toggle — always visible */
.theme-btn {
  background: none;
  border: none;
  color: var(--header-text);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 5px;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.12s;
}
.theme-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* ===================== LAYOUT ===================== */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-search {
  padding: 10px 12px;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #3a3f5a;
  background: #2a2f45;
  color: var(--sidebar-text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.sidebar-search input::placeholder { color: #5a6080; }
.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 12px;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #3a3f5a; border-radius: 2px; }

/* ===================== NAV GROUPS ===================== */
.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5a6080;
  padding: 14px 14px 4px;
  user-select: none;
}

/* Accordion group header */
.nav-group-label--accordion {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.12s;
}
.nav-group-label--accordion:hover { color: #8a92b0; }

.accordion-indicator {
  font-size: 9px;
  flex-shrink: 0;
  display: inline-block;
  width: 10px;
  text-align: center;
}

/* ===================== NAV ITEMS ===================== */
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 8px;
  transition: background 0.12s, color 0.12s;
  font-size: 13.5px;
  user-select: none;
}

.nav-item:hover { background: var(--sidebar-hover); color: #fff; }

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.nav-item.disabled {
  color: var(--disabled);
  cursor: not-allowed;
  font-style: italic;
}

/* ===================== MAIN AREA ===================== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 44px;
}

.current-title {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.current-title span {
  color: var(--text);
  font-weight: 500;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: #333;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn:hover { background: var(--bg); border-color: #c0c5d8; }
.btn:active { background: #eaecf5; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.iframe-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#sheet-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 5;
  transition: opacity 0.2s;
}

.loading-overlay.hidden { display: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #d0d4e8;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay p { color: var(--muted); font-size: 13px; }

/* Empty / error state */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  background: var(--bg);
}

.empty-state.hidden { display: none; }
.empty-state svg { opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ===================== STAR / FAVORITES ===================== */
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 1px;
  flex-shrink: 0;
  color: #5a6080;
  opacity: 0.35;
  transition: opacity 0.12s, color 0.12s;
}

.nav-item:hover .star-btn { opacity: 0.7; }
.nav-item.active .star-btn { color: rgba(255,255,255,0.5); opacity: 0.6; }
.nav-item.active .star-btn:hover { color: #fff; opacity: 1; }

.star-btn.starred {
  color: #f5c518;
  opacity: 1;
}

.star-btn.starred:hover { color: #e8b800; }
.nav-item.active .star-btn.starred { color: #ffe066; opacity: 1; }

.nav-group-label--favorites {
  color: #8890a8;
  border-bottom: 1px solid #2a2f45;
  margin-bottom: 2px;
  padding-bottom: 6px;
}

/* No search results */
.no-results {
  padding: 12px 14px;
  font-size: 12px;
  color: #5a6080;
  font-style: italic;
}

/* ===================== MOBILE SIDEBAR BACKDROP ===================== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--header-h);
  background: rgba(0, 0, 0, 0.45);
  z-index: 199;
}
.sidebar-backdrop.open { display: block; }

/* ===================== RESPONSIVE — mobile ≤768px ===================== */
@media (max-width: 768px) {
  body { overflow: hidden; }

  /* Show hamburger */
  .hamburger-btn { display: flex; }

  /* Sidebar slides in as overlay */
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: 82vw;
    max-width: 300px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: translateX(0); }

  /* Layout stays row — main takes full width */
  .layout { flex-direction: row; overflow: hidden; }
  .main { flex: 1; overflow: hidden; }
  .iframe-wrap { height: 100%; }

  /* Bigger touch targets on mobile */
  .nav-item { padding: 13px 16px; font-size: 15px; margin: 1px 6px; }
  .star-btn { font-size: 16px; }
  .nav-group-label { font-size: 11px; padding: 16px 16px 6px; }
}
