/* ============================================================
   CAMINO — estilos. Tema oscuro: verdes, turquesas y dorados.
   ============================================================ */

:root {
  --bg: #0b1712;
  --bg-2: #10221b;
  --panel: #14281f;
  --panel-2: #1a3227;
  --line: #24443a;
  --text: #e9f4ee;
  --text-2: #a8c3b6;
  --muted: #7d9a8d;
  --green: #35c283;
  --green-dark: #1f8f5f;
  --teal: #2fb9b0;
  --teal-dark: #1c8a84;
  --gold: #e6b34c;
  --gold-dark: #c2902f;
  --danger: #e5644f;
  --radius: 14px;
  --radius-s: 9px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 80% -100px, rgba(47, 185, 176, .12), transparent 60%),
    radial-gradient(900px 420px at -10% 110%, rgba(230, 179, 76, .07), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
}
.app-shell { max-width: 1180px; margin: 0 auto; padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }

/* ---------- cabecera ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 2px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 42px; height: 42px; filter: drop-shadow(0 2px 6px rgba(230,179,76,.35)); }
.brand-text h1 {
  margin: 0; font-size: 1.45rem; letter-spacing: .14em; font-weight: 800;
  background: linear-gradient(90deg, var(--gold), #f3d489);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-text p { margin: 0; font-size: .78rem; color: var(--muted); letter-spacing: .05em; }
.update-btn {
  background: var(--gold); color: #241a05; border: none; border-radius: 999px;
  padding: 9px 16px; font-weight: 700; font-size: .85rem; cursor: pointer;
}
.hidden { display: none !important; }

/* ---------- navegación ---------- */
.main-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center; gap: 4px;
  background: rgba(11, 23, 18, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  flex: 1; max-width: 170px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .74rem; font-weight: 600;
  padding: 8px 6px; border-radius: var(--radius-s); letter-spacing: .02em;
}
.nav-item svg { width: 26px; height: 26px; fill: currentColor; }
.nav-item[aria-current="page"] { color: var(--gold); background: rgba(230, 179, 76, .10); }
.nav-item:hover { color: var(--text); }

/* ---------- botones y controles ---------- */
button { font-family: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text);
  padding: 12px 18px; font-size: 1rem; font-weight: 700; cursor: pointer;
  min-height: 48px; transition: transform .06s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.98); }
