:root {
  --bg: #F6F7F3;
  --surface: #FFFFFF;
  --surface-2: #F0F2EC;
  --border: #DDE1D6;
  --text: #1F261C;
  --muted: #65705F;
  --brand: #7EA872;
  --brand-strong: #4E7A43;
  --brand-ink: #FFFFFF;
  --s-done: #3E8E41;
  --s-progress: #2F6FB0;
  --s-ready: #B88A00;
  --s-waiting: #8A9285;
  --s-blocked: #C0392B;
  --shadow: 0 1px 2px rgba(20, 30, 15, .06), 0 4px 16px rgba(20, 30, 15, .06);
  --radius: 10px;
  --edge: #B9C0B2;
  --edge-hi: #3B6B30;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121511; --surface: #1A1E18; --surface-2: #222720; --border: #313830;
    --text: #E8ECE4; --muted: #9AA594; --brand: #8DB881; --brand-strong: #A6CC9B; --brand-ink: #0F140D;
    --s-done: #6BBF6E; --s-progress: #6FA6E0; --s-ready: #E0B83E; --s-waiting: #8E978A; --s-blocked: #EF6F61;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --edge: #4A5347; --edge-hi: #B9DDAE;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121511; --surface: #1A1E18; --surface-2: #222720; --border: #313830;
  --text: #E8ECE4; --muted: #9AA594; --brand: #8DB881; --brand-strong: #A6CC9B; --brand-ink: #0F140D;
  --s-done: #6BBF6E; --s-progress: #6FA6E0; --s-ready: #E0B83E; --s-waiting: #8E978A; --s-blocked: #EF6F61;
  --edge: #4A5347; --edge-hi: #B9DDAE;
  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, "Helvetica Neue", Arial, sans-serif;
  padding: 0 24px 24px; max-width: 1600px; margin: 0 auto; overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Encabezado */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 0 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { height: 48px; width: auto; }
.brand h1 { font-size: 22px; }
.brand p { margin: 2px 0 0; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge-mode { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: var(--s-ready); color: #1b1600; font-weight: 600; }
body.embed .brand .logo { display: none; }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--s-blocked); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn:focus-visible, .tab:focus-visible, .chip:focus-visible, .node:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: 1.6fr repeat(5, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--brand); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* Pestañas y barra */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { background: none; border: 0; padding: 9px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--brand-strong); font-weight: 600; }
.toolbar { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; flex-wrap: wrap; align-items: center; }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.toolbar input[type=search] { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; width: 220px; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 4px 10px; border-radius: 99px; cursor: pointer; font-size: 13px; }
.chip .dot, .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.chip.off { opacity: .45; }

/* Grafo */
.graph-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.zoom { display: flex; gap: 4px; }
.graph-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; height: min(70vh, 760px); box-shadow: var(--shadow); cursor: grab; }
.graph-wrap.panning { cursor: grabbing; user-select: none; }
.graph { position: relative; transform-origin: 0 0; }
.graph svg { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.graph .edge { fill: none; stroke: var(--edge); stroke-width: 1.6; }
.graph .edge.done { stroke-dasharray: none; opacity: .55; }
.graph .edge.hi { stroke: var(--edge-hi); stroke-width: 2.4; opacity: 1; }
.graph .edge.dim { opacity: .12; }
.graph .arrow { fill: var(--edge); }
.phase-label { position: absolute; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.node {
  position: absolute; width: 230px; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--role);
  border-radius: 8px; padding: 7px 9px 7px 10px; cursor: pointer; box-shadow: var(--shadow); transition: opacity .15s, box-shadow .15s;
}
.node:hover { box-shadow: 0 0 0 2px var(--brand), var(--shadow); }
.node.sel { box-shadow: 0 0 0 3px var(--edge-hi), var(--shadow); }
.node.dim { opacity: .25; }
.node.filtered { opacity: .12; pointer-events: none; }
.node .t { font-weight: 600; font-size: 13px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.node .meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.node .role-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node.overdue { border-top-color: var(--s-blocked); border-right-color: var(--s-blocked); border-bottom-color: var(--s-blocked); }
.node.done { background: color-mix(in srgb, var(--s-done) 9%, var(--surface)); }

/* Estado */
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-done { color: var(--s-done); }
.st-in_progress { color: var(--s-progress); }
.st-ready { color: var(--s-ready); }
.st-waiting { color: var(--s-waiting); }
.st-blocked { color: var(--s-blocked); }
.late { color: var(--s-blocked); font-weight: 600; }
.clip { display: inline-flex; gap: 3px; align-items: center; }

/* Cronograma */
.timeline { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.tl-inner { min-width: 900px; position: relative; }
.tl-row { display: grid; grid-template-columns: 280px 1fr; border-bottom: 1px solid var(--border); min-height: 32px; }
.tl-row.head { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.tl-row.phase { background: var(--surface-2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); min-height: 28px; }
.tl-label { padding: 6px 10px; border-right: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; cursor: pointer; }
.tl-row.phase .tl-label { cursor: default; }
.tl-track { position: relative; }
.tl-month { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); padding: 6px; }
.tl-grid { position: absolute; top: 0; bottom: 0; border-left: 1px dashed var(--border); }
.tl-today { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--s-blocked); z-index: 2; }
.tl-today span { position: absolute; top: 2px; left: 4px; font-size: 11px; color: var(--s-blocked); font-weight: 600; background: var(--surface); padding: 0 3px; }
.tl-bar { position: absolute; top: 8px; height: 16px; border-radius: 4px; background: var(--role); opacity: .85; cursor: pointer; min-width: 6px; }
.tl-bar.done { opacity: .4; }
.tl-bar.overdue { outline: 2px solid var(--s-blocked); outline-offset: 1px; }
.tl-ms { position: absolute; top: 9px; width: 14px; height: 14px; transform: translateX(-7px) rotate(45deg); background: var(--role); border: 2px solid var(--surface); }

/* Lista */
.group { margin-bottom: 18px; }
.group h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
table.tasks { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.tasks th, table.tasks td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tasks th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); cursor: pointer; white-space: nowrap; }
table.tasks tr:last-child td { border-bottom: 0; }
table.tasks tbody tr { cursor: pointer; }
table.tasks tbody tr:hover { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Resumen */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card ul { list-style: none; padding: 0; margin: 8px 0 0; }
.card li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--border); cursor: pointer; }
.card li span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.stats b { color: var(--text); font-size: 15px; display: block; }

