* { box-sizing: border-box; }

body {
  font-family: 'Source Sans 3', system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 0;
  background: #faf9f7;
  color: #2c2c2c;
  line-height: 1.5;
}

a { color: var(--primary-bg); }
a:hover { color: var(--primary-hover); }

/* ── Header ─────────────────────────────────────────── */
.site-header {
  background: #fff;
  border-bottom: 1px solid #e8e5e0;
  padding: .8rem 1.5rem;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: #2c2c2c;
  text-decoration: none;
}
.logo:hover {
  color: var(--primary-bg);
}
.site-header nav { display: flex; gap: 1rem; }
.site-header nav a {
  color: var(--primary-bg);
}
.site-header nav a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────── */
.layout {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}
main {
  flex: 1;
  min-width: 0;
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
}
.sidebar .menu {
  list-style: none;
  padding: 0;
  margin: 0;
  background: #fff;
  border: 1px solid #e8e5e0;
  border-radius: 8px;
  overflow: hidden;
}
.sidebar .menu li a {
  display: block;
  padding: .6rem 1rem;
  text-decoration: none;
  color: #2c2c2c;
  font-size: .9rem;
  border-bottom: 1px solid #f0eeeb;
  transition: background .1s;
}
.sidebar .menu li:last-child a { border-bottom: none; }
.sidebar .menu li a:hover {
  color: var(--primary-bg);
  background: #f5f7f5;
}
.sidebar .menu li.active a {
  background: var(--primary-bg);
  color: var(--primary-text);
}
.sidebar .menu .count { font-size: .8em; opacity: .7; }

.sidebar .menu li a .menu-icon { margin-right: .3rem; }
.sidebar .menu li a .menu-label { display: inline; }

/* ── Footer ─────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 1.5rem 0;
  font-size: .8rem;
  color: #999;
}

/* ── Page-specific (shared) ─────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; margin-top: 0; color: #2c2c2c; }
h2 { font-size: 1.15rem; font-weight: 600; margin-top: 1.5rem; color: #2c2c2c; }
h3 { font-size: .95rem; font-weight: 600; color: #6b6b6b; }
.error {
  color: var(--danger-bg);
}
table { border-collapse: collapse; width: 100%; margin-top: .5rem; }
th, td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid #e8e5e0; }
th { width: 200px; font-weight: 600; color: #6b6b6b; font-size: .8rem; text-transform: uppercase; }
.empty { color: #6b6b6b; padding: 2rem 0; text-align: center; }

/* ── Map page ───────────────────────────────────────── */
#map {
width: 100%;
height: calc(100vh - 120px);
border-radius: 8px;
border: 1px solid #e8e5e0;
}
.map-popup { font-size: .9rem; }
.map-popup a { color: var(--primary-bg); text-decoration: none; font-weight: 600; }
.map-popup a:hover { text-decoration: underline; }
.map-popup .coords { font-size: .75rem; color: #888; margin-top: .3rem; }
.no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 120px);
  color: #888;
  font-size: 1.1rem;
}

