/* ============================================================
   ChronicalizeASean – Main Stylesheet
   Dark theme: slate-900 bg, slate-100 text
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-900: #0f172a;
  --bg-800: #1e293b;
  --bg-700: #334155;
  --bg-600: #475569;
  --text-100: #f1f5f9;
  --text-200: #e2e8f0;
  --text-400: #94a3b8;
  --text-600: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #06b6d4;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --timeline-axis-y: 140px;  /* px from top of SVG where axis lives */
}

html, body {
  height: 100%;
  background: var(--bg-900);
  color: var(--text-100);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Setup Banner ── */
.setup-banner {
  background: #78350f;
  color: #fef3c7;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  border-bottom: 1px solid #92400e;
}
.setup-banner code { background: rgba(0,0,0,0.3); padding: 1px 4px; border-radius: 3px; }

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-800);
  border-bottom: 1px solid var(--bg-700);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.header-left { flex-shrink: 0; }
.header-center { flex: 1; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.app-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-100);
  white-space: nowrap;
}

/* ── Filter Bar ── */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-input, .filter-select {
  background: var(--bg-700);
  border: 1px solid var(--bg-600);
  color: var(--text-100);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.filter-input { min-width: 160px; }
.filter-select { min-width: 130px; }
.filter-input:focus, .filter-select:focus { border-color: var(--accent); }

/* ── Auth / User Info ── */
.user-info { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--accent); object-fit: cover; }
.user-name { font-size: 13px; color: var(--text-200); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-actions { display: flex; gap: 6px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--bg-700); color: var(--text-200); border: 1px solid var(--bg-600); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-600); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Main Layout ── */
.app-main {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - 57px);
}

/* ── Zoom Controls ── */
.zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 50;
  display: flex;
  gap: 6px;
  background: var(--bg-800);
  border: 1px solid var(--bg-700);
  border-radius: var(--radius);
  padding: 4px 8px;
}

/* ── Timeline Wrapper ── */
.timeline-wrapper {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
  user-select: none;
  background: var(--bg-900);
  padding-bottom: 60px;
}
.timeline-wrapper:active { cursor: grabbing; }

.timeline-svg {
  display: block;
  min-height: 320px;
}

/* SVG elements via CSS classes */
.axis-line { stroke: var(--bg-600); stroke-width: 2; }
.tick-line { stroke: var(--bg-600); stroke-width: 1; }
.tick-label { fill: var(--text-400); font-size: 11px; font-family: inherit; }
.duration-bar { opacity: 0.6; rx: 3; ry: 3; }
.emoji-marker { cursor: pointer; transition: filter 0.1s; }
.emoji-marker:hover { filter: drop-shadow(0 0 6px rgba(59,130,246,0.8)); }
.connection-line { pointer-events: none; }
.cluster-rect { rx: 8; ry: 8; }

/* ── Mini-map ── */
.minimap-container {
  position: absolute;
  bottom: 8px;
  right: 12px;
  z-index: 50;
  background: var(--bg-800);
  border: 1px solid var(--bg-700);
  border-radius: var(--radius);
  overflow: hidden;
  width: 200px;
  height: 44px;
}
.minimap-canvas { display: block; }
.minimap-viewport {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(59,130,246,0.2);
  border: 1px solid var(--accent);
  pointer-events: none;
  transition: left 0.05s, width 0.05s;
}

/* ── Empty State ── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}
.empty-state * { pointer-events: all; }
.empty-icon { font-size: 48px; }
.empty-state h2 { font-size: 20px; color: var(--text-200); }
.empty-state p { color: var(--text-400); }
.empty-actions { display: flex; gap: 10px; }

/* ── Heatmap Panel ── */
.heatmap-panel {
  position: absolute;
  bottom: 60px;
  left: 12px;
  z-index: 50;
  background: var(--bg-800);
  border: 1px solid var(--bg-700);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 260px;
  max-width: 400px;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.heatmap-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.heatmap-header h3 { font-size: 14px; font-weight: 600; }
.heatmap-content { font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
.heatmap-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: var(--radius-sm); background: var(--bg-700); }
.heatmap-tag { font-weight: 600; color: var(--accent); min-width: 80px; }
.heatmap-count { color: var(--text-400); font-size: 11px; }
.heatmap-events { color: var(--text-200); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-800);
  border: 1px solid var(--bg-600);
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
  max-width: 380px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast-dismiss { background: none; border: none; color: var(--text-400); cursor: pointer; font-size: 16px; padding: 0 2px; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Spinner ── */
.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.7);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--bg-700);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(59,130,246,0.5);
  transition: background 0.15s, transform 0.15s;
  line-height: 1;
}
.fab:hover { background: var(--accent-hover); transform: scale(1.08); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--bg-800);
  border: 1px solid var(--bg-700);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-sm { max-width: 380px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--bg-700);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 17px; font-weight: 600; }
.modal-body-text { padding: 20px; color: var(--text-200); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--bg-700);
  flex-shrink: 0;
}
.modal-footer .btn-danger:first-child { margin-right: auto; }

/* ── Form ── */
.modal-form { padding: 16px 20px; flex: 1; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group-full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-400); text-transform: uppercase; letter-spacing: 0.05em; }
.required { color: var(--danger); }
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-700);
  border: 1px solid var(--bg-600);
  color: var(--text-100);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
  resize: vertical;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }
.form-group input.invalid { border-color: var(--danger); }

/* ── Popover ── */
.popover {
  position: fixed;
  z-index: 500;
  background: var(--bg-800);
  border: 1px solid var(--bg-700);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 280px;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  pointer-events: all;
}
.popover-image-wrap { width: 100%; height: 100px; overflow: hidden; background: var(--bg-700); }
.popover-image { width: 100%; height: 100%; object-fit: cover; display: block; }
.popover-image[data-hidden="true"] { display: none; }
.popover-body { padding: 10px 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.popover-name { font-size: 14px; font-weight: 700; color: var(--text-100); text-decoration: none; }
.popover-name:hover { color: var(--accent); }
.popover-dates { font-size: 11px; color: var(--text-400); }
.popover-category { display: inline-flex; }
.category-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 600;
  color: #fff;
}
.popover-importance { display: flex; gap: 2px; }
.importance-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-600);
}
.importance-pip.filled { background: var(--warning); }
.popover-desc { font-size: 12px; color: var(--text-200); line-height: 1.5; }
.popover-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--bg-700);
  color: var(--accent);
  border: 1px solid var(--bg-600);
}
.popover-actions { display: flex; gap: 6px; padding-top: 4px; border-top: 1px solid var(--bg-700); margin-top: 2px; }

/* ── Drag & Drop highlight ── */
.drop-highlight {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

/* ── Utility ── */
.hidden { display: none !important; }
.hidden-input { display: none; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .app-header { flex-direction: column; align-items: flex-start; }
  .header-center, .header-right { width: 100%; }
  .filter-bar { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
}
