:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1b1f27;
  --muted: #687082;
  --line: #e2e5eb;
  --hover: #f0f2f6;
  --franja: #f1f4f9;
  --fila-activa: #e2eafd;
  --cabecera: #f8f9fb;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --danger: #c23a3a;
  --late: #c23a3a;
  /* Estados: fondo suave + texto */
  --gris-bg: #eef0f4; --gris-tx: #4a5263;
  --azul-bg: #e3ecff;  --azul-tx: #2448a8;
  --ambar-bg: #fff2d9;  --ambar-tx: #8a5a00;
  --verde-bg: #dff5e6;  --verde-tx: #1d7340;
  --violeta-bg: #f1e6fb; --violeta-tx: #6b3a9a;
  --rojo-bg: #f6e3e3;  --rojo-tx: #9a3333;
  --alta: #c23a3a; --media: #b77900; --baja: #687082;
  --sombra: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b1f27;
    --text: #e6e8ee;
    --muted: #9aa2b3;
    --line: #2c323e;
    --hover: #232833;
    --franja: #222834;
    --fila-activa: #263457;
    --cabecera: #1f242d;
    --accent: #6d8ff0;
    --accent-text: #0f1320;
    --danger: #ef6b6b;
    --late: #ef6b6b;
    --gris-bg: #2a2f3a; --gris-tx: #b9c0cf;
    --azul-bg: #1f2c4d;  --azul-tx: #9db7ff;
    --ambar-bg: #3a2f17;  --ambar-tx: #f2c66d;
    --verde-bg: #173323;  --verde-tx: #7fd8a0;
    --violeta-bg: #2f2340; --violeta-tx: #cfa6f5;
    --rojo-bg: #3a2020;  --rojo-tx: #f19a9a;
    --alta: #ef6b6b; --media: #f2c66d; --baja: #9aa2b3;
    --sombra: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h2 .sutil { font-weight: 400; font-size: 13px; margin-left: 6px; }
.sutil { color: var(--muted); }
.txt-vencido { color: var(--late); font-weight: 600; }
.txt-ambar { color: var(--ambar-tx); font-weight: 600; }
.chico { font-size: 12px; }
.relleno { flex: 1; }
[hidden] { display: none !important; }

/* ── Controles ── */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}
button:hover { background: var(--hover); }
button:disabled { opacity: 0.6; cursor: default; }
button.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primario:hover { filter: brightness(1.08); }
button.peligro { color: var(--danger); }
button.link { border: 0; background: none; padding: 2px 6px; color: var(--accent); }
button.link:hover { text-decoration: underline; background: none; }
button.link.peligro { color: var(--danger); }
input, select, textarea {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }

