:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f2430;
  --panel-3: #242b39;
  --border: #2a3040;
  --text: #e8edf7;
  --muted: #9ca6ba;
  --accent: #5b8cff;
  --accent-2: #7aa2ff;
  --danger: #ff6b6b;
  --ok: #34d399;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.45;
  background: var(--bg);
  transition: border-color .12s ease, box-shadow .12s ease, filter .12s ease, background .12s ease;
  color: var(--text);
}

/* Generic cards for auth/dialogs */
.login-card { width: 420px; max-width: 92vw; border:1px solid var(--border); background: var(--panel); border-radius:12px; padding:16px; }
.login-card.small { width: 360px; }

.btn.danger { background: linear-gradient(135deg, #ff6b6b, #e85a5a); color: #fff; border-color: transparent; }
.btn:disabled, .btn[disabled] { opacity: .6; cursor: not-allowed; filter: none; }
/* Form structure helpers */
.form-row { display:flex; flex-direction:column; gap:6px; margin-bottom:10px; }
.form-row label { color: var(--muted); font-size:0.9rem; }
.form-row input, .form-row select { background: var(--panel-2); border:1px solid var(--border); color: var(--text); border-radius:10px; padding:10px 12px; }

/* Toolbar helper */
.toolbar { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }

/* Focus and accessibility */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display:flex; justify-content:space-between; align-items:center; gap:8px; }

/* Alerts */
.err { color:#ffe4e4; background: rgba(255,107,107,0.08); border:1px solid rgba(255,107,107,0.4); padding:8px 10px; border-radius:10px; margin-bottom:10px; }
.ok  { color:#d1fae5; background: rgba(52,211,153,0.08); border:1px solid rgba(52,211,153,0.35); padding:8px 10px; border-radius:10px; margin-bottom:10px; }

/* Drawer backdrop (ensure hidden by default on all viewports) */
.drawer-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 9999; }
body.drawer-open .drawer-backdrop { display: block; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr 360px;
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 20001; /* Keep sidebar above any transient overlays */
  /* Stick sidebar on desktop and allow its own scroll */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  overflow-y: auto;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.logo-dot { display: none; }
.logo-icon {
  width: 22px;
  height: 22px;
  display: block;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 0 14px rgba(91, 140, 255, 0.25);
}
.logo-title { font-weight: 700; }
.logo-sub { font-size: 0.75rem; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.nav-item:hover {
  border-color: var(--border);
  background: rgba(255,255,255,0.02);
}
.nav-item.active {
  border-color: rgba(91,140,255,0.45);
  background: rgba(91,140,255,0.12);
  box-shadow: inset 2px 0 0 var(--accent);
}
.mapper-nav-menu {
  margin: 0;
  padding: 0;
  border: 0;
}
.sidebar .mapper-tree {
  margin-top: 0;
  background: transparent;
  border: none !important;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  padding: 2px 6px 4px 8px;
}
.sidebar .mapper-tree-link {
  font-size: 0.88rem;
  padding: 2px 4px;
  border: none;
  background: transparent;
  border-radius: 0;
  color: var(--muted);
}
.sidebar .mapper-tree-item {
  padding: 1px 0;
}
.sidebar .mapper-tree-caret {
  width: 28px;
  height: 26px;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.sidebar .mapper-tree-caret:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}
.sidebar .mapper-tree-caret:disabled {
  cursor: default;
  background: transparent;
}
.sidebar .mapper-tree-link:hover {
  border: none;
  background: transparent;
  color: var(--text);
  text-decoration: underline;
}
.sidebar .mapper-tree-link.active {
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 600;
}
.sidebar-card {
  margin-top: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 12px;
}
.sidebar-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.sidebar-card p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}
.sidebar-card .hint { color: #c9d4ea; }
.sidebar-footer {
  margin-top: auto;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.mini-link {
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}
.mini-link:hover { color: var(--text); }

/* Small form bits */
.mini-label { color: var(--muted); font-size: 0.82rem; }
.ai-toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.ai-toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.ai-toggle-slider {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  position: relative;
  transition: background .15s ease, border-color .15s ease;
}
.ai-toggle-slider::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .15s ease;
}
.ai-toggle-input:checked + .ai-toggle-slider {
  background: rgba(91,140,255,0.28);
  border-color: var(--accent);
}
.ai-toggle-input:checked + .ai-toggle-slider::after {
  transform: translateX(20px);
}
.ai-toggle-input:focus-visible + .ai-toggle-slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.input-number {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
}
.input-number.small { width: 70px; }

/* Main */
.main {
  padding: 16px;
}
.topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 8px 10px;
}
.topbar .btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91,140,255,0.12); }
.menu-btn { display: none; }
.search-shell {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 0 1 360px;
  min-width: 42px;
  max-width: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 0;
  justify-content: center;
  overflow: hidden;
  transition: max-width .24s ease, padding .24s ease, border-color .2s ease, box-shadow .2s ease;
}
.search-shell.expanded {
  max-width: 360px;
  padding: 0 8px 0 4px;
  justify-content: flex-start;
}
.search-shell:focus-within,
.search-shell.expanded {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91,140,255,0.12);
}
.mapper-header-actions {
  display: none;
  position: relative;
  align-items: center;
  gap: 8px;
}
.mapper-header-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--panel);
  transition: max-height .24s ease, opacity .2s ease, transform .24s ease, border-color .2s ease;
  z-index: 20;
}
.mapper-header-menu.open {
  max-height: 180px;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  border-color: var(--border);
}
.mapper-header-menu-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.95rem;
}
.mapper-header-menu-item:hover {
  background: rgba(255,255,255,0.04);
}
.mapper-header-menu-item:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.mapper-search-shell {
  flex: 0 1 360px;
  gap: 0;
  max-width: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 0;
  justify-content: center;
  transition: max-width .24s ease, padding .24s ease, border-color .2s ease, box-shadow .2s ease;
}
.mapper-search-shell.expanded {
  max-width: 360px;
  padding: 0 8px 0 4px;
  justify-content: flex-start;
}
.mapper-search-shell:focus-within,
.mapper-search-shell.expanded {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91,140,255,0.12);
}
.mapper-search-shell .search-toggle-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: none;
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}
.mapper-search-shell .search-toggle-btn:hover {
  filter: none;
  background: transparent;
}
.mapper-search-shell .search-wrap {
  opacity: 0;
  transform: translateX(-4px);
}
.mapper-search-shell.expanded .search-wrap {
  opacity: 1;
  transform: translateX(0);
}
.mapper-search-shell .search-wrap input {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 10px 6px 10px 2px;
}
.mapper-search-shell .search-wrap input:focus {
  border: none;
  outline: none;
}
.search-toggle-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: none;
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  box-shadow: none;
}
.search-toggle-btn:hover {
  filter: none;
  background: transparent;
}
.search-wrap {
  flex: 1;
  min-width: 0;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity .2s ease, transform .2s ease;
}
.search-shell.expanded .search-wrap {
  opacity: 1;
  transform: translateX(0);
}
.search-shell:not(.expanded) .search-wrap input {
  pointer-events: none;
}
.search-wrap input, .select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
.search-wrap input::placeholder { color: #a7b1c6; }
.input-number::placeholder { color: #a7b1c6; }
.search-shell .search-wrap input {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 10px 6px 10px 2px;
}
.search-shell .search-wrap input:focus {
  border: none;
  outline: none;
}
.select {
  width: 170px;
  height: 34px;
  padding: 6px 10px;
}
.select:focus {
  border-color: var(--accent);
}
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.btn.small { padding: 6px 10px; font-size: 0.9rem; }
.btn:hover { filter: brightness(1.08); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
.btn.ghost {
  background: var(--panel-2);
}
.btn.full { width: 100%; text-align: center; }

.content-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.content-header h1 {
  margin: 0;
  font-size: 1.35rem;
}
.content-header p {
  margin: 6px 0 0;
  color: var(--muted);
}
.stats {
  display: flex;
  gap: 8px;
}
.stat-card {
  min-width: 92px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 10px;
}
.stat-label {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
}
.stat-value {
  display: block;
  font-size: 1rem;
  margin-top: 4px;
  font-weight: 700;
}

.status {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--muted);
}
.status.ok { border-color: rgba(52, 211, 153, 0.45); color: #d1fae5; }
.status.err { border-color: rgba(255, 107, 107, 0.45); color: #ffe4e4; }
.hidden { display: none !important; }

.mapper-tools {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 12px;
}
.mapper-tools-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.mapper-input {
  min-width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.mapper-input::placeholder { color: #a7b1c6; }
.mapper-input:focus { border-color: var(--accent); }
.mapper-tools-row #mapperCurrentPath {
  min-width: 220px;
}
.mapper-tools-row #mapperUpBtn {
  padding: 8px 12px;
}
.mapper-tree {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.01);
  border-radius: 10px;
  padding: 8px;
}
.mapper-tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.mapper-tree-caret,
.mapper-tree-link {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}
.mapper-tree-caret {
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--muted);
}
.mapper-tree-link {
  flex: 1;
  text-align: left;
  padding: 5px 8px;
}
.mapper-tree-link:hover,
.mapper-tree-caret:hover {
  border-color: var(--border);
  background: rgba(255,255,255,0.03);
}
.mapper-tree-link.active {
  border-color: rgba(91,140,255,0.45);
  background: rgba(91,140,255,0.12);
}
.btn.loading {
  position: relative;
  pointer-events: none;
}
.btn.loading::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: btn-spin .75s linear infinite;
  vertical-align: -1px;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}
.mapper-dropzone {
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,0.01);
}
.mapper-dropzone.dragover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(91,140,255,0.09);
}

