:root {
  --navy: #0e2545;
  --navy-700: #15315a;
  --navy-900: #0a1c36;
  --gold: #c8a44d;
  --gold-600: #b08f3c;
  --bg: #f5f6f8;
  --white: #ffffff;
  --text: #1a2233;
  --text-light: #647089;
  --border: #e3e7ee;
  --success: #0f9d6b;
  --error: #d6453d;
  --info: #2f6fdb;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(14, 37, 69, 0.08);
  --header-h: 60px;
  --bottom-nav-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

body.nav-open { overflow: hidden; }

/* ── Header ───────────────────────────────────────────── */
header.site {
  background: var(--navy);
  border-bottom: 3px solid var(--gold);
  padding: 0.65rem clamp(1rem, 2vw, 2rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--header-h);
}
.brand { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; flex-shrink: 0; }
.brand img { height: 40px; width: auto; display: block; }
.brand span {
  color: var(--white);
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 0.95rem;
}

.nav-desktop { display: flex; gap: 1.1rem; align-items: center; flex-wrap: wrap; }
.nav-desktop a {
  color: #d7deea;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}
.nav-desktop a:hover,
.nav-desktop a.active { color: var(--gold); }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--white);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 28, 54, 0.45);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.nav-backdrop.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.nav-drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 85vw);
  background: var(--white);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  box-shadow: -8px 0 32px rgba(14, 37, 69, 0.15);
  padding: calc(var(--header-h) + var(--safe-top) + 0.5rem) 1.25rem 1.5rem;
  overflow-y: auto;
}
.nav-drawer.open {
  display: block;
  transform: translateX(0);
}
.nav-drawer nav { display: flex; flex-direction: column; gap: 0.15rem; }
.nav-drawer a {
  display: block;
  padding: 0.85rem 0.75rem;
  color: var(--navy);
  text-decoration: none;
  font-weight: 500;
  font-size: 1rem;
  border-radius: 10px;
}
.nav-drawer a:hover,
.nav-drawer a.active { background: var(--bg); color: var(--navy-700); }
.nav-drawer-logout { color: var(--error) !important; margin-top: 0.5rem; border-top: 1px solid var(--border); padding-top: 1rem !important; }
.nav-drawer-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem 1.25rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.nav-drawer-user img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--gold); }

.user-chip {
  display: flex; align-items: center; gap: 0.5rem;
  color: #d7deea; font-size: 0.85rem;
}
.user-chip img { height: 28px; width: 28px; border-radius: 50%; border: 2px solid var(--gold); }

/* ── Bottom nav (mobile PWA) ──────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.25rem calc(0.35rem + var(--safe-bottom));
  justify-content: space-around;
  align-items: stretch;
  box-shadow: 0 -4px 20px rgba(14, 37, 69, 0.08);
}
.bottom-nav a,
.bottom-nav .bottom-nav-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  flex: 1;
  min-height: 52px;
  padding: 0.25rem;
  border: none;
  background: none;
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
}
.bottom-nav svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.bottom-nav a.active,
.bottom-nav a:hover,
.bottom-nav .bottom-nav-more:hover { color: var(--navy); }
.bottom-nav a.active svg { fill: var(--gold-600); }

/* ── Layout ───────────────────────────────────────────── */
main {
  flex: 1;
  width: 100%;
  padding: clamp(1rem, 2vw, 1.75rem) clamp(1rem, 2.5vw, 2.5rem);
  padding-bottom: calc(clamp(1rem, 2vw, 1.75rem) + var(--bottom-nav-h));
}

