:root {
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --line: #e2e1dc;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7a7974;
  --accent: #2a78d6; --accent-soft: #e3eefb;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b; --none: #9a9993;
  --good-ink: #067a06; --warn-ink: #8a5d00; --crit-ink: #b42c2c;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-soft: #1c2c40;
    --good-ink: #4fd44f; --warn-ink: #fab219; --crit-ink: #ff8a8a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --accent-soft: #1c2c40;
  --good-ink: #4fd44f; --warn-ink: #fab219; --crit-ink: #ff8a8a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }

/* ---- barra superior */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; height: 54px; }
.marca { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.marca small { font-weight: 500; color: var(--muted); }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav a { padding: 7px 11px; border-radius: 7px; color: var(--text-2); white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.activo { background: var(--accent-soft); color: var(--accent); }
.nav .cuenta { margin-left: 4px; font-size: 11px; background: var(--crit); color: #fff; border-radius: 9px; padding: 0 6px; font-weight: 700; }
.top-der { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 5px 10px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 28px 0 10px; }
.sub { color: var(--text-2); margin: 0 0 18px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---- tarjetas */
.grid { display: grid; gap: 14px; }
.g3 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card.click { cursor: pointer; transition: border-color .15s; }
.card.click:hover { border-color: var(--accent); }
.card-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-cab h3 { margin: 0; font-size: 15px; }
.card-cab p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

/* ---- semáforo: siempre punto + texto */
.estado { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px; background: var(--surface-2); white-space: nowrap; }
.punto { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.ok .punto, .punto.ok { background: var(--good); }
.aviso .punto, .punto.aviso { background: var(--warn); }
.critica .punto, .punto.critica, .punto.mal { background: var(--crit); }
.sin_datos .punto, .punto.desconocido, .punto.pendiente { background: var(--none); }
.estado.ok { color: var(--good-ink); } .estado.aviso { color: var(--warn-ink); } .estado.critica { color: var(--crit-ink); }

/* ---- medidores */
.medidores { display: grid; gap: 9px; }
.med { display: grid; grid-template-columns: 52px 1fr 118px; align-items: center; gap: 10px; font-size: 12.5px; }
.med .et { color: var(--text-2); }
.med .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.barra { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.barra i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.barra i.aviso { background: var(--warn); } .barra i.critica { background: var(--crit); }
.datos-mini { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-2); }
.datos-mini b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---- tablas */
.tabla-env { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nw { white-space: nowrap; }
.vacio { padding: 18px; color: var(--muted); text-align: center; }

/* ---- alertas */
.alerta { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.alerta:last-child { border-bottom: 0; }
.alerta .cuando { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.alerta .punto { margin-top: 5px; }
.todo-bien { display: flex; align-items: center; gap: 10px; padding: 14px; color: var(--good-ink); font-weight: 600; }

/* ---- clientes */
.item { display: grid; grid-template-columns: 14px 1fr auto; gap: 4px 10px; padding: 9px 0; border-top: 1px solid var(--line); align-items: start; }
.item:first-of-type { border-top: 0; }
.item .punto { margin-top: 5px; }
.item .nom { font-weight: 600; }
.item .det { grid-column: 2 / 4; color: var(--text-2); font-size: 12px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }

/* ---- gráficas */
.graficas { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.graf h4 { margin: 0 0 2px; font-size: 13px; }
.graf .ahora { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.graf .ahora small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.graf svg { width: 100%; height: 150px; display: block; margin-top: 6px; overflow: visible; }
.graf .eje { stroke: var(--line); stroke-width: 1; }
.graf .eje-t { fill: var(--muted); font-size: 10px; }
.graf .linea { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.graf .area { fill: var(--accent); opacity: .10; }
.graf .umbral { stroke: var(--crit); stroke-dasharray: 3 3; stroke-width: 1; opacity: .7; }
.graf .cruz { stroke: var(--muted); stroke-width: 1; }
.graf .marca-p { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.tip { position: fixed; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 6px; z-index: 50; white-space: nowrap; display: none; }
.rango { display: inline-flex; gap: 4px; }

.cab-detalle { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 18px; }
.pestanas-srv { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---- proyectos */
.proximamente { border: 1px dashed var(--line); border-radius: var(--radius); padding: 22px; background: var(--surface); }
.campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 16px; }
.campo { background: var(--surface-2); border-radius: 8px; padding: 12px; }
.campo b { display: block; margin-bottom: 4px; }
.campo span { color: var(--text-2); font-size: 12.5px; }

/* ---- login */
.login-env { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login label { display: block; font-size: 12.5px; color: var(--text-2); margin: 16px 0 6px; font-weight: 500; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login button { width: 100%; margin-top: 20px; padding: 11px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login button:disabled { opacity: .6; }
.login .error { color: var(--crit-ink); font-size: 13px; margin-top: 12px; min-height: 18px; }

@media (max-width: 700px) {
  .top-in { height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 6px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .g3, .g2, .graficas { grid-template-columns: 1fr; }
  .med { grid-template-columns: 46px 1fr 110px; }
  .alerta { flex-wrap: wrap; }
  .alerta .cuando { margin-left: 21px; }
}

/* ---- proyectos */
.btn.primario { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
.btn.primario:hover { filter: brightness(1.08); }
.btn.peligro { color: var(--crit-ink); }
.btn.peligro:hover { border-color: var(--crit); }
.btn.mini { padding: 2px 8px; font-size: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 4px 0 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi small.vencida, .vencida { color: var(--crit-ink); font-weight: 600; }
.filtros { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.proyecto { border-left: 3px solid var(--line); }
.proyecto.est-en_curso { border-left-color: var(--accent); }
.proyecto.est-pausado { border-left-color: var(--warn); }
.proyecto.est-entregado { border-left-color: var(--good); opacity: .85; }
.acciones-p { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chip.prio-alta { color: var(--crit-ink); font-weight: 600; }
.chip.prio-baja { color: var(--muted); }
.linea-p { font-size: 13px; color: var(--text-2); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.linea-p b { color: var(--text); }
.linea-p .sep { margin: 0 8px; color: var(--muted); }
.enlaces-p { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; margin-bottom: 8px; }
.enlace-p { display: inline-flex; align-items: center; gap: 6px; }
.ico-repo { color: var(--muted); }
.notas-p { white-space: pre-wrap; font-size: 13px; color: var(--text-2); background: var(--surface-2); border-radius: 7px; padding: 8px 10px; margin-bottom: 8px; max-height: 9em; overflow: auto; }
.tareas-p { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.tareas-cab { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.tarea { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.tarea label { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; cursor: pointer; }
.tarea label span { overflow-wrap: anywhere; }
.tarea input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.tarea.hecha label span { text-decoration: line-through; color: var(--muted); }
.fecha-t { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.fecha-t.hoy { color: var(--warn-ink); font-weight: 600; }
.fecha-t.vencida { color: var(--crit-ink); font-weight: 600; }
.btn-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 6px; border-radius: 5px; }
.btn-x:hover { color: var(--crit-ink); background: var(--surface-2); }
.nueva-tarea { display: grid; grid-template-columns: 1fr 90px 132px auto; gap: 6px; margin-top: 8px; }
.nueva-tarea input, .dlg input, .dlg select, .dlg textarea { padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; font-size: 13px; min-width: 0; }
.nueva-tarea input:focus, .dlg input:focus, .dlg select:focus, .dlg textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); padding: 22px; width: min(640px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0, 0, 0, .45); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
.form-grid label input, .form-grid label select, .form-grid label textarea { width: 100%; }
.form-grid .ancho { grid-column: 1 / -1; }
.dlg .error { color: var(--crit-ink); font-size: 13px; min-height: 18px; margin-top: 10px; }
.dlg-pie { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .nueva-tarea { grid-template-columns: 1fr 1fr; }
  .nueva-tarea input[name=titulo] { grid-column: 1 / -1; }
}
