/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface2: #1a1a1a;
  --surface3: #222222;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-muted: #888888;
  --text-dim: #555555;
  --accent-start: #e1306c;
  --accent-end: #833ab4;
  --gradient: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  --sidebar-width: 240px;
  --header-height: 56px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
#root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
#header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.header-logo svg {
  width: 26px;
  height: 26px;
}

.header-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.header-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}

/* Search bar */
.search-wrap {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  width: 15px;
  height: 15px;
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

#search-input::placeholder {
  color: var(--text-dim);
}

#search-input:focus {
  border-color: var(--accent-start);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

#post-count {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px;
  display: flex;
  align-items: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  border-color: #444;
  background: var(--surface2);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* ── Upload Section ─────────────────────────────────────────────────────────── */
#upload-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

#upload-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 60px 80px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  max-width: 480px;
  width: 100%;
}

#upload-zone:hover, #upload-zone.drag-over {
  border-color: var(--accent-start);
  background: rgba(225, 48, 108, 0.04);
}

#upload-zone.drag-over {
  background: rgba(225, 48, 108, 0.08);
}

.upload-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
}

.upload-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.upload-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.upload-btn {
  display: inline-block;
  padding: 10px 24px;
  background: var(--gradient);
  color: white;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  pointer-events: none; /* handled by parent click */
}

.upload-error {
  color: #ff6b6b;
  font-size: 12px;
  margin-top: 12px;
}

#file-input {
  display: none;
}

/* ── Main Layout (sidebar + grid) ───────────────────────────────────────────── */
#main-layout {
  flex: 1;
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

/* ── Categorize Bar ──────────────────────────────────────────────────────────── */
#categorize-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}

/* When categorize bar is present, it sits between header and main-layout */
#wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Left column — lines up with the sidebar */
.categorize-bar-left {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-right: 1px solid var(--border);
}

/* Right column — lines up with the grid */
.categorize-bar-right {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 10px 20px;
}

#categorize-btn {
  width: 100%;
  padding: 8px 16px;
  background: var(--gradient);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

#categorize-btn:hover { opacity: 0.88; }
#categorize-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#categorize-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.progress-track {
  flex: 1;
  height: 4px;
  background: var(--surface3);
  border-radius: 4px;
  overflow: hidden;
}

.progress-track-fill {
  height: 100%;
  background: var(--gradient);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s ease;
}

#categorize-progress-text {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  min-width: 160px;
}

