/* Monitor it+ — estilos del panel. Paleta heredada de build_dashboard.py (fase 1). */
:root {
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e; --muted: #6f6d68;
  --border: rgba(11,11,11,.12); --grid: #e1e0d9; --base: #c3c2b7; --hover: #f1f0ec;
  --accent: #2a78d6;
  --red: #d03b3b; --yellow: #fab219; --green: #0ca30c;
  --red-bg: #fbeaea; --yellow-bg: #fff5dc; --green-bg: #e7f6e7;
  --s1: #2a78d6; --s2: #8a4fd0; --s3: #e0712c; --s4: #1a9a8c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #9a988f;
    --border: rgba(255,255,255,.12); --grid: #2c2c2a; --base: #383835; --hover: #232321;
    --accent: #3987e5;
    --red: #e5534b; --yellow: #f5b82e; --green: #2fb52f;
    --red-bg: #3a1c1b; --yellow-bg: #3a2f12; --green-bg: #143014;
    --s1: #3987e5; --s2: #a575e6; --s3: #f08a4b; --s4: #33b3a4;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* cabecera */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  background: var(--ink); color: var(--page); font-weight: 800; font-size: 14px; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a, .linkbtn { color: var(--ink2); text-decoration: none; padding: 6px 10px; border-radius: 6px;
  font: inherit; background: none; border: 0; cursor: pointer; }
.nav a:hover, .linkbtn:hover { background: var(--hover); }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 600; background: var(--hover); }
.nav form { margin: 0; }

/* tarjetas y formularios */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin: 0 0 16px; }
.narrow { max-width: 460px; margin: 40px auto; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 500; }
.narrow-form { max-width: 380px; }
input, textarea { font: inherit; color: var(--ink); background: var(--page); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; width: 100%; }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { display: inline-block; font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); text-decoration: none; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.danger { color: var(--red); }
.error { background: var(--red-bg); border-left: 4px solid var(--red); padding: 10px 12px; border-radius: 6px; }
.ok-box { background: var(--green-bg); border-left: 4px solid var(--green); padding: 10px 12px; border-radius: 6px; }
.warn-box { background: var(--yellow-bg); border-left: 4px solid var(--yellow); padding: 10px 12px; border-radius: 6px; }
.bigkey { font: 700 1.6rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .06em; text-align: center;
  padding: 16px; border: 2px dashed var(--base); border-radius: 8px; user-select: all; overflow-wrap: anywhere; }
.inline { display: inline; margin: 0; }
.row-form { display: flex; gap: 8px; margin: 0 0 8px; max-width: 520px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.mini { width: 120px; padding: 4px 6px; font-size: 13px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--ink2); vertical-align: middle; }