/* ── Barra superior ── */
.barra {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.marca { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.marca:hover { text-decoration: none; }
.barra nav { display: flex; gap: 4px; flex: 1; }
.barra nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.barra nav a:hover { background: var(--hover); text-decoration: none; }
.barra nav a.activo { color: var(--text); background: var(--hover); }
.cuenta { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
/* La grilla de proyectos usa casi todo el ancho de la pantalla. */
main.ancha { max-width: 1840px; padding-left: 32px; padding-right: 32px; }

/* ── Ingreso ── */
.login { min-height: 80vh; display: grid; place-items: center; }
.login .tarjeta { width: min(380px, 100%); padding: 32px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin-top: 4px; }
.login p { margin: 0 0 8px; }
.boton-ms {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--text); color: var(--bg); font-weight: 600;
  padding: 11px 16px; border-radius: 9px;
}
.boton-ms:hover { text-decoration: none; opacity: 0.9; }

/* ── Bloques ── */
.tarjeta { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sombra); }
.encabezado { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.encabezado p { margin: 4px 0 0; }
.botones { display: flex; gap: 8px; }
.volver { display: inline-block; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.vacio { padding: 40px 16px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: 12px; list-style: none; }
.vacio.chico { padding: 16px; }

/* ── Resumen por estado ── */
.resumen { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 16px; }
.chip-estado {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px 14px; border-radius: 12px; border: 2px solid transparent; text-align: left;
}
.chip-estado .num { font-size: 22px; font-weight: 700; line-height: 1.1; }
.chip-estado span:last-child { font-size: 12px; font-weight: 500; }
.chip-estado.sel { border-color: currentColor; }
.chip-estado:hover { filter: brightness(0.97); }

.c-gris    { background: var(--gris-bg);    color: var(--gris-tx); }
.c-azul    { background: var(--azul-bg);    color: var(--azul-tx); }
.c-ambar   { background: var(--ambar-bg);   color: var(--ambar-tx); }
.c-verde   { background: var(--verde-bg);   color: var(--verde-tx); }
.c-violeta { background: var(--violeta-bg); color: var(--violeta-tx); }
.c-rojo    { background: var(--rojo-bg);    color: var(--rojo-tx); }
.s-ok      { background: var(--verde-bg);   color: var(--verde-tx); }
.s-riesgo  { background: var(--ambar-bg);   color: var(--ambar-tx); }
.s-bloq    { background: var(--rojo-bg);    color: var(--rojo-tx); }

.estado, .salud { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.prio { font-size: 12px; font-weight: 600; }
.prio::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; }
.p-Alta { color: var(--alta); }
.p-Media { color: var(--media); }
.p-Baja { color: var(--baja); }

/* ── Filtros y tabla ── */
.filtros { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filtros input[type=search] { flex: 1; min-width: 200px; }
.tabla-cont { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sombra); }
.tabla { width: 100%; border-collapse: collapse; }
.tabla th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tabla td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabla tbody tr:last-child td { border-bottom: 0; }

.tabla tbody tr[data-id]:hover { background: var(--hover); }
.tabla .nombre { font-weight: 600; color: var(--text); }
.tabla .sutil { font-size: 12px; }
.tabla tr.inactivo td { opacity: 0.55; }
.der { text-align: right; white-space: nowrap; }

.avance { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.avance span { font-size: 12px; color: var(--muted); width: 34px; }
progress { appearance: none; width: 80px; height: 6px; border: 0; border-radius: 99px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }

/* ── Detalle ── */
.ficha { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px 24px; padding: 20px; margin-bottom: 24px; }
.dato { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.dato a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dato.completo { grid-column: 1 / -1; }
.rotulo { font-size: 12px; color: var(--muted); font-weight: 500; }
.texto-largo { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.sel-color { font-weight: 600; border: 0; }


.alta-pend { padding: 12px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.alta-pend .fila { display: flex; gap: 8px; flex-wrap: wrap; }
.alta-pend .fila select, .alta-pend .fila input { flex: 1; min-width: 110px; }

.pendientes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pend {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.pend .tilde { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.pend .cuerpo { flex: 1; min-width: 0; }
.pend .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.pend.hecho .desc { text-decoration: line-through; color: var(--muted); }
.acciones-item { display: flex; opacity: 0; transition: opacity 0.15s; }
.pend:hover .acciones-item, .pend:focus-within .acciones-item { opacity: 1; }
@media (hover: none) { .acciones-item { opacity: 1; } }
.hechos { margin-top: 14px; }
.hechos summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }


/* ── Diálogos ── */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--card); color: var(--text); width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.25);
}
dialog:has(form.ancho) { width: min(680px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 14 22 / 0.45); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 18px; margin: 0; }
.grilla { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grilla .doble { grid-column: 1 / -1; }
.acciones { display: flex; justify-content: flex-end; gap: 8px; }

/* ── Aviso flotante ── */
#aviso {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 20; max-width: calc(100vw - 32px);
}
#aviso.visible { opacity: 1; transform: translate(-50%, 0); }
#aviso.error { background: var(--danger); color: #fff; }

/* ── Pantallas chicas ── */
@media (max-width: 900px) {
  .resumen { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  main { padding: 16px; }
  .barra { padding: 0 16px; gap: 12px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .barra nav { order: 3; flex-basis: 100%; padding-bottom: 8px; overflow-x: auto; }
  .marca span { display: none; }
  .cuenta { margin-left: auto; }
  .resumen { grid-template-columns: repeat(2, 1fr); }
  .grilla { grid-template-columns: 1fr; }
}

/* ── Situación ── */
.salud::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }

/* ── Grilla de proyectos ── */
.grilla-proy td { vertical-align: top; }
.grilla-proy .col-estado { min-width: 360px; max-width: 760px; line-height: 1.5; }
.col-acciones { width: 1%; white-space: nowrap; text-align: right; }
.icono { border: 0; background: none; padding: 6px; border-radius: 8px; color: var(--muted); line-height: 0; }
.icono:hover { background: var(--hover); color: var(--text); }
.icono.peligro:hover { color: var(--danger); }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.sin-margen { margin: 0; }

/* ── Estado actual (detalle) ── */
.estado-actual { padding: 18px 20px; margin-bottom: 24px; }
.estado-actual .cab { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.estado-actual .cab h2 { margin: 0; }
.estado-actual form { display: flex; flex-direction: column; gap: 10px; }
.estado-actual textarea { line-height: 1.55; }
.nowrap { white-space: nowrap; }

/* En pantallas chicas cada proyecto se ve como tarjeta, con el estado actual a la vista. */
@media (max-width: 700px) {
  .grilla-proy thead { display: none; }
  .grilla-proy, .grilla-proy tbody, .grilla-proy tr { display: block; }
  .grilla-proy tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .grilla-proy tbody tr:last-child { border-bottom: 0; }
  .grilla-proy td { display: block; border: 0; padding: 3px 0; }
  .grilla-proy td.insignias { display: inline-block; margin: 4px 6px 4px 0; }
  .grilla-proy td.insignias:empty { display: none; }
  .grilla-proy td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  .grilla-proy td:empty { display: none; }
  .grilla-proy .col-estado, .grilla-proy .col-proy { min-width: 0; max-width: none; }
}

/* Grilla: filas alternadas y cabecera fija debajo de la barra superior al bajar. */
.tabla-cont:has(.grilla-proy) { overflow: visible; }
.grilla-proy tbody tr:nth-child(even) { background: var(--franja); }
/* La fila bajo el mouse toma un tono propio, distinto de las dos franjas. */
.tabla.grilla-proy tbody tr[data-id]:hover { background: var(--fila-activa); }
.grilla-proy thead th { position: sticky; top: 56px; z-index: 2; background: var(--cabecera); }
.grilla-proy thead th:first-child { border-top-left-radius: 12px; }
.grilla-proy thead th:last-child { border-top-right-radius: 12px; }
.grilla-proy tbody tr:last-child td:first-child { border-bottom-left-radius: 12px; }
.grilla-proy tbody tr:last-child td:last-child { border-bottom-right-radius: 12px; }
@media (max-width: 700px) {
  .grilla-proy tbody tr:last-child { border-radius: 0 0 12px 12px; }
}

/* Etapas visibles: una casilla por etapa para filtrar la grilla. */
.filtros-chk { display: flex; flex-wrap: wrap; gap: 10px; margin: -4px 0 14px; }
.filtros-chk > fieldset { margin: 0; }
.filtros-chk { justify-content: space-between; }
.filtros-chk > .prioridades { margin-left: auto; column-gap: 10px; }
.etapas, .prioridades { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: -4px 0 14px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.etapas legend, .prioridades legend { float: left; padding: 0; margin-right: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.etapa-chk { flex-direction: row; align-items: center; gap: 6px; cursor: pointer; color: var(--text); }
.etapa-chk input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.etapa-chk .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.etapa-chk:has(input:not(:checked)) .estado, .etapa-chk:has(input:not(:checked)) .prio-num { opacity: 0.45; }
.etapas .sep, .prioridades .sep { width: 1px; height: 18px; background: var(--line); }
.etapas .link, .prioridades .link { font-size: 12px; }
.grilla-proy .col-proy { min-width: 240px; }
.grilla-proy .col-num { width: 1%; padding-right: 4px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
@media (max-width: 700px) {
  .grilla-proy td.col-num { display: none; }
}

/* Prioridad 1 (más urgente) a 5: círculo con color de rojo a gris. */
.prio-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.prio-num.p1 { background: var(--rojo-bg); color: var(--rojo-tx); box-shadow: inset 0 0 0 1.5px currentColor; }
.prio-num.p2 { background: var(--rojo-bg); color: var(--rojo-tx); }
.prio-num.p3 { background: var(--ambar-bg); color: var(--ambar-tx); }
.prio-num.p4 { background: var(--azul-bg); color: var(--azul-tx); }
.prio-num.p5 { background: var(--gris-bg); color: var(--gris-tx); }
.grilla-proy .col-prio { width: 1%; text-align: center; }
@media (max-width: 700px) {
  .grilla-proy td.col-prio { display: inline-block; margin: 0 8px 4px 0; vertical-align: middle; }
  .grilla-proy td.col-prio::before { display: none; }
}

/* Marca de la empresa en la barra y en el ingreso. */
.marca .logo { height: 24px; width: auto; display: block; }
.marca .sep-marca { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.logo-login { height: 60px; width: auto; align-self: flex-start; margin-bottom: 4px; }
@media (max-width: 600px) {
  .marca .sep-marca { display: none; }
}
.boton-chico { padding: 3px 10px; font-size: 12px; border-radius: 7px; }