/* ── Grid & Cards ───────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  border: 1px solid #e8e5e0;
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: #fff;
  transition: box-shadow .2s, transform .2s;
}
.card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  transform: translateY(-2px);
}
.card img { width: 100%; height: 160px; object-fit: cover; display: block; }
.card .info { padding: .7rem .9rem; }
.card .info .name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #2c2c2c; }
.card .info .meta { font-size: .75rem; color: #6b6b6b; margin-top: .2rem; }

/* ── Search bar ─────────────────────────────────────── */
.search-bar {
  margin-bottom: 1.5rem;
  display: flex;
  gap: .5rem;
}
.search-bar input {
  flex: 1;
  padding: .5rem .7rem;
  border: 1px solid #e8e5e0;
  border-radius: 6px;
  font-size: .9rem;
  background: #fff;
  color: #2c2c2c;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--primary-bg);
  box-shadow: 0 0 0 3px rgba(45,90,61,.1);
}
.search-bar button {
  padding: .5rem 1.2rem;
  background: var(--primary-bg);
  color: var(--primary-text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s;
}
.search-bar button:hover { background: var(--primary-hover); }

/* ── Sidebar sections ───────────────────────────────── */
.sidebar-section {
  margin-top: 1.5rem;
}
.sidebar-section h3 {
  font-size: .8rem;
  text-transform: uppercase;
  color: #888;
  margin: 0 0 .4rem;
  padding: 0 1rem;
}

/* ── View page ──────────────────────────────────────── */
img.full {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid #e8e5e0;
  border-radius: 8px;
}

details summary {
  list-style: none;
  cursor: pointer;
}
details summary::before {
  content: '▸ ';
  transition: transform .2s;
  display: inline-block;
}
details[open] summary::before {
  transform: rotate(90deg);
}

.cropper-container,
.cropper-container * {
  box-sizing: content-box !important;
}

.crop-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.crop-modal.active { display: flex; }

.crop-box {
  background: #fff;
  border-radius: 10px;
  padding: 1.2rem;
  max-width: 90vw;
  max-height: 80vh;
  overflow: auto;
}

.crop-box > img {
  display: block;
  max-height: 65vh;
  max-width: 100%;
}

.crop-actions {
  margin-top: .8rem;
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
}
.crop-actions button {
  padding: .4rem 1rem;
  border-radius: 6px;
  border: 1px solid #e8e5e0;
  cursor: pointer;
  background: #fff;
  font-size: .9rem;
}
.crop-actions .confirm {
  background: var(--primary-bg);
  color: var(--primary-text);
  border-color: var(--primary-border);
}
.crop-actions .confirm:hover {
  background: var(--primary-hover);
}

/* ── Manip bar ──────────────────────────────────────── */
.manip-bar {
  display: flex;
  gap: .3rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.manip-bar button {
  background: #fff;
  border: 1px solid #e8e5e0;
  border-radius: 4px;
  padding: .25rem .5rem;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
  transition: background .1s, border-color .1s;
}
.manip-bar button:hover {
  background: #f0f5f1;
  border-color: var(--primary-border);
}
.manip-bar .sep {
  width: 1px;
  height: 1.2rem;
  background: #e8e5e0;
  margin: 0 .8rem;
}
.arrow-group {
  display: flex;
  gap: 2px;
  flex-wrap: nowrap;
}
.arrow-group button {
  padding: .25rem .4rem;
  min-width: 1.8rem;
}
.arrow-group button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-border);
  color: #fff;
}

/* ── Pagination ─────────────────────────────────────── */
.pagination {
  margin-top: 1.5rem;
  display: flex;
  gap: .4rem;
  justify-content: center;
}
.pagination a, .pagination span {
  padding: .35rem .7rem;
  border: 1px solid #e8e5e0;
  border-radius: 5px;
  text-decoration: none;
  color: #2c2c2c;
  font-size: .85rem;
  transition: background .1s;
}
.pagination .current {
  background: var(--primary-bg);
  color: var(--primary-text);
  border-color: var(--primary-border);
}
.pagination a:hover {
  background: #f0f5f1;
  border-color: var(--primary-border);
}

.sort-bar {
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  display: flex;
  gap: .5rem;
  align-items: center;
  font-size: .85rem;
  color: #6b6b6b;
}
.sort-bar a {
  padding: .3rem .6rem;
  border: 1px solid #e8e5e0;
  border-radius: 4px;
  text-decoration: none;
  color: #2c2c2c;
}
.sort-bar a:hover {
  background: #f0f5f1;
  border-color: var(--primary-border);
}
.sort-bar a.active {
  background: var(--primary-bg);
  color: var(--primary-text);
  border-color: var(--primary-border);
}

.pagination .dots {
  padding: .4rem .4rem;
  color: #999;
  user-select: none;
  border: none;
}

