/* ===== CSS Variables — Light Theme ===== */
:root {
  --primary:          #2e7d32;
  --primary-light:    #4caf50;
  --primary-dark:     #1b5e20;
  --primary-text:     #ffffff;
  --surface:          #ffffff;
  --surface-variant:  #f5f5f5;
  --on-surface:       #212121;
  --on-surface-dim:   #757575;
  --sidebar-bg:       #f1f8e9;
  --sidebar-border:   #c8e6c9;
  --border:           #e0e0e0;
  --hover:            rgba(46,125,50,0.08);
  --active:           rgba(46,125,50,0.16);
  --shadow:           0 2px 8px rgba(0,0,0,.12);
  --radius:           6px;
  --sidebar-w:        240px;
  --topbar-h:         52px;
}

[data-theme="dark"] {
  --primary:          #66bb6a;
  --primary-light:    #81c784;
  --primary-dark:     #43a047;
  --primary-text:     #000000;
  --surface:          #121212;
  --surface-variant:  #1e1e1e;
  --on-surface:       #e8e8e8;
  --on-surface-dim:   #9e9e9e;
  --sidebar-bg:       #1a2819;
  --sidebar-border:   #2e4d2e;
  --border:           #333333;
  --hover:            rgba(102,187,106,0.1);
  --active:           rgba(102,187,106,0.2);
  --shadow:           0 2px 8px rgba(0,0,0,.4);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; }
body { background: var(--surface); color: var(--on-surface); overflow: hidden; }

a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }

/* ===== App Layout ===== */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Topbar ── */
#topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--primary);
  color: var(--primary-text);
  gap: 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 200;
}
#topbar h1 { font-size: 18px; font-weight: 600; letter-spacing: .3px; flex: 1; }
.topbar-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--primary-text);
  transition: background .15s;
}
.topbar-btn:hover { background: rgba(255,255,255,.18); }
.topbar-btn i { font-size: 18px; }

/* ── Body Row ── */
#body-row { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  overflow: hidden;
}
#album-tree { flex: 1; overflow-y: auto; padding: 8px 0; }
.album-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--on-surface-dim);
  cursor: pointer;
  user-select: none;
}
.album-group-header i.chevron { margin-left: auto; font-size: 12px; transition: transform .2s; }
.album-group-header.collapsed i.chevron { transform: rotate(-90deg); }
.album-group-content { overflow: hidden; transition: max-height .2s ease; }
.album-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 28px;
  border-radius: 0 20px 20px 0;
  margin-right: 8px;
  cursor: pointer;
  color: var(--on-surface);
  font-size: 13px;
  transition: background .15s;
  user-select: none;
}
.album-item > button { flex-shrink: 0; }
.album-item:hover { background: var(--hover); }
.album-item.active { background: var(--active); color: var(--primary); font-weight: 500; }
.album-item i { font-size: 15px; color: var(--on-surface-dim); flex-shrink: 0; }
.album-item.active i { color: var(--primary); }
.album-item .album-name {
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  min-width: 0;
}
.album-item .album-count {
  margin-left: auto; font-size: 11px;
  background: var(--border);
  padding: 1px 5px; border-radius: 10px;
  color: var(--on-surface-dim);
  flex-shrink: 0;
}
.album-item-root {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--on-surface);
  font-size: 13px;
  transition: background .15s;
  user-select: none;
}
.album-item-root:hover { background: var(--hover); }
.album-item-root.active { background: var(--active); color: var(--primary); font-weight: 500; }
.album-divider { height: 1px; background: var(--sidebar-border); margin: 6px 0; }
#new-album-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px 7px 28px;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  transition: background .15s;
}
#new-album-btn:hover { background: var(--hover); }

/* Preview progress bar */
#preview-progress {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--on-surface-dim);
  border-top: 1px solid var(--sidebar-border);
  display: none;
}
#preview-progress .prog-bar {
  height: 4px; background: var(--border); border-radius: 2px; margin-top: 4px; overflow: hidden;
}
#preview-progress .prog-fill {
  height: 100%; background: var(--primary); border-radius: 2px;
  animation: prog-pulse 1.4s ease-in-out infinite;
}
@keyframes prog-pulse { 0%,100%{opacity:.6} 50%{opacity:1} }

