:root {
  --bg: #eef3f6;
  --bg-accent: #e3eef3;
  --surface: #ffffff;
  --ink: #0b1f2a;
  --muted: #5b7380;
  --brand: #1f6f8b;
  --brand-dark: #0f3d4c;
  --brand-soft: #d7ebf2;
  --accent: #c2410c;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #ffedd5;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --line: #d0dde5;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(15, 61, 76, 0.07);
  --shadow-sm: 0 2px 10px rgba(15, 61, 76, 0.05);
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --dock-h: 68px;
  --touch: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 100% 0%, rgba(31, 111, 139, 0.1), transparent 55%),
    linear-gradient(180deg, #e8f1f5 0%, var(--bg) 35%, #e9f0f4 100%);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); text-decoration: underline; }

/* ——— App shell ——— */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}

.sidebar {
  display: none;
  flex-direction: column;
  background: linear-gradient(180deg, #0b1f2a 0%, #0f3d4c 55%, #134a5c 100%);
  color: #e8f3f7;
  padding: 1.25rem 1rem 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.35rem 0.75rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 1rem;
  text-decoration: none;
  color: #fff;
}
.sidebar-brand:hover { text-decoration: none; color: #fff; }
.sidebar-brand .brand-name {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.sidebar-brand .brand-sub {
  font-size: 0.78rem;
  color: #9fc0cd;
  font-weight: 500;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}
.sidebar-nav a,
.mobile-drawer a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  color: #c5dbe4;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover,
.mobile-drawer a:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  text-decoration: none;
}
.sidebar-nav a.active,
.mobile-drawer a.active {
  background: rgba(31, 111, 139, 0.55);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.nav-ico {
  width: 1.35rem;
  text-align: center;
  opacity: 0.9;
  font-size: 1rem;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: grid;
  gap: 0.5rem;
}
.user-chip {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  font-size: 0.85rem;
}
.user-chip strong { display: block; color: #fff; }
.user-chip span { color: #9fc0cd; text-transform: capitalize; }

.main-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mobile-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  background: rgba(11, 31, 42, 0.96);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(8px);
}
.mobile-topbar .brand {
  font-family: var(--font-display);
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  font-size: 1.2rem;
}
.mobile-topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch);
  min-height: var(--touch);
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1.15rem;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: rgba(255,255,255,0.14); text-decoration: none; color: #fff; }

.mobile-drawer {
  display: none;
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(11, 31, 42, 0.97);
  z-index: 40;
  padding: 1rem;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}
body.nav-open .mobile-drawer { display: flex; }

.content {
  width: 100%;
  max-width: none;
  padding: 1.1rem 1rem calc(var(--dock-h) + 1.25rem);
  flex: 1;
}

.mobile-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  padding: 0.45rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom));
  background: rgba(11, 31, 42, 0.97);
  border-top: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
}
.mobile-dock a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  color: #9fc0cd;
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.4rem 0.2rem;
  border-radius: 12px;
  min-height: 52px;
}
.mobile-dock a .dock-ico { font-size: 1.15rem; line-height: 1; }
.mobile-dock a.active,
.mobile-dock a:hover { color: #fff; background: rgba(255,255,255,0.08); text-decoration: none; }
.mobile-dock a.dock-primary {
  background: var(--brand);
  color: #fff;
}
.mobile-dock a.dock-primary:hover { background: #24819f; }

/* ——— Typography / page ——— */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-title {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--brand-dark);
}
.subtitle { color: var(--muted); margin: 0; font-size: 0.98rem; }

.card, .panel, .hero-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.2rem;
}
.card h2, .panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  color: var(--brand-dark);
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1.15rem;
}
.stat {
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: linear-gradient(160deg, #fff, #f4fafc);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.75rem;
  color: var(--brand-dark);
  line-height: 1.1;
}
.stat span { color: var(--muted); font-size: 0.88rem; font-weight: 600; }

.progress-bar {
  height: 8px;
  background: #e5eef2;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.55rem;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), #2a9d8f);
  border-radius: inherit;
}

/* ——— Tabs ——— */
.tabs {
  display: flex;
  gap: 0.45rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-bottom: 1rem;
  padding-bottom: 0.15rem;
  -webkit-overflow-scrolling: touch;
}
.tabs a {
  flex: 0 0 auto;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  background: #e5eef2;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 650;
  white-space: nowrap;
}
.tabs a.active {
  background: var(--brand);
  color: #fff;
}
.tabs a:hover { text-decoration: none; }

/* ——— Tables / cards ——— */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}
.data-table th, .data-table td {
  padding: 0.8rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table tbody tr:hover { background: #f7fbfd; }
.data-table a { font-weight: 650; }

.desktop-only { display: none; }
.mobile-only { display: block; }

.card-list { display: grid; gap: 0.75rem; }
.item-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.item-card:hover {
  border-color: #a8c5d2;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}
.item-card-title {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--brand-dark);
  margin: 0 0 0.45rem;
}
.item-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}
.item-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.7rem;
}
.meta-dot::before {
  content: "·";
  margin-right: 0.45rem;
  color: #9bb0bb;
}

