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

:root {
  --bg-base:     #f6f8fb;
  --bg-surface:  #ffffff;
  --bg-subtle:   #f1f5f9;
  --bg-elevated: #ffffff;
  --accent:      #2563eb;
  --accent-hover:#1d4ed8;
  --accent-soft: #eff6ff;
  --accent-teal: #0891b2;
  --text-primary:#0f172a;
  --text-muted:  #64748b;
  --danger:      #dc2626;
  --success:     #16a34a;
  --border:      #e2e8f0;
  --header-h:    56px;
  --sidebar-w:   300px;
  --rail-w:      44px;
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --shadow-sm:   0 1px 2px rgba(15,23,42,0.06);
  --shadow-card: 0 4px 12px rgba(15,23,42,0.10);
  --shadow-pop:  0 8px 30px rgba(15,23,42,0.12);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Logo ────────────────────────────────────────────────────────────────── */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
}
.logo-icon { height: 30px; width: auto; flex-shrink: 0; object-fit: contain; }
.logo-text  { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.logo-octo  { color: var(--accent); }

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 100;
}
.header-spacer { flex: 1; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  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: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-subtle); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-icon     { padding: 8px; background: transparent; border: none; color: var(--text-muted); }
.btn-icon:hover { color: var(--text-primary); background: var(--bg-elevated); border-radius: var(--radius-sm); }
.btn-full     { width: 100%; justify-content: center; }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 10px 12px;
  transition: border-color 0.15s;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-teal   { background: rgba(6,182,212,0.15);  color: var(--accent-teal); }

/* ── Form group ──────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.form-error { color: var(--danger); font-size: 0.8rem; padding: 8px 12px; background: rgba(239,68,68,0.1); border-radius: var(--radius-sm); border: 1px solid rgba(239,68,68,0.2); }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow-card); }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Divider ────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* ─────────────────────────────────────────────────────────────────────────── */
/* LOGIN PAGE                                                                  */
/* ─────────────────────────────────────────────────────────────────────────── */
.login-body {
  overflow: auto;
  justify-content: center;
  align-items: center;
  background: radial-gradient(ellipse at 50% -10%, #eaf1fc 0%, var(--bg-base) 60%);
}
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 400px;
  padding: 24px;
}
.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow-pop);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.login-tagline { font-size: 0.8rem; color: var(--text-muted); }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-footer { font-size: 0.72rem; color: var(--text-muted); text-align: center; }

/* ─────────────────────────────────────────────────────────────────────────── */
/* GALLERY PAGE                                                                */
/* ─────────────────────────────────────────────────────────────────────────── */
.gallery-body { overflow: auto; }
.gallery-main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
}
.gallery-header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.gallery-count { font-size: 0.8rem; color: var(--text-muted); }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.slide-card-thumb {
  aspect-ratio: 4/3;
  background: var(--bg-elevated);
  overflow: hidden;
  position: relative;
}
.slide-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.slide-card-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 2rem;
}
.slide-card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.slide-card-name { font-size: 0.875rem; font-weight: 500; }
.slide-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.slide-card-dims { font-size: 0.72rem; color: var(--text-muted); }
.slide-card-annots { font-size: 0.75rem; color: var(--text-muted); }

/* Delete button on slide cards (reveal on hover) */
.slide-card-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--danger);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, border-color 0.12s;
  z-index: 2;
}
.card:hover .slide-card-del { opacity: 1; }
.slide-card-del:hover { background: #fff; border-color: var(--danger); }
.slide-card-del .lucide { width: 16px; height: 16px; }

/* Upload zone */
.upload-zone {
  margin-top: 32px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 36px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(59,130,246,0.05);
  color: var(--text-primary);
}
.upload-zone-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-zone p { font-size: 0.875rem; }
.upload-zone small { font-size: 0.75rem; }
.upload-progress { margin-top: 16px; }
progress { width: 100%; height: 6px; border-radius: 3px; }

/* ─────────────────────────────────────────────────────────────────────────── */
/* VIEWER PAGE                                                                 */
/* ─────────────────────────────────────────────────────────────────────────── */
.viewer-body { overflow: hidden; }
.viewer-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.viewer-sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-section { padding: 14px 14px 10px; }
.sidebar-section-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.tool-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tool-btn {
  aspect-ratio: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  font-family: inherit;
}
.tool-btn:hover { background: var(--bg-base); color: var(--text-primary); }
.tool-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.class-select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 8px 10px;
  outline: none;
  cursor: pointer;
}
.class-select:focus { border-color: var(--accent); }
.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* Annotation list */
.ann-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.ann-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.ann-item:hover { background: var(--bg-elevated); }
.ann-item-icon { font-size: 0.9rem; flex-shrink: 0; }
.ann-item-info { flex: 1; min-width: 0; }
.ann-item-name { font-size: 0.8rem; font-weight: 500; }
.ann-item-class { font-size: 0.72rem; color: var(--text-muted); }
.ann-item-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}
.ann-item:hover .ann-item-del { opacity: 1; }
.ann-item-del:hover { color: var(--danger); }

