:root {
  --bg: #081221;
  --bg2: #0e1f38;
  --card: #122440;
  --card2: #18314f;
  --line: #234866;
  --text: #eaf7ff;
  --muted: #8fb3cf;
  --primary: #0fbcf5;   /* cian · portal oficial Irapuato */
  --primary2: #5bd6ff;  /* cian claro */
  --accent: #ff187c;    /* rosa · logo CAM */
  --blue: #0077f8;      /* azul · logo CAM */
  --navy: #152a47;      /* azul marino · logo CAM */
  --green: #00d0a4;
  --radius: 16px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}

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

html, body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(15, 188, 245, .18) 0%, transparent 55%),
    radial-gradient(900px 550px at 108% 8%, rgba(255, 24, 124, .16) 0%, transparent 50%),
    radial-gradient(700px 500px at 50% 115%, rgba(0, 119, 248, .14) 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* retícula digital sutil */
body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(91, 214, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 214, 255, .045) 1px, transparent 1px);
  background-size: 44px 44px;
}

/* ciudad inteligente de fondo */
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: url('../assets/smart-city.svg') no-repeat center bottom;
  background-size: cover;
  opacity: .9;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; position: relative; z-index: 1; }

/* ============ LOGIN ============ */
#login-screen { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 760px;
  background: linear-gradient(160deg, rgba(18, 36, 64, .92), rgba(14, 31, 56, .92));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--blue), var(--accent), var(--primary));
  background-size: 300% 100%;
  animation: gradientFlow 6s linear infinite;
}
@keyframes gradientFlow {
  0% { background-position: 0% 0; }
  100% { background-position: 300% 0; }
}

.brand { margin-bottom: 18px; }
.brand-tag { color: var(--muted); margin-top: 4px; font-size: 14px; }

.brand-logo {
  display: inline-block; background: #ffffff; padding: 12px 20px; border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35); margin: 8px 0 10px;
}
.brand-logo img { display: block; width: 300px; height: auto; max-width: 100%; }
.brand-logo.small { padding: 4px 9px; border-radius: 10px; margin: 0; }
.brand-logo.small img { width: 110px; }

.login-card h2 { font-size: 24px; margin: 10px 0 4px; }
.login-sub { color: var(--muted); margin-bottom: 24px; }
.role-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.role-grid.cols2 { grid-template-columns: repeat(2, 1fr); max-width: 480px; margin: 0 auto; }
.role-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--card2); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius); padding: 24px 12px;
  cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.role-card:hover {
  transform: translateY(-4px); border-color: var(--primary);
  box-shadow: 0 12px 30px rgba(15, 188, 245, .35);
}
.role-icon { font-size: 40px; }
.role-name { font-weight: 700; font-size: 17px; }
.role-desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.login-foot { color: var(--muted); font-size: 12.5px; margin-top: 24px; }