/* ── Main Content ── */
#main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Album Header ── */
#album-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#album-title { font-size: 18px; font-weight: 600; flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn-primary {
  display: flex; align-items: center; gap: 6px;
  background: var(--primary); color: var(--primary-text);
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-variant); color: var(--on-surface);
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary.active { background: var(--active); color: var(--primary); }
.btn-secondary.active:hover { background: var(--active); }

/* ── Scrollable Grid Area ── */
#grid-area { flex: 1; display: flex; overflow: hidden; }
#grid-scroll { flex: 1; overflow-y: auto; position: relative; }

/* ── Date-nav sidebar ── */
#date-nav {
  display: none;
  flex-direction: column;
  width: 84px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 8px 2px;
  border-left: 1px solid var(--border);
  font-size: 12px;
}
#date-nav .date-nav-year {
  text-align: center;
  font-weight: 600;
  padding: 5px 2px 4px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: var(--on-surface);
  white-space: nowrap;
}
#date-nav .date-nav-month {
  text-align: center;
  padding: 3px 2px;
  cursor: pointer;
  color: var(--on-surface-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: var(--radius);
}
#date-nav .date-nav-year:hover,
#date-nav .date-nav-month:hover { color: var(--primary); background: var(--hover); }

/* ── Error Logs (admin) ── */
#error-logs-view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 24px;
  gap: 10px;
}
#error-logs-toolbar { max-width: 220px; margin-bottom: 0; }
#error-logs-scroll { flex: 1; overflow-y: auto; }
.error-logs-table { table-layout: fixed; width: 100%; }
.error-logs-table th.col-type    { width: 90px; }
.error-logs-table th.col-message { width: auto; }
.error-logs-table th.col-details { width: 260px; }
.error-logs-table th.col-when    { width: 160px; }
.error-logs-table td { overflow: hidden; }
.error-logs-table .cell-ellipsis {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#error-logs-pagination {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 13px; padding-top: 4px;
}

/* ── Virtual Grid ── */
#virtual-container { position: relative; width: 100%; }
.grid-row {
  position: absolute; left: 0; right: 0;
  display: flex; gap: 3px;
  padding: 0 3px;
}
.photo-card {
  position: relative; overflow: hidden;
  background: var(--surface-variant);
  cursor: pointer;
  flex-shrink: 0;
}
.photo-card img {
  display: block; width: 100%; height: 100%;
  object-fit: cover;
  transition: opacity .2s;
}
.photo-card img.loading { opacity: 0; }
.photo-card:hover .photo-overlay { opacity: 1; }
.photo-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s;
  gap: 8px;
}
.photo-overlay button {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.photo-overlay button:hover { background: rgba(255,255,255,.35); }
.photo-card .trash-badge {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: rgba(244,67,54,.85);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: #fff;
}
.photo-card .photo-select-wrap {
  position: absolute; top: 4px; left: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.photo-card:hover .photo-select-wrap,
.photo-card .photo-select-wrap:has(.photo-select:checked) {
  opacity: .8;
  pointer-events: auto;
}
.photo-card .photo-select {
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* ── Selection toolbar ── */
#selection-count {
  display: flex; align-items: center;
  font-size: 13px; color: var(--on-surface-dim);
  padding: 0 4px;
}

/* ── Empty State ── */
#empty-state {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 12px; color: var(--on-surface-dim);
}
#empty-state i { font-size: 64px; }
#empty-state p { font-size: 16px; }

/* ── Lightbox Viewer ── */
#viewer {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
}
#viewer.open { display: flex; }
#viewer-bg { position: absolute; inset: 0; background: rgba(0,0,0,.92); }
#viewer-wrap {
  position: relative; z-index: 1;
  max-width: 100vw; max-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
}
#viewer-img {
  max-width: 100vw; max-height: calc(100vh - 56px);
  object-fit: contain;
  display: block;
}
#viewer-controls {
  display: flex; align-items: center; gap: 4px;
  padding: 8px;
  background: rgba(0,0,0,.6);
  border-radius: var(--radius);
  margin-top: 8px;
}
.viewer-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background .15s;
}
.viewer-btn:hover { background: rgba(255,255,255,.15); }
.viewer-btn.danger:hover { background: rgba(244,67,54,.5); }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  z-index: 2;
  transition: background .15s;
}
.viewer-nav:hover { background: rgba(0,0,0,.75); }
#viewer-prev { left: 12px; }
#viewer-next { right: 12px; }