/* ——— Pills ——— */
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.22rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pill-abierto, .pill-planificada { background: #e2e8f0; color: #334155; }
.pill-en_progreso, .pill-en_preparacion { background: var(--warn-soft); color: #9a3412; }
.pill-evidencia_cargada, .pill-dia_de_visita { background: var(--info-soft); color: #1d4ed8; }
.pill-validado { background: var(--ok-soft); color: #166534; }
.pill-rechazado { background: var(--danger-soft); color: #991b1b; }
.pill-cerrada { background: #e2e8f0; color: #475569; }

.prio-critica, .prio-alta { color: var(--danger); font-weight: 800; }
.prio-media { color: var(--warn); font-weight: 700; }
.prio-baja { color: var(--muted); font-weight: 700; }

/* ——— Forms / buttons ——— */
.form-grid { display: grid; gap: 0.95rem; }
.form-card { max-width: 720px; }
label {
  display: grid;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.92rem;
}
input[type=text], input[type=email], input[type=password], input[type=date], input[type=file],
select, textarea {
  width: 100%;
  min-height: var(--touch);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  font: inherit;
  background: #fff;
}
textarea { min-height: 110px; resize: vertical; }
select { appearance: auto; }
.help { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.check-row {
  display: flex !important;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
}

.btn, button.btn, input[type=submit] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 0;
  border-radius: 12px;
  padding: 0.72rem 1.1rem;
  min-height: var(--touch);
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover, input[type=submit]:hover {
  background: var(--brand-dark);
  text-decoration: none;
  color: #fff;
}
.btn-secondary { background: #e8eef2; color: var(--ink); }
.btn-secondary:hover { background: #d7e3ea; color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-ok { background: var(--ok); }
.btn-warn { background: var(--warn); }
.btn-sm { padding: 0.4rem 0.75rem; min-height: 36px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.stack-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.form-sticky-actions {
  position: sticky;
  bottom: calc(var(--dock-h) + 0.5rem);
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  margin-top: 1rem;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* ——— Flashes / misc ——— */
.flashes { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.flash { padding: 0.8rem 1rem; border-radius: 12px; font-weight: 600; }
.flash-success { background: var(--ok-soft); color: #166534; }
.flash-danger { background: var(--danger-soft); color: #991b1b; }
.flash-warning { background: var(--warn-soft); color: #9a3412; }
.muted { color: var(--muted); }
.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 800;
}
.evidence-img {
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.empty-state {
  text-align: center;
  padding: 1.75rem 1rem;
  color: var(--muted);
}
.visit-hero {
  background: linear-gradient(135deg, #0f3d4c 0%, #1f6f8b 55%, #2a8aa5 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow);
}
.visit-hero .page-title { color: #fff; }
.visit-hero .subtitle { color: #cce3eb; }
.visit-hero .pill { background: rgba(255,255,255,0.18); color: #fff; }
.timeline-item {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.admin-tile {
  display: block;
  padding: 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
}
.admin-tile:hover {
  border-color: #a8c5d2;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}
.admin-tile h2 { margin: 0 0 0.35rem; font-size: 1.1rem; color: var(--brand-dark); }

.ready-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-weight: 800;
  font-size: 0.92rem;
}
.ready-verde { background: var(--ok-soft); color: #166534; }
.ready-ambar { background: var(--warn-soft); color: #9a3412; }
.ready-rojo { background: var(--danger-soft); color: #991b1b; }
.ready-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: currentColor;
}
.blocking-list { display: grid; gap: 0.45rem; margin-top: 0.75rem; }
.blocking-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  background: #fff7f7;
  border: 1px solid #fecaca;
  text-decoration: none;
  color: inherit;
}
.blocking-item:hover { text-decoration: none; border-color: #f87171; }
.privacy-note {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  margin-bottom: 1rem;
}
.filter-bar label { min-width: 140px; }
.check-grid { display: grid; gap: 0.65rem; }
.check-row-card {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.2fr;
  gap: 0.5rem;
  align-items: center;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}
@media (max-width: 767px) {
  .check-row-card { grid-template-columns: 1fr; }
}

[x-cloak] { display: none !important; }

.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.65rem;
  margin-top: 0.75rem;
}
.service-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: left;
  min-height: 88px;
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font: inherit;
  box-shadow: var(--shadow-sm);
}
.service-tile:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow);
}
.service-tile.status-ok { border-color: #86efac; background: #f0fdf4; }
.service-tile.status-no_ok { border-color: #fca5a5; background: #fff7f7; }
.service-tile.status-na { opacity: 0.75; }

.capture-panel {
  border-color: #7eb6c9 !important;
  box-shadow: var(--shadow);
}
.photo-drop {
  position: relative;
  display: grid;
  gap: 0.5rem;
  padding: 1rem;
  border: 2px dashed #9fc0cd;
  border-radius: 14px;
  background: #f3fafc;
  min-height: 120px;
}
.photo-drop input[type=file] {
  min-height: var(--touch);
}
.photo-drop-label {
  font-weight: 800;
  color: var(--brand-dark);
}
.photo-preview {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--brand);
  cursor: pointer;
  text-align: left;
}
.linkish:hover { text-decoration: underline; }

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

/* ——— Login ——— */
body.login-page {
  padding: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(31,111,139,0.25), transparent 40%),
    radial-gradient(circle at 85% 10%, rgba(194,65,12,0.12), transparent 35%),
    linear-gradient(160deg, #0b1f2a 0%, #0f3d4c 45%, #1a5568 100%);
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(440px, 100%);
  padding: 1.85rem 1.6rem;
  background: rgba(255,255,255,0.97);
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.4);
  box-shadow: 0 24px 60px rgba(0,0,0,0.28);
}
.login-card .brand-mark {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--brand-dark);
  margin: 0 0 0.2rem;
}
.login-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}
.login-card .subtitle { margin-bottom: 1.25rem; }

/* ——— Breakpoints ——— */
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .content { padding: 1.35rem 1.5rem 2rem; }
  .form-sticky-actions { bottom: 1rem; }
  .desktop-only { display: block; }
  .desktop-only-table { display: table; width: 100%; }
  .mobile-only { display: none; }
}

@media (min-width: 1100px) {
  .app-shell {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .sidebar { display: flex; }
  .mobile-topbar,
  .mobile-dock,
  .mobile-drawer { display: none !important; }
  body.nav-open .mobile-drawer { display: none !important; }
  .content {
    padding: 1.5rem 1.75rem 2rem;
  }
  .form-sticky-actions {
    position: static;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
    margin-top: 0.5rem;
  }
  .form-card { max-width: 760px; }
}

@media (min-width: 1400px) {
  .content { padding: 1.75rem 2.25rem 2.25rem; }
  :root { --sidebar-w: 280px; }
}