/* puntos y etiquetas de estado */
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; margin-right: 7px; vertical-align: -1px; }
.dot.st-rojo { background: var(--red); }
.dot.st-amarillo { background: var(--yellow); }
.dot.st-verde { background: var(--green); }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.badge.st-rojo { background: var(--red); color: #fff; }
.badge.st-amarillo { background: var(--yellow); color: #0b0b0b; }
.badge.st-verde { background: var(--green); color: #fff; }

/* semáforo */
.sem { margin-bottom: 20px; }
.sem-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.sem-btn { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 14px; align-items: center; text-align: left; padding: 16px 40px 16px 18px; border-radius: 12px;
  cursor: pointer; font: inherit; border: 2px solid transparent; color: var(--ink); }
.sem-btn.st-rojo { background: var(--red-bg); border-color: var(--red); }
.sem-btn.st-amarillo { background: var(--yellow-bg); border-color: var(--yellow); }
.sem-btn.st-verde { background: var(--green-bg); border-color: var(--green); }
.sem-btn:hover { filter: brightness(.97); }
.sem-btn[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--page), 0 0 0 5px var(--ink2); }
.sem-n { grid-row: 1 / 3; font-size: 2.6rem; font-weight: 800; line-height: 1; min-width: 1.4ch; text-align: center; }
.sem-l { font-weight: 700; font-size: 1.1rem; }
.sem-s { color: var(--ink2); font-size: .9rem; }
.chev { position: absolute; right: 16px; top: 50%; width: 10px; height: 10px; margin-top: -7px;
  border-right: 2px solid var(--ink2); border-bottom: 2px solid var(--ink2); transform: rotate(45deg); transition: transform .15s; }
.sem-btn[aria-expanded="true"] .chev { transform: rotate(-135deg); margin-top: -2px; }
.tree-panel { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; border-top-width: 4px; }
.tp-rojo { border-top-color: var(--red); } .tp-amarillo { border-top-color: var(--yellow); } .tp-verde { border-top-color: var(--green); }
.tp-title { display: flex; align-items: center; }
.summary { color: var(--muted); font-size: .85rem; margin: 10px 2px 0; }

/* árbol */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree > li { margin: 4px 0; }
.tree summary { cursor: pointer; padding: 4px 0; font-weight: 600; }
.tree ul[role="group"] { margin-left: 8px; padding-left: 16px; border-left: 1px solid var(--base); }
.tree ul[role="group"] > li { padding: 4px 0; }
.tree a { font-weight: 600; }
.count { display: inline-block; min-width: 22px; text-align: center; font-size: 12px; padding: 0 6px; border-radius: 999px;
  background: var(--hover); color: var(--ink2); font-weight: 600; }
.reasons { margin: 2px 0 0 18px !important; padding-left: 0; color: var(--ink2); font-size: .9rem; list-style: disc !important; }
.reasons li { margin-left: 14px; }
.empty { color: var(--muted); }

/* farmacias */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 10px; }
.section-head h2 { margin: 0; }
.section-head input { max-width: 280px; }
.farm { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; }
.farm > summary { display: flex; align-items: center; gap: 8px; padding: 12px 16px; cursor: pointer; list-style: none; }
.farm > summary::-webkit-details-marker { display: none; }
.farm > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted); transform: rotate(-45deg); margin-left: 4px; transition: transform .15s; }
.farm[open] > summary::after { transform: rotate(45deg); }
.farm-name { font-weight: 700; font-size: 1.05rem; }
.chips { display: flex; gap: 4px; margin-left: auto; }
.chip { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.chip.st-rojo { background: var(--red); color: #fff; } .chip.st-amarillo { background: var(--yellow); color: #0b0b0b; }
.chip.st-verde { background: var(--green); color: #fff; }
.farm-n { color: var(--muted); font-size: .85rem; min-width: 44px; text-align: right; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; padding: 0 16px 4px; }
.farm-foot { margin: 8px 16px 12px; font-size: .85rem; }
.filter { margin: 0 0 12px; }
.pc { display: grid; gap: 4px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  border-left-width: 5px; text-decoration: none; color: var(--ink); background: var(--page); }
.pc:hover { background: var(--hover); }
.pc.st-rojo { border-left-color: var(--red); } .pc.st-amarillo { border-left-color: var(--yellow); } .pc.st-verde { border-left-color: var(--green); }
.pc-head { display: flex; align-items: center; gap: 6px; }
.pc-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-reason { font-size: .9rem; color: var(--ink2); }
.pc-meta { font-size: .8rem; color: var(--muted); }

/* detalle de PC */
.crumbs { margin: 0 0 10px; font-size: .9rem; color: var(--muted); }
.pc-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pc-title h1 { margin: 0; }
.actions { margin: 8px 0 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.al { display: flex; align-items: center; padding: 8px 12px; border-radius: 6px; }
.al.st-rojo { background: var(--red-bg); } .al.st-amarillo { background: var(--yellow-bg); }
.al.st-observacion { background: var(--hover); color: var(--ink2); }
.alerts.obs { margin-top: 6px; }
.dot.st-observacion { background: transparent; border: 2px solid var(--muted); box-sizing: border-box; }
.charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 16px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.chart figcaption { font-weight: 600; margin-bottom: 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--base); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ref { stroke-width: 1.25; stroke-dasharray: 5 4; }
.chart .ref-amarillo { stroke: var(--yellow); } .chart .ref-rojo { stroke: var(--red); }
.ln.s1 { stroke: var(--s1); } .ln.s2 { stroke: var(--s2); } .ln.s3 { stroke: var(--s3); } .ln.s4 { stroke: var(--s4); }
.pt.s1 { fill: var(--s1); } .pt.s2 { fill: var(--s2); } .pt.s3 { fill: var(--s3); } .pt.s4 { fill: var(--s4); }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--ink2); margin-bottom: 4px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); } .sw.s3 { background: var(--s3); } .sw.s4 { background: var(--s4); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin: 0 0 16px; }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 5px 10px 5px 0; vertical-align: top; width: 38%; }
.kv td { padding: 5px 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--base); padding: 6px 8px; }
.tbl td { border-bottom: 1px solid var(--grid); padding: 6px 8px; vertical-align: middle; }
.tbl .n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.acts { white-space: nowrap; }
.tbl td.acts form { margin-right: 4px; }
.scroll { overflow-x: auto; }
.tbl.smart { min-width: 640px; } .tbl.smart td:nth-child(2) { white-space: nowrap; } .tbl.smart .bar { min-width: 90px; }
.bar { width: 120px; height: 8px; display: block; }
.bar-bg { fill: var(--grid); }
.bar-fg.st-verde { fill: var(--green); } .bar-fg.st-amarillo { fill: var(--yellow); } .bar-fg.st-rojo { fill: var(--red); }
.plain { margin: 0; padding-left: 18px; }

/* ajustes: umbrales */
.th-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 24px; }
.th-row { display: flex !important; align-items: center; justify-content: space-between; gap: 10px; font-weight: 400 !important;
  border-bottom: 1px solid var(--grid); padding: 4px 0; }
.th-in { display: flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--muted); }
.th-in input { width: 80px; text-align: right; }

