:root {
  /* Los colores están en theme.css (tema «Negro total» / «Blanco total»). */
  --sidebar-w: 224px;
  --topbar-h: 58px;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.pre-line { white-space: pre-line; }
.spacer { flex: 1; }

/* ---------- estructura ---------- */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--side-bg); color: var(--side-text); border-right: 1px solid var(--side-border);
  display: flex; flex-direction: column; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; color: var(--side-strong); font-weight: 700; font-size: 20px; letter-spacing: 1px; flex: 0 0 auto; }
.brand-logo { width: 32px; height: 32px; flex: 0 0 32px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); box-sizing: border-box; }
.brand-text { min-width: 0; }
.brand small { display: block; font-weight: 400; font-size: 12px; letter-spacing: 0; color: var(--side-text); opacity: .75; }
/* menú: los apartados arriba (con scroll propio si no caben) y «Ajustes» fijo abajo */
.side-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.nav { list-style: none; margin: 0; padding: 6px 10px; }
.side-bottom { flex: 0 0 auto; padding: 8px 0 12px; border-top: 1px solid var(--side-border); }
.side-bottom .nav { padding-top: 4px; padding-bottom: 2px; }
.side-version { padding: 2px 22px 0; font-size: 11px; color: var(--side-text); opacity: .5; font-variant-numeric: tabular-nums; min-height: 15px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 2px;
  border-radius: 8px; color: var(--side-text); text-decoration: none;
}
.nav a:hover { background: var(--color-seleccion-hover); color: var(--side-strong); }
.nav a.active { background: var(--color-seleccion); color: var(--side-strong); }
.nav .ico { width: 22px; text-align: center; font-size: 16px; }
.nav .soon { margin-left: auto; font-size: 10px; padding: 2px 7px; border-radius: 10px; background: var(--side-soon-bg); }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
#view { flex: 1; overflow: auto; padding: 20px 22px; }
.top-account { display: flex; align-items: center; gap: 8px; }
.account-select { min-width: 220px; max-width: 340px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-weight: 600; }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status.error { color: var(--danger); font-weight: 600; white-space: normal; }
.menu-btn { display: none !important; font-size: 18px; }
#backdrop { display: none; }

@media (max-width: 900px) {
  #sidebar { position: fixed; top: 0; bottom: 0; left: 0; height: 100%; transform: translateX(-100%); transition: transform .2s ease; }
  body.menu-open #sidebar { transform: none; box-shadow: var(--shadow); }
  body.menu-open #backdrop { display: block; position: fixed; inset: 0; background: var(--backdrop); z-index: 25; }
  .menu-btn { display: inline-flex !important; }
  #view { padding: 12px; }
  #topbar { padding: 0 10px; gap: 8px; }
  .account-select { min-width: 0; max-width: 190px; }
  .top-account > .muted { display: none; }
}

