/* ═══════════════════════════════════════════════
   Variables & Reset
═══════════════════════════════════════════════ */
:root {
  --coin-d: 25.75mm;          /* real coin diameter */
  --slot-d: 30mm;             /* album slot diameter (slightly larger) */
  --slot-gap: 3mm;
  --group-gap: 8mm;
  --page-w: 202mm;
  --page-h: 252mm;
  --print-safe-margin: 5mm;
  --cols: 5;
  --accent: #6b7280;
  --bg: #ececec;
  --surface: #f7f7f7;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-dim: #6b7280;
  --collected-ring: #1f9d45;
  --missing-overlay: rgba(0,0,0,0.55);
  --screen-scale: 1;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
}

/* ═══════════════════════════════════════════════
   Burger Menu / Controls
═══════════════════════════════════════════════ */
.menu-toggle {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1002;
  width: 44px;
  height: 44px;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  padding: 0 10px;
  cursor: pointer;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

body.menu-open .menu-toggle {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.menu-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: #374151;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.45);
}

.side-menu {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: min(320px, 86vw);
  z-index: 1001;
  background: linear-gradient(180deg, #ffffff 0%, #f3f4f6 100%);
  border-right: 1px solid #e5e7eb;
  box-shadow: 10px 0 30px rgba(0,0,0,0.35);
  padding: 12px 14px 14px;
  overflow-y: auto;
  transform: translateX(-103%);
  transition: transform 0.2s ease;
}

.side-menu.open {
  transform: translateX(0);
}

.menu-close {
  position: absolute;
  top: 6px;
  right: 10px;
  border: none;
  background: transparent;
  color: #374151;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.menu-controls {
  margin-bottom: 12px;
  padding-top: 26px;
}

.control-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  font-size: 0.8rem;
}

.compact-group {
  gap: 5px;
}

.control-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.control-check input {
  width: 16px;
  height: 16px;
}

.control-group select {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  width: 100%;
  padding: 7px 8px;
  font-size: 0.85rem;
}

.text-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.text-toggle {
  border: 1px solid #d1d5db;
  background: transparent;
  color: #4b5563;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.78rem;
  line-height: 1.2;
  cursor: pointer;
}

.text-toggle.is-active {
  border-color: #1f2937;
  background: #1f2937;
  color: #fff;
}

.filter-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-header-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
}

.mini-link {
  border: none;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
}

.filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-right: 4px;
}

.filter-chip {
  width: auto;
  flex: 0 0 auto;
  border: 1px solid #d6d9de;
  border-radius: 8px;
  background: #fff;
  color: #4b5563;
  padding: 5px 10px;
  font-size: 0.74rem;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.filter-chip.is-active {
  border-color: #1f9d45;
  background: #eef9f1;
  color: #175b2f;
}

.btn-print {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.85rem;
  text-align: left;
}
.btn-print:hover { opacity: 0.85; }

.btn-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  width: 100%;
  border: 1px solid #d6d9de;
  border-radius: 4px;
  padding: 8px 12px;
  color: #4b5563;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1;
}

.btn-logout:hover {
  background: #f3f4f6;
}

.stats {
  margin-left: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
  line-height: 1.4;
}

/* ═══════════════════════════════════════════════
   Album — screen layout
═══════════════════════════════════════════════ */
#albumContainer {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
}

.album-page {
  background: #fff;
  color: #333;
  width: var(--page-w);
  min-height: var(--page-h);
  padding: 8mm;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  border-radius: 3px;
  position: relative;
  border: 1px solid #cfcfcf;
  zoom: var(--screen-scale);
}

/* Sheet boundary 202x252 and visual print-safe area */
.album-page::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid #8e8e8e;
  pointer-events: none;
}

.album-page::after {
  content: '';
  position: absolute;
  inset: var(--print-safe-margin);
  border: 1px dashed #c5c5c5;
  pointer-events: none;
}

.page-label {
  font-size: 8pt;
  color: #666;
  margin-bottom: 4mm;
  text-align: center;
  font-style: italic;
}

.coin-grid {
  display: grid;
  grid-template-columns:
    var(--slot-d) var(--slot-gap) var(--slot-d) var(--group-gap)
    var(--slot-d) var(--group-gap)
    var(--slot-d) var(--slot-gap) var(--slot-d);
  column-gap: 0;
  row-gap: var(--slot-gap);
  justify-content: center;
}

/* Optima 27 layout: 2 columns + 1 column + 2 columns */
.coin-grid .coin-cell:nth-child(5n + 1) { grid-column: 1; }
.coin-grid .coin-cell:nth-child(5n + 2) { grid-column: 3; }
.coin-grid .coin-cell:nth-child(5n + 3) { grid-column: 5; }
.coin-grid .coin-cell:nth-child(5n + 4) { grid-column: 7; }
.coin-grid .coin-cell:nth-child(5n + 5) { grid-column: 9; }