.empty {
  margin-top: 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,0.01);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.places-map-popup {
  color: var(--text);
}
.places-map-popup .thumb {
  width: 180px; height: 120px; object-fit: cover; display: block; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 6px;
}
.places-map-popup .meta { font-size: 0.8rem; color: var(--muted); }

/* Map HTML markers */
.photo-marker,
.cluster-marker {
  width: 36px; height: 36px;
  background: #1b2535;
  background-size: cover; background-position: center; background-repeat: no-repeat;
  border: 2px solid rgba(11,16,32,0.9);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 2px rgba(91,140,255,0.3) inset;
}
.photo-marker { border-radius: 8px; }
.cluster-marker { position: relative; border-radius: 12px; }
.cluster-badge {
  position: absolute; right: -6px; top: -6px;
  background: linear-gradient(135deg, #4f6bdc, #2c8cff);
  color: #fff; font-size: 11px; line-height: 1; font-weight: 700;
  border: 2px solid #0b1020; border-radius: 999px; padding: 4px 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

/* Bottom sheet for cluster contents */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9998; background: var(--panel); border:1px solid var(--border); box-shadow: 0 -10px 22px rgba(0,0,0,0.35); border-top-left-radius:12px; border-top-right-radius:12px; border-bottom-left-radius:0; border-bottom-right-radius:0; }
.sheet.hidden { display:none; }
.sheet-bar { width:36px; height:4px; background:#5b6a8d; border-radius:999px; margin:6px auto 4px; opacity:0.7; }
.sheet-content { max-height: 22vh; overflow-x: auto; overflow-y: hidden; padding: 8px 12px 10px; }
.sheet-grid { display:flex; gap:10px; align-items:center; }
.sheet-grid img { width:140px; height:105px; object-fit:cover; border-radius:10px; border:1px solid var(--border); cursor:pointer; display:block; flex:0 0 auto; }
.gallery-grid.folders-view {
  grid-template-columns: repeat(auto-fill, 220px);
}
.photo-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.photo-card:hover {
  transform: translateY(-2px);
  border-color: rgba(91, 140, 255, 0.55);
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
}
.photo-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.15);
}
.card-thumb {
  background: #1b1f29;
  aspect-ratio: 1 / 1; /* more square thumbs */
  display: block;
  position: relative;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb.folder-mosaic { position: relative; width: 100%; }
.card-thumb.folder-mosaic::before { content: ""; display: block; padding-top: 100%; }
.folder-mosaic .folder-grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1px;
}
.folder-mosaic img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Make folder cards uniform height regardless of title length */
.folder-card { display: flex; flex-direction: column; }
.folder-card .card-body { min-height: 74px; display: flex; flex-direction: column; justify-content: center; }
.folder-card .card-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-card .card-meta { justify-content: space-between; }
.folder-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.15);
}
.folder-select-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 17, 21, 0.78);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 700;
  pointer-events: none;
}
.card-thumb.placeholder {
  background: linear-gradient(135deg, #33415c, #1f2a3d);
  display: grid;
  place-items: center;
  color: #d7e0f1;
  font-size: 0.8rem;
}
.video-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(15, 17, 21, 0.72);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}
.video-badge-icon {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 9px solid var(--text);
  margin-left: 2px;
}
.card-body { padding: 10px; }
.card-title {
  margin: 0 0 5px;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  font-size: 0.76rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.pills {
  margin-top: 8px;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.pill {
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.68rem;
  color: #dbe4f8;
}
.pill.fav {
  border-color: rgba(255, 221, 89, 0.35);
  background: rgba(255, 221, 89, 0.08);
}

/* Simple toggle control */
.toggle { display:inline-flex; align-items:center; gap:8px; cursor:pointer; user-select:none; }
.toggle .switch { margin-right:2px; }

/* Switch (custom checkbox) */
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 42px;
  height: 24px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  outline: none;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  transition: left 0.2s ease;
}
.switch:checked {
  background: #2ecc71; /* green on */
  border-color: rgba(46, 204, 113, 0.6);
}
.switch:checked::after { left: 21px; }

/* Viewer slide-out info */
.viewer-info { position: absolute; top: 0; width: 360px; max-width: 92vw; background: var(--panel); border-left: 1px solid var(--border); transform: translateX(0); transition: transform .44s cubic-bezier(.22,1,.36,1); box-shadow: -6px 0 18px rgba(0,0,0,0.35); z-index: 1; will-change: transform; pointer-events: none; border-top-left-radius: 0; border-bottom-left-radius: 0; border-top-right-radius: 12px; border-bottom-right-radius: 12px; overflow: hidden; }
.viewer-info.open { transform: translateX(100%); pointer-events: auto; }
.viewer-info.hidden { display: none; }
.viewer-info-inner { padding: 14px; height: 100%; overflow: auto; }
.viewer-info-inner h3 { margin: 0 0 10px; font-size: 1.05rem; }
.vi-actions { margin-top: 12px; display:flex; gap:8px; }

/* Inside the slide-out viewer panel, override sticky/full-height rules
   from .detail-panel so the panel matches the media's height (top/bottom
   are anchored dynamically from JS). */
.viewer-info .detail-panel {
  position: static;
  top: auto;
  height: 100%;
  overflow: auto;
}

/* Make main media sit "over" the sliding panel so it looks like panel glides out from behind */
#viewerImg, #viewerVideo { position: relative; z-index: 2; }

/* Detail panel */
.detail-panel {
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  /* Stick details panel on desktop and allow its own scroll */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  overflow-y: auto;
}
.detail-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}
.detail-content { display: block; }
.detail-thumb-wrap {
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #11151d;
}
.detail-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.detail-header {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.detail-header h3 {
  margin: 0;
  font-size: 1rem;
  flex: 1;
}
.detail-actions { display:flex; gap:8px; align-items:center; margin: 6px 0 8px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: #ffe38a;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
}
.icon-btn.tiny { width: 28px; height: 28px; font-size: 0.9rem; display:inline-flex; align-items:center; justify-content:center; }
.detail-path {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
  word-break: break-word;
}
.detail-list {
  margin-top: 12px;
  display: grid;
  gap: 7px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.84rem;
  position: relative;
  min-height: 40px;
  overflow: visible;
  z-index: 1;
}
.detail-row.popover-open { z-index: 20000; }
.detail-row span { color: var(--muted); }
.detail-row strong {
  text-align: right;
  max-width: unset;
  white-space: nowrap;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail-val { display:flex; align-items:center; gap:8px; justify-content:flex-end; max-width:60%; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.accordion { margin-top: 12px; }
.raw-meta {
  margin-top: 8px;
  border: 1px solid var(--border);
  background: #0d1016;
  color: #dbe4f8;
  border-radius: 10px;
  padding: 10px;
  max-height: 260px;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

/* Colored log lines (UI logs) */
.raw-meta .log-line { display: block; white-space: pre-wrap; }
.raw-meta .log-ok { color: #34d399; }
.raw-meta .log-warn { color: #fbbf24; }
.raw-meta .log-err { color: #f87171; }
.raw-meta .log-info { color: var(--muted); }

/* Inline date editor popover (keeps row size unchanged) */
.date-popover { position: absolute; right: 8px; top: calc(100% + 6px); background: var(--panel); border:1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,0.45); padding:10px; border-radius:10px; z-index: 10000; }
.date-popover.floating { position: fixed; right: auto; top: auto; }

/* GPS centered modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 9999; display:none; align-items:center; justify-content:center; pointer-events: none; }
.modal-backdrop.active { display:flex; pointer-events: auto; }
.gps-modal { position: relative; z-index: 10000; width: min(900px, 92vw); background: var(--panel); border:1px solid var(--border); box-shadow: 0 18px 40px rgba(0,0,0,0.55); border-radius: 12px; padding: 12px; }
.gps-modal.hidden { display:none !important; }
.gps-map { width: 100%; height: 60vh; min-height: 360px; border:1px solid var(--border); border-radius: 8px; margin-bottom: 8px; overflow:hidden; }
.btn.toggled { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91,140,255,0.15); }
.gps-search { position: relative; margin-bottom: 8px; }
.gps-search input { width: 100%; background: var(--panel-2); border:1px solid var(--border); color: var(--text); border-radius: 8px; padding: 10px 12px; }
.gps-results { position: absolute; left:0; right:0; top: 40px; background: var(--panel); border:1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.45); max-height: 220px; overflow:auto; z-index: 5; }
.gps-results.hidden { display:none; }
.gps-result-item { padding: 8px 10px; cursor: pointer; border-bottom:1px solid var(--border); }
.gps-result-item:last-child { border-bottom:none; }
.gps-result-item:hover { background: rgba(255,255,255,0.04); }
.date-popover.hidden { display: none !important; }

/* Duplicate groups */
.dupe-groups { display: grid; gap: 12px; }
.dupe-group {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 10px;
}
.dupe-group h4 { margin: 0 0 8px; font-size: 0.95rem; }
.dupe-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.dupe-thumb { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display:block; }
.dupe-item { text-align: center; }
.dupe-item small { display:block; color: var(--muted); font-size: 0.72rem; margin-top: 4px; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 230px 1fr; }
  .detail-panel { display: none; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  /* Sidebar becomes slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 82vw; max-width: 300px;
    transform: translateX(-102%);
    transition: transform .2s ease, box-shadow .2s ease;
    z-index: 10000;
  }
  body.drawer-open .sidebar { transform: translateX(0); box-shadow: 8px 0 24px rgba(0,0,0,0.45); }
  /* backdrop rules moved to global section above */

  .topbar { flex-wrap: wrap; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; }
  .select { width: 100%; }
  #scanBtn { width: 100%; }
  .content-header { flex-direction: column; }
  #shareGrid.gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

/* Hide non-relevant chrome when viewing Settings */
body.view-settings .topbar,
body.view-settings .content-header,
body.view-settings #statusBar,
body.view-settings #emptyState,
body.view-settings .gallery-grid { display: none !important; }

/* On mobile, keep topbar for burger menu, but hide search/sort controls */
@media (max-width: 760px) {
  .mapper-search-shell { display: none !important; }
  body.view-mapper .topbar { display: flex !important; }
  body.view-mapper .topbar .search-shell,
  body.view-mapper .topbar .search-wrap,
  body.view-mapper .topbar .select { display: none !important; }
  body.view-settings .topbar { display: flex !important; }
  body.view-settings .topbar .search-shell,
  body.view-settings .topbar .search-wrap,
  body.view-settings .topbar .select,
  body.view-settings .topbar #aiToggle { display: none !important; }
}

/* Hide status bar on all non-library views */
body:not(.view-timeline) #statusBar { display: none !important; }

/* Mapper view: hide top-right stats cards for now */
body.view-mapper .content-header .stats { display: none !important; }
body.view-mapper .mapper-header-actions { display: flex; }
@media (min-width: 761px) {
  body.view-mapper .topbar { display: none !important; }
}

/* Timeline view grouping */
.timeline-group { margin-top: 14px; }
.timeline-header {
  position: sticky; top: 0; z-index: 2;
  background: transparent;
  border: none;
  padding: 4px 0;
  margin: 10px 0 6px;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
}
.timeline-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }

/* Upload overlay */
.upload-overlay { position: fixed; inset: 0; display: none; place-items: center; background: rgba(8,10,14,0.84); backdrop-filter: blur(2px); z-index: 10001; pointer-events: none; }
.upload-overlay.active { display: grid; pointer-events: auto; }
.upload-box { width: min(900px, 96vw); border: 3px dashed rgba(91,140,255,0.9); background: rgba(23,26,33,0.96); border-radius: 18px; padding: 28px; box-shadow: 0 18px 46px rgba(0,0,0,0.55); }
.upload-title { font-weight: 900; font-size: clamp(1.9rem, 3.1vw, 2.8rem); text-align: center; margin-bottom: 14px; letter-spacing: 0.4px; }
.upload-progress { height: 10px; background: #131722; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.upload-progress .bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .12s linear; }
.upload-text { text-align: center; color: #d6dff2; margin-top: 10px; font-size: 1.05rem; font-weight: 600; }
.upload-overlay.upload-blocked .upload-box { border-color: rgba(255,107,107,0.85); }
.upload-overlay.upload-blocked .upload-progress .bar { background: linear-gradient(90deg, #ff6b6b, #ff9a9a); }

/* Settings local header (visible only inside settings panel) */
.settings-header { margin: 4px 0 12px; }
.settings-header h1 { margin: 0; font-size: 1.35rem; }
.settings-header p { margin: 6px 0 0; color: var(--muted); }

/* Settings tabs */
.tabs { display:flex; gap:14px; margin: 6px 0 12px; border-bottom:1px solid var(--border); }
.tab-btn { background: transparent; color: var(--muted); border:none; border-bottom:2px solid transparent; border-radius:0; padding:10px 2px; cursor:pointer; font-weight:600; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel.hidden { display: none; }

/* Panels and data tables */
.panel { border:1px solid var(--border); background: var(--panel); border-radius:12px; padding:12px; }
.data-table { border:1px solid var(--border); background: var(--panel); border-radius:12px; overflow:hidden; }
.data-table table { width:100%; border-collapse: collapse; }
.data-table thead th { text-align:left; font-size:0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; padding:10px 12px; background: var(--panel-2); }
.data-table tbody td { padding:12px; border-top:1px solid var(--border); }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.data-table td.muted, .data-table th.muted { color: var(--muted); }

/* Simple table alias (legacy) */
.table { width: 100%; border-collapse: collapse; }
.table thead th { text-align:left; font-size:0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; padding:10px 12px; background: var(--panel-2); }
.table tbody td { padding:12px; border-top:1px solid var(--border); }
.table tbody tr:hover { background: rgba(255,255,255,0.02); }

/* Badges */
.badge { display:inline-block; background: var(--panel-3); color: #dbe4f8; border:1px solid var(--border); border-radius:999px; padding:3px 8px; font-size:0.72rem; font-weight:600; line-height:1; }
.badge.admin { border-color: rgba(91,140,255,0.45); background: rgba(91,140,255,0.14); }
.badge.twofa { border-color: rgba(52, 211, 153, 0.45); background: rgba(52, 211, 153, 0.14); color:#d1fae5; }
.badge.muted { color: var(--muted); }

/* Map attribution text styling: force black text for readability */
#placesMap .maplibregl-ctrl-attribution,
#placesMap .maplibregl-ctrl-attrib,
#placesMap .maplibregl-ctrl-attrib a,
#placesMap .maplibregl-ctrl-attribution a {
  color: #000 !important;
  text-shadow: none !important;
}
