/* Mundo visual: Operate, restrained. Ver DESIGN.md */

:root {
  --ink-shell: #18212f;
  --ground: #f2f4f7;
  --surface: #ffffff;
  --ink: #18212f;
  --ink-2: #4b5565;
  --line: #d8dde6;
  --accent: #0f6e6a;
  --accent-tint: #e2f0ef;
  --approve: #b7791f;
  --approve-tint: #fbf1dc;
  --danger: #b42318;
  --radius-panel: 12px;
  --radius-control: 8px;
}

* { box-sizing: border-box; }

html { scrollbar-color: #c3cad6 transparent; scrollbar-width: thin; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-tint); color: var(--ink); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin-bottom: 8px; }
p { margin: 0; }
.muted { color: var(--ink-2); font-size: 13px; margin: 4px 0 10px; }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Barra superior ---------- */

.shell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  background: var(--ink-shell);
  color: #fff;
  padding: 12px 16px;
}
.brand { font-size: 15px; font-weight: 600; }

.stats { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.stat { display: flex; gap: 6px; align-items: baseline; font-size: 13px; color: #c5ccd8; }
.stat-value { color: #fff; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  max-width: 1200px;
  margin: 16px auto 32px;
  padding: 0 16px;
}

@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); align-items: start; }
  .tree-panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
  .tree { overflow: auto; min-height: 0; }
}

.side { display: grid; gap: 16px; align-content: start; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 16px;
  min-width: 0;
}

.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; }

input[type="search"] { margin-bottom: 4px; }

/* ---------- Árbol ---------- */

.tree-list, .tree-list ul { list-style: none; margin: 0; padding: 0; }
.tree-list ul { margin-left: 9px; padding-left: 14px; border-left: 1px solid var(--line); }

.tree-line { display: flex; align-items: center; gap: 2px; }

.toggle {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  color: var(--ink-2);
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
}
.toggle:hover { background: var(--accent-tint); }
.toggle-spacer { flex: 0 0 22px; width: 22px; }

/* Chevron dibujado con bordes, no con glifos */
.chevron {
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-1px) rotate(45deg);
  transition: transform 120ms ease;
}
.chevron.closed { transform: translateX(-1px) rotate(-45deg); }

.row {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 32px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 4px 8px;
  border-radius: var(--radius-control);
  cursor: pointer;
  font: inherit;
  transition: background-color 120ms ease;
}
.row:hover { background: var(--accent-tint); }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* Firma: la cadena de mando de la persona seleccionada */
.row.on-path { background: var(--accent-tint); }
.row.on-path .name { color: var(--accent); }

.row.selected { background: var(--accent); color: #fff; }
.row.selected .name, .row.selected .meta { color: #fff; }
.row.selected .meta { opacity: 0.9; }

/* Ancestro común de "¿Quién aprueba?" */
.row.approver { background: var(--approve-tint); outline: 1px solid var(--approve); outline-offset: -1px; }

.row.match .name { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

/* ---------- Detalle ---------- */

.detail-head h2 { font-size: 20px; margin-bottom: 2px; }
.detail-head .muted { margin-top: 0; }

.chain { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 12px 0; font-size: 13px; }
.chain-link {
  border: none;
  background: var(--accent-tint);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.chain-link[aria-current="true"] { background: var(--accent); color: #fff; }
.chain .sep { color: var(--ink-2); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }
.kpi { margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-control); }
.kpi dt { color: var(--ink-2); font-size: 12px; }
.kpi dd { margin: 0; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

.section-title { font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 14px 0 6px; }

.report-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.report-list button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: var(--radius-control);
  font: inherit;
  cursor: pointer;
}
.report-list button:hover { background: var(--accent-tint); }
.report-list .meta { color: var(--ink-2); font-size: 13px; margin-left: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.move { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.move-row { display: flex; gap: 8px; align-items: end; }
.move-row label { flex: 1; margin-bottom: 0; }

/* ---------- Controles ---------- */

input, select, button { font: inherit; }

input, select {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  min-height: 36px;
}
input::placeholder { color: var(--ink-2); opacity: 1; }

label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }

form .actions { margin-top: 4px; }

button {
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: var(--ink-shell);
  color: #fff;
  cursor: pointer;
  transition: filter 120ms ease;
}
button:hover { filter: brightness(1.12); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); }
button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.ghost:hover { background: var(--accent-tint); filter: none; }
button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; filter: none; }
button.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }

.pair { display: grid; gap: 0; }
.result { margin-top: 10px; font-size: 14px; }
.result strong { color: var(--accent); }

.area-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.area-table th, .area-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.area-table th { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.area-table th:last-child, .area-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(360px, calc(100vw - 32px));
  background: var(--ink-shell);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-control);
  font-size: 14px;
  z-index: 10;
}
.toast.error { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