.btn svg { width: 22px; height: 22px; fill: currentColor; }
.btn-primary { background: linear-gradient(160deg, var(--green), var(--green-dark)); border-color: #2ea374; color: #06231a; }
.btn-teal { background: linear-gradient(160deg, var(--teal), var(--teal-dark)); border-color: #2a9d96; color: #04231f; }
.btn-gold { background: linear-gradient(160deg, var(--gold), var(--gold-dark)); border-color: #d8a63e; color: #2a1d05; }
.btn-danger { background: linear-gradient(160deg, #ef7a66, #c74832); border-color: #d95740; color: #2b0c06; }
.btn-ghost { background: transparent; }
.btn-ghost.danger { color: var(--danger); border-color: rgba(229, 100, 79, .5); }
.btn-lg { font-size: 1.12rem; padding: 16px 26px; min-height: 60px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, a.nav-item:focus-visible, .btn:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

input[type="number"], input[type="date"], input[type="time"], input[type="text"], select {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 10px 12px; font-size: 1rem;
  font-family: inherit; min-height: 48px; width: 100%;
}
input[type="number"] { text-align: center; font-size: 1.15rem; font-weight: 700; }

/* ---------- paneles ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 1.12rem; letter-spacing: .03em; }
.panel h2 .panel-sub { display: block; font-size: .78rem; color: var(--muted); font-weight: 500; margin-top: 2px; }
.panel + .panel { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.section-title { margin: 20px 0 10px; font-size: .85rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

/* ---------- Inicio ---------- */
.home-top { display: grid; gap: 14px; }
@media (min-width: 920px) {
  .home-top { grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); align-items: start; }
  .home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .home-grid .span-2 { grid-column: span 2; }
}

.map-panel { position: relative; }
.map-svg { width: 100%; height: auto; display: block; border-radius: var(--radius-s); background: #0d1c15; }
.map-note { font-size: .74rem; color: var(--muted); margin: 8px 2px 0; }
.map-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .74rem; color: var(--text-2); margin-top: 6px; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

.activity-box { display: flex; flex-direction: column; gap: 14px; }
.chrono { text-align: center; }
.chrono .chrono-time {
  font-family: var(--mono); font-size: clamp(2.6rem, 8vw, 3.6rem); font-weight: 800;
  letter-spacing: .04em; color: var(--text); line-height: 1.05; margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.chrono .chrono-dist { font-size: 1.05rem; color: var(--green); font-weight: 700; }
.chrono .chrono-pace { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.chrono.state-paused .chrono-time { color: var(--gold); }
.chrono.state-idle .chrono-time { color: var(--muted); }

.speed-control { display: flex; align-items: center; gap: 10px; justify-content: center; }
.speed-control .speed-input { width: 110px; }
.speed-control .btn-step { width: 54px; height: 54px; border-radius: 50%; font-size: 1.5rem; padding: 0; font-weight: 800; }
.speed-hint { text-align: center; font-size: .74rem; color: var(--muted); margin-top: 6px; }

.activity-actions { display: grid; gap: 10px; }
.activity-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat-quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.stat-quick > div { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px; text-align: center; }
.stat-quick .v { font-size: 1.05rem; font-weight: 800; color: var(--teal); }
.stat-quick .k { font-size: .68rem; color: var(--muted); }

/* Diagrama circular */
.donut-wrap { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; }
.donut { position: relative; width: 180px; height: 180px; }
.donut svg { transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-center .big { font-size: 1.7rem; font-weight: 800; color: var(--gold); line-height: 1; }
.donut-center .sub { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.donut-legend { display: grid; gap: 8px; min-width: 190px; }
.donut-legend .row { display: flex; justify-content: space-between; gap: 14px; border-bottom: 1px dashed var(--line); padding-bottom: 6px; font-size: .88rem; }
.donut-legend .row b { color: var(--text); }
.donut-legend .row span { color: var(--text-2); }

/* Gráfico semanal */
.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 150px; margin-top: 8px; }
.week-col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week-col .bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.week-col .bar {
  width: min(70%, 38px); border-radius: 6px 6px 2px 2px; min-height: 3px;
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
}
.week-col.today .bar { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); }
.week-col .wlab { font-size: .72rem; color: var(--muted); font-weight: 700; }
.week-col.today .wlab { color: var(--gold); }
.week-col .wkm { font-size: .64rem; color: var(--text-2); }

/* Barras por sesión */
.session-bars { display: grid; gap: 8px; margin-top: 6px; max-height: 220px; overflow: auto; padding-right: 4px; }
.session-bar-row { display: grid; grid-template-columns: 92px 1fr 70px; gap: 10px; align-items: center; font-size: .8rem; }
.session-bar-row .d { color: var(--muted); }
.session-bar-row .track { background: var(--bg-2); border-radius: 999px; height: 14px; overflow: hidden; }
.session-bar-row .fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--teal)); border-radius: 999px; }
.session-bar-row .km { color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.session-empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 12px 0; }

/* Etapas */
.stage-bars { display: grid; gap: 12px; margin-top: 8px; }
.stage-row .stage-head { display: flex; justify-content: space-between; gap: 10px; font-size: .82rem; margin-bottom: 5px; }
.stage-row .stage-head b { color: var(--text); }
.stage-row .stage-head span { color: var(--muted); white-space: nowrap; }
.stage-row .track { background: var(--bg-2); border: 1px solid var(--line); height: 18px; border-radius: 999px; overflow: hidden; }
.stage-row .fill { height: 100%; background: linear-gradient(90deg, var(--gold-dark), var(--gold)); border-radius: 999px; }
.stage-row.completed .fill { background: linear-gradient(90deg, var(--green-dark), var(--green)); }

/* Resumen hoy + sellos recientes */
.today-strip { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.today-strip > div { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px; }
.today-strip .k { font-size: .7rem; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.today-strip .v { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.recent-stamps { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.mini-stamp {
  width: 58px; height: 58px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 32% 28%, #f5d68b, var(--gold) 60%, var(--gold-dark));
  color: #40300a; font-size: .55rem; font-weight: 800; text-align: center; padding: 5px;
  line-height: 1.15; box-shadow: 0 2px 10px rgba(230, 179, 76, .35); letter-spacing: .01em;
}
.no-data { color: var(--muted); font-size: .85rem; }

/* Avisos */
.notice {
  border: 1px solid rgba(230, 179, 76, .45); background: rgba(230, 179, 76, .10);
  border-radius: var(--radius-s); padding: 12px 14px; font-size: .88rem; color: #f3d9a2;
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.notice.blue { border-color: rgba(47, 185, 176, .45); background: rgba(47, 185, 176, .10); color: #bfe9e5; }
.notice.plain { border-color: var(--line); background: var(--bg-2); color: var(--text-2); }
.info-note { font-size: .8rem; color: var(--muted); }
.info-note ul { margin: 6px 0; padding-left: 18px; }

/* ---------- Actividad (historial) ---------- */
.history-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.history-table th, .history-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history-table th { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.history-table td.num { font-variant-numeric: tabular-nums; }
.history-table .actions-cell { display: flex; gap: 6px; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2);
  border-radius: var(--radius-s); padding: 8px 12px; cursor: pointer; font-size: .8rem; font-weight: 700; min-height: 40px;
}
.icon-btn:hover { color: var(--text); filter: brightness(1.15); }
.icon-btn.danger { color: var(--danger); border-color: rgba(229, 100, 79, .5); }
.history-wrap { overflow-x: auto; }

.totals-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.totals-strip > div { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px; }
.totals-strip .k { font-size: .7rem; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.totals-strip .v { font-size: 1.3rem; font-weight: 800; }

/* Formulario dentro de la página */
.activity-form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 8px; }
.form-row label { font-size: .8rem; font-weight: 700; color: var(--text-2); letter-spacing: .03em; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-grid .form-row.full { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }
.form-error { color: #ffb3a5; font-size: .8rem; font-weight: 600; min-height: 1.1em; }
.form-errors { border: 1px solid rgba(229, 100, 79, .5); background: rgba(229, 100, 79, .10); border-radius: var(--radius-s); padding: 10px 14px; font-size: .85rem; color: #ffc9bd; }
.form-errors:empty { display: none; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Confirmación en línea (sin confirm()) */
.confirm-box { border: 1px solid rgba(229, 100, 79, .5); background: rgba(229, 100, 79, .08); border-radius: var(--radius-s); padding: 14px; display: grid; gap: 10px; margin-top: 10px; }
.confirm-box p { margin: 0; font-size: .9rem; }
.confirm-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Credencial ---------- */
.credential-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.credential-head .count { font-size: 1rem; color: var(--gold); font-weight: 800; }
.stamp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 14px; }
.stamp-card {
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  background: var(--bg-2);
}
.stamp-card .scalloped {
  width: 96px; height: 96px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.stamp-card.earned .scalloped {
  background: radial-gradient(circle at 30% 25%, #f7dda1, var(--gold) 55%, var(--gold-dark));
  box-shadow: 0 4px 18px rgba(230, 179, 76, .35), inset 0 0 0 3px rgba(255, 255, 255, .25);
}
.stamp-card.locked .scalloped {
  background: var(--panel-2); border: 2px solid var(--line);
}
.stamp-card .scalloped svg { width: 60%; height: 60%; }
.stamp-card .sc-name { font-weight: 800; font-size: .9rem; line-height: 1.2; }
.stamp-card .sc-meta { font-size: .72rem; color: var(--muted); }
.stamp-card.locked .sc-name { color: var(--muted); }
.stamp-card.earned { border-style: solid; border-color: rgba(230, 179, 76, .5); }
.stamp-km-chip { font-size: .66rem; color: var(--text-2); background: var(--panel-2); border-radius: 999px; padding: 2px 8px; }

/* ---------- Ajustes ---------- */
.settings-group { display: grid; gap: 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.setting-row .desc { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.setting-row input[type="number"] { width: 110px; }
.switch { position: relative; width: 62px; height: 34px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .slider {
  position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; transition: background .18s ease; pointer-events: none;
}
.switch .slider::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--muted); transition: transform .18s ease, background .18s ease;
}
.switch input:checked + .slider { background: rgba(53, 194, 131, .25); }
.switch input:checked + .slider::after { transform: translateX(28px); background: var(--green); }
.switch input:focus-visible + .slider { outline: 3px solid var(--gold); outline-offset: 2px; }

.backup-status { font-size: .85rem; color: var(--text-2); display: grid; gap: 4px; }
.backup-status b { color: var(--text); }
.restore-preview { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 14px; display: grid; gap: 6px; font-size: .88rem; }
.restore-preview .num { color: var(--gold); font-weight: 800; }

/* ---------- Toasts y notificaciones ---------- */
.toast-area { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 480px); }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--teal);
  border-radius: var(--radius-s); padding: 12px 16px; font-size: .9rem; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px;
}
.toast.success { border-left-color: var(--green); }
.toast.warn { border-left-color: var(--gold); }
.toast.error { border-left-color: var(--danger); }
.notification-area { position: fixed; bottom: calc(92px + env(safe-area-inset-bottom)); right: 14px; z-index: 60; display: grid; gap: 8px; width: min(88vw, 360px); }
.stamp-toast {
  background: linear-gradient(160deg, #223c30, #16291f); border: 1px solid rgba(230, 179, 76, .55);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; animation: pop .35s ease;
}
.stamp-toast .st-label { font-size: .68rem; color: var(--gold); text-transform: uppercase; letter-spacing: .12em; font-weight: 800; }
.stamp-toast .st-name { font-weight: 800; font-size: .95rem; }
.stamp-toast .st-date { font-size: .74rem; color: var(--muted); }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Llegada a Santiago */
.arrival-banner {
  border: 1px solid var(--gold); border-radius: var(--radius); overflow: hidden; position: relative;
  background: linear-gradient(150deg, rgba(230, 179, 76, .18), rgba(53, 194, 131, .12));
  padding: 22px; text-align: center;
}
.arrival-banner h2 { color: var(--gold); font-size: 1.4rem; margin: 0 0 6px; letter-spacing: .04em; }
.arrival-banner p { margin: 0; color: var(--text-2); font-size: .9rem; }
.arrival-banner .shell-big { width: 74px; height: 74px; margin: 0 auto 10px; }

/* Utilidades responsive */
@media (max-width: 640px) {
  .app-shell { padding: 10px 10px calc(80px + env(safe-area-inset-bottom)); }
  .activity-actions .row { grid-template-columns: 1fr; }
  .session-bar-row { grid-template-columns: 70px 1fr 58px; font-size: .72rem; }
  .history-table th, .history-table td { padding: 8px 6px; font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
