:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e5ea;
  --color-text: #1c1f26;
  --color-text-muted: #6b7280;
  --color-primary: #2f5fd6;
  --color-primary-dark: #23479f;
  --color-danger: #d1453b;
  --radius: 8px;
  --sidebar-width: 220px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-brand {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
  padding: 0 0.5rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav a {
  color: var(--color-text);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  font-weight: 500;
}

.sidebar-nav a:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--color-primary);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-brand {
  font-weight: 700;
}

.topbar-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  font-size: 1rem;
  cursor: pointer;
}

.content {
  padding: 1.5rem 2rem;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn:hover {
  background: var(--color-primary-dark);
  text-decoration: none;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg);
}

.btn-danger {
  background: var(--color-danger);
}

.btn-danger:hover {
  background: #a8352c;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.25rem;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 5;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-item {
  display: block;
  padding: 0.6rem 0.9rem;
  color: var(--color-text);
  font-size: 0.9rem;
  text-decoration: none;
}

.dropdown-item + .dropdown-item {
  border-top: 1px solid var(--color-border);
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--color-bg);
  text-decoration: none;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .stat-label {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0.35rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
}

.empty-state h2 {
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

table.data-table th {
  background: var(--color-bg);
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table th.thumb-col,
table.data-table td.thumb-cell {
  width: 48px;
  padding-right: 0.5rem;
}

table.data-table th.checkbox-col,
table.data-table td.checkbox-cell {
  width: 36px;
  padding-right: 0.25rem;
  /* Drag-select (see static/js/bulk_select.js) fires mouseover as the
     pointer crosses row boundaries mid-drag; without this the browser's
     own text-selection would fight that drag on every row it passes. */
  user-select: none;
}

table.data-table tr.row-selected {
  background: rgba(47, 95, 214, 0.07);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.modal-box h2 {
  margin-top: 0;
}

.list-thumb-link {
  display: block;
  width: 40px;
  height: 40px;
}

.list-thumb {
  display: block;
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.badge-success {
  background: #e6f4ea;
  color: #1e7e34;
  border-color: #c3e6cb;
}

.badge-danger {
  background: #fbe9e7;
  color: var(--color-danger);
  border-color: #f3c6c1;
}

form.styled-form {
  max-width: 560px;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--color-surface);
  color: var(--color-text);
}

.form-control:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.help-text {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.errorlist {
  list-style: none;
  color: var(--color-danger);
  padding: 0;
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

form.form-wide {
  max-width: 720px;
}

.form-section {
  margin-bottom: 2rem;
}

.form-section h2 {
  font-size: 1.05rem;
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.photo-thumb {
  position: relative;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--color-bg);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb .primary-tag {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.photo-remove-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  padding: 0.4rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.detail-gallery {
  margin-bottom: 1.5rem;
}

.detail-hero-image {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  display: block;
  margin-bottom: 0.75rem;
}

.detail-thumb-row {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.detail-thumb-row img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

.detail-hero-btn,
.detail-thumb-btn {
  display: block;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.detail-hero-btn {
  width: 100%;
}

.detail-thumb-row .detail-thumb-btn {
  flex-shrink: 0;
}

.detail-hero-btn img,
.detail-thumb-btn img {
  transition: opacity 0.15s ease;
}

.detail-hero-btn:hover img,
.detail-thumb-btn:hover img {
  opacity: 0.85;
}

.detail-hero-btn:focus-visible,
.detail-thumb-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.lightbox-overlay.open {
  display: flex;
}

.lightbox-image {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius);
  display: block;
  cursor: zoom-in;
  transition: transform 0.05s linear;
}

.lightbox-image.zoomed {
  cursor: zoom-out;
  transform: scale(2.5);
}

.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
  opacity: 0.75;
}

.lightbox-nav,
.lightbox-zoom-toggle {
  position: fixed;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-nav:hover,
.lightbox-nav:focus-visible,
.lightbox-zoom-toggle:hover,
.lightbox-zoom-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-close:focus-visible,
.lightbox-nav:focus-visible,
.lightbox-zoom-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.lightbox-prev {
  left: 1rem;
}

.lightbox-next {
  right: 1rem;
}

.lightbox-zoom-toggle {
  top: 1rem;
  left: 1.25rem;
  font-size: 1.5rem;
}

.lightbox-position {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 0.9rem;
}

body.lightbox-open {
  overflow: hidden;
}

@media (max-width: 640px) {
  .lightbox-overlay {
    padding: 1rem;
  }

  .lightbox-nav,
  .lightbox-zoom-toggle {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.4rem;
  }
}

.empty-photo-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.messages li {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  margin-bottom: 0.5rem;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-top: 0;
}

.auth-card .switch-link {
  margin-top: 1.25rem;
  font-size: 0.9rem;
  text-align: center;
}

.scout-drop-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.scout-drop-area.scout-drop-active {
  border-color: var(--color-primary);
  background: var(--color-bg);
}

.scout-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0;
}

.scout-preview-thumb {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.scout-preview-item {
  position: relative;
}

.scout-preview-remove {
  position: absolute;
  top: -0.4rem;
  right: -0.4rem;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.scout-preview-remove:hover {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}

.detail-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.detail-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}

.detail-list li:last-child {
  border-bottom: none;
}

.detail-list .label {
  color: var(--color-text-muted);
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .sidebar.open {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

  .topbar {
    display: flex;
  }

  .content {
    padding: 1.25rem;
  }
}