/* ---------- controles ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--color-acento); border-color: var(--color-acento); color: var(--color-sobre-acento); font-weight: 600; }
.btn-primary:hover { background: var(--color-acento-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--color-sobre-peligro); }
.btn-danger:hover { background: var(--danger-h); }
.btn-light { background: var(--surface-2); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--head); color: var(--text); }
.input, .form select, .form input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.input:focus, .form select:focus, .form input:focus { outline: 2px solid var(--color-foco); outline-offset: -1px; }
.textarea-big { min-height: 260px; resize: vertical; line-height: 1.45; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.form { display: grid; gap: 12px; }
.form label > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); min-height: 1em; font-size: 13px; }

/* ---------- páginas y tarjetas ---------- */
.page { max-width: 1100px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card > h2 { margin-bottom: 4px; }
.card > .hint { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
.placeholder { text-align: center; padding: 60px 20px; margin-top: 30px; }
.placeholder-icon { font-size: 46px; margin-bottom: 10px; }
.badge-soon { display: inline-block; margin: 6px 0 10px; padding: 3px 12px; border-radius: 20px; background: var(--warn-bg); color: var(--warn-fg); font-weight: 600; font-size: 12px; }
.boot-error { max-width: 620px; margin: 60px auto; padding: 24px; background: var(--surface); border: 1px solid var(--sl-bg); border-radius: var(--radius); }

/* ---------- journal ---------- */
.journal { max-width: none; height: 100%; display: flex; flex-direction: column; gap: 10px; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.toolbar h1 { margin: 0 8px 0 0; }
.toolbar .count { color: var(--muted); font-size: 13px; }
.paste-hint { font-size: 12px; color: var(--muted); }
.grid-wrap { flex: 1; min-height: 220px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.grid-empty { padding: 40px; text-align: center; color: var(--muted); }

table.grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.grid th, .grid td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 0; vertical-align: middle; background: var(--surface); }
.grid thead th { position: sticky; top: 0; z-index: 3; background: var(--head); font-size: 12px; font-weight: 600; text-align: center; }
.grid .c-actions { position: sticky; left: 0; z-index: 2; text-align: center; }
.grid .col-nbr { position: sticky; left: 38px; z-index: 2; box-shadow: 1px 0 0 var(--border); }
.grid thead .c-actions, .grid thead .col-nbr { z-index: 4; }
.grid tbody tr:hover td { background: var(--row-hover); }
.th-inner { display: flex; align-items: center; gap: 2px; padding: 6px 4px 6px 6px; min-height: 54px; }
.th-label { flex: 1; line-height: 1.25; text-align: center; }
.badge-new { display: inline-block; margin-left: 5px; padding: 1px 6px; border-radius: 8px; background: var(--color-seleccion); color: var(--text); font-size: 10px; font-weight: 700; vertical-align: 1px; }
.filter-btn { display: inline-flex; align-items: center; gap: 2px; border: 0; background: transparent; color: var(--muted); padding: 3px 4px; border-radius: 4px; cursor: pointer; font-size: 10px; }
.filter-btn:hover { background: var(--head); color: var(--text); }
.filter-btn.on { background: var(--color-acento); color: var(--color-sobre-acento); }

.grid td { height: 58px; }
.cell-input { display: block; width: 100%; height: 57px; border: 0; padding: 4px 8px; background: transparent; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
.cell-input:focus { outline: 2px solid var(--color-foco); outline-offset: -2px; background: var(--focus-bg); }
.cell-input[readonly] { cursor: pointer; }
select.cell-input { cursor: pointer; }
.cell-input.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.cell-input.num.pos { color: var(--pos); }
.cell-input.num.neg { color: var(--neg); }
.grid td:has(> .outcome-TP) { background: var(--tp-bg); }
.grid td:has(> .outcome-SL) { background: var(--sl-bg); }
.grid td:has(> .outcome-BE) { background: var(--be-bg); }
.outcome-TP { color: var(--tp-fg); font-weight: 700; }
.outcome-SL { color: var(--sl-fg); font-weight: 700; }
.outcome-BE { color: var(--be-fg); font-weight: 700; }
.nbr { display: block; text-align: center; font-weight: 600; color: var(--muted); }
.readonly-cell { display: block; padding: 0 8px; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-cell { position: relative; }
.text-cell .cell-input { padding-right: 24px; }
.expand-btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; cursor: pointer; color: var(--muted); opacity: 0; padding: 2px 4px; border-radius: 4px; }
.text-cell:hover .expand-btn, .text-cell:focus-within .expand-btn { opacity: 1; }
.expand-btn:hover { background: var(--head); }
.del-btn:hover { color: var(--danger); }

.img-cell { position: relative; display: flex; align-items: center; justify-content: center; gap: 4px; height: 57px; padding: 3px; cursor: pointer; }
.img-cell:focus { outline: 2px dashed var(--color-foco); outline-offset: -3px; }
.img-cell.drag { background: var(--color-seleccion); }
.img-cell.busy { opacity: .5; pointer-events: none; }
.img-cell .thumb { width: 84px; height: 48px; flex: 0 0 auto; border-radius: 4px; border: 1px solid var(--border); cursor: zoom-in; object-fit: cover; }
.img-placeholder { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.2; }
.img-actions { display: flex; flex-direction: column; gap: 2px; }
.img-actions .icon-btn { min-width: 22px; height: 22px; font-size: 12px; }

/* alineación de la tabla: columnas cortas centradas; texto largo a la izquierda con margen interior */
.grid td.al-center .cell-input, .grid td.al-center .readonly-cell { text-align: center; text-align-last: center; }
.grid td.al-center input[type=date], .grid td.al-center input[type=time] { padding-left: 10px; padding-right: 6px; }
.grid td.al-left .cell-input { text-align: left; padding-left: 12px; padding-right: 12px; }
.grid td.al-left .text-cell .cell-input { padding-right: 28px; }
.grid td.al-left select.cell-input { padding-left: 10px; }

/* ---------- filtro ---------- */
.popover {
  position: fixed; z-index: 60; width: 270px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.popover .sort-row { display: flex; gap: 6px; }
.popover .sort-row .btn { flex: 1; justify-content: center; }
.popover .btn.on { background: var(--color-seleccion); border-color: var(--color-foco); }
.filter-list { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; }
.filter-list label { display: flex; gap: 6px; align-items: center; padding: 3px 0; cursor: pointer; font-size: 13px; overflow: hidden; }
.filter-list label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover .actions { display: flex; justify-content: space-between; gap: 6px; }

/* ---------- ventanas ---------- */
.overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 80; overflow: auto; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 88vh; }
.modal-wide { max-width: 980px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px 20px; overflow: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.lightbox { position: fixed; inset: 0; z-index: 90; background: var(--lightbox-bg); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; box-shadow: var(--shadow); border-radius: 4px; }
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { max-width: 380px; padding: 11px 15px; border-radius: 8px; background: var(--toast-bg); color: var(--toast-fg); box-shadow: var(--shadow); transition: opacity .35s; }
.toast-error { background: var(--danger); color: var(--color-sobre-peligro); }
.toast-success { background: var(--pos); }
.toast.hide { opacity: 0; }

/* ---------- importar ---------- */
.import-grid { display: grid; gap: 14px; }
.map-table, .preview-table, .simple-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.map-table th, .map-table td, .preview-table th, .preview-table td, .simple-table th, .simple-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.map-table th, .preview-table th, .simple-table th { background: var(--surface-2); font-weight: 600; }
.map-table select { width: 100%; padding: 5px 6px; border: 1px solid var(--border); border-radius: 6px; }
.map-table td.sample { color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-wrap { overflow: auto; max-height: 260px; border: 1px solid var(--border); border-radius: 8px; }
.preview-table td { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-fg); padding: 9px 12px; border-radius: 8px; font-size: 13px; }

/* tablas sencillas (cuentas, estadísticas): misma alineación que el Journal */
.simple-table th { text-align: center; vertical-align: middle; padding: 9px 10px; }
.simple-table td { vertical-align: middle; padding: 9px 10px; }
.simple-table th:first-child { text-align: left; }
.simple-table .num-col, .simple-table .al-center { text-align: center !important; font-variant-numeric: tabular-nums; }
.tr-table th { text-align: left; }

/* ---------- ajustes ---------- */
.theme-pick { display: flex; gap: 10px; }
.theme-pick-btn { padding: 6px; border: 2px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; line-height: 0; }
.theme-pick-btn:hover { background: var(--color-seleccion-hover); }
.theme-pick-btn.on { border-color: var(--color-foco); background: var(--color-seleccion); }
.theme-pick-btn img { width: 48px; height: 32px; object-fit: contain; display: block; }
.acc-trash { margin-top: 18px; padding-top: 6px; border-top: 1px solid var(--border); }
.acc-trash h3 { margin-top: 12px; }
.settings-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.settings-row select, .settings-row input[type=text] { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.settings-row input[type=text] { flex: 1; min-width: 240px; }
.order-list { list-style: none; margin: 0; padding: 0; max-width: 420px; }
.order-list li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--surface-2); }
.order-list li span.lbl { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 3px 4px 3px 10px; border-radius: 16px; background: var(--head); font-size: 13px; }
.chip .icon-btn { min-width: 22px; height: 22px; font-size: 11px; }
.sugg-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.sugg-list li { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-bottom: 1px solid var(--border); }
.sugg-list li:last-child { border-bottom: 0; }
.sugg-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-path { font-family: Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.tr-table td:first-child { font-family: Consolas, monospace; font-size: 11px; color: var(--muted); white-space: nowrap; }
.tr-search { margin-bottom: 10px; }
.type-pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--head); }
.type-pill.real { background: var(--tp-bg); color: var(--tp-fg); }
.type-pill.backtest { background: var(--color-seleccion); color: var(--text); }
.type-pill.test { background: var(--be-bg); color: var(--be-fg); }
