/* TrazaPro Panel — estilos. Mismo lenguaje visual que el panel actual:
   encabezado verde, tarjetas blancas con borde de color arriba, números grandes. */
:root {
  color-scheme: light;
  --verde-osc: #1a472a; --verde: #2d6a4f; --verde-claro: #68d391;
  --fondo: #f0f4f8; --texto: #1a202c; --gris: #718096; --gris-claro: #a0aec0; --borde: #e2e8f0;
  --green: #38a169; --blue: #3182ce; --purple: #805ad5; --teal: #319795; --orange: #dd6b20;
  --yellow: #d69e2e; --cyan: #0987a0; --red: #e53e3e;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, 'Helvetica Neue', Arial, sans-serif;
  background: var(--fondo); color: var(--texto); min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--verde); }
.oculto { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
[hidden] { display: none !important; }

/* Encabezado */
.header {
  background: linear-gradient(135deg, var(--verde-osc), var(--verde)); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) 10px calc(18px + env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15); position: sticky; top: 0; z-index: 20;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 8px; }
.header h1 { font-size: 1.1rem; font-weight: 800; white-space: nowrap; }
.h1-sub { font-weight: 500; opacity: .75; }
.logo-dot { width: 9px; height: 9px; background: var(--verde-claro); border-radius: 50%; box-shadow: 0 0 7px var(--verde-claro); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .4 } }
.header-right { display: flex; align-items: center; gap: 8px; font-size: .76rem; }
.updated-text { opacity: .8; white-space: nowrap; }
.updated-text.viejo { color: #fbd38d; opacity: 1; font-weight: 700; }
.btn-head { background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); color: #fff; padding: 6px 11px; border-radius: 6px; cursor: pointer; font-size: .76rem; white-space: nowrap; }
.btn-head:hover { background: rgba(255,255,255,.27); }
.btn-head:disabled { opacity: .45; cursor: not-allowed; }

/* Navegación */
.nav { display: flex; gap: 2px; background: #fff; border-bottom: 1px solid var(--borde); padding: 0 calc(12px + env(safe-area-inset-left)); position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 19; overflow-x: auto; }
.nav a { padding: 10px 14px; font-size: .8rem; font-weight: 700; color: var(--gris); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav a.activa { color: var(--verde); border-bottom-color: var(--verde); }

.main { padding: 14px calc(16px + env(safe-area-inset-right)) 14px calc(16px + env(safe-area-inset-left)); max-width: 1440px; margin: 0 auto; }
.section-label { font-size: .65rem; font-weight: 800; color: var(--gris-claro); text-transform: uppercase; letter-spacing: .8px; margin: 16px 0 8px 1px; }
.section-label:first-child { margin-top: 4px; }
.nota { font-size: .72rem; color: var(--gris); margin: -2px 0 10px 1px; line-height: 1.4; }
.nota-caja { background: #ebf8ff; border: 1px solid #bee3f8; color: #2c5282; border-radius: 8px; padding: 8px 12px; font-size: .76rem; margin-bottom: 10px; line-height: 1.45; }

.alert-warn { background: #fffaf0; border: 1px solid #fbd38d; border-radius: 8px; padding: 9px 13px; margin-bottom: 12px; color: #c05621; font-size: .8rem; line-height: 1.5; }
.alert-warn a { color: #c05621; font-weight: 700; }

/* Grillas */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.grid-2, .grid-3 { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 10px; }
.grid-2 > *, .grid-3 > * { min-width: 0; }

/* Tarjetas KPI */
.kpi-card { background: #fff; border-radius: 10px; padding: 11px 12px; box-shadow: 0 1px 4px rgba(0,0,0,.07); border-top: 3px solid var(--borde); min-width: 0; }
.kpi-card.c-green { border-top-color: var(--green) } .kpi-card.c-blue { border-top-color: var(--blue) }
.kpi-card.c-purple { border-top-color: var(--purple) } .kpi-card.c-teal { border-top-color: var(--teal) }
.kpi-card.c-orange { border-top-color: var(--orange) } .kpi-card.c-yellow { border-top-color: var(--yellow) }
.kpi-card.c-cyan { border-top-color: var(--cyan) } .kpi-card.c-red { border-top-color: var(--red) }
.kpi-card.c-gray { border-top-color: var(--gris-claro) }
.kpi-label { font-size: .6rem; color: var(--gris); text-transform: uppercase; letter-spacing: .7px; font-weight: 700; margin-bottom: 5px; }
.kpi-value { font-size: 1.5rem; font-weight: 800; line-height: 1.05; overflow-wrap: anywhere; }
.kpi-value.chico { font-size: 1.05rem; }
.kpi-sub { font-size: .66rem; color: var(--gris-claro); margin-top: 4px; line-height: 1.35; }
.kpi-sub a { color: var(--gris); }
.dur-ok { color: var(--green) } .dur-warn { color: var(--yellow) } .dur-slow { color: var(--red) }
.pendiente { color: var(--gris-claro); font-size: .95rem; font-weight: 700; }

/* Tarjetas */
.card { background: #fff; border-radius: 10px; padding: 12px 13px; box-shadow: 0 1px 4px rgba(0,0,0,.07); min-width: 0; }
.card.borde-top { border-top: 3px solid var(--verde); }
.card-title { font-size: .63rem; font-weight: 800; color: var(--gris); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 10px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-title .extra { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--gris-claro); }
.sin-datos { color: var(--gris-claro); font-size: .8rem; padding: 10px 0; font-style: italic; }
.ok-msg { color: var(--green); font-size: .82rem; padding: 8px 0; }

/* Barras */
.bar-row { margin-bottom: 8px; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: .76rem; margin-bottom: 3px; }
.bar-label span:last-child { color: var(--gris-claro); font-size: .69rem; white-space: nowrap; }
.bar-track { background: var(--borde); border-radius: 4px; height: 6px; }
.bar-fill { height: 6px; border-radius: 4px; transition: width .6s; }
.subgrupo { font-size: .66rem; font-weight: 800; color: var(--gris); text-transform: uppercase; letter-spacing: .5px; margin: 10px 0 6px; }
.subgrupo:first-child { margin-top: 0; }

/* Tablas */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl-wrap.alto { max-height: 340px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: .74rem; }
th { text-align: left; padding: 6px 8px; background: #f7fafc; color: var(--gris); font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--borde); white-space: nowrap; position: sticky; top: 0; }
td { padding: 7px 8px; border-bottom: 1px solid #f1f4f8; vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nw { white-space: nowrap; }
td.tenue { color: var(--gris-claro); }
td.fuerte { font-weight: 700; color: var(--verde); }
td.wrap { word-break: break-word; max-width: 280px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }
tr.total td { background: #f7fafc; font-weight: 700; border-top: 2px solid var(--borde); }
tr.clic { cursor: pointer; }
.col-ancha { display: none; }
a.cli { color: var(--texto); font-weight: 600; text-decoration: none; }
a.cli:hover { color: var(--verde); text-decoration: underline; }
.sub-cli { display: block; font-size: .64rem; color: var(--gris-claro); font-weight: 400; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 9px; font-size: .63rem; font-weight: 700; white-space: nowrap; }
.badge-ok { background: #c6f6d5; color: #276749 } .badge-err { background: #fed7d7; color: #c53030 }
.badge-parcial { background: #e9d8fd; color: #553c9a } .badge-cliente { background: #feebc8; color: #9c4221 }
.badge-plan { background: var(--fondo); color: var(--gris); }
.badge-warn { background: #fefcbf; color: #975a16 }
.etbadge { display: inline-block; padding: 2px 7px; border-radius: 8px; font-size: .62rem; font-weight: 700; font-family: ui-monospace, Menlo, monospace; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: .68rem; color: var(--gris); }

/* Pestañas */
.tabs { display: flex; border-bottom: 2px solid var(--borde); margin-bottom: 12px; gap: 2px; overflow-x: auto; }
.tabs.sin-borde { border-bottom: none; margin-bottom: 0; }
.tab-btn { padding: 6px 12px; font-size: .74rem; font-weight: 700; color: var(--gris-claro); background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab-btn.active { color: var(--verde); border-bottom-color: var(--verde); }

/* Histórico */
.hist-controls { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; background: #fff; border-radius: 10px; padding: 8px 11px; box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 10px; }
.range-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.range-btn, .nav-btn { padding: 5px 11px; border: 1px solid var(--borde); border-radius: 6px; font-size: .73rem; font-weight: 700; cursor: pointer; background: #fff; color: var(--gris); }
.range-btn.active { background: var(--verde); color: #fff; border-color: var(--verde); }
.nav-btns { display: flex; align-items: center; gap: 8px; width: 100%; justify-content: space-between; }
.nav-btn { color: #4a5568; font-weight: 500; }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.hist-label { font-size: .76rem; font-weight: 600; color: #4a5568; text-align: center; flex: 1; }
.chart-title { font-size: .62rem; font-weight: 800; color: var(--gris); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 8px; }
.chart-wrap { position: relative; height: 190px; }
.chart-wrap.alto { height: 260px; }

/* Controles */
.controls { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
select, input[type=search] { padding: 7px 10px; border: 1px solid var(--borde); border-radius: 6px; font-size: 16px; color: #4a5568; background: #fff; }
input[type=search] { width: 100%; }
.total-text { font-size: .74rem; color: var(--gris); }

/* Ficha */
.volver { display: inline-block; font-size: .78rem; margin-bottom: 8px; text-decoration: none; font-weight: 600; }
.ficha-head { background: #fff; border-radius: 10px; padding: 12px 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); border-top: 3px solid var(--verde); margin-bottom: 10px; }
.ficha-head h2 { font-size: 1.2rem; font-weight: 800; }
.ficha-head .empresa { color: var(--gris); font-size: .82rem; margin-top: 2px; }
.ficha-head .badges { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
dl.datos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; font-size: .78rem; }
dl.datos dt { color: var(--gris); font-weight: 600; }
dl.datos dd { overflow-wrap: anywhere; }
.notas { white-space: pre-wrap; background: #f7fafc; border-radius: 6px; padding: 8px; font-size: .76rem; }

/* Carga y errores */
.loading { display: flex; align-items: center; justify-content: center; min-height: 240px; flex-direction: column; gap: 13px; color: var(--gris); font-size: .88rem; }
.spin { width: 28px; height: 28px; border: 3px solid var(--borde); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: #fff5f5; border: 1px solid #fed7d7; border-radius: 10px; padding: 18px; color: #c53030; margin: 16px 0; text-align: center; font-size: .86rem; }
.error-box button { margin-top: 10px; }
.footer { text-align: center; padding: 14px; font-size: .66rem; color: #b8c2d2; }

/* Login */
.login { position: fixed; inset: 0; background: linear-gradient(160deg, var(--verde-osc), var(--verde)); display: flex; align-items: center; justify-content: center; z-index: 50; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
.login-card { background: #fff; border-radius: 14px; padding: 26px 22px; width: 100%; max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 8px; }
.login-logo { width: 56px; height: 56px; border-radius: 12px; align-self: center; }
.login-card h2 { text-align: center; font-size: 1.2rem; }
.login-sub { text-align: center; color: var(--gris); font-size: .8rem; margin-bottom: 8px; }
.login-card label { font-size: .75rem; font-weight: 700; color: var(--gris); }
.login-card input[type=password] { padding: 11px 12px; border: 1px solid var(--borde); border-radius: 8px; font-size: 16px; }
.login-card button { background: var(--verde); color: #fff; border: none; border-radius: 8px; padding: 12px; font-size: 1rem; font-weight: 700; cursor: pointer; margin-top: 6px; }
.login-card button:disabled { opacity: .6; }
.login-error { color: var(--red); font-size: .8rem; min-height: 1.2em; text-align: center; }

/* Pantallas medianas y anchas */
@media (min-width: 760px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .kpi-grid.dos { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid.tres { grid-template-columns: repeat(3, 1fr); }
  .kpi-card { padding: 13px 14px; }
  .kpi-value { font-size: 1.75rem; }
  .kpi-label { font-size: .63rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .card { padding: 14px 15px; }
  table { font-size: .79rem; }
  th { font-size: .65rem; padding: 6px 9px; }
  td { padding: 7px 9px; }
  .col-ancha { display: table-cell; }
  .hist-controls { flex-direction: row; align-items: center; justify-content: space-between; padding: 10px 14px; }
  .nav-btns { width: auto; }
  .controls { flex-direction: row; align-items: center; justify-content: space-between; }
  input[type=search] { max-width: 420px; font-size: .86rem; }
  select { font-size: .8rem; }
  .chart-wrap { height: 220px; }
  .chart-wrap.alto { height: 300px; }
  .nav { top: calc(56px + env(safe-area-inset-top)); }
}
@media (min-width: 1200px) {
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .chart-wrap { height: 250px; }
  .chart-wrap.alto { height: 340px; }
  .main { padding: 18px 26px; }
}
#btn-refresh.cargando .ico { display: inline-block; animation: spin .8s linear infinite; }
@media (max-width: 420px) {
  .updated-text { font-size: .6rem; max-width: 64px; white-space: normal; line-height: 1.15; text-align: right; }
  #btn-refresh .txt { display: none; }
  .header h1 { font-size: .98rem; }
  .h1-sub { display: none; }
  .btn-head { padding: 6px 9px; }
}
.espacio { height: 10px; }