footer.site {
  text-align: center;
  color: var(--text-light);
  font-size: 0.8rem;
  padding: 1rem clamp(1rem, 2vw, 2rem);
  padding-bottom: calc(1rem + var(--bottom-nav-h) + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

/* ── Flash ────────────────────────────────────────────── */
.flash {
  padding: 0.8rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.flash.success { background: #e3f6ee; color: var(--success); border-color: #bce8d4; }
.flash.error { background: #fdecea; color: var(--error); border-color: #f6cfcb; }
.flash.info { background: #e8f0fc; color: var(--info); border-color: #cadcf7; }

/* ── Cards ────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 2vw, 2rem);
  box-shadow: var(--shadow);
  width: 100%;
}
.card h2 { color: var(--navy); margin-bottom: 0.4rem; }
.card .muted { color: var(--text-light); font-size: 0.92rem; }

/* ── Sources (planillas) ─────────────────────────────── */
.sources-list {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.sources-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.sources-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--navy);
  font-weight: 600;
  text-decoration: none;
}
.sources-link:hover { color: var(--gold-600); text-decoration: underline; }
.sources-ext {
  width: 14px;
  height: 14px;
  fill: currentColor;
  flex-shrink: 0;
  opacity: 0.7;
}
.sources-desc {
  color: var(--text-light);
  font-size: 0.88rem;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.7rem 1.4rem;
  min-height: 44px;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: 10px;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--navy-700); }
.btn:active { transform: translateY(1px); }
.btn-gold { background: var(--gold); color: var(--navy-900); }
.btn-gold:hover { background: var(--gold-600); }
.btn-outline { background: transparent; color: var(--navy); border: 1.5px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-link {
  background: none; border: none; padding: 0; margin-left: 0.75rem;
  color: var(--error); font: inherit; cursor: pointer; text-decoration: underline;
  min-height: auto;
}
.btn-link:hover { color: #a8322b; }

/* ── Icon buttons (listas) ───────────────────────────── */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  pointer-events: none;
}
.btn-icon:hover { background: var(--bg); }
.btn-icon:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn-icon-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--navy-900);
}
.btn-icon-gold:hover { background: var(--gold-600); }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.35rem 0.6rem;
  background: var(--navy-900);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
  z-index: 20;
}
[data-tooltip]::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--navy-900);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
  z-index: 20;
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before,
[data-tooltip]:focus-visible::after,
[data-tooltip]:focus-visible::before {
  opacity: 1;
  visibility: visible;
}

/* ── Hero (landing) ───────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-900) 100%);
  color: var(--white);
  border-radius: var(--radius);
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1.25rem, 3vw, 2.5rem);
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 5px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.hero img.logo { height: clamp(80px, 15vw, 120px); margin-bottom: 1.5rem; }
.hero h1 { font-size: clamp(1.5rem, 3vw, 2rem); letter-spacing: 0.05em; margin-bottom: 0.75rem; }
.hero p { color: #c2cde0; max-width: 540px; margin: 0 auto 2rem; line-height: 1.6; }
.hero .accent { color: var(--gold); }

/* ── Feature grid ─────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 1.25rem;
  margin-top: 1.75rem;
}
.tile {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: 12px;
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.12s, box-shadow 0.12s;
}
a.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.tile h3 { color: var(--navy); margin-bottom: 0.4rem; font-size: 1.05rem; }
.tile p { color: var(--text-light); font-size: 0.88rem; line-height: 1.5; }

/* ── Login ────────────────────────────────────────────── */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 55vh; }
.login-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-top: 4px solid var(--gold);
  border-radius: 16px;
  padding: clamp(1.75rem, 4vw, 2.75rem) clamp(1.25rem, 3vw, 2.5rem);
  width: 100%; max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card img.logo { height: 90px; margin-bottom: 1.25rem; }
.login-card h2 { color: var(--navy); margin-bottom: 0.4rem; }
.login-card p { color: var(--text-light); font-size: 0.9rem; margin-bottom: 1.75rem; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  width: 100%; padding: 0.85rem 1.25rem;
  min-height: 48px;
  border: 2px solid var(--border); border-radius: 10px;
  background: var(--white);
  font-size: 0.95rem; font-weight: 600; color: var(--text);
  text-decoration: none; transition: border-color 0.2s, background 0.2s;
}
.google-btn:hover { border-color: var(--navy); background: var(--bg); }
.g-icon { width: 22px; height: 22px; }

/* ── Tables ───────────────────────────────────────────── */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--white);
}
.table-scroll table { margin-top: 0; }
table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.65rem 0.8rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-light); font-weight: 600; white-space: nowrap; }
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.admin { background: #fbf1d6; color: var(--gold-600); }
.badge.user { background: #eef1f6; color: var(--text-light); }

.notice {
  background: #fbf6e7;
  border: 1px solid #ecdfb6;
  color: #7a6320;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  margin-top: 1rem;
}

/* ── Desktop: pantalla completa ───────────────────────── */
@media (min-width: 1024px) {
  main {
    padding: 1.5rem 2rem 2rem;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (min-width: 1400px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

/* ── Mobile / PWA ───────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --bottom-nav-h: 64px;
    --header-h: 56px;
  }

  .brand span { display: none; }
  .nav-desktop { display: none; }
  .nav-toggle { display: flex; }
  .bottom-nav { display: flex; }

  header.site {
    padding-left: max(1rem, var(--safe-left));
    padding-right: max(1rem, var(--safe-right));
  }

  main {
    padding: 1rem;
    padding-bottom: calc(1rem + var(--bottom-nav-h) + var(--safe-bottom));
  }

  footer.site {
    display: none;
  }

  .card {
    padding: 1.15rem;
    border-radius: 12px;
  }

  .hero {
    border-radius: 12px;
  }

  th, td {
    padding: 0.75rem 0.65rem;
    font-size: 0.85rem;
  }

  .login-card .btn,
  .google-btn {
    width: 100%;
  }
}

/* Standalone PWA (instalada en el celular) */
html.pwa-standalone {
  --bottom-nav-h: 64px;
}
html.pwa-standalone body {
  background: var(--white);
}
html.pwa-standalone main {
  background: var(--bg);
}
html.pwa-standalone header.site {
  padding-top: calc(0.5rem + var(--safe-top));
}

@media (max-width: 480px) {
  .brand img { height: 34px; }
  .bottom-nav a span,
  .bottom-nav .bottom-nav-more span {
    font-size: 0.62rem;
  }
}
