:root {
  --green: #2ca01c;
  --green-dark: #108000;
  --green-soft: #e8f5e4;
  --ink: #393a3d;
  --muted: #6b6c72;
  --line: #d4d7dc;
  --line-soft: #e3e5e8;
  --bg: #f4f5f8;
  --blue: #0077c5;
  --amber: #b45309;
  --red: #c0392b;
  --sidebar: #2c2c2e;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------------------------------------------------------------- shell */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--sidebar);
  color: #d6d7d9;
  padding: 18px 0;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 0 18px 20px;
  color: #fff; font-weight: 600; font-size: 15px; letter-spacing: .2px;
}
.brand .mark {
  width: 26px; height: 26px; border-radius: 5px;
  background: var(--green); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.nav-item {
  display: block; padding: 10px 18px; color: #d6d7d9;
  text-decoration: none; font-size: 14px; border-left: 3px solid transparent;
}
.nav-item:hover { background: #3a3a3c; color: #fff; }
.nav-item.active { background: #3a3a3c; color: #fff; border-left-color: var(--green); font-weight: 600; }.nav-sep { height: 1px; background: #454547; margin: 12px 18px; }
.nav-note { padding: 8px 18px; font-size: 11px; color: #8c8d90; line-height: 1.5; }

.main { flex: 1; min-width: 0; background: #fff; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 26px; border-bottom: 1px solid var(--line-soft);
}
.topbar .search {
  flex: 1; max-width: 340px; padding: 7px 11px;
  border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; color: var(--ink);
}
.topbar .search:focus { outline: 2px solid rgba(0,119,197,.35); outline-offset: -1px; border-color: var(--blue); }
.topbar .spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); }

.btn {
  border: 1px solid var(--green); background: var(--green); color: #fff;
  padding: 8px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.page { padding: 22px 26px 60px; }
h1 { font-size: 24px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------------------------------------------------------------- list */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }

.cards { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.card {
  flex: 1 1 180px; border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 14px 16px; background: #fff;
}
.card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.card .value { font-size: 22px; font-weight: 600; margin-top: 6px; }
.card .foot { font-size: 12px; color: var(--muted); margin-top: 3px; }

.filters { display: flex; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 5px 12px; border-radius: 14px; font-size: 12px; cursor: pointer;
}
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.clickable:hover { background: #f7f8fa; cursor: pointer; }
.pname { font-weight: 600; color: var(--blue); }
.pname:hover { text-decoration: underline; }
.dim { color: var(--muted); font-size: 12px; }
.empty { padding: 26px 10px; color: var(--muted); font-size: 13px; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 11px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.pill.progreso { background: #e6f2fb; color: #0a5c93; }
.pill.cerrado { background: #eceef1; color: var(--muted); }
.pill.ok { background: var(--green-soft); color: var(--green-dark); }
.pill.warn { background: #fdf1dd; color: var(--amber); }
.pill.bad { background: #fbe6e4; color: var(--red); }

.m-ok { color: var(--green-dark); font-weight: 600; }
.m-warn { color: var(--amber); font-weight: 600; }
.m-bad { color: var(--red); font-weight: 600; }

/* ---------------------------------------------------------------- detail */
.crumb { font-size: 13px; color: var(--blue); text-decoration: none; }
.crumb:hover { text-decoration: underline; }

.detail-head { display: flex; align-items: flex-start; gap: 16px; margin: 10px 0 18px; }
.detail-head .spacer { flex: 1; }
.meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--muted); }
.meta b { color: var(--ink); font-weight: 600; }

.profit {
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 4px;
}
.profit-nums { display: flex; gap: 0; flex-wrap: wrap; }
.pn { flex: 1 1 150px; padding: 0 20px; border-left: 1px solid var(--line-soft); }
.pn:first-child { padding-left: 0; border-left: none; }
.pn .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.pn .value { font-size: 27px; font-weight: 600; margin-top: 5px; font-variant-numeric: tabular-nums; }
.pn .foot { font-size: 12px; color: var(--muted); margin-top: 3px; }

.bar { display: flex; height: 26px; border-radius: 3px; overflow: hidden; margin: 20px 0 12px; background: var(--bg); }
.seg { height: 100%; }
.seg.labor { background: #0077c5; }
.seg.mat { background: #4aa3df; }
.seg.sub { background: #8d5bb5; }
.seg.otro { background: #a6a9ae; }
.seg.util { background: var(--green); }
.seg.over { background: var(--red); }

.legend { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12px; }
.legend .item { display: flex; align-items: center; gap: 7px; }
.legend .dot { width: 10px; height: 10px; border-radius: 2px; flex: 0 0 10px; }
.legend .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.legend .pctd { color: var(--muted); }

.alert {
  display: flex; align-items: center; gap: 9px;
  background: #fbe6e4; color: #8c2a1f; border-left: 3px solid var(--red);
  padding: 10px 14px; border-radius: 3px; font-size: 13px; margin: 16px 0 0;
}
.alert.info { background: #fdf1dd; color: #7a4a08; border-left-color: #d9822b; }

.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin: 22px 0 0; overflow-x: auto; }
.tab {
  white-space: nowrap; flex: 0 0 auto;
  background: none; border: none; padding: 12px 2px; font-size: 14px; color: var(--muted);
  cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--green); }
.tabwrap { padding-top: 18px; }

.split { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.panel {
  flex: 1 1 320px; border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px 18px;
}
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.kv.total { border-top: 2px solid var(--line); border-bottom: none; margin-top: 4px; padding-top: 10px; font-size: 14px; }

.minibar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.minibar > span { display: block; height: 100%; background: var(--blue); }

.progress { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--green); }

/* fases */
.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: flex-start; gap: 12px; padding: 9px 0; }
.step .dot {
  width: 20px; height: 20px; border-radius: 50%; flex: 0 0 20px; margin-top: 1px;
  border: 2px solid var(--line); background: #fff; color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.step.done .dot { background: var(--green); border-color: var(--green); }
.step.next .dot { border-color: var(--green); border-style: dashed; }
.step .name { font-size: 13px; }
.step.done .name { color: var(--ink); }
.step:not(.done) .name { color: var(--muted); }
.step .when { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.linkout { color: var(--blue); text-decoration: none; font-size: 13px; }
.linkout:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- modal */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .35);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.backdrop[hidden] { display: none !important; }
.modal { background: #fff; border-radius: 6px; width: 100%; max-width: 460px; box-shadow: 0 8px 28px rgba(0,0,0,.24); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line-soft); font-weight: 600; font-size: 16px; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line-soft); display: flex; gap: 10px; justify-content: flex-end; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(0,119,197,.35); outline-offset: -1px; border-color: var(--blue);
}
.row2 { display: flex; gap: 12px; }
.row2 > * { flex: 1; }
.modaltabs { display: flex; gap: 6px; padding: 12px 20px 0; }
.modaltabs .chip { border-radius: var(--radius); }

.foot-note { margin-top: 26px; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ---------------------------------------------------------------- secciones */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line-soft); margin: 0 4px; }
.select {
  padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; background: #fff; color: var(--ink); font-family: inherit;
}
.select:focus { outline: 2px solid rgba(0,119,197,.35); outline-offset: -1px; border-color: var(--blue); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; margin-bottom: 20px; }
.grid2 > .panel { flex: none; min-width: 0; overflow-x: auto; }
.section-title { font-size: 15px; font-weight: 600; margin: 28px 0 12px; }
.section-title .dim { font-weight: 400; margin-left: 6px; }
.panel h2 .dim { font-weight: 400; margin-left: 6px; }

.attn { list-style: none; margin: 0; padding: 0; }
.attn li { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.attn li:last-child { border-bottom: none; }
.attn .pill { flex: 0 0 auto; }
.attn .what { flex: 1; min-width: 0; }
.attn a.pname { font-size: 13px; }

.hbar { display: grid; grid-template-columns: minmax(120px, 190px) 1fr 64px; gap: 12px; align-items: center; padding: 7px 0; }
.hbar .hlabel { min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { position: relative; height: 14px; background: var(--bg); border-radius: 3px; }
.hbar .fill { height: 100%; border-radius: 3px; background: var(--blue); }
.hbar .fill.ok { background: var(--green); }
.hbar .fill.warn { background: #e8a33d; }
.hbar .fill.bad { background: var(--red); }
.hbar .mark { position: absolute; top: -4px; bottom: -4px; border-left: 2px dashed #8c9096; }
.hbar .mark.target { border-left-color: var(--green-dark); }
.chart-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

.pill.toggle { cursor: pointer; border: none; font-family: inherit; }
.pill.toggle:hover { box-shadow: inset 0 0 0 1px currentColor; }

a.pname { text-decoration: none; }

/* login */
.login { max-width: 360px; margin: 60px auto; padding: 26px 28px; }
.login-error { color: var(--red); font-size: 13px; margin: -4px 0 12px; }
body.sin-sesion .sidebar, body.sin-sesion .mobile-nav, body.sin-sesion .topbar { visibility: hidden; }

/* fases clickeables */
.step { padding: 0; }
.step-btn {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 9px 6px;
  background: none; border: none; border-radius: var(--radius); text-align: left;
  font: inherit; color: inherit; cursor: pointer;
}
.step-btn:hover { background: var(--bg); }
.step-btn:focus-visible { outline: 2px solid rgba(0,119,197,.45); outline-offset: 1px; }
.step:not(.done) .when { color: var(--blue); }

/* borrar renglón */
.x-btn {
  background: none; border: none; color: #9aa0a6; font-size: 18px; line-height: 1;
  cursor: pointer; padding: 2px 6px; border-radius: var(--radius);
}
.x-btn:hover { color: var(--red); background: #fbe6e4; }

/* tarifas editables */
.rate-row { align-items: center; gap: 10px; margin: 0; }
.rate-edit { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.rate-input {
  width: 78px; padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; text-align: right; color: var(--ink);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* listas de pendientes: checkbox redondo, filas agrupadas, contador en tab, encabezado de sección con botón */
.modaltabs { flex-wrap: wrap; }
.modaltabs[hidden] { display: none; }
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.section-head .spacer { flex: 1; }
.section-head .section-title { margin: 0; }
.tab .count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--bg); color: var(--muted); font-size: 11px; font-weight: 600; text-align: center;
}
.tab.on .count { background: var(--green-soft); color: var(--green-dark); }
.check {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); background: #fff;
  color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.check:hover { border-color: var(--green); }
.check.on { background: var(--green); border-color: var(--green); }
.check:focus-visible { outline: 2px solid rgba(0,119,197,.45); outline-offset: 1px; }
tr.is-done .ttl { color: var(--muted); text-decoration: line-through; }
tr.group-row td { background: var(--bg); font-weight: 600; font-size: 13px; padding: 7px 10px; }
tr.group-row .dim { font-weight: 400; margin-left: 6px; }

/* barras con marca de avance (bullet): .hbar.wide + .tick sobre .track, leyenda .chart-legend */
.hbar.wide { grid-template-columns: minmax(120px, 190px) 1fr 92px; }
.hbar .hlabel .dim { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track[title] { cursor: help; }
.hbar .tick { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1px; background: var(--ink); border-radius: 2px; box-shadow: 0 0 0 2px #fff; }
.hbar.is-zero .hlabel, .hbar.is-zero .num { color: var(--muted); }
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .sw-fill { width: 14px; height: 10px; border-radius: 2px; background: var(--blue); }
.chart-legend .sw-tick { width: 3px; height: 14px; border-radius: 2px; background: var(--ink); }
@media (max-width: 900px) {
  .hbar.wide { grid-template-columns: 110px 1fr 82px; }
  .hbar .hlabel .dim { white-space: normal; }
}

.mobile-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .pn { border-left: none; padding: 10px 0; flex-basis: 50%; }
  .mobile-nav {
    display: flex; gap: 2px; overflow-x: auto; background: var(--sidebar); padding: 0 12px;
  }
  .mobile-nav a {
    color: #d6d7d9; text-decoration: none; font-size: 13px; padding: 11px 10px;
    border-bottom: 3px solid transparent; white-space: nowrap;
  }
  .mobile-nav a.active { color: #fff; border-bottom-color: var(--green); font-weight: 600; }
  .hbar { grid-template-columns: 110px 1fr 56px; }
  .card { flex-basis: 140px; padding: 12px; }
  .card .value { font-size: 19px; }
  .pn .value { font-size: 22px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .grid2 { grid-template-columns: 1fr; }
  .page { padding: 18px 16px 50px; }
  .topbar { padding: 10px 16px; }
  .who { display: none; }
}