/* móvil */
@media (max-width: 760px) {
  .sem-row { grid-template-columns: 1fr; }
  .charts, .cols, .th-grid { grid-template-columns: 1fr; }
  .section-head { flex-direction: column; align-items: stretch; }
  .section-head input { max-width: none; }
  .brand span:last-child { display: none; }
}

.wide { max-width: 640px; }
.row-form.tight { margin: 0; max-width: 380px; }
pre.cmd { background: var(--hover); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
  white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.4 ui-monospace, Consolas, monospace; user-select: all; }
code { font: 13px ui-monospace, Consolas, monospace; background: var(--hover); padding: 1px 5px; border-radius: 4px; }
.row-form .btn { white-space: nowrap; }

/* ---------------------------------------------------------------- recomendaciones */
:root { --blue: #2a78d6; --blue-bg: #e8f1fc; }
@media (prefers-color-scheme: dark) { :root { --blue: #3987e5; --blue-bg: #14233a; } }
.sec-title { font-size: 1.1rem; margin: 8px 0 10px; }
.farm-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.recs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rec { display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; border-radius: 6px; border-left: 4px solid; }
.rec-urgente { background: var(--red-bg); border-color: var(--red); }
.rec-recomendado { background: var(--yellow-bg); border-color: var(--yellow); }
.rec-planificar { background: var(--blue-bg); border-color: var(--blue); }
.rec-tag { flex: none; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  min-width: 92px; padding-top: 2px; color: var(--ink2); }
.rec-body { display: grid; gap: 2px; }
.rec-why { color: var(--ink2); font-size: .88rem; }
.pill { display: inline-block; white-space: nowrap; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; vertical-align: middle; }
.pill-urgente { background: var(--red); color: #fff; }
.pill-recomendado { background: var(--yellow); color: #0b0b0b; }
.pill-planificar { background: var(--blue); color: #fff; }
.pill-ok { background: var(--green); color: #fff; }

/* ---------------------------------------------------------------- informe */
.informe-barra { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.informe { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px 32px; max-width: 980px; margin: 0 auto; }
.informe h2 { margin: 26px 0 10px; font-size: 1.15rem; border-bottom: 2px solid var(--ink); padding-bottom: 4px; }
.informe h3 { margin: 14px 0 6px; }
.inf-cab { display: flex; gap: 18px; align-items: center; border-bottom: 3px solid var(--ink); padding-bottom: 16px; }
.inf-cab h1 { margin: 0; font-size: 1.5rem; }
.inf-farm { margin: 2px 0; font-size: 1.25rem; font-weight: 700; }
.inf-cab .muted { margin: 0; }
.inf-logo { flex: none; width: 74px; height: 74px; border-radius: 14px; background: #1aa3b8; color: #fff;
  display: grid; place-items: center; font: 800 30px/1 system-ui, Arial, sans-serif; }
.inf-resumen { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.kpi { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: grid; gap: 2px; border-top: 4px solid var(--ink2); }
.kpi-n { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.kpi-urgente { border-top-color: var(--red); } .kpi-recomendado { border-top-color: var(--yellow); } .kpi-ok { border-top-color: var(--green); }
.plan-h { display: flex; align-items: center; gap: 8px; }
.plan-h::before { content: ""; width: 12px; height: 12px; border-radius: 3px; }
.plan-urgente::before { background: var(--red); } .plan-recomendado::before { background: var(--yellow); } .plan-planificar::before { background: var(--blue); }
.tbl.plan td:first-child { width: 160px; }
.ficha { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.ficha h2 { border: 0; margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
.ficha-cols { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
.ficha-cols h3 { margin-top: 0; }
.notas { min-height: 110px; border: 1px dashed var(--base); border-radius: 8px; padding: 10px; white-space: pre-wrap; }
.notas:empty::before { content: "Escribe aquí observaciones, presupuestos o próximos pasos antes de imprimir…"; color: var(--muted); }
.inf-pie { margin-top: 26px; padding-top: 10px; border-top: 1px solid var(--base); font-size: .82rem; color: var(--muted); }
@media (max-width: 760px) {
  .inf-resumen { grid-template-columns: 1fr 1fr; }
  .ficha-cols { grid-template-columns: 1fr; }
  .informe { padding: 16px; }
}

/* ---------------------------------------------------------------- impresión (A4) */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  :root { --page: #fff; --surface: #fff; --ink: #000; --ink2: #333; --muted: #555; --border: #bbb; --base: #999; --grid: #ddd;
    --red-bg: #fdecec; --yellow-bg: #fff6df; --green-bg: #e9f7e9; --blue-bg: #eaf2fd; color-scheme: light; }
  body { background: #fff; font-size: 11pt; }
  .top, .no-print, .nav { display: none !important; }
  main { padding: 0; max-width: none; }
  .informe { border: 0; padding: 0; max-width: none; }
  .ficha, .rec, .kpi, tr, .inf-pie, .inf-notas, .inf-resumen { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
  .plan-h + table { break-before: avoid; }
  .notas:empty { display: none; }
  .notas:empty::before { content: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
