:root {
  --bg: #0f172a;
  --panel: #111827;
  --card: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-2: #10b981;
  --border: #1f2937;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
#app { display: flex; flex: 1; min-height: 0; }
.site-header {
  background: #ffffff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid rgba(224,224,224,0.85);
}
.site-nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
}
.nav-left { display: flex; align-items: center; gap: 15px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #1a1a2e; }
.brand-logo { width: 40px; height: 40px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-name { font-size: 1.4rem; font-weight: 700; color: #1a1a2e; line-height: 1; letter-spacing: -0.5px; }
.brand-tagline { font-size: 0.75rem; color: #666; font-weight: 400; letter-spacing: 0.3px; }
.nav-center { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 25px; }
.nav-links { display: flex; align-items: center; gap: 20px; }
.nav-link { text-decoration: none; color: #1a1a2e; font-weight: 500; font-size: 0.95rem; padding: 8px 12px; border-radius: 6px; transition: all 0.2s; white-space: nowrap; letter-spacing: 0.35px; }
.nav-link:hover, .nav-link.active { background: #f0f8ff; color: #0078ff; }
.coffee-mobile { display: none; }
.nav-actions { display: flex; align-items: center; gap: 16px; }
.nav-cta { padding: 10px 16px; border-radius: 10px; border: 1px solid #e0e7ff; background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); color: #fff; font-weight: 600; font-size: 0.95rem; text-decoration: none; box-shadow: 0 8px 20px rgba(37,99,235,0.18); }
.nav-cta:hover { opacity: 0.95; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; color: #1a1a2e; }

@media (max-width: 768px) {
  .site-nav { padding: 12px 20px; gap: 15px; }
  .brand-logo { width: 35px; height: 35px; }
  .brand-name { font-size: 1.2rem; }
  .brand-tagline { font-size: 0.7rem; }
  .nav-center { display: none; }
  .nav-center.mobile-open { display: flex; position: absolute; top: 100%; left: 0; right: 0; background: #fff; flex-direction: column; padding: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); gap: 15px; border-top: 1px solid #e0e0e0; }
  .nav-links { flex-direction: column; width: 100%; gap: 10px; }
  .nav-link { width: 100%; text-align: center; padding: 12px; }
  .coffee-mobile { display: block; font-weight: 700; color: #2563eb; }
  .menu-toggle { display: block; }
  .nav-actions { display: none; }
  /* Hide sidebar (Projects) on mobile for more space */
  #app { flex-direction: column; }
  .sidebar { display: none; }
  .content-area { width: 100%; }

  /* Viewer mobile: hide side panel by default, show via toggle */
  .viewer-inner { grid-template-columns: none; display: flex; flex-direction: column; position: relative; height: 100vh; }
  .viewer-main { flex: 1; min-height: 0; }
  .viewer-toolbar { flex-wrap: wrap; }
  .viewer-canvas { padding: 12px 0 32px; }
  .viewer-side { display: none; position: fixed; top: 0; bottom: 0; left: 0; width: 80%; max-width: 280px; z-index: 20; box-shadow: 2px 0 12px rgba(0,0,0,0.4); overflow: auto; }
  .viewer-side.open { display: flex; }
  .side-toggle { display: inline-flex; }
  .side-mobile-bar { display: flex; justify-content: flex-end; padding: 8px 12px; }
}
.sidebar {
  width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.topbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar input,
.topbar button,
.controls button,
.controls select,
.controls input {
  background: #111827;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.topbar input { flex: 1 1 160px; }
.topbar select { flex: 1 1 160px; min-width: 160px; }
.topbar button { flex: 0 0 auto; cursor: pointer; }
.topbar input { flex: 1 1 160px; }
.topbar select { flex: 1 1 160px; min-width: 160px; }
.topbar button { flex: 0 0 auto; }

.topbar button { cursor: pointer; }
.panel-title { padding: 12px 16px; font-weight: 700; color: var(--muted); letter-spacing: 0.3px; }
.tree,
.folder-contents { flex: 1; overflow: auto; padding: 4px 8px 8px 8px; }
.tree ul { list-style: none; padding-left: 10px; margin: 0; }
.tree li { padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.tree .row { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.tree .row.active { background: rgba(59,130,246,0.12); color: var(--text); }
.twisty { width:14px; display:inline-block; color:#9ca3af; text-align:center; }
.folder-icon { width:16px; display:inline-block; }
.folder-name { color: inherit; }
.file-node { padding-left: 18px; color: #cbd5e1; }
.file-icon { width:16px; display:inline-block; }
.content-area { flex: 1; display: flex; flex-direction: column; }
.controls {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.grid {
    flex: 1;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 200px));
    justify-content: flex-start;
    gap: 14px;
    overflow: auto;
}
.grid-wrapper { position: relative; flex:1; }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    width: 200px;
    position: relative;
}
.card canvas { width: 100%; height: 160px; border-radius: 6px; background: #0b1220; }
.card .meta { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.card.checked { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }
.file-check { position: absolute; top: 8px; left: 8px; }
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
  color: #e5e7eb;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text { font-size: 14px; color: #cbd5e1; }
@keyframes spin { to { transform: rotate(360deg); } }
.viewer { position: fixed; inset: 0; background: #0b1220; display: none; align-items: stretch; justify-content: stretch; overflow: auto; }
.viewer.open { display: flex; }
.viewer-inner { width: 100%; height: 100vh; background: #0b1220; display: grid; grid-template-columns: 260px 1fr; overflow: auto; }
.viewer-side { background: #0f172a; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.viewer-main { display: flex; flex-direction: column; min-height: 0; }
.viewer-toolbar { padding: 10px; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.viewer-canvas { flex: 1; overflow: auto; background: #0b1220; display: flex; justify-content: flex-start; align-items: flex-start; padding: 16px 12px 48px; }
.viewer-canvas canvas { margin: 0 auto; background: white; display: block; max-width: 100%; height: auto; }
.spread { display: flex; gap: 16px; justify-content: center; width: 100%; flex-wrap: wrap; }
.side-toggle { display: none; }
.side-mobile-bar { display: none; }
.side-section { padding: 12px; border-bottom: 1px solid var(--border); }
.side-section h4 { margin: 0 0 8px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.side-list { flex: 1; overflow: auto; padding: 0 12px 12px; }
.search-list { padding: 0 12px 4px; }
.bookmarks-header { padding-top: 8px; }
.side-list div { padding: 8px; border-radius: 6px; cursor: pointer; }
.side-list div:hover { background: rgba(59,130,246,0.1); }
.toast { position: fixed; bottom: 16px; right: 16px; background: #111827; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); color: var(--text); display: none; }
.toast.show { display: block; }
.controls-note { font-size: 12px; color: var(--muted); }
.privacy-note {
  margin: 10px 16px 0 16px;
  font-size: 12px;
  color: #9ca3af;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: 8px;
  padding: 8px 10px;
}
.empty-state {
  grid-column: 1 / -1;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}
.empty-title { font-weight: 700; margin-bottom: 6px; color: #e5e7eb; }
.empty-desc { font-size: 13px; color: #9ca3af; }

/* Mobile overrides (placed at end to win cascade) */
@media (max-width: 768px) {
  .viewer-inner {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    position: relative;
    height: 100vh;
  }
  .viewer-main { flex: 1; min-height: 0; }
  .viewer-toolbar { flex-wrap: wrap; }
  .viewer-canvas { padding: 12px 12px 32px; }
  .viewer-side {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 80%;
    max-width: 280px;
    z-index: 20;
    box-shadow: 2px 0 12px rgba(0,0,0,0.4);
    overflow: auto;
  }
  .viewer-side.open { display: flex; }
  .side-toggle { display: inline-flex; }
  .side-mobile-bar { display: flex; justify-content: flex-end; padding: 8px 12px; }
}