.btn-pause {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 5px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.btn-pause:hover { color: var(--text); border-color: var(--text-muted); }
.btn-pause.paused { color: #4ade80; border-color: #4ade80; }

/* ── Age Warning ─────────────────────────────────────────────────────────────── */
#age-warning {
  background: rgba(255, 170, 0, 0.1);
  border-bottom: 1px solid rgba(255, 170, 0, 0.2);
  color: #ffaa00;
  font-size: 12px;
  padding: 8px 20px;
  flex-shrink: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#folder-tree {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

#folder-tree::-webkit-scrollbar {
  width: 4px;
}
#folder-tree::-webkit-scrollbar-track { background: transparent; }
#folder-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Folder Tree Nodes ────────────────────────────────────────────────────────── */
.folder-tree, .folder-children {
  list-style: none;
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  user-select: none;
}

.folder-header:hover {
  background: var(--surface2);
}

.folder-header.active {
  background: rgba(225, 48, 108, 0.12);
  color: var(--text);
}

.folder-header.active .folder-name {
  color: var(--text);
}

.folder-chevron {
  color: var(--text-dim);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  width: 12px;
  height: 12px;
  transition: transform 0.15s;
}

.folder-chevron svg { width: 12px; height: 12px; }

.folder-chevron.open { transform: rotate(90deg); }

.folder-chevron.folder-chevron-hidden { visibility: hidden; }

/* Folder icon — shown for parent nodes, changes open/closed on expand */
.folder-icon {
  color: #c8a04a;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.folder-icon svg { width: 13px; height: 13px; }

.folder-header.active .folder-icon { color: #e0b85a; }

/* Dot icon — shown for leaf (tertiary) nodes */
.folder-icon-leaf {
  color: var(--text-dim);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: 0.5;
}

.folder-icon-leaf svg { width: 6px; height: 6px; }

.folder-header.active .folder-icon-leaf { color: var(--accent-start); opacity: 1; }

/* Leaf rows get slightly more left padding to align with folder label */
.folder-header-leaf {
  padding-left: 20px;
}

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

.folder-count {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface3);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.folder-children {
  padding-left: 16px;
}

/* ── Main Grid Area ───────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  min-width: 0;
}

#grid-header {
  padding: 14px 20px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: var(--header-height);
  z-index: 5;
}

#post-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  align-content: start;
}

#post-grid::-webkit-scrollbar { width: 6px; }
#post-grid::-webkit-scrollbar-track { background: transparent; }
#post-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

/* ── Post Cards ────────────────────────────────────────────────────────────────── */
.post-card {
  background: var(--surface2);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.post-card:hover {
  transform: translateY(-2px);
  border-color: #444;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.post-thumb {
  position: relative;
  width: 100%;
  height: 160px;
  background: var(--surface3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Placeholder icon when no image is present */
.post-thumb::before {
  content: '📷';
  font-size: 28px;
  opacity: 0.15;
  position: absolute;
}

.post-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s;
  position: relative;
  z-index: 1;
}

.post-thumb.no-image {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 24px;
}

.post-thumb.no-image::after {
  content: '📷';
}

.post-type-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  backdrop-filter: blur(4px);
}

.post-info {
  padding: 7px 8px;
  min-height: 30px;
  display: flex;
  align-items: flex-start;
}

.post-slug {
  font-size: 10px;
  color: var(--text-dim);
  font-family: 'SF Mono', Consolas, monospace;
  word-break: break-all;
}

.post-category-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface3);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Empty State ──────────────────────────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Settings Modal ───────────────────────────────────────────────────────────── */
#settings-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#settings-modal.hidden {
  display: none;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 400px;
  max-width: 90vw;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: 'SF Mono', Consolas, monospace;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--accent-start);
}

.form-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.form-hint-warning {
  color: #f59e0b;
}

/* ── Toggle switch ────────────────────────────────────────────────────────────── */
.toggle-row {
  margin-top: 4px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
}

.toggle-switch {
  position: relative;
  flex-shrink: 0;
}

.toggle-switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  display: block;
  width: 36px;
  height: 20px;
  background: var(--surface3);
  border-radius: 20px;
  transition: background 0.2s;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent-start);
}

.toggle-track::after {
  content: '';
  display: block;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  margin: 3px;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.btn-ghost {
  padding: 9px 16px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

.btn-danger {
  padding: 9px 16px;
  background: none;
  border: 1px solid rgba(255, 80, 80, 0.3);
  border-radius: 8px;
  color: #ff6b6b;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover {
  background: rgba(255, 80, 80, 0.1);
}

.btn-primary {
  padding: 9px 20px;
  background: var(--gradient);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.88; }

/* ── Onboarding Steps ─────────────────────────────────────────────────────────── */
.onboarding {
  max-width: 480px;
  width: 100%;
  margin-bottom: 32px;
  text-align: left;
}

.onboarding-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.onboarding-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.onboarding-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.step-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.step-body strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.step-body span {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.onboarding-footer {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
}

.privacy-link {
  color: var(--text-dim);
  text-decoration: none;
}

.privacy-link:hover {
  color: var(--text-muted);
  text-decoration: underline;
}

.onboarding-link {
  color: var(--accent-start);
  text-decoration: none;
}

.onboarding-link:hover {
  text-decoration: underline;
}

/* ── API Key Validation Status ───────────────────────────────────────────────── */
.api-key-status {
  font-size: 12px;
  min-height: 18px;
  margin-top: 6px;
  display: block;
}

.api-key-status.error {
  color: #ff6b6b;
}

.api-key-status.warning {
  color: #ffaa00;
}

.api-key-status.success {
  color: #4caf7d;
}

/* ── Guide Callouts ──────────────────────────────────────────────────────────── */
.guide-callout {
  position: fixed;
  z-index: 900;
  width: 250px;
  pointer-events: auto;
}

.guide-arrow {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 9px solid rgba(225, 48, 108, 0.45);
  /* margin-left set by JS to point at target */
}

.guide-bubble {
  background: var(--surface2);
  border: 1px solid rgba(225, 48, 108, 0.35);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(225, 48, 108, 0.08);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.guide-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.guide-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.guide-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.guide-desc strong {
  color: var(--text);
}

.guide-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.guide-skip-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 6px;
}
.guide-skip-btn:hover { color: var(--text-muted); }

.guide-next-btn,
.guide-done-btn {
  background: var(--gradient);
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.guide-next-btn:hover,
.guide-done-btn:hover { opacity: 0.88; }

/* ── Utilities ────────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}
