@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700;800&family=Lato:wght@400;600;700&display=swap');

:root {
  --mf: #0057A8; --mf-d: #003876; --mf-b: #0082C8; --mf-l: #E8F4FC; --mf-bg: #F0F7FF;
  --ac: #00C2A8; --ok: #1E8E3E; --ok-bg: #E6F4EA; --wn: #E8900A; --wn-bg: #FFF3E0;
  --dg: #D93025; --dg-bg: #FCE8E6; --tx: #1A1D23; --tx-m: #6B7280; --tx-l: #9CA3AF;
  --bd: #D1D5DB; --bd-l: #E5E7EB; --wh: #fff;
  --r: 8px; --rl: 12px;
  --f-head: 'Montserrat', 'Segoe UI', sans-serif;
  --f-body: 'Lato', 'Segoe UI', sans-serif;
}

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

body {
  font-family: var(--f-body); background: var(--mf-bg); color: var(--tx);
  font-size: 14px; height: 100vh; overflow: hidden; display: flex; flex-direction: column
}

/* LOGIN */
#login-screen { position: fixed; inset: 0; background: var(--mf-d); display: flex; align-items: center; justify-content: center; z-index: 999 }
.login-box { background: var(--wh); border-radius: 16px; padding: 36px; width: min(360px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3) }
.login-logo { text-align: center; margin-bottom: 28px }
.login-logo h1 { font-family: var(--f-head); font-size: 22px; font-weight: 800; color: var(--mf-d); letter-spacing: .5px }
.login-logo p { font-size: 12px; color: var(--tx-m); margin-top: 4px }
.login-err { background: var(--dg-bg); color: var(--dg); border-radius: var(--r); padding: 8px 12px; font-size: 12px; margin-bottom: 10px; display: none; font-weight: 600 }
.form-row { margin-bottom: 12px }
.form-row label { display: block; font-size: 11px; font-weight: 600; color: var(--tx-m); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px }
.form-row input { width: 100%; padding: 9px 12px; border: 1.5px solid var(--bd); border-radius: var(--r); font-size: 13px; outline: none; font-family: var(--f-body); transition: .15s }
.form-row input:focus { border-color: var(--mf) }
.btn-login { width: 100%; padding: 10px; background: var(--mf); color: var(--wh); border: none; border-radius: var(--r); font-size: 14px; font-weight: 700; font-family: var(--f-head); cursor: pointer; margin-top: 4px; letter-spacing: .3px }
.btn-login:hover { background: var(--mf-d) }

/* APP */
#app { display: flex; height: 100%; display: none }