/* ── Modals ── */
/* NOTE: names intentionally avoid Bootstrap's .modal and .modal-backdrop */
.mew-overlay {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,.5);
  display: none; align-items: center; justify-content: center;
}
.mew-overlay.open { display: flex; }
.mew-dialog {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  min-width: 320px; max-width: 480px; width: 100%;
  position: relative;
}
.mew-dialog h3 { font-size: 16px; margin-bottom: 16px; }
.mew-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--on-surface-dim); margin-bottom: 4px; }
.form-group input, .form-group select {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-variant);
  color: var(--on-surface);
  font-size: 14px;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary);
}

/* ── Details Panel ── */
#details-panel {
  position: fixed; top: var(--topbar-h); right: 0;
  width: 280px; height: calc(100vh - var(--topbar-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 1100;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .25s ease;
}
#details-panel.open { transform: translateX(0); }
#details-panel .details-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.detail-row { padding: 8px 16px; font-size: 13px; }
.detail-row label { display: block; font-size: 11px; color: var(--on-surface-dim); margin-bottom: 2px; }
.detail-row span { word-break: break-all; }

/* ── Toast ── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 16px;
  background: var(--on-surface);
  color: var(--surface);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #c62828; }

/* ── Upload Drop Overlay ── */
#drop-overlay {
  position: fixed; inset: 0; z-index: 800;
  background: rgba(46,125,50,.18);
  border: 3px dashed var(--primary);
  display: none; align-items: center; justify-content: center;
  pointer-events: none;
}
#drop-overlay.active { display: flex; }
#drop-overlay span { font-size: 24px; color: var(--primary); font-weight: 600; }

/* ── Scrollbar Styling ── */
::-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(--on-surface-dim); }

/* ── Migration banner (album header) ── */
#migration-banner {
  display: none; align-items: center; gap: 10px;
  padding: 8px 16px; font-size: 12px; color: var(--on-surface-dim);
  border-bottom: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
}
#migration-banner .prog-bar { flex: 1; max-width: 240px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
#migration-banner .prog-fill { height: 100%; background: var(--primary); border-radius: 2px; transition: width .3s; }

.spin { display: inline-block; animation: spin-rotate 1.2s linear infinite; }
@keyframes spin-rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.alert-info {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 10px;
  background: var(--hover); color: var(--on-surface);
  border-radius: var(--radius); font-size: 12px;
}

/* ── Storage admin table ── */
.storage-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.storage-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .3px;
  color: var(--on-surface-dim); padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.storage-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.storage-table tr:hover td { background: var(--hover); }
.storage-table .icon-btn {
  background: none; border: none; cursor: pointer; color: var(--on-surface-dim);
  padding: 4px; border-radius: var(--radius); font-size: 14px;
}
.storage-table .icon-btn:hover { background: var(--hover); color: var(--primary); }
.storage-table .icon-btn:disabled { opacity: .3; cursor: default; }
.storage-table .icon-btn:disabled:hover { background: none; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
}
.badge-default { background: var(--active); color: var(--primary-dark); }
[data-theme="dark"] .badge-default { color: var(--primary-light); }
.badge-builtin { background: var(--border); color: var(--on-surface-dim); }

/* ── Responsive ── */
@media (max-width: 640px) {
  :root { --sidebar-w: 200px; }
}