.coin-cell {
  width: var(--slot-d);
  height: var(--slot-d);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.coin-meta {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  color: #5d5d5d;
  font-size: 5.5pt;
  line-height: 1;
  letter-spacing: 0.02em;
}

.coin-meta-item {
  position: absolute;
}

.coin-meta-item.country,
.coin-meta-item.year,
.coin-meta-item.volume {
  font-weight: 600;
}

.coin-meta-item.country {
  top: 0.8mm;
  left: 0.8mm;
}

.coin-meta-item.year {
  top: 0.8mm;
  right: 0.8mm;
}

.coin-meta-item.volume {
  right: 0.8mm;
  bottom: 0.8mm;
}

.coin-meta-item.coin-id {
  left: 50%;
  bottom: 0.4mm;
  transform: translateX(-50%);
  max-width: 68%;
  padding: 0.15mm 0.5mm;
  border-radius: 999px;
  background: rgba(255,255,255,0.82);
  color: #4b5563;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 3.5pt;
  line-height: 1.1;
  z-index: 3;
}

.coin-flag-badge {
  position: absolute;
  left: 0.8mm;
  bottom: 0.8mm;
  width: 6.8mm;
  height: 4.6mm;
  object-fit: cover;
  border: 0.25mm solid #fff;
  border-radius: 0.35mm;
  box-shadow: 0 0 0 0.2mm rgba(0,0,0,0.18);
  z-index: 0;
}

.group-separator-cell {
  background: #f8f9fb;
}

.group-separator-box {
  width: calc(var(--slot-d) - 1.1mm);
  height: calc(var(--slot-d) - 1.1mm);
  border: 1px dashed #d1d5db;
  border-radius: 1.2mm;
  background: #fff;
  color: #374151;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8mm;
  padding: 1mm;
  text-align: center;
}

.group-separator-box.year .group-separator-year {
  font-size: 11pt;
  font-weight: 700;
  line-height: 1.1;
}

.national-sides-intro-text {
  line-height: 1.15;
}

.group-separator-flag {
  width: 10.5mm;
  height: 6.6mm;
  object-fit: cover;
  border: 0.35mm solid #fff;
  border-radius: 0.5mm;
  box-shadow: 0 0 0 0.25mm rgba(0,0,0,0.18);
}

.group-separator-country {
  width: 100%;
  font-size: 5pt;
  font-weight: 600;
  line-height: 1.2;
  word-break: break-word;
  hyphens: auto;
}

/* Optional 30x30 placeholder grid box */
.show-slot-boxes .coin-cell {
  outline: 1px dotted #dedede;
  outline-offset: -0.5px;
}

/* ── Individual coin slot ── */
.coin-slot {
  width: var(--coin-d);
  height: var(--coin-d);
  border-radius: 50%;
  border: 1.5px solid #bbb;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.coin-slot:hover { border-color: var(--accent); }
.coin-slot:hover .coin-actions { opacity: 1; }

/* Collected ring */
.coin-slot.collected {
  border: 2.5px solid var(--collected-ring);
  box-shadow: 0 0 0 0.5mm rgba(31,157,69,0.2);
}

/* Coin image */
.coin-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.coin-placeholder-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 5.5pt;
  line-height: 1.3;
  color: #555;
  padding: 3px;
  background: #fff;
}

.national-side-placeholder-text {
  font-size: 5pt;
  font-weight: 600;
  color: #6b7280;
}

/* Web-only status logos */
.coin-status-logo {
  position: absolute;
  left: 0.8mm;
  bottom: 0.8mm;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  line-height: 1;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  z-index: 3;
}

body.show-country-flag-badges .coin-status-logo {
  display: none;
}

.coin-status-logo.missing {
  background: #ef4444;
  color: #fff;
}

.coin-status-logo.collected {
  background: #16a34a;
  color: #fff;
}

/* Hover actions */
.coin-actions {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.coin-actions button {
  font-size: 9px;
  padding: 2px 6px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  background: #ffd700;
  color: #000;
  font-weight: bold;
}
.coin-actions button:hover { background: #fff; }
.btn-upload-img { background: #7f5521 !important; color: #fff !important; }


/* ═══════════════════════════════════════════════
   Modal
═══════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.modal[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 24px;
  min-width: 280px;
  max-width: 380px;
  color: var(--text);
}
.modal-box h2 { margin-bottom: 10px; font-size: 1rem; }
.modal-box p  { margin-bottom: 14px; font-size: 0.85rem; color: var(--text-dim); }
.modal-box input[type=file] { width: 100%; margin-bottom: 14px; }

.modal-actions { display: flex; gap: 10px; }
.btn-primary   { background: var(--accent); color: #000; border: none; border-radius: 4px; padding: 7px 18px; cursor: pointer; font-weight: bold; }
.btn-secondary { background: #444; color: var(--text); border: none; border-radius: 4px; padding: 7px 14px; cursor: pointer; }
.btn-primary:hover   { opacity: 0.85; }
.btn-secondary:hover { background: #555; }

/* ═══════════════════════════════════════════════
   PRINT MEDIA QUERY
═══════════════════════════════════════════════ */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  /* Hide everything except album pages */
  .no-print,
  .modal,
  .coin-actions,
  .menu-toggle,
  .menu-backdrop,
  .side-menu {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  #albumContainer {
    padding: 0;
    gap: 0;
  }

  .album-page {
    width: var(--page-w);
    min-height: var(--page-h);
    max-height: var(--page-h);
    box-shadow: none;
    border-radius: 0;
    page-break-after: always;
    break-after: page;
    padding: 8mm;
    background: #fff;
    /* Outline to mimic album border */
    outline: 1px solid #aaa;
    zoom: 1 !important;
  }

  .coin-grid {
    grid-template-columns:
      var(--slot-d) var(--slot-gap) var(--slot-d) var(--group-gap)
      var(--slot-d) var(--group-gap)
      var(--slot-d) var(--slot-gap) var(--slot-d);
    column-gap: 0;
    row-gap: var(--slot-gap);
  }

  .coin-cell {
    width: var(--slot-d);
    height: var(--slot-d);
    background: #fff;
  }

  .coin-slot {
    width: var(--coin-d);
    height: var(--coin-d);
    border: 1.3px solid #999;
    background: #fff;
  }

  /* Collected: full colour */
  .coin-slot.collected {
    border: 2px solid #1f9d45;
  }

  .coin-status-logo {
    display: none !important;
  }

  .coin-meta-item.coin-id {
    background: rgba(255,255,255,0.92);
  }

  /* Placeholder text always visible */
  .coin-placeholder-text {
    font-size: 5pt;
    color: #777;
  }
}

@media (max-width: 680px) {
  :root {
    --mobile-gap: 10px;
  }

  html,
  body {
    overflow-x: hidden;
  }

  .side-menu {
    width: min(340px, 92vw);
    padding: 12px 12px 14px;
  }

  .menu-toggle {
    top: 10px;
    left: 10px;
  }

  #albumContainer {
    max-width: 100vw;
    width: 100%;
    align-items: stretch;
    gap: 14px;
    padding: 68px 10px 18px;
    overflow-x: hidden;
  }

  .album-page {
    max-width: 100%;
    width: 100%;
    min-height: auto;
    margin: 0;
    padding: 14px 12px 12px;
    border-radius: 14px;
    border: 1px solid #d8dbe0;
    box-shadow: 0 10px 30px rgba(0,0,0,0.14);
    zoom: 1 !important;
    overflow: hidden;
  }

  .album-page::before {
    border-color: #d0d4da;
    border-radius: 14px;
  }

  .album-page::after {
    inset: 8px;
    border-color: #d7dce2;
    border-radius: 10px;
  }

  .page-label {
    margin-bottom: 12px;
    font-size: 0.92rem;
  }

  .coin-grid {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--mobile-gap);
    justify-content: stretch;
    overflow: hidden;
  }

  .coin-grid .coin-cell:nth-child(5n + 1),
  .coin-grid .coin-cell:nth-child(5n + 2),
  .coin-grid .coin-cell:nth-child(5n + 3),
  .coin-grid .coin-cell:nth-child(5n + 4),
  .coin-grid .coin-cell:nth-child(5n + 5) {
    grid-column: auto;
  }

  .coin-cell {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .coin-meta {
    font-size: 0.56rem;
  }

  .coin-slot {
    width: 82%;
    height: auto;
    aspect-ratio: 1 / 1;
    border-width: 1.5px;
  }

  .coin-slot.collected {
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(31,157,69,0.14);
  }

  .coin-flag-badge {
    width: 20px;
    height: 14px;
    left: 3px;
    bottom: 3px;
    border-width: 1px;
  }

  .coin-status-logo {
    left: 3px;
    bottom: 3px;
    width: 16px;
    height: 16px;
    font-size: 10px;
  }

  .group-separator-box {
    width: 88%;
    height: 88%;
    border-radius: 10px;
  }

  .group-separator-box.year .group-separator-year {
    font-size: 1.35rem;
  }

  .national-sides-intro-box {
    padding: 8px 6px;
  }

  .national-sides-intro-text {
    font-size: 0.72rem;
    line-height: 1.15;
    word-break: break-word;
  }

  .group-separator-country {
    font-size: 0.62rem;
  }

  .coin-placeholder-text,
  .national-side-placeholder-text {
    font-size: 0.62rem;
    line-height: 1.25;
  }

  .coin-actions {
    display: none;
  }

  .coin-actions button {
    font-size: 0.68rem;
    padding: 4px 8px;
  }
}

@media (max-width: 480px) {
  .album-page {
    padding: 12px 10px 10px;
  }
}
