/* ============================================================
   Planeswalker Checklist - Stili
   Tema chiaro/scuro automatico + override manuale via [data-theme]
   ============================================================ */

:root {
  --primary: #6b46c1;
  --primary-dark: #553c9a;
  --primary-light: #9f7aea;
  --accent: #f6ad55;
  --success: #48bb78;
  --danger: #e53e3e;

  /* Tema chiaro (default) */
  --bg: #f7fafc;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text: #1a202c;
  --text-muted: #4a5568;
  --border: #e2e8f0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1d29;
  --bg-elevated: #232636;
  --text: #f7fafc;
  --text-muted: #a0aec0;
  --border: #2d3142;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --bg-card: #1a1d29;
    --bg-elevated: #232636;
    --text: #f7fafc;
    --text-muted: #a0aec0;
    --border: #2d3142;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ============================================================
   HEADER
   ============================================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 16px 12px;
  box-shadow: var(--shadow);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
}

.app-title {
  margin: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--border);
  outline: none;
}

.search-row {
  margin-top: 12px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(107, 70, 193, 0.2);
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  flex: 1;
  min-width: 0;
}

.filter-btn {
  flex: 1;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn.active {
  background: var(--primary);
  color: white;
}

.sort-select {
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

/* ============================================================
   STATS
   ============================================================ */

.stats {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
}

.stat {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   STATUS BAR
   ============================================================ */

.status-bar {
  margin: 12px 16px 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg-card);
  border-left: 3px solid var(--primary);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.status-bar.error {
  border-left-color: var(--danger);
  color: var(--danger);
}

.status-bar.success {
  border-left-color: var(--success);
}

/* ============================================================
   CARD GRID
   ============================================================ */

.app-main {
  padding-bottom: 16px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px 16px;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1200px) {
  .card-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.card:active {
  transform: scale(0.97);
}

.card.owned {
  border-color: var(--success);
  box-shadow: 0 0 0 1px var(--success), var(--shadow);
}

.card-image-wrap {
  aspect-ratio: 488 / 680;
  background: var(--border);
  position: relative;
  overflow: hidden;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card.missing .card-image {
  filter: grayscale(0.9) brightness(0.7);
  opacity: 0.6;
}

.card-badges {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  pointer-events: none;
}

.badge {
  font-size: 0.7rem;
  padding: 3px 7px;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  backdrop-filter: blur(4px);
}

.badge.new {
  background: var(--accent);
  color: #1a202c;
}

.badge.qty {
  background: var(--success);
}

.badge.reprints {
  background: var(--primary);
}

.card-info {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* ============================================================
   BOTTOM BAR
   ============================================================ */

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

.bottom-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
}

.bottom-btn:hover, .bottom-btn:focus-visible {
  background: var(--border);
  outline: none;
}

.bottom-icon {
  font-size: 1.2rem;
}

.bottom-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============================================================
   DIALOG
   ============================================================ */

.card-dialog {
  width: min(560px, 92vw);
  max-height: 88vh;
  border: none;
  border-radius: 16px;
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.card-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: flex-end;
  padding: 8px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.dialog-content {
  padding: 16px 20px 20px;
  overflow-y: auto;
  max-height: calc(88vh - 60px);
}

.dialog-card-image {
  width: 100%;
  max-width: 280px;
  margin: 0 auto 16px;
  display: block;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.dialog-card-name {
  font-size: 1.4rem;
  margin: 0 0 4px;
  text-align: center;
}

.dialog-card-mana {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px;
}

.reprints-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.reprint-tag {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

.copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}

.copy-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.copy-meta {
  font-size: 0.85rem;
  font-weight: 500;
}

.copy-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.copy-actions {
  display: flex;
  gap: 4px;
}

.copy-actions button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.85rem;
}

.copy-actions button:hover {
  border-color: var(--primary);
}

.copy-actions .delete-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.add-copy-btn {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.add-copy-btn:hover {
  background: var(--primary-dark);
}

/* ============================================================
   FORM
   ============================================================ */

#copy-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#copy-form h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-field input,
.form-field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
}

.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   AUTH (login/setup password)
   ============================================================ */

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

.icon-btn.unlocked {
  color: var(--success);
}

.auth-dialog {
  width: min(420px, 92vw);
}

.auth-dialog form {
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.auth-icon {
  font-size: 2.5rem;
  margin: 0 auto 4px;
}

.auth-dialog h2 {
  margin: 0;
  font-size: 1.25rem;
}

.auth-subtitle {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.auth-dialog .form-field {
  text-align: left;
}

.auth-error {
  background: rgba(229, 62, 62, 0.1);
  color: var(--danger);
  border-left: 3px solid var(--danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: left;
}

/* Stato locked: pulsanti di modifica con opacità ridotta */
.locked-action {
  position: relative;
}

.locked-action::after {
  content: "🔒";
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.7rem;
  opacity: 0.7;
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-icon {
  font-size: 2.5rem;
  margin: 0 auto 4px;
}

.auth-dialog h2 {
  margin: 0;
  font-size: 1.25rem;
}

.auth-subtitle {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.auth-dialog .form-field {
  text-align: left;
}

.auth-error {
  background: rgba(229, 62, 62, 0.1);
  color: var(--danger);
  border-left: 3px solid var(--danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: left;
}

/* Stato locked: pulsanti di modifica con opacità ridotta */
.locked-action {
  position: relative;
}

.locked-action::after {
  content: "🔒";
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.7rem;
  opacity: 0.7;
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
