:root {
  --bg: #f4f7f9;
  --ink: #0f172a;
  --muted: #4b5563;
  --card: #ffffff;
  --line: #dbe4ea;
  --brand: #0f766e;
  --brand-soft: #dff8f5;
  --success: #16a34a;
  --warn: #b45309;
  --danger: #be123c;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
  --radius: 22px;
}

* { box-sizing: border-box; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); font-family: 'Manrope', system-ui, sans-serif; }

/* ---------- Barra superior ---------- */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(255,255,255,0.9);
  border-radius: 999px;
  padding: 10px 14px 10px 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.02em; color: inherit; text-decoration: none; min-width: 0; }
.logo-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-badge {
  width: 36px; height: 36px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #0ea5a0); color: #fff; font-size: 18px; font-weight: 900;
}
.nav-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Botones ---------- */
.ghost-btn, .primary-btn {
  border: 0; border-radius: 12px; cursor: pointer; padding: 10px 14px; font-weight: 800;
  text-decoration: none; display: inline-block; text-align: center; transition: transform 0.15s ease, opacity 0.15s ease;
}
.ghost-btn:hover, .primary-btn:hover { transform: translateY(-1px); }
.ghost-btn { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.primary-btn { background: linear-gradient(135deg, var(--brand), #0ea5a0); color: #fff; box-shadow: 0 10px 24px rgba(15, 118, 110, 0.22); }
button:disabled { opacity: 0.6; cursor: wait; }
.danger-btn { color: var(--danger) !important; border-color: #fecdd3 !important; }
.danger-btn.solid { background: var(--danger); color: #fff !important; border-color: var(--danger) !important; }
.small-link { background: transparent; border: 0; color: var(--brand); cursor: pointer; font-weight: 800; padding: 0; text-align: left; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 800; color: inherit; cursor: pointer; text-decoration: underline; text-decoration-color: rgba(15,118,110,0.35); text-underline-offset: 3px; }
.link-btn:hover { color: var(--brand); }

.mini-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 10px;
  padding: 6px 10px; font-weight: 800; font-size: 0.82rem; cursor: pointer; text-decoration: none; display: inline-block;
}
.mini-btn:hover { border-color: var(--brand); color: var(--brand); }
.mini-btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.mini-btn.danger { color: var(--danger); }
.mini-btn.danger:hover { border-color: var(--danger); }

.lang-switch { display: inline-flex; background: #f1f5f9; border-radius: 12px; padding: 3px; }
.lang-switch button { border: 0; background: transparent; border-radius: 9px; padding: 6px 9px; font-weight: 800; font-size: 0.82rem; color: var(--muted); cursor: pointer; }
.lang-switch button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(15,23,42,0.08); }

.user-chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.color-dot { width: 14px; height: 14px; flex: none; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,0.12); vertical-align: middle; }

.bell { position: relative; padding: 10px 12px; }
.bell svg { width: 18px; height: 18px; display: block; }
.bell-count {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 900; display: grid; place-items: center;
}

/* ---------- Tarjetas y datos ---------- */
.panel { background: var(--card); border: 1px solid rgba(255,255,255,0.9); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-box { background: #f8fafb; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat-kicker { color: var(--muted); font-size: 12px; margin-bottom: 6px; font-weight: 700; }
.stat-value { font-size: clamp(1.3rem, 2vw, 1.8rem); font-weight: 800; letter-spacing: -0.04em; }
.text-muted { color: var(--muted); font-size: 0.92rem; line-height: 1.5; margin: 0; }
.chip { background: #f8fafb; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 12px; color: var(--muted); font-weight: 800; }
.tag { font-size: 11px; font-weight: 800; border-radius: 999px; padding: 2px 8px; background: #e2e8f0; color: #334155; white-space: nowrap; }
.tag.mine { background: var(--brand-soft); color: var(--brand); }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.danger { background: #ffe4e6; color: #9f1239; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.list { display: grid; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
h3 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; }

.row-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 12px; background: #f8fafb;
}
.row-item .name { flex: 1; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item b { font-size: 0.9rem; white-space: nowrap; }
.row-item.me { border-color: var(--brand); background: var(--brand-soft); }
.rank-pos { width: 28px; font-weight: 900; color: var(--muted); }

.progress { height: 10px; border-radius: 999px; background: #e6edf2; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), #14b8a6); border-radius: inherit; }

/* ---------- Niveles ---------- */
.lvl { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: 30px; height: 20px; padding: 0 6px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 900; color: #fff; vertical-align: middle; line-height: 1; }
.lvl-1 { background: #64748b; }
.lvl-2 { background: #0f766e; }
.lvl-3 { background: #2563eb; }
.lvl-4 { background: #7c3aed; }
.lvl-5 { background: #be123c; }
.lvl-6 { background: linear-gradient(135deg, #f59e0b, #b45309); }
.level-card { display: flex; gap: 14px; align-items: center; padding: 14px; border-radius: 16px; background: #f8fafb; border: 1px solid var(--line); }
.level-medal { width: 54px; height: 54px; flex: none; border-radius: 16px; display: grid; place-items: center; color: #fff; font-size: 1.5rem; font-weight: 900; }
.level-name { font-family: 'Sora', 'Manrope', sans-serif; font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: #f1f5f9; border-radius: 14px; padding: 4px; }
.seg button { border: 0; border-radius: 10px; padding: 9px 6px; font-weight: 800; background: transparent; color: var(--muted); cursor: pointer; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(15,23,42,0.08); }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.badge { border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; background: #f8fafb; display: grid; gap: 4px; }
.badge strong { font-size: 0.85rem; }
.badge small { color: var(--muted); font-size: 0.75rem; line-height: 1.3; }
.badge .medal { width: 34px; height: 34px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 0.75rem; color: #fff; background: linear-gradient(135deg, #f59e0b, #ea580c); }
.badge.locked { opacity: 0.45; }
.badge.locked .medal { background: #cbd5e1; }

/* ---------- Formularios ---------- */
.field { width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); min-width: 0; }
.field:focus { outline: 2px solid rgba(15,118,110,0.25); border-color: var(--brand); }
textarea.field { resize: vertical; min-height: 72px; }
.form-msg { min-height: 1.2em; font-size: 0.92rem; font-weight: 700; color: var(--danger); }
.form-msg.ok { color: var(--success); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.link-row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.note { margin: 0; padding: 12px 14px; border-radius: 12px; line-height: 1.5; font-weight: 600; }
.note.danger { background: #fff1f2; color: #9f1239; }
.note.warn { background: #fffbeb; color: #92400e; }
.note.ok { background: var(--brand-soft); color: var(--brand); }

.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.3rem; font-weight: 800; letter-spacing: 0.06em;
  text-align: center; padding: 14px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); user-select: all;
}

.dropzone {
  display: grid; place-items: center; gap: 6px; text-align: center; padding: 26px 16px; border: 2px dashed var(--line);
  border-radius: 16px; background: #f8fafb; cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone.drag, .dropzone:focus-within { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.has-file { border-style: solid; border-color: var(--brand); }
.dropzone-icon { font-size: 1.8rem; line-height: 1; }
.dropzone-file { font-weight: 800; color: var(--brand); word-break: break-all; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------- Perfil ---------- */
.profile-head { display: flex; align-items: center; gap: 12px; }
.profile-avatar {
  width: 48px; height: 48px; flex: none; border-radius: 14px; display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 1.3rem; text-transform: uppercase;
}
.profile-name { font-weight: 900; font-size: 1.15rem; word-break: break-all; }
.profile-section { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type="color"] { width: 56px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; }
.color-row .primary-btn, .color-row .field { flex: 1; }

/* ---------- Detalle de ruta ---------- */
.elev-chart { width: 100%; height: auto; display: block; background: #f8fafb; border: 1px solid var(--line); border-radius: 14px; }
.elev-chart text { font-size: 11px; fill: var(--muted); font-family: 'Manrope', system-ui, sans-serif; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: none; align-items: center;
  justify-content: center; z-index: 3000; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: #fff; border-radius: 22px;
  box-shadow: 0 24px 70px rgba(15,23,42,0.24); padding: 18px 18px 16px; border: 1px solid #edf2f7;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 900; font-size: 1.2rem;
  position: sticky; top: -18px; z-index: 5; background: #fff; margin: -18px -18px 14px; padding: 18px 18px 8px;
}
.x-btn { border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; color: var(--muted); min-width: 40px; min-height: 40px; border-radius: 12px; }
.x-btn:hover { background: #f1f5f9; }
.modal-content { display: grid; gap: 12px; }

/* ---------- Avisos ---------- */
.toasts { position: fixed; top: 88px; right: 14px; z-index: 3500; display: grid; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow); max-width: 340px; }
.toast.error { background: var(--danger); }

.notif { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafb; }
.notif.unread { border-color: var(--brand); background: var(--brand-soft); }
.notif small { color: var(--muted); font-size: 0.78rem; }

/* ---------- Subida múltiple ---------- */
.preview-map { height: 190px; border-radius: 14px; border: 1px solid var(--line); overflow: hidden; }
.file-row { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafb; cursor: pointer; }
.file-row.active { border-color: var(--brand); background: var(--brand-soft); }
.file-row-main { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; align-items: center; }
.file-row .field { padding: 8px 10px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

/* ---------- Tutorial ---------- */
.tutorial { display: grid; gap: 10px; padding: 8px 4px 4px; text-align: center; }
.tutorial-num { justify-self: center; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 4px 10px; font-weight: 800; font-size: 0.8rem; }
.tutorial-dots { display: flex; justify-content: center; gap: 6px; }
.tutorial-dots span { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; }
.tutorial-dots span.on { background: var(--brand); width: 22px; border-radius: 999px; }

.site-footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 18px 0 6px; }
.site-footer a { color: var(--brand); font-weight: 700; }

@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { gap: 8px; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 .stat-box, .grid-3 .stat-box { padding: 10px; }
  .grid-2 .stat-value, .grid-3 .stat-value { font-size: 1.15rem; }
  .grid-2 .stat-kicker, .grid-3 .stat-kicker { font-size: 0.7rem; margin-bottom: 4px; }
  /* 16px avoids the automatic zoom of iOS when focusing a field */
  .field { font-size: 16px; }
  .form-msg:empty { min-height: 0; }
  .dropzone { padding: 16px 12px; }
  .dropzone.has-file { padding: 10px 12px; }
  .dropzone.has-file .dropzone-icon, .dropzone.has-file .text-muted { display: none; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 22px 22px 0 0; border-bottom: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .toasts { left: 14px; right: 14px; top: auto; bottom: calc(18px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
@media (max-width: 380px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Barra superior compacta en móvil (páginas con data-collapse) ---------- */
.logo-short, .nav-menu-btn, .lbl-short { display: none; }
.nav-extras { display: contents; }
@media (max-width: 760px) {
  .nav[data-collapse] { gap: 8px; padding: 8px 10px 8px 12px; }
  .nav[data-collapse] .logo { gap: 8px; flex: none; }
  .nav[data-collapse] > .nav-actions, .nav[data-collapse] #navAuth { min-width: 0; }
  .nav[data-collapse] .user-chip { min-width: 0; max-width: 150px; }
  .nav[data-collapse] .logo-badge { width: 32px; height: 32px; border-radius: 10px; font-size: 16px; }
  .nav[data-collapse] .logo-text, .nav[data-collapse] .lbl-long { display: none; }
  .nav[data-collapse] .logo-short, .nav[data-collapse] .lbl-short { display: inline; }
  .nav[data-collapse] .logo-short { font-size: 0.95rem; }
  .nav[data-collapse] .nav-actions { flex-wrap: nowrap; gap: 6px; }
  .nav[data-collapse] .nav-actions .ghost-btn, .nav[data-collapse] .nav-actions .primary-btn { padding: 8px 9px; font-size: 0.86rem; white-space: nowrap; }
  .nav[data-collapse] .nav-menu-btn { display: inline-grid; place-items: center; min-width: 36px; font-size: 1.05rem; }
  .nav[data-collapse] .nav-extras { display: none; }
  .nav[data-collapse].menu-open .nav-extras {
    display: grid; gap: 8px; position: absolute; top: calc(100% + 8px); left: 0; right: 0; padding: 12px;
    background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  }
  .nav[data-collapse].menu-open .nav-extras .ghost-btn { text-align: center; padding: 12px; }
  .nav[data-collapse].menu-open .nav-extras .lang-switch button { flex: 1; padding: 9px; }
}
@media (max-width: 380px) {
  .nav[data-collapse] .logo-short { display: none; }
}
