/* ── Google Font ────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* ── Design Tokens ──────────────────────────────────────────── */
:root {
  /* Brand */
  --orchid:       #6A1B9A;
  --orchid-soft:  #8E24AA;
  --fuchsia:      #C2185B;
  --magenta:      #E91E63;
  --orange:       #FF5722;
  --yellow:       #FFEB3B;
  --cyan:         #00E5FF;
  --cosmic:       #1A1A2E;
  --gray:         #212121;
  --gray-mid:     #6B6B6B;  /* era #757575 — ratio 4.7:1 sobre #F7F7F9 ✅ WCAG AA */
  --gray-light:   #F7F7F9;
  --border:       #EBEBF0;
  --white:        #FFFFFF;
  --danger:       #D32F2F;
  --success:      #2E7D32;

  /* Gradients */
  --grad-primary: linear-gradient(135deg, var(--orchid) 0%, var(--fuchsia) 100%);
  --grad-warm:    linear-gradient(135deg, var(--fuchsia) 0%, var(--orange) 100%);

  /* Elevation */
  --shadow-1:      0 1px 4px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --shadow-2:      0 4px 16px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --shadow-3:      0 8px 32px rgba(0,0,0,.14), 0 4px 12px rgba(0,0,0,.08);
  --shadow-up:     0 -1px 0 rgba(0,0,0,.06), 0 -4px 20px rgba(0,0,0,.08);
  --shadow-orchid: 0 8px 24px rgba(106,27,154,.28);

  /* Radius */
  --r-xs:   6px;
  --r-s:    10px;
  --r-m:    14px;
  --r-l:    20px;
  --r-xl:   28px;
  --r-full: 999px;

  /* Layout */
  --nav-h:    64px;
  --safe-b:   env(safe-area-inset-bottom, 0px);
  --safe-t:   env(safe-area-inset-top, 0px);
  --page-max: 480px;

  /* Motion */
  --t-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-med:  250ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 380ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Surface */
  --surface:     #FFFFFF;
  --surface-alt: #F7F5FC;

  /* Semantic states */
  --warning: #E65100;
  --info:    #00798A;

  /* Shadow alias */
  --shadow-s: var(--shadow-1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-light);
  color: var(--gray);
  min-height: 100dvh;
  padding-bottom: 0;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea { font: inherit; }

/* ── Typography ─────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; letter-spacing: -.4px; }
h2 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.3px; }
h3 { font-size: 1.05rem; font-weight: 600; }
p  { line-height: 1.65; }

.text-muted    { color: var(--gray-mid); font-size: .875rem; }
.text-cyan     { color: var(--cyan); }
.text-orchid   { color: var(--orchid); }
.text-center   { text-align: center; }
.text-sm       { font-size: .85rem; }
.text-xs       { font-size: .75rem; }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

/* ── Layout ─────────────────────────────────────────────────── */
#app {
  max-width: var(--page-max);
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

.view {
  padding: calc(var(--safe-t) + 64px) 16px 8px;
  animation: view-enter var(--t-med) both;
}

@keyframes view-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Sidebar Nav ─────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  left: 0; top: 0;
  width: 240px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding: calc(var(--safe-t) + 20px) 14px 20px;
  gap: 2px;
  background: var(--white);
  border-right: 1px solid var(--border);
  z-index: 200;
  overflow-y: auto;
}

/* Mobile: empieza fuera de pantalla, desliza al abrir */
@media (max-width: 767px) {
  .bottom-nav {
    transform: translateX(-100%);
    transition: transform var(--t-med);
    box-shadow: var(--shadow-3);
  }
  .bottom-nav.open { transform: translateX(0); }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
  opacity: 0;
  transition: opacity var(--t-med);
}
.sidebar-overlay.visible { opacity: 1; }

.sidebar-toggle {
  position: fixed;
  top: calc(var(--safe-t) + 12px);
  left: 12px;
  z-index: 120;
  width: 40px; height: 40px;
  border-radius: var(--r-m);
  background: var(--white);
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--orchid);
  transition: box-shadow var(--t-fast);
}
.sidebar-toggle:active { box-shadow: var(--shadow-1); }

