*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --radius: 8px; --accent: #4f46e5; --bg: #f5f7fa; --card: #ffffff; --in: #f0f2f5;
  --border: #e3e6ea; --text: #2d3142; --muted: #6b7280; --danger: #dc2626; --ok: #16a34a;
}
body { font-family: 'Geist', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
header { background: linear-gradient(135deg, #1f2937 0%, #111827 100%); color: #f9fafb; padding: 12px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 12px rgba(0,0,0,.15); }
header h1 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 1.3rem; margin-right: auto; }
header .note { font-size: .7rem; color: #9ca3af; font-family: 'Geist Mono', monospace; }
.tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.tabs button { border: 1px solid #374151; background: transparent; color: #e5e7eb; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; font-family: 'Geist', sans-serif; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { border: 1px solid transparent; padding: 7px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: .82rem; font-family: 'Geist', sans-serif; background: #efefef; color: #374151; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.success { background: var(--ok); color: #fff; }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.ghost { background: transparent; color: #e5e7eb; border-color: #4b5563; }
.btn.gray { background: #eef0f4; }
.btn.sm { padding: 3px 8px; font-size: .72rem; }
.btn:hover { filter: brightness(.95); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(.92); }
.btn.primary:hover { filter: brightness(1.1); box-shadow: 0 2px 8px rgba(79,70,229,.3); }
main { display: flex; gap: 16px; padding: 16px 20px; align-items: flex-start; max-width: 1700px; margin: 0 auto; }
aside { width: 400px; flex-shrink: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; position: sticky; top: 92px; max-height: calc(100vh - 100px); overflow: auto; transition: width .2s ease, padding .2s ease, min-width .2s ease; }
aside.collapsed { width: 52px; min-width: 52px; padding: 14px 8px; }
aside.collapsed .tree-hdr h2 { display: none; }
aside.collapsed .tree-hdr { justify-content: center; }
aside.collapsed .tnode .row { justify-content: center; padding: 5px 0; }
aside.collapsed .tnode .nm, aside.collapsed .tnode .tag, aside.collapsed .tnode .btns, aside.collapsed .tchildren, aside.collapsed .divider, aside.collapsed .hint { display: none; }
aside.collapsed .tree-hdr h2 + .btn { margin-left: 0; }
#toggleSidebar { flex-shrink: 0; width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; font-size: .85rem; }
aside.collapsed #toggleSidebar { margin: 0 auto; }
.tree { display: flex; flex-direction: column; gap: 4px; }
.tnode { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tnode .row { display: flex; align-items: center; gap: 5px; padding: 5px 7px; cursor: pointer; border-left: 3px solid transparent; background: #fff; }
.tnode.epica > .row { border-left-color: #a78bfa; font-weight: 600; }
.tnode.historia > .row { border-left-color: #7cc990; }
.tnode.tarea > .row { border-left-color: #d6dbe2; }
.tnode .row:hover { background: #f7f8fa; }
.tnode .row.active { background: #eef2ff; box-shadow: inset 0 0 0 1px rgba(79,70,229,.15); }
.tnode .nm { flex: 1; font-size: .8rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tnode .tag { font-family: 'Geist Mono', monospace; font-size: .64rem; color: #9aa3b2; }
.tnode .btns { display: flex; gap: 1px; }
.tnode .btns button { border: none; background: transparent; color: #9aa3b2; cursor: pointer; padding: 2px 5px; font-size: .82rem; border-radius: 4px; }
.tnode .btns button:hover { background: #eef0f4; color: #374151; }
.tnode .btns button.del:hover { background: #fee2e2; color: var(--danger); }
.tchildren { margin-left: 12px; border-left: 1px solid var(--border); padding-left: 5px; display: flex; flex-direction: column; gap: 3px; }
.tnode .row.dragging { opacity: .45; outline: 2px dashed var(--accent); outline-offset: 1px; }
.dnd-hint { height: 0; border-top: 2px solid var(--accent); margin: 1px 0; }
.divider { height: 1px; background: var(--border); margin: 10px 0; }
section { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; overflow: auto; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.fase-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.fase-meta input, .fase-meta textarea { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-family: 'Geist', sans-serif; font-size: .82rem; background: var(--in); }
.fase-meta input[type=text] { flex: 2; min-width: 210px; }
.fase-meta textarea { flex: 2; min-width: 260px; resize: vertical; }
.form { display: grid; gap: 9px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.form label { font-size: .73rem; color: var(--muted); font-weight: 500; display: flex; flex-direction: column; gap: 4px; }
.form input, .form select, .form textarea { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-family: 'Geist', sans-serif; font-size: .83rem; background: var(--in); width: 100%; }
.form input[type=color] { padding: 0; height: 34px; width: 60px; cursor: pointer; }
.form textarea { min-height: 58px; resize: vertical; }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.form .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.form-hdr { display: flex; justify-content: space-between; align-items: center; }
.form-hdr h3 { font-size: .92rem; font-weight: 600; }
.gantt-toolbar { display:flex; align-items:center; gap:8px; margin:4px 0 10px; flex-wrap:wrap; }
.gantt-toolbar-label { font-size:0.8rem; color:#6b7280; font-weight:500; text-transform:uppercase; letter-spacing:0.05em; }
.z-pct { min-width:44px; text-align:center; font-size:0.85rem; font-weight:500; color:#212529; font-variant-numeric:tabular-nums; }
.gantt-wrap { overflow:auto; border-radius: 8px; background: #f5f5f5; max-height: 70vh; }
.gantt-svg { display: block; width: 100%; height: auto; transition: width .15s ease-out; }
.gantt-svg rect[data-bar] { transition: filter .12s ease, opacity .12s ease; }
.gantt-svg rect[data-bar]:hover { filter: brightness(1.08) drop-shadow(0 2px 4px rgba(0,0,0,.18)); }
.gantt-svg rect[data-bar].dragging { cursor: grabbing; filter: brightness(1.12) drop-shadow(0 3px 6px rgba(0,0,0,.22)); opacity:.88; }
.gantt-wrap.panning { cursor: grabbing; user-select: none; }
.gantt-wrap.panning * { pointer-events: none; }
.status { font-size: .75rem; color: var(--ok); display: none; }
.empty { padding: 24px 12px; text-align: center; color: var(--muted); font-size: .85rem; display:flex; flex-direction:column; align-items:center; gap:10px; }
.empty p { margin: 0; }
.hint { font-size: .74rem; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.errtxt { color: var(--danger); font-size: .75rem; min-height: 1em; }
.cfgrow { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cfgrow label { width: 210px; flex-shrink: 0; font-size: .78rem; color: var(--muted); }
.cfgrow input[type=color] { width: 46px; height: 28px; padding: 0; border-radius: 5px; cursor: pointer; }
.cfgrow input[type=text], .cfgrow input[type=number] { width: 90px; padding: 5px 7px; border: 1px solid var(--border); border-radius: 5px; background: var(--in); font-size: .82rem; }
.cfgrow input[type=number] { width: 60px; }
.modal-ov { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 760px; max-height: 86vh; overflow: auto; padding: 18px; }
.modal h3 { font-size: 1rem; margin-bottom: 12px; }
.modal .mfoot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.sp-row { display: flex; align-items: center; gap: 6px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; background: #fafbfc; flex-wrap: wrap; }
.sp-row .num { width: 46px; }
.sp-row .fechas { display: flex; gap: 6px; flex: 1; }
.sp-row input { padding: 4px 6px; border: 1px solid var(--border); border-radius: 5px; background: #fff; font-size: .78rem; font-family: 'Geist Mono', monospace; }
.sp-row input[type=number] { width: 58px; }
.sp-row .spremo { cursor: pointer; color: var(--muted); border: none; background: none; font-size: .95rem; }
.sp-row .spremo:hover { color: var(--danger); }
.chklist { display: flex; flex-wrap: wrap; gap: 8px; }
.chklist label { display: flex; align-items: center; gap: 4px; font-size: .8rem; border: 1px solid var(--border); padding: 4px 8px; border-radius: 6px; cursor: pointer; background: #fafbfc; }
.chklist label.on { background: #eef2ff; border-color: var(--accent); }
.tip { font-size: .72rem; color: var(--muted); margin-top: 4px; }
@media (max-width: 1100px) { main { flex-direction: column; } aside { width: 100%; position: static; max-height: none; } }

/* ====================== Sidebar tools ====================== */
.sidebar-tools { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.sidebar-search input {
  width: 100%; padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--in); font-family: 'Geist', sans-serif; font-size: .8rem;
}
.sidebar-search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sidebar-btns { display: flex; gap: 5px; }
.sidebar-btns .btn { padding: 4px 8px; font-size: .72rem; }
.sidebar-btns .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
aside.collapsed .sidebar-tools { display: none; }

/* ====================== Tree nodes ====================== */
.tnode .row { position: relative; }
.tnode .icon { display: inline-flex; align-items: center; justify-content: center; }
.tnode .swatch { flex-shrink: 0; width: 12px; height: 12px; border-radius: 2px; }
.tnode .nm.ed:hover { outline: 1px dashed rgba(79,70,229,.4); outline-offset: 2px; border-radius: 3px; cursor: text; }
.tnode .tag.ed:hover { outline: 1px dashed rgba(79,70,229,.4); outline-offset: 2px; border-radius: 3px; cursor: text; }
.tnode .toggle { border: none; background: transparent; cursor: pointer; padding: 0 3px; font-size: .8rem; color: var(--muted); }
.tnode .actions { display: none; gap: 1px; align-items: center; flex-shrink: 0; }
.tnode .row:hover .actions, .tnode .row:focus-visible .actions, .tnode .row.active .actions { display: flex; }
.kebab {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 0 5px; font-size: 1rem; line-height: 1; border-radius: 4px;
}
.kebab:hover { background: #eef0f4; color: #374151; }
.tnode .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 1; }
.tnode .row.dragging { opacity: .45; outline: 2px dashed var(--accent); outline-offset: 1px; }

/* inline add rows */
.inline-add-row { padding: 3px 8px 3px 26px; }
.ghost-add { color: var(--accent); opacity: .85; background: transparent; border: 1px dashed #c7d2fe; }
.ghost-add:hover { background: #eef2ff; opacity: 1; }

/* dnd hint */
.dnd-hint { height: 3px; background: var(--accent); border-radius: 2px; margin: 1px 0; }

/* ====================== Inline editor ====================== */
.editor { display: flex; flex-direction: column; gap: 7px; padding: 4px 0; width: 100%; min-width: 0; }
.editor label { font-size: .7rem; color: var(--muted); font-weight: 500; display: flex; flex-direction: column; gap: 3px; }
.editor input[type=text], .editor input[type=date], .editor select, .editor textarea {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px;
  font-family: 'Geist', sans-serif; font-size: .82rem; background: #fff; width: 100%;
}
.editor input[type=color] { padding: 0; height: 28px; width: 52px; cursor: pointer; }
.editor textarea { min-height: 48px; resize: vertical; }
.editor input:focus-visible, .editor textarea:focus-visible, .editor select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.editor-foot { display: flex; gap: 6px; justify-content: flex-end; }
.tnode .row.editing { background: #f6f7fb; box-shadow: inset 0 0 0 2px rgba(79,70,229,.18); cursor: default; }

/* ====================== Color palette in inline editor ====================== */
.editor .cf-color { gap: 4px; }
.palette-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 2px; }
.palette-row .sw {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; cursor: pointer;
  box-shadow: 0 0 0 1px var(--border); padding: 0; transition: transform .1s ease;
}
.palette-row .sw:hover { transform: scale(1.18); }
.palette-row .sw.sel { box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px rgba(79,70,229,.25); transform: scale(1.12); }
.palette-row .color-custom { width: 28px !important; height: 24px !important; padding: 0 !important; cursor: pointer; border: 1px solid var(--border); border-radius: 5px; }

/* ====================== Context / kebab menu ====================== */
.menu-pop {
  position: fixed; z-index: 200; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 4px;
  min-width: 150px;
}
.menu-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 7px 10px; font-size: .8rem; font-family: 'Geist', sans-serif; color: var(--text);
  border-radius: 5px; cursor: pointer;
}
.menu-item:hover { background: #eef2ff; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: #fee2e2; }

/* ====================== Toasts ====================== */
.toast-host {
  position: fixed; top: 70px; right: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; max-width: 340px;
}
.toast {
  display: flex; align-items: center; gap: 8px; background: #1f2937; color: #f9fafb;
  padding: 10px 12px; border-radius: 8px; font-size: .82rem; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(-8px); transition: opacity .2s ease, transform .2s ease;
}
.toast.in { opacity: 1; transform: none; }
.toast.out { opacity: 0; transform: translateY(-8px); }
.toast-ok { background: #14532d; }
.toast-error { background: #7f1d1d; }
.toast-msg { flex: 1; }
.toast-action {
  border: none; background: transparent; color: #93c5fd; cursor: pointer;
  font-size: .8rem; font-weight: 600; text-decoration: underline;
}
.toast-close { border: none; background: transparent; color: #9ca3af; cursor: pointer; font-size: .8rem; }

/* ====================== Confirm dialog ====================== */
.confirm-ov {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center;
  justify-content: center; z-index: 400; opacity: 0; transition: opacity .18s ease;
}
.confirm-ov.in { opacity: 1; }
.confirm-ov.out { opacity: 0; }
.confirm-box {
  background: #fff; border-radius: 12px; max-width: 420px; width: 100%; padding: 18px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); transform: translateY(6px); transition: transform .18s ease;
}
.confirm-ov.in .confirm-box { transform: none; }
.confirm-box h3 { font-size: 1rem; margin-bottom: 8px; }
.confirm-box p { font-size: .84rem; color: var(--muted); margin-bottom: 16px; line-height: 1.5; }
.confirm-foot { display: flex; gap: 8px; justify-content: flex-end; }

/* ====================== Search highlight ====================== */
mark { background: #fde68a; color: #1f2937; border-radius: 2px; padding: 0 1px; }

/* ====================== Resizable sidebar ====================== */
aside { resize: horizontal; overflow: auto; min-width: 200px; }