:root {
  --bg: #0b1320;
  --surface: #111d30;
  --surface-2: #18273e;
  --surface-3: #213049;
  --border: #28405f;
  --text: #e8eef6;
  --text-dim: #9fb2c8;
  --text-mut: #6f849f;
  --accent: #e8553a;
  --accent-2: #ff7a52;
  --blue: #2e7bc0;
  --ok: #4ca64c;
  --warn: #d19900;
  --crit: #b3261e;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 2px 10px rgba(0,0,0,.35);
  --font-body: 'Inter', system-ui, sans-serif;
  --font-display: 'Source Serif 4', Georgia, serif;
}
[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --surface-3: #e6ebf3;
  --border: #d6dde8;
  --text: #16212e;
  --text-dim: #48586b;
  --text-mut: #7a8a9c;
  --shadow: 0 2px 10px rgba(16,40,80,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100%;
}
h1, h2, h3, h4 { font-family: var(--font-body); font-weight: 700; margin: 0 0 .4em; }
h1 { font-size: 1.05rem; font-weight: 700; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
a { color: var(--blue); cursor: pointer; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 18px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; color: #0b2a4a; flex: none; border-radius: 8px; }
.brand h1 { margin: 0; }
.sub { display: block; font-size: .72rem; color: var(--text-mut); font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  font: inherit; font-size: .85rem; font-weight: 600;
  padding: 8px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; transition: .15s;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: .78rem; }
.btn.danger { color: var(--crit); }
.select {
  font: inherit; font-size: .85rem; padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); max-width: 320px; min-width: 0;
}

/* Layout */
.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar {
  width: 232px; flex: none; padding: 12px 10px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}
.nav-item {
  display: block; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); text-decoration: none; font-size: .88rem; font-weight: 500;
  cursor: pointer; transition: .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); border-left: 3px solid var(--accent); padding-left: 9px; }
.nav-item.small { font-size: .8rem; color: var(--text-mut); }
.nav-item.file { position: relative; }
.nav-item.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.nav-foot { font-size: .72rem; color: var(--text-mut); padding: 6px 10px; line-height: 1.4; }
.content { flex: 1; padding: 24px 28px; max-width: 1080px; min-width: 0; }

/* Cards & sections */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi .label { font-size: .76rem; color: var(--text-mut); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.85rem; font-weight: 700; margin-top: 4px; }
.kpi .sub { font-size: .78rem; color: var(--text-dim); margin-top: 2px; }
.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.muted { color: var(--text-mut); }
.dim { color: var(--text-dim); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap-sm { gap: 6px; }

/* Tags */
.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .72rem; font-weight: 600; }
.tag.blue { background: rgba(46,123,192,.18); color: #6db4e8; }
.tag.amber { background: rgba(209,153,0,.18); color: #e6b54a; }
.tag.red { background: rgba(179,38,30,.2); color: #f0867c; }
.tag.green { background: rgba(76,166,76,.18); color: #74c474; }
.tag.gray { background: var(--surface-3); color: var(--text-dim); }

/* Inputs */
input[type="text"], input[type="date"], input[type="number"], textarea, select.input {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
textarea { resize: vertical; min-height: 56px; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: .78rem; color: var(--text-dim); margin-bottom: 4px; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Requirement workbench */
.req { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; margin-bottom: 14px; }
.req-head { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; cursor: pointer; border-left: 4px solid var(--border); }
.req-head.open { border-left-color: var(--accent); }
.req-code { font-weight: 800; font-size: .95rem; padding: 4px 9px; border-radius: var(--radius-sm); background: var(--surface-3); min-width: 42px; text-align: center; }
.req-title { font-weight: 600; font-size: .98rem; }
.req-meta { font-size: .76rem; color: var(--text-mut); margin-top: 2px; }
.req-body { padding: 0 16px 16px; display: none; }
.req.open .req-body { display: block; }
.maturity-pick { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.maturity-pick button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-dim);
  border-radius: 99px; padding: 5px 11px; font: inherit; font-size: .8rem; cursor: pointer;
}
.maturity-pick button.on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.check { display: flex; gap: 9px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { margin-top: 3px; flex: none; width: 16px; height: 16px; }
.check span { font-size: .9rem; }
.subhead { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mut); font-weight: 700; margin: 14px 0 6px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mut); font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }

/* Phase */
.phase { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.phase-num { width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; color: var(--text-dim); }
.phase.done .phase-num { background: var(--ok); color: #fff; }
.phase.active .phase-num { background: var(--accent); color: #fff; }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface-3); border: 1px solid var(--border); color: var(--text); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 100; font-size: .85rem; }

.empty { text-align: center; padding: 40px; color: var(--text-mut); }
.pill-stage { display: inline-flex; gap: 0; }
.pill-stage span { padding: 3px 9px; font-size: .72rem; border: 1px solid var(--border); }
.pill-stage span:first-child { border-radius: 99px 0 0 99px; }
.pill-stage span:last-child { border-radius: 0 99px 99px 0; }
.pill-stage span.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Print */
@media print {
  .topbar, .sidebar, .toast { display: none !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff !important; color: #000 !important; }
  .card, .req, .kpi { background: #fff !important; color: #000 !important; box-shadow: none; border-color: #ccc !important; }
  .tag, .tag.red, .tag.green, .tag.amber, .tag.blue, .tag.gray { background: #eee !important; color: #222 !important; border: 1px solid #ccc; }
  .progress { background: #ddd !important; }
  .progress > span { background: #999 !important; }
  .muted, .dim { color: #555 !important; }
  table th { color: #333 !important; }
}

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .select { max-width: 55vw; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .nav-sep, .nav-foot { display: none; }
  .nav-item { white-space: nowrap; }
  .content { padding: 16px; }
  .field-row { grid-template-columns: 1fr; }
  table { font-size: .8rem; }
}

/* ===== Módulos nuevos: árbol de rol, evidencias, hito ===== */
.rtq { display:flex; gap:12px; align-items:flex-start; padding:10px 0; border-bottom:1px solid var(--border); }
.rtq-text { flex:1; }
.rtq-opts { display:flex; gap:6px; flex-shrink:0; }
.chip { display:inline-flex; align-items:center; gap:4px; padding:4px 10px; border:1px solid var(--border); border-radius:999px; font-size:.8rem; cursor:pointer; background:var(--surface-2); }
.chip input { margin:0; }
.chip.on { border-color:var(--accent); background:rgba(232,85,58,.18); color:var(--text); }
.rt-result { margin-top:14px; padding:14px; border:1px solid var(--border); border-radius:10px; background:var(--surface-2); }
.rt-verdict { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.ev { padding:12px 0; border-bottom:1px solid var(--border); }
.ev .check { align-items:flex-start; }
.ev-notes { margin-top:8px; min-height:54px; font-size:.82rem; }
.milestone { border-left:3px solid var(--accent); }
.milestone .check { padding:4px 0; }

/* Opinion + legal blocks in report */
.opinion { margin: 12px 0; padding: 12px 14px; border:1px solid var(--border); border-radius:10px; background:var(--surface-2); }
.legal { margin: 12px 0; padding: 12px 14px; border-left:3px solid var(--accent); background:var(--surface-2); border-radius:6px; font-size:.84rem; }