@media (min-width: 768px) { .sidebar-toggle { display: none; } }

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  width: 100%;
  flex-shrink: 0;
}
.nav-brand-logo {
  width: 32px; height: 32px;
  object-fit: contain;
  border-radius: var(--r-s);
  padding: 2px;
  box-shadow: var(--shadow-1);
  background: var(--white);
}
.nav-brand-name {
  font-size: .975rem;
  font-weight: 700;
  color: var(--orchid);
  letter-spacing: -.025em;
}

.nav-sep {
  width: calc(100% - 20px);
  height: 1px;
  background: var(--border);
  margin: 6px 10px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  color: var(--gray-mid);
  padding: 10px 12px;
  border-radius: var(--r-m);
  transition: color var(--t-fast), background var(--t-fast);
  text-decoration: none;
  width: 100%;
  flex-shrink: 0;
}
.nav-item:hover { background: var(--gray-light); }
.nav-item-danger { color: var(--danger) !important; }

.nav-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--r-s);
  transition: background var(--t-med), color var(--t-fast), box-shadow var(--t-med);
  color: currentColor;
  flex-shrink: 0;
}

.nav-label {
  font-size: .875rem;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
}

.nav-item.active { color: var(--orchid); background: rgba(106,27,154,.07); }
.nav-item.active .nav-icon-wrap {
  background: var(--grad-primary);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(106,27,154,.32);
}
.nav-item.active .nav-label { color: var(--orchid); }

/* ── View Header ────────────────────────────────────────────── */
.view-header {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.view-header-left { flex: 1; }
.view-header .subtitle {
  color: var(--gray-mid);
  font-size: .875rem;
  margin-top: 3px;
  font-weight: 400;
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--safe-b) + 20px);
  left: 50%; transform: translateX(-50%);
  background: var(--cosmic);
  color: var(--white);
  padding: 12px 22px;
  border-radius: var(--r-full);
  font-size: .875rem;
  font-weight: 600;
  z-index: 300;
  white-space: nowrap;
  box-shadow: var(--shadow-3);
  transition: opacity var(--t-fast), transform var(--t-fast);
  pointer-events: none;
}
.toast.error   { background: var(--danger); }
.toast.success { background: var(--success); }
.toast.hidden  { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-4   { margin-top: 4px; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-4   { margin-bottom: 4px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.mb-24  { margin-bottom: 24px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.flex   { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.w-full { width: 100%; }
.rounded-full { border-radius: var(--r-full); }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cronómetro activo — banner persistente ─────────────────── */
.crono-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--orchid);
  color: #fff;
  font-size: .85rem;
  font-weight: 500;
  transition: opacity .2s;
  position: sticky;
  top: 0;
  z-index: 90;
}
.crono-banner.hidden { display: none; }
.crono-banner-icon   { font-size: 1rem; flex-shrink: 0; }
.crono-banner-nombre { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crono-banner-tiempo { font-variant-numeric: tabular-nums; font-weight: 700; flex-shrink: 0; }
.crono-banner-cta    { font-size: .78rem; opacity: .85; flex-shrink: 0; }

/* ── Desktop Layout (768px+) ───────────────────────────────── */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  #app { max-width: none; }
  #bottom-nav:not(.hidden) ~ #app { margin-left: 240px; }
  #bottom-nav:not(.hidden) ~ .crono-banner { margin-left: 240px; }
  .view { max-width: 880px; padding: 36px 48px; }
  .toast { bottom: 28px; right: 32px; left: auto; transform: none; }
  .toast.hidden { opacity: 0; transform: translateY(8px); }
}

/* ── Skip link ───────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--orchid);
  color: var(--white);
  padding: 8px 16px;
  border-radius: 0 0 var(--r-s) 0;
  font-weight: 600;
  font-size: .875rem;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* ── Focus visible ───────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--orchid);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