/* SIDEBAR */
#sidebar { width: 230px; flex-shrink: 0; background: var(--mf-d); display: flex; flex-direction: column; overflow-y: auto }
.sb-logo { padding: 20px 16px 14px; border-bottom: 1px solid rgba(255, 255, 255, .1) }
.sb-brand { display: flex; align-items: center; gap: 10px }
.sb-icon { width: 38px; height: 38px; border-radius: 9px; background: var(--mf); display: flex; align-items: center; justify-content: center; flex-shrink: 0 }
.sb-title { font-family: var(--f-head); font-size: 14px; font-weight: 800; color: #fff; letter-spacing: .2px; line-height: 1.2 }
.sb-sub { font-size: 9px; color: rgba(255, 255, 255, .5); margin-top: 2px; letter-spacing: .4px }
.sb-sec { padding: 12px 14px 4px; font-size: 9px; font-weight: 700; letter-spacing: .8px; color: rgba(255, 255, 255, .35); text-transform: uppercase }
.sb-item { display: flex; align-items: center; gap: 9px; padding: 9px 14px; margin: 1px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; color: rgba(255, 255, 255, .7); transition: .15s; font-family: var(--f-body) }
.sb-item:hover { background: rgba(255, 255, 255, .08); color: #fff }
.sb-item.active { background: var(--mf); color: #fff; font-weight: 600 }
.sb-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .3); flex-shrink: 0 }
.sb-item.active .sb-dot { background: #fff }
.sb-sep { height: 1px; background: rgba(255, 255, 255, .08); margin: 6px 14px }
.sb-user { margin-top: auto; padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .1); display: flex; align-items: center; gap: 9px }
.sb-av { width: 32px; height: 32px; border-radius: 50%; background: var(--mf); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: #fff; font-family: var(--f-head); flex-shrink: 0 }
.sb-nm { font-size: 12px; font-weight: 600; color: #fff; font-family: var(--f-body) }
.sb-rl { font-size: 10px; color: rgba(255, 255, 255, .5) }
.sb-logout { margin-left: auto; background: none; border: none; color: rgba(255, 255, 255, .5); cursor: pointer; font-size: 14px; padding: 2px 4px }
.sb-logout:hover { color: #fff }

/* MAIN */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0 }
#topbar { height: 52px; background: var(--wh); border-bottom: 1px solid var(--bd-l); display: flex; align-items: center; padding: 0 20px; gap: 12px; flex-shrink: 0; box-shadow: 0 1px 4px rgba(0, 53, 102, .07) }
#ptitle { font-family: var(--f-head); font-size: 14px; font-weight: 700; color: var(--mf-d) }
#ptitle span { color: var(--mf) }
.tb-r { margin-left: auto; display: flex; align-items: center; gap: 8px }
.st-pill { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--tx-m); padding: 3px 10px; border-radius: 20px; border: 1px solid var(--bd); font-family: var(--f-body) }
.st-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok) }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .4 } }
.st-dot.live { animation: pulse 2s infinite }
.tb-btn { padding: 4px 12px; border-radius: 6px; border: 1px solid var(--bd); background: var(--wh); font-size: 11px; color: var(--tx-m); cursor: pointer; font-family: var(--f-body); transition: .15s }
.tb-btn:hover { border-color: var(--mf); color: var(--mf) }
#content { flex: 1; overflow-y: auto; padding: 18px }

/* FILTROS */
#filtros-bar { background: var(--wh); border: 1px solid var(--bd-l); border-radius: var(--r); padding: 8px 14px; display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap }
.fl { font-size: 11px; font-weight: 600; color: var(--tx-m); font-family: var(--f-body) }
.fb { padding: 4px 12px; border-radius: 20px; border: 1px solid var(--bd); background: var(--wh); font-size: 11px; color: var(--tx-m); cursor: pointer; transition: .15s; font-family: var(--f-body) }
.fb:hover { border-color: var(--mf); color: var(--mf) }
.fb.act { background: var(--mf); border-color: var(--mf); color: #fff; font-weight: 600 }
select.fs { padding: 4px 10px; border-radius: 20px; border: 1px solid var(--bd); background: var(--wh); font-size: 11px; color: var(--tx-m); cursor: pointer; outline: none; font-family: var(--f-body) }
select.fs:focus { border-color: var(--mf) }

/* SECCIÓN */
.sec-lbl { font-family: var(--f-head); font-size: 10px; font-weight: 700; color: var(--mf-d); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 8px; border-left: 3px solid var(--mf); padding-left: 7px }

/* ALERT BANNER */
.alert-banner { background: var(--wn-bg); border: 1px solid #FFCC80; border-radius: var(--r); padding: 7px 12px; font-size: 11px; color: #E65100; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; font-weight: 500; font-family: var(--f-body) }
.alert-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--wn); flex-shrink: 0 }

/* KPI CARDS */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-bottom: 14px }
.kc { background: var(--wh); border: 1px solid var(--bd-l); border-radius: var(--r); padding: 12px 14px; border-top: 3px solid var(--mf) }
.kc.ac { border-top-color: var(--ac) }
.kc.ok { border-top-color: var(--ok) }
.kc.wn { border-top-color: var(--wn) }
.kc.dg { border-top-color: var(--dg) }
.kc.gr { border-top-color: var(--tx-l) }
.kl { font-size: 9px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--tx-m); margin-bottom: 4px; font-family: var(--f-body) }
.kv { font-family: var(--f-head); font-size: 20px; font-weight: 700; color: var(--mf-d); line-height: 1 }
.ks { font-size: 10px; color: var(--tx-m); margin-top: 2px; font-family: var(--f-body) }
.badge { display: inline-flex; align-items: center; gap: 2px; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; margin-top: 4px; font-family: var(--f-body) }
.up { background: var(--ok-bg); color: var(--ok) }
.dn { background: var(--dg-bg); color: var(--dg) }
.nt { background: var(--mf-l); color: var(--mf) }