/* Panel lateral */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -8px 0 30px rgba(0,0,0,.12); transform: translateX(105%); transition: transform .2s ease; z-index: 20; overflow-y: auto; }
.drawer.open { transform: none; }
.drawer-inner { padding: 18px 20px 28px; }
.drawer-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.drawer h2 { font-size: 18px; margin: 6px 0 10px; }
.field-grid { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 13px; margin: 10px 0 14px; }
.field-grid dt { color: var(--muted); }
.field-grid dd { margin: 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 6px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.dep-list { list-style: none; padding: 0; margin: 0; }
.dep-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-left: 4px solid var(--role); border-radius: 6px; margin-bottom: 5px; cursor: pointer; font-size: 13px; }
.dep-list li:hover { border-color: var(--brand); border-left-color: var(--role); }
.files li { border-left-width: 1px; cursor: default; }
.files a { color: var(--brand-strong); text-decoration: none; word-break: break-all; }
.files a:hover { text-decoration: underline; }
.desc { white-space: pre-wrap; font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 10px; }
.drop { display: block; border: 2px dashed var(--border); border-radius: 8px; padding: 14px; text-align: center; color: var(--muted); font-size: 13px; cursor: pointer; }
.drop.over { border-color: var(--brand); background: var(--surface-2); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.ready-banner { background: color-mix(in srgb, var(--s-done) 14%, var(--surface)); border: 1px solid var(--s-done); border-radius: 8px; padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.wait-banner { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-top: 8px; }

/* Modal */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 15, 8, .45); }
.modal-form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-form h2 { font-size: 18px; }
.modal-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-form input, .modal-form select, .modal-form textarea { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 8px 10px; color: var(--text); width: 100%; }
.modal-form textarea { min-height: 80px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.deps-picker { border: 1px solid var(--border); border-radius: 8px; max-height: 220px; overflow-y: auto; padding: 4px 8px; background: var(--bg); }
.deps-picker .ph { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 0 2px; font-weight: 600; }
.deps-picker label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); padding: 2px 0; }
.deps-picker input { width: auto; }
.role-row { display: grid; grid-template-columns: 44px 1fr 150px auto; gap: 8px; align-items: center; }
.role-row input[type=color] { padding: 2px; height: 36px; }
.err { color: var(--s-blocked); font-size: 13px; min-height: 1em; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; transition: transform .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%); }

.activity-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.activity-list li { padding: 9px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; font-size: 13px; }
.activity-list li:last-child { border: 0; }
.activity-list time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Portada y multiproyecto */
.logo-link { display: inline-flex; }
.back { color: var(--brand-strong); text-decoration: none; display: inline-block; margin-bottom: 2px; }
.back:hover { text-decoration: underline; }
.message { padding: 48px 0; text-align: center; font-size: 15px; }
.project-card { display: block; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.project-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.pc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pc-head h3 { font-size: 16px; margin: 0; }
.pc-tags { display: flex; gap: 4px; flex: none; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag-edit { color: var(--brand-strong); border-color: var(--brand); }
.pc-sub { margin: 4px 0 10px; min-height: 1.4em; }
.pc-pct { display: flex; align-items: baseline; gap: 8px; }
.pc-pct b { font-size: 24px; font-variant-numeric: tabular-nums; }
.pc-next { margin: 8px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-roles { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.pc-roles > span { display: inline-flex; align-items: center; gap: 5px; }
.modal-form label.check { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); }
.modal-form label.check input { width: auto; margin-top: 3px; }
.slug-row { display: flex; align-items: center; gap: 6px; }
.slug-row input { flex: 1; min-width: 0; }
.user-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.user-actions { display: flex; gap: 4px; flex: none; }
.creds { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0; white-space: pre-wrap; word-break: break-all; font-size: 13px; user-select: all; }

.foot { margin-top: 28px; text-align: center; }
.hint { margin: 8px 2px 0; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpis .kpi:first-child { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  body { padding: 0 16px 16px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .logo { height: 38px; }
  .brand h1 { font-size: 18px; }
  .toolbar-right { width: 100%; }
  .toolbar input[type=search] { flex: 1; width: auto; }
  .graph-wrap { height: 62vh; }
  .row2 { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 100px 1fr; }
  table.tasks thead { display: none; }
  table.tasks, table.tasks tbody, table.tasks tr, table.tasks td { display: block; width: 100%; }
  table.tasks tr { border-bottom: 1px solid var(--border); padding: 6px 0; }
  table.tasks td { border: 0; padding: 2px 10px; }
  .role-row { grid-template-columns: 44px 1fr auto; }
  .role-row .short { display: none; }
}
