:root {
  --bg: #0b1220;
  --bg2: #111827;
  --card: #1e293b;
  --card2: #243044;
  --border: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary2: #3b82f6;
  --primary-soft: rgba(37, 99, 235, 0.18);
  --accent: #38bdf8;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Syne", var(--font);
}

*, *::before, *::after { box-sizing: border-box; }
html {
  margin: 0;
  padding: 0;
  background: var(--bg);
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
}
body {
  margin: 0;
  padding: 0;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: visible;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(37, 99, 235, 0.25), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.12), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(64px + var(--safe-t));
  padding-bottom: calc(72px + var(--safe-b));
}

.topbar {
  position: fixed;
  top: 0;
  left: max(0px, calc(50% - 240px));
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(480px, 100%);
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: #0b1220;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
  overflow: visible;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  display: grid; place-items: center;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.45);
  flex-shrink: 0;
  aspect-ratio: 1;
}
.brand-logo {
  width: 44px;
  height: 44px;
  display: block;
  object-fit: contain;
  object-position: center;
}
.brand-name {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  display: block;
  line-height: 1.15;
  color: #ffffff;
  text-shadow: 0 1px 0 rgba(255,255,255,0.12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-tld {
  font-weight: 600;
  font-size: 0.72em;
  color: #7dd3fc;
  letter-spacing: 0;
  opacity: 0.9;
  margin-left: 1px;
}
.brand-sub {
  font-size: 0.78rem;
  color: #94a3b8;
  margin-top: 2px;
  display: block;
  font-weight: 500;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  color: #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.icon-btn svg {
  display: block;
  width: 20px;
  height: 20px;
  stroke: #f1f5f9;
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.96); }
.brand > div {
  min-width: 0;
  overflow: hidden;
}
.nav-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.nav-svg svg { display: block; }

.main { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.hero-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 12px 16px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #1e3a8a, #2563eb 55%, #38bdf8);
  box-shadow: var(--shadow);
}
.hero-stat {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.hero-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  margin-bottom: 2px;
}
.hero-icon svg { display: block; opacity: 0.95; }
.hero-num {
  display: block;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.55rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.hero-label {
  font-size: 0.72rem;
  opacity: 0.92;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-title {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-head .panel-title { margin: 0; }
.filter-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg2);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary2);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field input.readonly {
  opacity: 0.85;
  color: var(--accent);
  font-weight: 600;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.photo-box {
  position: relative;
  border-radius: 14px;
  border: 1.5px dashed var(--border);
  background: var(--bg2);
  min-height: 140px;
  overflow: hidden;
}
.photo-box input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.photo-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  pointer-events: none;
}
.photo-placeholder span { font-size: 1.8rem; }
#photoPreview {
  width: 100%;
  height: 180px;
  object-fit: cover;
}
.photo-clear {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 3;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  transition: transform 0.12s, filter 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary2), var(--primary));
  color: #fff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35);
}
.btn-block { width: 100%; margin-top: 4px; }
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
  font-size: 0.8rem;
  padding: 6px 10px;
}

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
}
.history-item.has-photo { cursor: pointer; }
.history-thumb {
  width: 64px; height: 64px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--card2);
}
.history-thumb.placeholder {
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  color: var(--muted);
}
.history-body h3 {
  margin: 0 0 2px;
  font-size: 0.98rem;
  font-weight: 700;
}
.history-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}
.history-mark {
  font-family: var(--display);
  font-weight: 800;
  color: var(--accent);
  font-size: 0.95rem;
  text-align: right;
}
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: #93c5fd;
  margin-right: 4px;
}
.badge.pr {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}
.empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 1.5rem 0.5rem;
  margin: 0;
}
.empty[hidden], [hidden] {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}
.modal[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.bottom-nav {
  position: fixed;
  left: max(0px, calc(50% - 240px));
  bottom: 0;
  z-index: 60;
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: #0f172a;
  border-top: 1px solid var(--border);
  box-sizing: border-box;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 1.15rem;
}
.nav-item small { font-size: 0.68rem; font-weight: 600; }
.nav-item.active {
  color: #fff;
  background: var(--primary-soft);
}
.nav-add {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-size: 1.35rem;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.45);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: min(480px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 16px 16px;
  padding: 20px 18px 24px;
  border: 1px solid var(--border);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg2);
  font-size: 1.3rem;
}
.modal-card h2 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 1.2rem;
}
.stats-body { display: flex; flex-direction: column; gap: 10px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--bg2);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.stat-row strong { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: #1e3a8a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 200;
  max-width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 481px) {
  .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* —— ApuntaTuMarca: privacidad y branding —— */
.privacy-banner {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.15), rgba(56, 189, 248, 0.08));
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
}
.privacy-banner p { margin: 0 0 6px; }
.privacy-banner p:last-child { margin-bottom: 0; }
.privacy-banner strong { color: var(--accent); }
.privacy-banner-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.home-footer-note {
  text-align: center;
  padding: 8px 4px 20px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}
.home-footer-note p { margin: 0 0 6px; }
.app-version {
  font-size: 0.72rem;
  opacity: 0.85;
}