/* ── Buttons ────────────────────────────────────────── */
.btn-primary {
  background: var(--primary-bg);
  border: 1px solid var(--primary-border);
  color: var(--primary-text);
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  padding: .35rem .9rem;
  height: 2.1rem;
  text-decoration: none;
  display: inline-block;
  transition: background .15s;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-danger {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  padding: .35rem .9rem;
  height: 2.1rem;
  text-decoration: none;
  display: inline-block;
  transition: background .15s;
}
.btn-danger:hover {
  background: var(--danger-hover);
}

/* ── View page content ──────────────────────────────── */
main table {
  font-size: .85rem;
}
main th, main td {
  padding: .3rem .5rem;
}
pre.ocr {
  font-size: .85rem;
}

.meta {
  font-size: .8rem;
  color: #6b6b6b;
  margin-top: 1rem;
}

/* ── Form elements ──────────────────────────────────── */
input[type="text"], input[type="password"], input[type="search"], select, textarea {
  border: 1px solid #e8e5e0;
  border-radius: 6px;
  padding: .45rem .7rem;
  font-size: .9rem;
  background: #fff;
  color: #2c2c2c;
  font-family: inherit;
}
input[type="text"]:focus, input[type="password"]:focus, input[type="search"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-bg);
  box-shadow: 0 0 0 3px rgba(45,90,61,.1);
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    padding: 0 .8rem;
  }

  .sidebar {
    width: 100%;
    flex-shrink: 1;
    margin-bottom: 1rem;
  }

  .sidebar .menu li a .menu-label { display: none; }
  .sidebar .menu li a .menu-icon { margin-right: 0; font-size: 1.2rem; }
  .sidebar .menu li a { text-align: center; padding: .6rem .8rem; }

  .sidebar .menu {
    display: flex;
    overflow-x: auto;
    border-radius: 8px;
  }

  .sidebar .menu li {
    flex-shrink: 0;
  }

  .sidebar .menu li a {
    border-bottom: none;
    border-right: 1px solid #f0eeeb;
    padding: .5rem .8rem;
    white-space: nowrap;
  }

  .sidebar .menu li:last-child a {
    border-right: none;
  }

  .sidebar-section {
    display: none;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .6rem;
  }

  .card img {
    height: 120px;
  }

  .search-bar {
    flex-wrap: wrap;
  }

  .sort-bar {
    flex-wrap: wrap;
  }

  .manip-bar {
    gap: .2rem;
  }

  .manip-bar button {
    padding: .2rem .4rem;
    font-size: .8rem;
  }

  .pagination a,
  .pagination span {
    padding: .3rem .5rem;
    font-size: .85rem;
  }

  #map {
  height: calc(100vh - 180px);
  }

  h1 {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }

  .card img {
    height: 100px;
  }

  .card .info .name {
    font-size: .75rem;
  }

  .site-header nav {
    gap: .6rem;
    font-size: .85rem;
  }

  .header-inner {
    flex-wrap: wrap;
    gap: .5rem;
  }
}

/* ── View toggle ─────────────────────────────────────── */
.view-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid #e8e5e0;
  border-radius: 5px;
  overflow: hidden;
  margin-left: auto;
}
.view-toggle button {
  padding: .3rem .6rem;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: .85rem;
  color: #6b6b6b;
  line-height: 1;
  transition: background .1s;
}
.view-toggle button.active {
  background: var(--primary-bg);
  color: var(--primary-text);
}

/* ── List view ───────────────────────────────────────── */
.grid.list-view {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.grid.list-view .card {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.grid.list-view .card img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.grid.list-view .card .info {
  flex: 1;
  min-width: 0;
}
.grid.list-view .card .name {
  font-size: .9rem;
}
.grid.list-view .card .meta {
  font-size: .8rem;
}

/* ── Print ───────────────────────────────────────────── */
@media print {
  .site-header, .sidebar, .site-footer, .manip-bar, #prev-next, #edit-form, .crop-modal, .sort-bar, .search-bar { display: none !important; }
  .layout { display: block; }
  main { max-width: 100%; }
  img.full { border: none; }
}