/* Viewer area */
.viewer-main { flex: 1; overflow: hidden; position: relative; background: var(--bg-subtle); }
#viewer { width: 100%; height: 100%; }

/* Status bar */
.viewer-statusbar {
  height: 28px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 20px;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.statusbar-item strong { color: var(--text-primary); font-weight: 500; }

/* Sidebar footer */
.sidebar-footer { padding: 12px 14px; border-top: 1px solid var(--border); }

/* Toast */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  z-index: 9999;
  box-shadow: var(--shadow-card);
  transition: opacity 0.3s;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

/* ── Back link ──────────────────────────────────────────────────────────── */
.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text-primary); }

/* ── Dropdown ───────────────────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  min-width: 180px;
  z-index: 200;
  overflow: hidden;
}
.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s;
}
.dropdown-item:hover { background: var(--bg-elevated); }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Search input in header ─────────────────────────────────────────────── */
.search-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 7px 12px;
  outline: none;
  width: 220px;
  transition: border-color 0.15s, width 0.2s;
}
.search-input:focus { border-color: var(--accent); width: 280px; }
.search-input::placeholder { color: var(--text-muted); }

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state-icon { font-size: 3rem; }
.empty-state h3 { font-size: 1rem; color: var(--text-primary); }
.empty-state p { font-size: 0.875rem; }

/* ── Annotation popup editor ────────────────────────────────────────────── */
.ann-popup {
  position: absolute;
  z-index: 30;
  width: 220px;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ann-popup.hidden { display: none; }

.ann-popup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.ann-popup-row input[type="text"],
.ann-popup-row select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
}
.ann-popup-row input[type="color"] {
  width: 40px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  cursor: pointer;
}
.ann-popup-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.ann-popup-actions .btn { flex: 1; }

/* ── Lucide icons ───────────────────────────────────────────────────────── */
.lucide { width: 20px; height: 20px; flex-shrink: 0; display: block; }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }

/* ── Gallery search wrap ────────────────────────────────────────────────── */
.search-wrap { position: relative; display: inline-flex; align-items: center; }
.search-wrap .search-icon { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.search-wrap .search-icon .lucide { width: 16px; height: 16px; }
.search-wrap .search-input { padding-left: 32px; }
.btn .lucide { width: 16px; height: 16px; }
.upload-zone-icon .lucide { width: 40px; height: 40px; }
.empty-state-icon .lucide { width: 48px; height: 48px; }

/* ── Viewer: collapsible panel ──────────────────────────────────────────── */
.viewer-sidebar {
  width: var(--sidebar-w);
  transition: width 0.2s ease;
  position: relative;
  overflow: hidden;
}
.viewer-sidebar.collapsed { width: 0; border-right: none; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 8px 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}
/* Floating expand button shown over the canvas when the panel is collapsed */
.panel-expand {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 24;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  color: var(--text-muted);
  cursor: pointer;
}
.panel-expand:hover { color: var(--accent); background: var(--bg-subtle); }
.panel-expand .lucide { width: 18px; height: 18px; }

/* ── Viewer: floating top-center toolbar ────────────────────────────────── */
.viewer-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
}
.viewer-toolbar .tool-btn {
  width: 36px;
  height: 36px;
  aspect-ratio: auto;
  border: none;
  background: none;
  border-radius: 999px;
  color: var(--text-muted);
}
.viewer-toolbar .tool-btn:hover { background: var(--bg-subtle); color: var(--text-primary); }
.viewer-toolbar .tool-btn.active { background: var(--accent-soft); color: var(--accent); }
.toolbar-divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

.ann-item-icon .lucide { width: 16px; height: 16px; }
.ann-item-del .lucide { width: 14px; height: 14px; }
.back-link .lucide { width: 16px; height: 16px; }
