:root {
  --primary: #2c3e50;
  --primary-light: #3d5166;
  --accent: #2980b9;
  --accent-hover: #2471a3;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1a2533;
  --text-muted: #6b7a8d;
  --green-bg: #d4efdf;
  --green-fg: #1a6b3c;
  --red-bg: #fde0d8;
  --red-fg: #9b2a1a;
  --orange-bg: #fef3cd;
  --orange-fg: #7d5a00;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08), 0 2px 12px rgba(0,0,0,0.05);
}

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

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

/* ── Header ───────────────────────────────── */
header {
  background: var(--primary);
  color: white;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-title {
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}
.app-title:hover { opacity: 0.75; }

.title-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}

.version {
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  font-weight: 400;
  line-height: 1;
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-import {
  display: none;
  cursor: pointer;
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-import.visible { display: inline-flex; }
.btn-import:hover { background: var(--accent-hover); }

/* Icon-only header buttons */
.btn-icon {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  padding: 0;
}
.btn-icon.visible { display: inline-flex; }
.btn-icon:hover { background: rgba(255,255,255,0.22); }
.btn-icon:disabled { opacity: 0.5; cursor: default; }

.sync-spin { display: inline-block; }
@keyframes sync-spin { to { transform: rotate(-360deg); } }
.btn-icon.syncing .sync-spin { animation: sync-spin 0.8s linear infinite; }

/* Auth button (always visible) */
.btn-icon-auth {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon-auth:hover { opacity: 0.8; }

.auth-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.5);
  display: block;
}

#import-status {
  font-size: 12px;
  color: #90caf9;
  min-width: 120px;
}

.btn-auth {
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-auth:hover { background: rgba(255,255,255,0.22); }
.btn-auth-out   { border-color: rgba(255,100,100,0.5); }

#user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  object-fit: cover;
}

#auth-area {
  display: flex;
  align-items: center;
}

/* ── Tabs ─────────────────────────────────── */
.tabs {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  display: flex;
  padding: 0 16px;
  gap: 2px;
}