.login-qr-box { margin-top: 20px; border-top: 1px dashed var(--line); padding-top: 18px; }
.login-qr-label { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.login-qr { background: #fff; display: inline-block; padding: 8px; border-radius: 12px; line-height: 0; margin-bottom: 10px; }
.login-qr-warn { color: #ff5f6d; font-size: 11.5px; line-height: 1.4; max-width: 260px; margin: 0 auto 10px; }
.login-qr-warn:empty { display: none; }

/* ============ TOPBAR ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 28px; background: rgba(8, 18, 33, 0.82);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
}
.topbar-brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.topbar-sub { color: var(--muted); font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.role-badge {
  background: linear-gradient(135deg, var(--primary), var(--blue));
  color: #fff; font-weight: 700; padding: 6px 14px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 4px 14px rgba(15, 188, 245, .35);
}

/* ============ VISTAS / LAYOUT ============ */
.view { padding: 28px; max-width: 1200px; margin: 0 auto; }
.view h1 { font-size: 26px; letter-spacing: -0.5px; }
.view-sub { color: var(--muted); margin: 6px 0 24px; }

.card {
  background: linear-gradient(160deg, rgba(18, 36, 64, .92), rgba(14, 31, 56, .92));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.section-title { font-size: 18px; margin-bottom: 14px; color: var(--text); }
.section-title .dot { color: var(--primary2); }

/* ============ BOTONES ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; border-radius: 12px; font-weight: 700;
  padding: 11px 18px; font-size: 14px; color: #fff;
  background: var(--card2); transition: transform .12s, box-shadow .12s, opacity .12s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[disabled] {
  opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; filter: grayscale(.35);
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--blue)); box-shadow: 0 6px 18px rgba(15,188,245,.3); }
.btn-green { background: linear-gradient(135deg, #00c9a7, #00d0a4); }
.btn-accent { background: linear-gradient(135deg, var(--accent), #ff5aa7); box-shadow: 0 6px 18px rgba(255,24,124,.3); }
.btn-danger { background: linear-gradient(135deg, #ff5f6d, #d63031); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }

/* ============ FORMULARIOS ============ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,188,245,.15); }
.field input::placeholder { color: #5d7f9c; }

/* campo de búsqueda */
.search-input {
  padding: 10px 14px; border-radius: 12px; min-width: 240px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: #5d7f9c; }
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,188,245,.15); }

/* aviso cuando los datos NO se comparten (modo archivo / sin servidor) */
.env-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 999;
  padding: 10px 16px; text-align: center; font-size: 13px; line-height: 1.4;
  background: #7a2b00; color: #ffe9d6; border-bottom: 1px solid #ff9d4d;
}
.env-banner a { color: #ffd166; font-weight: 700; }

/* aceptación del aviso de privacidad */
.consent {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 4px 0 16px; padding: 12px 14px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  font-size: 13px; color: var(--muted); line-height: 1.45; text-align: left;
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.consent:hover { border-color: var(--primary); }
.consent input[type="checkbox"] {
  flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px;
  accent-color: var(--primary); cursor: pointer;
}
.consent a { color: var(--primary2); font-weight: 600; text-decoration: underline; }
.consent a:hover { color: var(--primary); }

select {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; outline: none; cursor: pointer;
}
select:focus { border-color: var(--primary); }
select option { background: var(--bg2); color: var(--text); }

/* ============ PASAPORTE ============ */
.passport {
  background: linear-gradient(150deg, #12314f 0%, #0e2540 55%, #182b52 100%);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 24px; position: relative; overflow: hidden;
}
.passport::before {
  content: ''; position: absolute; right: -50px; top: -50px; width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(15, 188, 245, .4), transparent 70%);
}
.passport::after {
  content: ''; position: absolute; left: -60px; bottom: -60px; width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(255, 24, 124, .25), transparent 70%);
}
.passport-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; position: relative; z-index: 1; }
.passport-id { font-size: 12px; color: var(--primary2); letter-spacing: 1px; font-weight: 700; }
.passport-name { font-size: 22px; font-weight: 800; }
.passport-meta { color: var(--muted); font-size: 13px; }
.passport-qr { background: #fff; padding: 8px; border-radius: 12px; line-height: 0; }
.passport-progress { margin-top: 18px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.progress-bar { height: 12px; background: rgba(0,0,0,.4); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 999px; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--blue));
  box-shadow: 0 0 12px rgba(15, 188, 245, .6);
  transition: width .4s ease;
}

.stamp-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.stamp {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid var(--accent); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; transform: rotate(-12deg); position: relative;
  box-shadow: 0 2px 10px rgba(255, 24, 124, .4);
  animation: stampIn .35s ease;
}
.stamp::after {
  content: 'SELLO'; position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
  font-size: 7px; font-weight: 800; letter-spacing: 1px; color: var(--accent); background: #12314f;
  padding: 0 3px; border-radius: 2px;
}
@keyframes stampIn {
  0% { transform: rotate(0deg) scale(1.6); opacity: 0; }
  100% { transform: rotate(-12deg) scale(1); opacity: 1; }
}

/* ============ ESTACIONES ============ */
.station-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.station {
  background: var(--card2); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; text-align: center; cursor: pointer; transition: transform .12s, border-color .12s;
  position: relative;
}
.station:hover { transform: translateY(-3px); border-color: var(--primary); }
.station.done { border-color: var(--green); background: linear-gradient(160deg, rgba(0,208,164,.16), var(--card2)); }
.station .station-icon { font-size: 30px; }
.station .station-name { font-weight: 700; font-size: 14px; margin-top: 8px; line-height: 1.25; }
.station .station-status { font-size: 12px; margin-top: 6px; }
.station .check {
  position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--green); color: #fff; font-size: 14px; display: none;
  align-items: center; justify-content: center;
}
.station.done .check { display: flex; }

/* ============ ENCUESTA ============ */
.rating { display: flex; gap: 6px; }
.rating span { font-size: 30px; cursor: pointer; opacity: .35; transition: transform .1s; color: var(--primary2); }
.rating span:hover, .rating span.on { opacity: 1; transform: scale(1.15); }

/* respuestas de sí / no */
.choice { display: flex; gap: 10px; flex-wrap: wrap; }
.choice-btn {
  padding: 10px 26px; border-radius: 12px; cursor: pointer;
  background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; font-weight: 600; transition: border-color .15s, background .15s, color .15s;
}
.choice-btn:hover { border-color: var(--primary); }
.choice-btn.on {
  border-color: var(--primary); color: var(--primary2);
  background: rgba(15, 188, 245, .14); box-shadow: 0 0 0 3px rgba(15, 188, 245, .12);
}

/* ============ TABLAS ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:hover td { background: rgba(15, 188, 245, .06); }
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-ok { background: rgba(0,208,164,.18); color: #4dffd5; }
.badge-warn { background: rgba(255,24,124,.16); color: #ff8ac0; }
.badge-info { background: rgba(15,188,245,.2); color: #6fd9ff; }
.badge-muted { background: rgba(143,179,207,.15); color: var(--muted); }

/* ============ KPIs ============ */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
  background: linear-gradient(160deg, var(--card), var(--bg2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}
.kpi .kpi-label { color: var(--muted); font-size: 13px; }
.kpi .kpi-value { font-size: 34px; font-weight: 800; margin-top: 4px; }
.kpi .kpi-ico { position: absolute; right: 14px; top: 14px; font-size: 26px; opacity: .5; }

.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.chart-card canvas { max-height: 280px; }

/* ============ MODALES ============ */
.modal {
  position: fixed; inset: 0; background: rgba(4, 9, 17, 0.78);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-box {
  width: 100%; max-width: 520px; background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 22px;
  box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 18px; }
.qr-reader { width: 100%; min-height: 240px; border-radius: 12px; overflow: hidden; background: #000; }
.qr-manual { display: flex; gap: 8px; margin-top: 14px; }
.qr-manual input { flex: 1; padding: 11px 14px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); color: var(--text); }
.scanner-msg { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 22px; border-radius: 999px; font-weight: 600; z-index: 100;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .role-grid, .grid-3, .grid-4, .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .view { padding: 18px; }
}
@media (max-width: 560px) {
  .role-grid, .grid-3, .grid-4, .kpi-grid { grid-template-columns: 1fr; }
}
