:root {
  --red: #D8272E; --red-dark: #A81C22; --ink: #262626; --gray: #7F7F7F; --muted: #5F5F5F;
  --line: #E4E4E2; --soft: #F6F6F5; --bg: #F3F3F2; --white: #FFFFFF;
  --ok: #2E8B57; --warn: #D4A017; --risk: #E36414; --pause: #6B7280;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'IBM Plex Sans', system-ui, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--red); }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }
.sr { position: absolute; left: -9999px; }

/* Botones */
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid #BDBDBA; background: var(--white); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:hover { border-color: var(--ink); }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-red { background: var(--red); color: #fff; border-color: var(--red); }
.btn-red:hover { background: var(--red-dark); }
.btn-outline { border: 2px solid var(--ink); font-weight: 700; }
.btn-big { min-height: 52px; padding: 0 20px; font-size: 16px; font-weight: 700; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pill { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid #CFCFCC; background: #fff; font-weight: 600; font-size: 14px; }
.pill.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.input { min-height: 48px; font-size: 16px; border: 2px solid #CFCFCC; border-radius: 10px; padding: 0 12px; background: #fff; width: 100%; }
textarea.input { min-height: 84px; padding: 10px 12px; resize: vertical; }
.input:focus { outline: none; border-color: var(--ink); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.err { color: var(--red-dark); font-weight: 600; font-size: 14px; min-height: 20px; }

/* Login */
.login-wrap { min-height: 100vh; background: var(--ink); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 420px; background: #fff; border-radius: 20px; padding: 36px 32px; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 48px; height: 48px; border-radius: 12px; background: var(--red); color: #fff; font-weight: 700; font-size: 19px; display: flex; align-items: center; justify-content: center; flex: none; }
.brand small { display: block; font-size: 13px; color: var(--muted); }
.brand strong { font-size: 22px; }

/* Encabezado */
header.top { background: var(--ink); color: #fff; padding: 12px 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
header.top .brand small { color: #C9C9C9; }
.top-right { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.status { font-size: 13px; color: #C9C9C9; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: #3FB871; }
.top-btn { min-height: 40px; padding: 0 14px; border-radius: 9px; border: 1px solid #4A4A4A; background: #333; color: #fff; font-weight: 600; font-size: 14px; }
.top-btn:hover { background: #444; }

main { max-width: 1400px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 24px; }
.panel { background: #fff; border-radius: 16px; padding: 18px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; font-size: 19px; }
.panel .sub { font-size: 13px; color: var(--muted); }
.split { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.split > .main-col { flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.split > .side-col { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { min-height: 132px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 16px 18px; border-radius: 16px; background: #fff; border: 1px solid var(--line); }
.kpi.on { border: 3px solid var(--ink); box-shadow: 0 6px 18px rgba(0,0,0,.10); }
.kpi.alarm { background: #FCE8E9; border: 2px solid var(--red); }
.kpi.alarm.on { border: 3px solid var(--ink); }
.kpi .lbl { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .n { font-size: 52px; font-weight: 700; line-height: 1; font-family: var(--mono); }
.kpi .s { font-size: 13px; color: var(--muted); }
.kdot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* Filtros */
.search { flex: 1 1 320px; display: flex; align-items: center; gap: 8px; border: 2px solid var(--ink); border-radius: 12px; padding: 0 12px; min-height: 52px; background: #fff; }
.search input { flex: 1; border: none; outline: none; font-size: 16px; min-height: 48px; background: transparent; }
.flabel { font-size: 13px; font-weight: 600; color: var(--muted); width: 84px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding-top: 10px; border-top: 1px solid #EEEEEC; font-size: 13px; color: #4A4A4A; }
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* Tarjetas */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.list-head h2 { margin: 0; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line); background: #fff; }
.card.ok { background: #EEF7F1; border-color: #CBE6D5; }
.card.atencion { background: #FDF7E6; border-color: #F0DFA6; }
.card.riesgo { background: #FDEEE3; border-color: #F5C7A6; }
.card.vencida { background: #FCE8E9; border: 2px solid var(--red); }
.card.espera { background: #F1F2F4; border-color: #D5D8DD; }
.card.cerrada { background: #fff; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.chip.ok { background: var(--ok); color: #fff; } .chip.atencion { background: var(--warn); color: var(--ink); }
.chip.riesgo { background: var(--risk); color: #fff; } .chip.vencida { background: var(--red); color: #fff; }
.chip.espera { background: var(--pause); color: #fff; } .chip.cerrada { background: #E5E5E3; color: var(--ink); }
.chip.p-Crítica { background: var(--ink); color: #fff; font-weight: 600; } .chip.p-Alta { background: #5F5F5F; color: #fff; font-weight: 600; }
.chip.p-Media { background: #E5E5E3; font-weight: 600; } .chip.p-Baja { background: #fff; border: 1px solid #BDBDBA; font-weight: 600; }
.chip.escalada { background: #fff; color: var(--red-dark); border: 2px solid var(--red); }
.origin { font-size: 12px; font-weight: 600; color: #4A4A4A; margin-left: auto; }
.code { font-family: var(--mono); font-size: 14px; background: var(--ink); color: #fff; padding: 2px 8px; border-radius: 6px; }
.from { font-size: 13px; color: #4A4A4A; }
.card h3 { margin: 0; font-size: 17px; line-height: 1.3; }
.ctx { font-size: 13px; color: #3A3A3A; background: #fff; border: 1px dashed #BDBDBA; border-radius: 8px; padding: 8px 10px; white-space: pre-line; }
.owner { font-size: 14px; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.av { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.av.none { background: #BDBDBA; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; font-size: 13px; }
.grid2 .k { color: var(--muted); } .grid2 .v { font-weight: 600; } .grid2 .v.mono { font-family: var(--mono); font-size: 15px; font-weight: 700; }
.bar { height: 10px; border-radius: 6px; background: rgba(0,0,0,.08); overflow: hidden; }
.bar > div { height: 100%; border-radius: 6px; }
.bar-ok { background: var(--ok); } .bar-atencion { background: var(--warn); } .bar-riesgo { background: var(--risk); } .bar-vencida { background: var(--red); } .bar-espera { background: #9CA3AF; } .bar-cerrada { background: var(--gray); }
.due { font-size: 13px; font-weight: 600; margin-top: 6px; }
.block { background: #fff; border: 1px solid #D5D8DD; border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ro { font-size: 13px; color: var(--muted); align-self: center; }
.empty { background: #fff; border-radius: 16px; padding: 32px; text-align: center; color: var(--muted); border: 1px dashed #CFCFCC; }

/* Lateral */
.person { display: flex; align-items: center; gap: 12px; background: var(--soft); border-radius: 12px; padding: 12px; }
.person .av { width: 44px; height: 44px; font-size: 15px; background: var(--red); }
.person .av.none { background: #BDBDBA; }
.person b { font-size: 16px; display: block; } .person small { font-size: 13px; color: var(--muted); }
.zab { border: 2px solid var(--risk); background: #FDEEE3; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.zab.esc { border-color: var(--red); background: #FCE8E9; }
.zab b { font-size: 15px; } .zab small { font-size: 13px; color: #7C2D12; font-weight: 600; }
.okbox { font-size: 14px; color: #1F6B42; background: #E8F5EC; border-radius: 10px; padding: 12px; }
.load { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 6px; border-radius: 10px; border: 1px solid transparent; background: #fff; width: 100%; }
.load.on { border: 2px solid var(--ink); }
.load .nm { width: 96px; text-align: left; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.load .tr { flex: 1; height: 14px; border-radius: 7px; background: #EEEEEC; overflow: hidden; display: block; }
.load .tr > span { display: block; height: 100%; border-radius: 7px; }
.load .tx { width: 72px; text-align: right; font-size: 13px; font-weight: 600; }

/* Reportes */
.rep-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.rep { background: var(--soft); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.rep .t { font-size: 15px; font-weight: 700; } .rep .big { font-size: 40px; font-weight: 700; font-family: var(--mono); line-height: 1; } .rep .s { font-size: 13px; color: #4A4A4A; }
.mini { display: flex; flex-direction: column; gap: 2px; }
.mini .l { display: flex; justify-content: space-between; font-size: 12px; } .mini .l b { font-weight: 600; }
.mini .tr { height: 8px; border-radius: 6px; background: var(--line); overflow: hidden; display: block; }
.mini .tr > span { display: block; height: 100%; border-radius: 6px; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
.tbl th { text-align: left; color: var(--muted); font-size: 13px; padding: 10px 8px; border-bottom: 2px solid var(--ink); }
.tbl td { padding: 10px 8px; border-bottom: 1px solid #EEEEEC; vertical-align: top; }
.tbl td.mono { font-family: var(--mono); }
.dateinp { min-height: 44px; font-size: 15px; border: 2px solid var(--ink); border-radius: 10px; padding: 0 10px; background: #fff; }

/* Modal */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px; overflow-y: auto; z-index: 50; }
.modal { width: 100%; max-width: 720px; background: #fff; border-radius: 18px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.modal.wide { max-width: 1000px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.x { width: 44px; height: 44px; border-radius: 10px; border: 1px solid #CFCFCC; background: #fff; font-size: 22px; line-height: 1; }
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); }
.tab { min-height: 44px; padding: 0 16px; border: none; background: none; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab.on { border-bottom-color: var(--red); }
.ev { font-size: 13px; border-left: 3px solid var(--line); padding: 4px 10px; }
.ev b { font-weight: 600; }
.secret { font-family: var(--mono); font-size: 18px; background: var(--soft); border: 2px dashed var(--ink); border-radius: 10px; padding: 12px; text-align: center; user-select: all; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; }

/* Reporte editable */
.report-doc { border: 1px solid var(--line); border-radius: 12px; padding: 28px; font-size: 14px; line-height: 1.5; }
.report-doc h1 { font-size: 22px; margin: 0 0 4px; color: var(--red); }
.report-doc h2 { font-size: 16px; margin: 18px 0 6px; border-bottom: 2px solid var(--red); padding-bottom: 4px; }
.report-doc [contenteditable="true"]:focus { outline: 2px dashed var(--gray); outline-offset: 4px; }
.report-doc table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-doc td, .report-doc th { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; }

@media (max-width: 640px) {
  main { padding: 14px; }
  .flabel { width: 100%; }
  .kpi .n { font-size: 40px; }
}

@media print {
  body * { visibility: hidden; }
  .report-doc, .report-doc * { visibility: visible; }
  .report-doc { position: absolute; left: 0; top: 0; width: 100%; border: none; padding: 0; }
  .report-doc [contenteditable] { outline: none !important; }
}