.info-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}
.info-body p { margin: 0 0 12px; }
.info-body ul {
  margin: 0 0 12px;
  padding-left: 1.2em;
}
.info-body li { margin-bottom: 6px; }
.info-body .tiny {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 16px;
}

/* —— Wider desktop —— */
@media (min-width: 768px) {
  .app {
    max-width: 720px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
  .main { padding: 20px 24px; gap: 20px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .hero-card { padding: 20px 16px 22px; }
  .hero-num { font-size: 1.85rem; }
  .hero-icon { width: 42px; height: 42px; border-radius: 12px; }
  .panel { padding: 20px; }
  .field-row { grid-template-columns: 1fr 1fr; gap: 14px; }
  .bottom-nav, .topbar {
    max-width: 720px;
    width: min(720px, 100%);
    left: max(0px, calc(50% - 360px));
  }
  .app { max-width: 720px; padding-top: calc(68px + var(--safe-t)); }
  .history-list { gap: 12px; }
}
@media (min-width: 1024px) {
  .app { max-width: 860px; }
  .bottom-nav, .topbar {
    max-width: 860px;
    width: min(860px, 100%);
    left: max(0px, calc(50% - 430px));
  }
  .app { max-width: 860px; }
  .main { padding: 24px 28px; }
}

/* —— Links —— */
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}
.link-btn.inline { display: inline; }

/* —— Share modal —— */
.share-card { max-width: 420px; }
.share-intro {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.45;
}
.share-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.share-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  transition: border-color 0.15s, transform 0.12s;
}
.share-btn:hover, .share-btn:active {
  border-color: var(--primary2);
  transform: translateY(-2px);
}
.share-btn-icon { font-size: 1.35rem; line-height: 1; }
.share-hint {
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* —— Legal / privacy —— */
.legal-card {
  max-width: 520px;
  max-height: min(85vh, 640px);
  overflow-y: auto;
}
.legal-body {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
}
.legal-body p { margin: 0 0 12px; }
.legal-date {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 16px !important;
}

/* —— Exit modal —— */
.exit-card { max-width: 400px; text-align: center; }
.exit-hero { margin-bottom: 8px; }
.exit-emoji { font-size: 2.4rem; margin-bottom: 8px; }
.exit-card h2 { margin: 0 0 8px; }
.exit-lead {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0 0 4px;
  line-height: 1.45;
}
.exit-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.btn-secondary {
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}
.btn-secondary:active { transform: scale(0.98); }
.btn-text {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.88rem;
  cursor: pointer;
  margin-top: 4px;
  text-decoration: underline;
  padding: 8px;
}
.btn-sm { padding: 10px 16px; font-size: 0.9rem; }

/* —— Cookie banner —— */
.cookie-banner {
  position: fixed;
  bottom: calc(72px + var(--safe-b));
  left: 10px;
  right: 10px;
  background: #0f172a;
  color: #e2e8f0;
  z-index: 300;
  padding: 14px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  border: 1px solid var(--border);
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  animation: cookieIn 0.3s ease;
}
@media (min-width: 768px) {
  .cookie-banner { max-width: 560px; bottom: 24px; }
}
@media (min-width: 1024px) {
  .cookie-banner { max-width: 640px; }
}
@keyframes cookieIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.cookie-content p {
  font-size: 0.84rem;
  line-height: 1.45;
  margin: 0 0 12px;
}
.cookie-content .link-btn { color: #7dd3fc; }
.cookie-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.cookie-actions .btn-primary {
  background: #fff;
  color: #0f172a;
}
.cookie-actions .btn-secondary {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.45);
  color: #fff;
}

/* Modal card base tweaks when stacked */
.modal-card.share-card,
.modal-card.exit-card,
.modal-card.legal-card {
  width: min(100% - 24px, 520px);
}


/* —— Mobile: cabecera en 2 filas, iconos a ancho completo —— */
@media (max-width: 640px) {
  .topbar, .bottom-nav, .app {
    max-width: 100%;
    left: 0;
    width: 100%;
  }
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    padding: calc(8px + var(--safe-t)) 12px 10px;
    /* altura mayor → más padding en .app */
  }
  .brand {
    width: 100%;
    gap: 8px;
  }
  .brand-mark, .brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }
  .brand-name { font-size: 1.05rem; }
  .brand-tld { display: none; }
  .brand-sub { font-size: 0.7rem; }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    gap: 8px;
    flex-shrink: 0;
  }
  /* install hidden no ocupa hueco */
  .topbar-actions .icon-btn[hidden] {
    display: none !important;
  }
  .icon-btn {
    width: 100%;
    min-width: 0;
    height: 44px;
    border-radius: 12px;
    background: #1e293b;
    border: 1px solid rgba(148, 163, 184, 0.35);
    color: #f8fafc;
  }
  .icon-btn svg {
    width: 22px;
    height: 22px;
    stroke: #f8fafc !important;
  }

  /* espacio para cabecera de 2 filas */
  .app {
    padding-top: calc(108px + var(--safe-t));
  }
}
@media (max-width: 360px) {
  .brand-sub { display: none; }
}