/* ZONA CARDS */
.zona-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 14px }
.zc { background: var(--wh); border: 1px solid var(--bd-l); border-radius: var(--r); padding: 10px 12px }
.zc.alert-z { border-left: 3px solid var(--dg); border-color: var(--dg) }
.ztag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 9px; font-weight: 700; margin-bottom: 5px; font-family: var(--f-head) }
.SUR { background: #FFF3CD; color: #856404 }
.NORTE { background: #D1ECF1; color: #0C5460 }
.CENTRO { background: #D4EDDA; color: #155724 }
.MEDITERRANEO { background: #CCE5FF; color: #004085 }
.ISLAS { background: #F8D7DA; color: #721C24 }
.INTERNACIONAL { background: #E2D9F3; color: #432874 }
.zv { font-family: var(--f-head); font-size: 15px; font-weight: 700; color: var(--mf-d) }
.zs { font-size: 9px; color: var(--tx-m); margin-top: 1px; font-family: var(--f-body) }
.zalert { font-size: 9px; color: var(--dg); font-weight: 600; margin-top: 3px; font-family: var(--f-body) }

/* CHARTS */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px }
.card { background: var(--wh); border: 1px solid var(--bd-l); border-radius: var(--r); padding: 14px 16px }
.card.full { grid-column: 1/-1 }
.ct { font-family: var(--f-head); font-size: 12px; font-weight: 700; color: var(--mf-d); margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px }
.ct small { font-family: var(--f-body); font-size: 10px; color: var(--tx-m); font-weight: 400 }
canvas { display: block; width: 100% !important }
.legend { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap }
.li { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--tx-m); font-family: var(--f-body) }
.ld { width: 14px; height: 3px; border-radius: 2px; flex-shrink: 0 }
.dl { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; justify-content: center }
.di { display: flex; align-items: center; gap: 4px; font-size: 10px; color: var(--tx-m); font-family: var(--f-body) }
.dd { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0 }

/* TABLA */
.tbl-wrap { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-size: 11px }
thead th { background: var(--mf-d); color: #fff; padding: 8px 10px; text-align: left; font-weight: 600; font-size: 10px; white-space: nowrap; font-family: var(--f-head); letter-spacing: .2px }
thead th:first-child { border-radius: 6px 0 0 0 }
thead th:last-child { border-radius: 0 6px 0 0 }
tbody tr { border-bottom: 1px solid var(--mf-bg) }
tbody tr:nth-child(even) { background: var(--mf-l) }
tbody tr:hover { background: #DCEEFa; cursor: pointer }
tbody td { padding: 7px 10px; color: var(--tx); font-family: var(--f-body) }

/* CLÍNICA */
.search-wrap { position: relative; max-width: 360px; flex: 1 }
.search-wrap input { width: 100%; padding: 8px 14px 8px 34px; border: 1.5px solid var(--mf); border-radius: 20px; font-size: 13px; outline: none; font-family: var(--f-body) }
.search-wrap::before { content: '🔍'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 12px; pointer-events: none }
#sr-box, #prod-sr-box { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--wh); border: 1px solid var(--bd); border-radius: var(--r); box-shadow: 0 4px 16px rgba(0, 53, 102, .12); z-index: 100; max-height: 250px; overflow-y: auto; display: none }
.sri { padding: 9px 14px; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--mf-bg); display: flex; align-items: center; justify-content: space-between; font-family: var(--f-body) }
.sri:hover { background: var(--mf-l) }
.cli-card { background: var(--wh); border: 1.5px solid var(--mf); border-radius: var(--rl); padding: 12px 16px; display: flex; align-items: center; gap: 12px; margin-bottom: 14px }
.cli-av { width: 42px; height: 42px; border-radius: 10px; background: var(--mf); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; font-weight: 700; font-family: var(--f-head); flex-shrink: 0 }
.cli-name { font-family: var(--f-head); font-size: 13px; font-weight: 700; color: var(--mf-d) }
.cli-sub { font-size: 10px; color: var(--tx-m); margin-top: 2px; font-family: var(--f-body) }
.inc-bar { height: 5px; border-radius: 3px; background: var(--bd-l); margin-top: 4px; overflow: hidden }
.inc-fill { height: 100%; border-radius: 3px }
.pct-bar { display: inline-block; width: 36px; height: 4px; border-radius: 2px; background: var(--bd-l); margin-left: 4px; vertical-align: middle; overflow: hidden }
.pct-fill { height: 100%; border-radius: 2px }
.top3 { display: flex; flex-direction: column; gap: 3px; margin-top: 3px }
.t3 { font-size: 9px; color: var(--tx-m); display: flex; align-items: center; gap: 4px; font-family: var(--f-body) }
.t3n { background: var(--mf-l); color: var(--mf); border-radius: 3px; padding: 0 4px; font-weight: 700; font-size: 9px; font-family: var(--f-head) }

/* ADMIN */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--bd); margin-bottom: 16px }
.tab { padding: 8px 16px; font-size: 12px; font-weight: 500; color: var(--tx-m); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; font-family: var(--f-body); transition: .15s }
.tab:hover { color: var(--mf) }
.tab.active { color: var(--mf); border-bottom-color: var(--mf); font-weight: 600 }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--r); font-size: 12px; font-weight: 600; border: 1px solid transparent; cursor: pointer; font-family: var(--f-body); transition: .15s }
.btn-p { background: var(--mf); color: #fff; border-color: var(--mf) }
.btn-p:hover { background: var(--mf-d) }
.btn-o { background: var(--wh); border-color: var(--bd); color: var(--tx-m) }
.btn-o:hover { border-color: var(--mf); color: var(--mf) }
.btn-d { background: var(--dg); color: #fff }
.btn-d:hover { background: #b71c1c }
.btn-sm { padding: 4px 10px; font-size: 11px }
.upload-zone { border: 2px dashed var(--bd); border-radius: var(--r); padding: 40px; text-align: center; cursor: pointer; transition: .2s; font-family: var(--f-body) }
.upload-zone:hover, .upload-zone.drag { border-color: var(--mf); background: var(--mf-l) }
.form-g { margin-bottom: 12px }
.form-g label { display: block; font-size: 11px; font-weight: 600; color: var(--tx-m); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px; font-family: var(--f-body) }
.form-g input, .form-g select { width: 100%; padding: 8px 10px; border: 1.5px solid var(--bd); border-radius: var(--r); font-size: 13px; outline: none; font-family: var(--f-body); transition: .15s }
.form-g input:focus, .form-g select:focus { border-color: var(--mf) }

.modal-bd { position: fixed; inset: 0; background: rgba(0, 56, 118, .45); display: flex; align-items: center; justify-content: center; z-index: 500; opacity: 0; pointer-events: none; transition: .2s }
.modal-bd.open { opacity: 1; pointer-events: all }
.modal { background: var(--wh); border-radius: var(--rl); width: min(460px, calc(100vw - 32px)); max-height: 85vh; overflow-y: auto; padding: 28px; box-shadow: 0 8px 40px rgba(0, 0, 0, .2); transform: translateY(16px); transition: .2s }
.modal-bd.open .modal { transform: none }
.modal h2 { font-family: var(--f-head); font-size: 16px; font-weight: 700; color: var(--mf-d); margin-bottom: 18px }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px }

/* CONFIG INICIAL */
#cfg-screen { position: fixed; inset: 0; background: var(--mf-d); display: flex; align-items: center; justify-content: center; z-index: 998; display: none }
.cfg-box { background: var(--wh); border-radius: 16px; padding: 36px; width: min(380px, calc(100vw - 32px)) }
.cfg-box h2 { font-family: var(--f-head); font-size: 18px; font-weight: 700; color: var(--mf-d); margin-bottom: 6px }
.cfg-box p { font-size: 12px; color: var(--tx-m); margin-bottom: 20px }

@media(max-width:768px) {
  #sidebar { display: none }
  .zona-grid { grid-template-columns: 1fr 1fr }
  .charts-grid { grid-template-columns: 1fr }
  .card.full { grid-column: auto }
  #content { padding: 12px }
}
@media(max-width:480px) {
  .zona-grid { grid-template-columns: 1fr }
  .kpi-grid { grid-template-columns: 1fr 1fr }
}