:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --primary: #3fb950;
  --primary-dark: #2ea043;
  --danger: #f85149;
  --warning: #d29922;
  --unread: #e94560;
  --brand-zeiss: #00a0e3;
  --brand-icu: #ff8c00;
  --brand-seissiger: #9b59b6;
  --brand-other: #8b949e;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

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

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

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────── */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.login-logo p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ── Forms ──────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
select,
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  transition: border-color .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
select option { background: var(--surface2); }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success-msg { color: var(--primary); font-size: 13px; margin-top: 8px; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  line-height: 1;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Header ─────────────────────────────────────── */
#app-view { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  white-space: nowrap;
}

.header-brand .logo-icon { font-size: 20px; }

.header-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: color .15s, background .15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.unread-badge {
  background: var(--unread);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

/* ── Main Layout ─────────────────────────────────── */
.app-main { flex: 1; overflow: hidden; }
.panel { display: flex; height: calc(100vh - 54px); }
.panel.hidden { display: none; }

/* ── Filters Sidebar ─────────────────────────────── */
.filters-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.filters-sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  font-weight: 600;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 12px; color: var(--muted); }

.filter-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
}

.filter-check input { width: auto; cursor: pointer; accent-color: var(--primary); }

.filter-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.filter-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Gallery ─────────────────────────────────────── */
.gallery-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.gallery-count { color: var(--muted); font-size: 13px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.photo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
  position: relative;
}

.photo-card:hover { transform: translateY(-2px); border-color: var(--muted); }
.photo-card.unread { border-color: var(--unread); }

.photo-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}

.photo-thumb-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--border);
}

.photo-meta {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.photo-camera {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.brand-zeiss { background: var(--brand-zeiss); }
.brand-icu { background: var(--brand-icu); }
.brand-seissiger { background: var(--brand-seissiger); }
.brand-other, .brand-null { background: var(--brand-other); }

.photo-time { font-size: 11px; color: var(--muted); }

.unread-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  background: var(--unread);
  border-radius: 50%;
  border: 2px solid var(--surface);
}

.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 20px;
  color: var(--muted);
  font-size: 15px;
}

.gallery-empty .empty-icon { font-size: 48px; }

/* ── Pagination ──────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}

.page-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s;
}

.page-btn:hover:not(:disabled) { background: var(--border); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn.active { background: var(--primary); color: #000; border-color: var(--primary); font-weight: 600; }
.page-info { color: var(--muted); font-size: 13px; }

/* ── Lightbox ────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-inner {
  display: flex;
  gap: 0;
  max-width: 1100px;
  width: 100%;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 48px rgba(0,0,0,.8);
}

.lightbox-img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-height: 400px;
  position: relative;
}

.lightbox-img-wrap img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,.1);
  border: none;
  color: #fff;
  font-size: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.lightbox-nav:hover { background: rgba(255,255,255,.2); }
.lightbox-nav:disabled { opacity: .2; cursor: not-allowed; }
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }

.lightbox-info {
  width: 260px;
  flex-shrink: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.lightbox-info h3 { font-size: 15px; }
.lightbox-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  align-self: flex-end;
  line-height: 1;
  padding: 2px;
}

.lightbox-close:hover { color: var(--text); }

.info-row { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.info-value { font-size: 13px; word-break: break-word; }

/* ── Cameras Panel ───────────────────────────────── */
.cameras-panel {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-header h2 { font-size: 18px; }

.cameras-table {
  width: 100%;
  border-collapse: collapse;
}

.cameras-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.cameras-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.cameras-table tr:hover td { background: var(--surface2); }

.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.brand-pill.brand-zeiss { background: rgba(0,160,227,.15); color: var(--brand-zeiss); }
.brand-pill.brand-icu { background: rgba(255,140,0,.15); color: var(--brand-icu); }
.brand-pill.brand-seissiger { background: rgba(155,89,182,.15); color: var(--brand-seissiger); }
.brand-pill.brand-other { background: var(--surface2); color: var(--muted); }

.table-actions { display: flex; gap: 6px; }

/* ── Settings Panel ──────────────────────────────── */
.settings-panel {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  max-width: 600px;
}

.settings-panel h2 { font-size: 18px; margin-bottom: 24px; }
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }

/* ── Modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Notification Toast ──────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 2000;
  max-width: 320px;
  animation: slideIn .2s ease;
}

.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Photo card select checkbox ─────────────────── */
.photo-select-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.75);
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #000;
  z-index: 3;
  pointer-events: none;
}

.photo-select-check.checked {
  background: var(--primary);
  border-color: var(--primary);
}

.photo-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

/* ── Admin badge ─────────────────────────────────── */
.admin-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--warning);
  background: rgba(210,153,34,0.15);
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: 600;
}

/* ── Photo card delete button ────────────────────── */
.photo-delete-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(248, 81, 73, 0.85);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
  padding: 0;
  line-height: 1;
}

.photo-card:hover .photo-delete-btn { opacity: 1; }
.photo-delete-btn:hover { background: var(--danger); }

/* ── Photo card description ──────────────────────── */
.photo-location {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Date Picker ─────────────────────────────────── */
.date-picker { position: relative; }

.dp-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s;
}

.dp-trigger:hover, .dp-trigger.open { border-color: var(--primary); }
.dp-arrow { color: var(--muted); font-size: 10px; margin-left: 4px; }

.dp-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  width: 230px;
  padding: 10px;
}

.dp-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dp-nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius);
  line-height: 1;
}

.dp-nav-btn:hover { background: var(--surface2); color: var(--text); }
.dp-month-label { font-size: 13px; font-weight: 600; }

.dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}

.dp-weekdays span {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 0;
  text-transform: uppercase;
}

.dp-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }

.dp-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text);
  transition: background .1s;
}

.dp-day:hover { background: var(--surface2); }
.dp-day.other-month { color: var(--border); }
.dp-day.today { color: var(--primary); font-weight: 700; }
.dp-day.selected { background: var(--primary); color: #000; font-weight: 700; }
.dp-day.selected:hover { background: var(--primary-dark); }

.dp-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.dp-clear-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}

.dp-clear-btn:hover { color: var(--danger); }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
  .filters-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); flex-direction: row; flex-wrap: wrap; max-height: 200px; overflow-y: auto; }
  .panel { flex-direction: column; height: auto; min-height: calc(100vh - 54px); }
  .gallery-content { padding: 12px; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .lightbox-inner { flex-direction: column; max-height: 95vh; }
  .lightbox-info { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .app-header { padding: 0 12px; gap: 8px; }
  .header-brand span:last-child { display: none; }
}