.tab-btn {
  background: none;
  border: none;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-badge {
  background: var(--primary);
  color: white;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}
.tab-badge.badge-warn { background: #c0392b; }
.tab-badge:empty { display: none; }

/* ── Tab Content ──────────────────────────── */
.tab-content { display: none; padding: 16px 20px 32px; }
.tab-content.active { display: block; }

/* ── Filters ──────────────────────────────── */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.filters input[type="text"],
.filters select {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.filters input[type="text"] { flex: 1; min-width: 160px; }
.filters input[type="text"]:focus,
.filters select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41,128,185,0.12);
}

.sort-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Stats bar ────────────────────────────── */
.stats-bar {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Serie filter button ──────────────────── */
.filter-serie-btn {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.filter-serie-btn:hover,
.filter-serie-btn:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(41,128,185,0.12); outline: none; }
.filter-serie-btn.active { border-color: var(--accent); color: var(--accent); background: #eef5ff; }
.filter-caret { font-size: 10px; opacity: 0.6; }

/* ── Serie picker modal ───────────────────── */
.modal-compact { max-height: 70vh; }

.serie-picker-search-wrap {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.serie-picker-search {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.serie-picker-search:focus { border-color: var(--accent); }

.serie-picker-list {
  overflow-y: auto;
  flex: 1;
}
.serie-picker-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.serie-picker-item:last-child { border-bottom: none; }
.serie-picker-item:hover { background: var(--bg); }
.serie-picker-item.active { background: #eef5ff; color: var(--accent); font-weight: 600; }
.picker-check { color: var(--accent); font-size: 15px; font-weight: 700; }

/* ── Sort bar ─────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.sort-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.sort-btn:hover { border-color: var(--accent); color: var(--accent); }
.sort-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.sort-btn.active.sort-asc::after  { content: ' ↑'; }
.sort-btn.active.sort-desc::after { content: ' ↓'; }

/* ── Collection list ──────────────────────── */
.collection-list {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.album-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.album-row:last-child { border-bottom: none; }
.album-row:active { background: #eef5ff; }

.album-num-badge {
  min-width: 34px;
  min-height: 34px;
  background: var(--primary);
  color: white;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1.2;
}

.num-a {
  font-size: 9px;
  font-weight: 500;
  color: #ffc107;
  line-height: 1;
}

.album-body { flex: 1; min-width: 0; }

.album-line1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.album-serie {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.album-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.album-line2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-top: 2px;
}
.album-titre {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.album-editeur-badge {
  display: inline-block;
  background: var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.col-num  { width: 44px; text-align: center; }
.col-year { width: 60px; }
.col-etat { width: 70px; }
.col-prix { width: 72px; text-align: right; }

.etat-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
}
.etat-1 { background: #fde8d8; color: #9b2a1a; }
.etat-2 { background: #fef3cd; color: #7d5a00; }
.etat-3 { background: #d4efdf; color: #1a6b3c; }
.etat-4 { background: #d0eaff; color: #154e7a; }
.etat-5 { background: #e8d5f9; color: #5b1e8a; }

/* ── Empty / loading ──────────────────────── */
.empty-msg {
  color: var(--text-muted);
  text-align: center;
  padding: 48px 20px;
  font-size: 15px;
}

/* ── À acheter cards ──────────────────────── */
#acheter-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.serie-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.apercu-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.apercu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.num-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
}

.num-sq {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: filter 0.1s;
}
.num-sq:hover { filter: brightness(0.9); }

.num-sq-owned   { background: #c8f0c8; color: #1a6e1a; }
.num-sq-missing { background: #f9c8c8; color: #8b1a1a; }
.num-sq-achete  { background: #ffe0b2; color: #e65100; }

.apercu-info {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.apercu-info.visible { opacity: 1; }

.serie-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  padding: 2px 0;
}
.serie-header::-webkit-details-marker { display: none; }

.serie-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  flex: 1;
  line-height: 1.3;
}

details.serie-card[open] .serie-header { margin-bottom: 10px; }

.serie-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  flex: 1;
  line-height: 1.3;
}

.serie-meta {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

.badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-owned   { background: var(--green-bg); color: var(--green-fg); }
.badge-missing { background: var(--red-bg);   color: var(--red-fg); }

.serie-details {
  font-size: 13px;
  margin-bottom: 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tomes-possessed {
  color: var(--text-muted);
  font-size: 12px;
}

.tomes-missing {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}
.tomes-missing strong { margin-right: 2px; font-size: 12px; }

.missing-num {
  display: inline-block;
  background: var(--red-bg);
  color: var(--red-fg);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 700;
}

.missing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 2px;
}
.missing-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.missing-table tr:last-child td { border-bottom: none; }
.missing-table tr.achete td { background: #fff3e0; color: #e65100; }
.missing-table tr.achete .col-num { font-weight: 700; }
.achete-check { font-size: 11px; margin-left: 4px; }
.missing-table .col-num {
  width: 50px;
  font-weight: 700;
  color: var(--red-fg);
  text-align: right;
  padding-right: 12px;
}

.col-date { white-space: nowrap; width: 100px; }

.serie-footer {
  border-top: 1px solid var(--border);
  padding-top: 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.total-input {
  width: 72px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.total-input:focus { border-color: var(--accent); }

.btn-fetch {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-fetch:hover:not(:disabled) { background: #e8f0fe; border-color: var(--accent); }
.btn-fetch:disabled { opacity: 0.5; cursor: not-allowed; }

.fetch-source {
  font-size: 10px;
  color: var(--green-fg);
  font-style: italic;
}

/* Sync indicator (top-right dot) */
.sync-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #27ae60;
  flex-shrink: 0;
  transition: background 0.3s;
}
.sync-idle    { background: #27ae60; }
.sync-saving  { background: #f39c12; animation: pulse 0.8s infinite; }
.sync-error   { background: #e74c3c; }
.sync-achete  { background: #ff9800; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* Spinner for fetch button */
.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid #ccc;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-desc {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.modal-credit {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted, #888);
  text-align: center;
}
.modal-credit a {
  color: var(--accent, #4a9eff);
  text-decoration: none;
}

.changelog-title {
  margin: 18px 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.changelog {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.changelog li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.cl-version {
  background: var(--primary);
  color: white;
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.btn-modal-close {
  padding: 8px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-modal-close:hover { background: var(--accent-hover); }

.config-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.config-field:last-child { margin-bottom: 0; }
.config-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.config-field input {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.config-field input:focus { border-color: var(--accent); }

.btn-achete {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  transition: background 0.15s, color 0.15s;
}
.btn-achete:hover { background: #d0d8e4; }
.btn-achete-on { background: #ff9800; color: white; }
.btn-achete-on:hover { background: #e65100; }

/* ── Album detail modal ───────────────────────────────────── */
.modal-album { max-width: 360px; }

.album-modal-body {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.album-modal-cover-wrap {
  flex-shrink: 0;
}

.album-modal-cover {
  width: 160px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: block;
}

.album-modal-dl {
  flex: 1;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.album-modal-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.album-modal-row dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.album-modal-row dd {
  margin: 0;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ── Responsive ───────────────────────────── */
@media (hover: hover) {
  .album-row:hover { background: #eef5ff; }
}

@media (max-width: 600px) {
  header { padding: 8px 10px; }
  header h1 { font-size: 15px; }
  .header-actions { gap: 6px; }
  .btn-txt { display: none; }
  #btn-bdgest-sync.visible { display: inline-flex !important; }
  #btn-config.visible { display: inline-flex !important; }
  .btn-import { padding: 5px 9px; font-size: 13px; }
  .btn-auth  { padding: 5px 9px; font-size: 13px; }
  #import-status { display: none; }

  .tabs { padding: 0 8px; }
  .tab-btn { padding: 10px 12px; font-size: 13px; }

  .tab-content { padding: 10px 10px 24px; }

  .filters { flex-direction: column; gap: 8px; }
  .filters input[type="text"] { width: 100%; min-width: 0; font-size: 14px; padding: 9px 11px; }
  .filter-serie-btn { width: 100%; justify-content: space-between; font-size: 14px; padding: 9px 12px; }

  .sort-bar { gap: 5px; }
  .sort-btn { font-size: 12px; padding: 5px 10px; }

  .album-row { padding: 10px 10px; gap: 10px; }
  .album-serie { font-size: 13px; }

  #acheter-list  { grid-template-columns: 1fr; }
  #apercu-list   { grid-template-columns: 1fr; }

  .num-grid { grid-template-columns: repeat(5, 1fr); }
  .num-sq { height: 32px; font-size: 13px; }
}
