  /* ============ TOKENS (estilo Alegra: fondo gris-lavanda, tarjetas blancas, acento verde-azulado) ============ */
  :root{
    color-scheme: light;
    --bg: #F4F5FB;
    --surface: #FFFFFF;
    --surface-2: #F8F9FD;
    --surface-hover: #F1F3FA;
    --border: #E7E9F2;
    --border-strong: #D6DAE8;
    --ink: #2C3252;
    --ink-secondary: #586082;
    --ink-muted: #8C93B0;
    --accent: #00B19D;
    --accent-strong: #00917F;
    --accent-soft: #E1F6F3;
    --accent-ink: #FFFFFF;
    --sidebar-bg: var(--surface);
    --sidebar-bg-2: var(--surface-2);
    --sidebar-border: var(--border);
    --sidebar-ink: var(--ink-secondary);
    --sidebar-ink-muted: var(--ink-muted);
    --sidebar-ink-strong: var(--ink);
    --sidebar-active-bg: var(--accent-soft);
    --sidebar-active-ink: var(--accent-strong);
    --good: #0B8A55; --good-soft:#E3F6EC; --good-dot:#1E9D5C;
    --warn: #A66300; --warn-soft:#FFF3DB; --warn-dot:#E0A23A;
    --crit: #C23A3A; --crit-soft:#FDE9E9; --crit-dot:#D75A5A;
    --neutral-pill-ink:#5E6684; --neutral-pill-soft:#EEF0F7; --neutral-pill-dot:#9AA1BC;
    --chart-ingresos: #00B19D;
    --chart-gastos: #F5A04D;
    --chart-ganancias: #3E7BEA;
    --chart-grid: #E7E9F2;
    --chart-axis: #C9CEE0;
    --shadow-sm: 0 1px 2px rgba(44,50,82,0.05), 0 2px 8px rgba(44,50,82,0.04);
    --shadow-md: 0 8px 24px rgba(44,50,82,0.14);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 14px;
    --font-display: 'Nunito Sans', system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-body: 'Nunito Sans', system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  }
  @media (prefers-color-scheme: dark){
    :root:not([data-theme="light"]){
      color-scheme: dark;
      --bg: #11131D; --surface: #1A1D2B; --surface-2: #202436; --surface-hover: #262B40;
      --border: rgba(255,255,255,0.08); --border-strong: rgba(255,255,255,0.16);
      --ink: #ECEEF7; --ink-secondary: #AEB4CE; --ink-muted: #7B82A0;
      --accent: #19C7B1; --accent-strong: #5EDFCF; --accent-soft: rgba(25,199,177,0.16); --accent-ink: #04231F;
      --good: #4ADE80; --good-soft:rgba(74,222,128,0.14); --good-dot:#34C759;
      --warn: #F0B33D; --warn-soft:rgba(240,179,61,0.14); --warn-dot:#E3A63D;
      --crit: #F28B8B; --crit-soft:rgba(242,139,139,0.14); --crit-dot:#E26A6A;
      --neutral-pill-ink:#B4BAD3; --neutral-pill-soft:rgba(255,255,255,0.07); --neutral-pill-dot:#868DAA;
      --chart-ingresos: #19C7B1; --chart-gastos: #F0A55A; --chart-ganancias: #6EA2FF;
      --chart-grid: rgba(255,255,255,0.08); --chart-axis: rgba(255,255,255,0.20);
      --shadow-sm: 0 1px 2px rgba(0,0,0,0.30); --shadow-md: 0 10px 26px rgba(0,0,0,0.45);
    }
  }
  :root[data-theme="dark"]{
    color-scheme: dark;
    --bg: #11131D; --surface: #1A1D2B; --surface-2: #202436; --surface-hover: #262B40;
    --border: rgba(255,255,255,0.08); --border-strong: rgba(255,255,255,0.16);
    --ink: #ECEEF7; --ink-secondary: #AEB4CE; --ink-muted: #7B82A0;
    --accent: #19C7B1; --accent-strong: #5EDFCF; --accent-soft: rgba(25,199,177,0.16); --accent-ink: #04231F;
    --good: #4ADE80; --good-soft:rgba(74,222,128,0.14); --good-dot:#34C759;
    --warn: #F0B33D; --warn-soft:rgba(240,179,61,0.14); --warn-dot:#E3A63D;
    --crit: #F28B8B; --crit-soft:rgba(242,139,139,0.14); --crit-dot:#E26A6A;
    --neutral-pill-ink:#B4BAD3; --neutral-pill-soft:rgba(255,255,255,0.07); --neutral-pill-dot:#868DAA;
    --chart-ingresos: #19C7B1; --chart-gastos: #F0A55A; --chart-ganancias: #6EA2FF;
    --chart-grid: rgba(255,255,255,0.08); --chart-axis: rgba(255,255,255,0.20);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.30); --shadow-md: 0 10px 26px rgba(0,0,0,0.45);
  }

  *{ box-sizing:border-box; }
  body{
    margin:0; background:var(--bg); color:var(--ink);
    font-family:var(--font-body); font-size:14px; line-height:1.5;
    -webkit-font-smoothing:antialiased;
  }
  h1,h2,h3,h4{ font-family:var(--font-display); font-weight:700; margin:0; text-wrap:balance; color:var(--ink); }
  a{ color:inherit; }
  button{ font-family:var(--font-body); }
  .tabular{ font-variant-numeric:tabular-nums; }
  .mono{ font-family:var(--font-mono); }

  /* ============ APP SHELL ============ */
  #app{ display:flex; min-height:100vh; }

  /* ---- Sidebar ---- */
  .sidebar{
    width:264px; flex:none; background:var(--sidebar-bg); color:var(--sidebar-ink);
    display:flex; flex-direction:column; position:sticky; top:0; height:100vh;
    border-right:1px solid var(--sidebar-border);
  }
  .brand{
    display:flex; align-items:center; gap:10px; padding:20px 20px 16px;
    border-bottom:1px solid var(--sidebar-border);
  }
  .brand-mark{
    width:32px; height:32px; border-radius:9px; flex:none;
    background:var(--accent);
    display:flex; align-items:center; justify-content:center;
    font-family:var(--font-display); font-weight:700; font-size:14px; color:var(--accent-ink);
  }
  .brand-name{ font-family:var(--font-display); font-weight:700; font-size:15px; color:var(--sidebar-ink-strong); letter-spacing:.2px; }
  .brand-sub{ font-size:11px; color:var(--sidebar-ink-muted); margin-top:1px; }
  .sidebar-toggle{ margin-left:auto; width:26px; height:26px; border-radius:6px; border:none; background:transparent; color:var(--ink-muted); display:flex; align-items:center; justify-content:center; cursor:pointer; }
  .sidebar-toggle:hover{ background:var(--surface-2); }

  .nav{ flex:1; overflow-y:auto; padding:8px 10px 14px; }
  .nav-solo{ margin:2px 0 8px; }
  .nav-group{ margin-top:2px; }
  .nav-group-head{
    display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:var(--radius-sm);
    color:var(--sidebar-ink); font-size:13.5px; font-weight:600; cursor:pointer; user-select:none;
  }
  .nav-group-head:hover{ background:var(--sidebar-bg-2); }
  .nav-group-head .chev{ margin-left:auto; width:14px; height:14px; stroke:var(--sidebar-ink-muted); fill:none; stroke-width:2; transition:transform .15s ease; }
  .nav-group.collapsed .chev{ transform:rotate(-90deg); }
  .nav-group-body{ overflow:hidden; max-height:400px; transition:max-height .18s ease; }
  .nav-group.collapsed .nav-group-body{ max-height:0; }
  .nav-item{
    display:flex; align-items:center; gap:10px; padding:8px 10px 8px 34px; border-radius:var(--radius-sm);
    color:var(--sidebar-ink); text-decoration:none; font-size:13.5px; font-weight:500; cursor:pointer;
    border:1px solid transparent; position:relative;
  }
  .nav-solo > .nav-item{ padding-left:10px; font-weight:600; }
  .nav-item:hover{ background:var(--sidebar-bg-2); color:var(--sidebar-ink-strong); }
  .nav-item.active{ background:var(--sidebar-active-bg); color:var(--sidebar-active-ink); font-weight:600; }
  .nav-item.active::before{
    content:""; position:absolute; left:0; top:6px; bottom:6px; width:3px; border-radius:0 3px 3px 0; background:var(--accent-strong);
  }
  .nav-ico{ width:17px; height:17px; flex:none; display:flex; align-items:center; justify-content:center; opacity:.85; }
  .nav-ico svg{ width:17px; height:17px; stroke:currentColor; fill:none; stroke-width:1.8; }
  svg.ico{ stroke:currentColor; fill:none; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; vertical-align:-3px; }

  .sidebar-foot{ padding:14px 16px; border-top:1px solid var(--sidebar-border); font-size:11.5px; color:var(--sidebar-ink-muted); }

  /* ---- Main column ---- */
  .main{ flex:1; min-width:0; display:flex; flex-direction:column; }
  .topbar{
    height:64px; flex:none; display:flex; align-items:center; justify-content:space-between; gap:20px;
    padding:0 28px; background:var(--surface); border-bottom:1px solid var(--border);
    position:sticky; top:0; z-index:20;
  }
  .topbar-left{ display:flex; flex-direction:column; gap:1px; min-width:0; flex:none; }
  .crumb{ font-size:11.5px; color:var(--ink-muted); }
  .page-title{ font-size:18px; }
  .topbar-search{ flex:1; max-width:420px; position:relative; }
  .topbar-search input{
    width:100%; padding:9px 14px 9px 34px; border-radius:999px; border:1px solid var(--border-strong);
    background:var(--surface-2); color:var(--ink); font-size:13px;
  }
  .topbar-search svg{ position:absolute; left:12px; top:50%; transform:translateY(-50%); width:14px; height:14px; color:var(--ink-muted); }
  .topbar-right{ display:flex; align-items:center; gap:10px; flex:none; }
  .icon-btn{
    width:34px; height:34px; border-radius:50%; border:1px solid var(--border); background:var(--surface-2);
    color:var(--ink-secondary); display:flex; align-items:center; justify-content:center; cursor:pointer; flex:none;
  }
  .icon-btn svg{ width:16px; height:16px; }
  .company-pill{
    display:flex; align-items:center; gap:8px; padding:5px 12px 5px 6px; border-radius:999px;
    border:1px solid var(--border-strong); background:var(--surface); cursor:pointer; position:relative;
  }
  .company-pill-dot{ width:22px; height:22px; border-radius:50%; background:var(--accent-soft); color:var(--accent-strong); font-size:10.5px; font-weight:700; font-family:var(--font-display); display:flex; align-items:center; justify-content:center; flex:none; }
  .company-pill select{
    appearance:none; border:none; background:transparent; font-size:12.5px; font-weight:600; color:var(--ink);
    padding-right:14px; cursor:pointer; max-width:150px; text-overflow:ellipsis;
  }
  .company-pill::after{ content:"⌄"; position:absolute; right:11px; top:50%; transform:translateY(-58%); color:var(--ink-muted); font-size:13px; pointer-events:none; }
  .avatar{
    width:34px; height:34px; border-radius:50%; background:var(--accent-soft); color:var(--accent-strong);
    display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; font-family:var(--font-display);
    border:1px solid var(--border); flex:none;
  }

  .content{ flex:1; padding:26px 28px 60px; max-width:1360px; width:100%; margin:0 auto; }
  .view{ display:none; }
  .view.active{ display:block; animation:fadeIn .18s ease; }
  @keyframes fadeIn{ from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;} }
  @media (prefers-reduced-motion:reduce){ .view.active{ animation:none; } }

  .view-head{ display:flex; align-items:flex-end; justify-content:space-between; gap:16px; margin-bottom:18px; flex-wrap:wrap; }
  .view-head h2{ font-size:21px; }
  .view-sub{ font-size:12.5px; color:var(--ink-muted); margin-top:3px; }

  /* ============ COMPONENTS ============ */
  .btn{
    display:inline-flex; align-items:center; gap:7px; border-radius:var(--radius-sm); border:1px solid var(--border-strong);
    background:var(--surface); color:var(--ink); font-size:13px; font-weight:600; padding:9px 14px; cursor:pointer;
  }
  .btn:hover{ background:var(--surface-hover); }
  .btn svg{ width:15px; height:15px; stroke:currentColor; fill:none; stroke-width:2; }
  .btn-primary{ background:var(--accent); border-color:var(--accent); color:var(--accent-ink); }
  .btn-primary:hover{ background:var(--accent-strong); border-color:var(--accent-strong); }
  .btn-ghost{ border-color:transparent; background:transparent; }
  .btn-ghost:hover{ background:var(--surface-hover); }
  .btn-sm{ padding:6px 10px; font-size:12.5px; }

  .card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg); box-shadow:var(--shadow-sm); }
  .card-pad{ padding:18px 20px; }

  .kpi-row{ display:grid; grid-template-columns:repeat(auto-fit, minmax(190px,1fr)); gap:14px; margin-bottom:18px; }
  .kpi{ padding:16px 18px; display:flex; flex-direction:column; gap:8px; }
  .kpi-label{ font-size:11.5px; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-muted); font-weight:600; display:flex; align-items:center; justify-content:space-between; }
  .kpi-value{ font-family:var(--font-display); font-size:23px; font-weight:700; }
  .kpi-delta{ font-size:12px; display:flex; align-items:center; gap:4px; font-weight:600; }
  .kpi-delta.up{ color:var(--good); } .kpi-delta.down{ color:var(--crit); }
  .kpi-ico{ width:30px; height:30px; border-radius:8px; display:flex; align-items:center; justify-content:center; flex:none; }
  .kpi-ico svg{ width:15px; height:15px; stroke-width:2; fill:none; }

  .grid-2{ display:grid; grid-template-columns:1.3fr 1fr; gap:16px; margin-bottom:16px; }
  @media (max-width:980px){ .grid-2{ grid-template-columns:1fr; } }

  .card-head{ display:flex; align-items:center; justify-content:space-between; padding:16px 20px 0; }
  .card-head h3{ font-size:14.5px; }
  .card-head .sub{ font-size:11.5px; color:var(--ink-muted); font-family:var(--font-body); font-weight:500; margin-top:2px; }

  .legend{ display:flex; gap:16px; padding:2px 20px 0; font-size:12px; color:var(--ink-secondary); }
  .legend-item{ display:flex; align-items:center; gap:6px; }
  .legend-dot{ width:9px; height:9px; border-radius:2px; flex:none; }

  .table-wrap{ overflow-x:auto; }
  table{ width:100%; border-collapse:collapse; font-size:13px; }
  thead th{
    text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:var(--ink-muted);
    font-weight:600; padding:10px 14px; background:var(--surface-2); border-bottom:1px solid var(--border);
    white-space:nowrap; position:sticky; top:0;
  }
  tbody td{ padding:11px 14px; border-bottom:1px solid var(--border); color:var(--ink); white-space:nowrap; }
  tbody tr:last-child td{ border-bottom:none; }
  tbody tr:hover{ background:var(--surface-hover); }
  td.num, th.num{ text-align:right; }
  td.wrap{ white-space:normal; min-width:160px; }
  .row-muted{ color:var(--ink-muted); }

  .toolbar{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; flex-wrap:wrap; }
  .toolbar-left{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
  .search{ position:relative; }
  .search input{
    width:230px; padding:8px 12px 8px 32px; border-radius:var(--radius-sm); border:1px solid var(--border-strong);
    background:var(--surface); color:var(--ink); font-size:13px;
  }
  .search svg{ position:absolute; left:10px; top:50%; transform:translateY(-50%); width:14px; height:14px; color:var(--ink-muted); fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; }
  .chip{ font-size:12px; padding:6px 11px; border-radius:999px; border:1px solid var(--border-strong); background:var(--surface); color:var(--ink-secondary); cursor:pointer; font-weight:600; }
  .chip.active{ background:var(--accent-soft); border-color:var(--accent); color:var(--accent-strong); }

  .pill{ display:inline-flex; align-items:center; font-size:11.5px; font-weight:700; padding:4px 11px; border-radius:999px; white-space:nowrap; }
  .pill-good{ background:var(--good-soft); color:var(--good); }
  .pill-warn{ background:var(--warn-soft); color:var(--warn); }
  .pill-crit{ background:var(--crit-soft); color:var(--crit); }
  .pill-neutral{ background:var(--neutral-pill-soft); color:var(--neutral-pill-ink); }

  .company-tag{ font-size:11.5px; font-weight:600; padding:3px 8px; border-radius:6px; background:var(--surface-2); border:1px solid var(--border); color:var(--ink-secondary); }
  .id-link{ color:var(--accent-strong); font-weight:700; font-family:var(--font-mono); }
  td.chk, th.chk{ width:36px; }
  input[type="checkbox"]{ width:15px; height:15px; accent-color:var(--accent); cursor:pointer; }

  .empty-note{ padding:14px 20px; font-size:12.5px; color:var(--ink-muted); background:var(--surface-2); border-top:1px solid var(--border); }

  .draft-banner{
    display:flex; gap:10px; align-items:flex-start; background:var(--warn-soft); color:var(--warn);
    border:1px solid var(--warn-dot); border-radius:var(--radius-md); padding:12px 14px; font-size:12.5px; margin-bottom:16px;
  }
  .draft-banner svg{ width:16px; height:16px; flex:none; margin-top:1px; stroke:currentColor; fill:none; stroke-width:2; }

  /* config forms */
  .form-grid{ display:grid; grid-template-columns:1fr 1fr; gap:14px; padding:18px 20px; }
  .form-grid.full{ grid-template-columns:1fr; }
  .field{ display:flex; flex-direction:column; gap:6px; }
  .field label{ font-size:12px; font-weight:600; color:var(--ink-secondary); }
  .field input, .field select, .field textarea{
    padding:9px 11px; border-radius:var(--radius-sm); border:1px solid var(--border-strong); background:var(--surface);
    color:var(--ink); font-size:13px; font-family:var(--font-body);
  }
  .field-note{ font-size:11px; color:var(--ink-muted); }

  .company-cards{ display:grid; grid-template-columns:repeat(auto-fit,minmax(260px,1fr)); gap:14px; }
  .company-card{ padding:16px 18px; display:flex; flex-direction:column; gap:10px; }
  .company-card-top{ display:flex; align-items:center; gap:11px; min-width:0; overflow:hidden; }
  .company-card-top > div:last-child{ min-width:0; }
  .company-logo{ width:42px; height:42px; border-radius:10px; background:var(--accent-soft); color:var(--accent-strong); display:flex; align-items:center; justify-content:center; font-family:var(--font-display); font-weight:700; }
  .company-meta{ font-size:12px; color:var(--ink-muted); display:flex; flex-direction:column; gap:3px; }
  .company-meta b{ color:var(--ink-secondary); font-weight:600; }

  /* modal */
  .modal-back{ position:fixed; inset:0; background:rgba(10,16,18,.45); display:none; align-items:center; justify-content:center; z-index:100; padding:20px; }
  .modal-back.open{ display:flex; }
  .modal{ width:min(560px,100%); max-height:88vh; overflow-y:auto; background:var(--surface); border-radius:var(--radius-lg); box-shadow:var(--shadow-md); border:1px solid var(--border); }
  .modal-head{ display:flex; align-items:center; justify-content:space-between; padding:16px 20px; border-bottom:1px solid var(--border); }
  .modal-head h3{ font-size:15.5px; }
  .modal-close{ width:28px; height:28px; border-radius:7px; border:none; background:var(--surface-2); color:var(--ink-secondary); cursor:pointer; display:flex; align-items:center; justify-content:center; }
  .modal-foot{ display:flex; justify-content:flex-end; gap:10px; padding:14px 20px; border-top:1px solid var(--border); }
  .modal-note{ margin:0 20px 4px; font-size:11.5px; color:var(--ink-muted); background:var(--surface-2); padding:8px 12px; border-radius:8px; }

  /* aging bars (cxc/cxp) */
  .aging-row{ display:grid; grid-template-columns:120px 1fr 90px; gap:12px; align-items:center; padding:9px 0; }
  .aging-track{ height:8px; border-radius:5px; background:var(--surface-2); overflow:hidden; }
  .aging-fill{ height:100%; border-radius:5px; }

  ::-webkit-scrollbar{ width:10px; height:10px; }
  ::-webkit-scrollbar-thumb{ background:var(--border-strong); border-radius:6px; }
  ::-webkit-scrollbar-track{ background:transparent; }

  .gridline{ stroke:var(--chart-grid); stroke-width:1; }
  .axislabel{ fill:var(--ink-muted); font-size:9.5px; font-family:var(--font-body); }
  .barlabel{ font-weight:600; fill:var(--ink-secondary); font-size:11px; }
  .endlabel{ font-size:10.5px; font-weight:700; font-family:var(--font-mono); }
  .bartrack{ fill:var(--surface-2); }
  .barfill{ fill:var(--accent); }
  .linechart, .barchart{ width:100%; height:auto; overflow:visible; }
  details.tableview{ margin:6px 20px 16px; }
  details.tableview summary{ cursor:pointer; font-size:12px; color:var(--accent-strong); font-weight:600; padding:6px 0; }
  details.tableview table{ margin-top:8px; }

/* ============ Extras para la app PHP (no estaban en el prototipo) ============ */
.flash{ padding:12px 16px; border-radius:var(--radius-md); font-size:13px; margin-bottom:16px; display:flex; align-items:center; gap:8px; }
.flash-ok{ background:var(--good-soft); color:var(--good); }
.flash-error{ background:var(--crit-soft); color:var(--crit); }
.flash svg{ width:16px; height:16px; flex:none; stroke:currentColor; fill:none; stroke-width:2; }

.field-error{ color:var(--crit); font-size:11.5px; margin-top:2px; }
.field input:disabled, .field select:disabled{ background:var(--surface-2); color:var(--ink-muted); cursor:not-allowed; }

a.btn{ text-decoration:none; }
.btn[disabled], .btn.disabled{ opacity:.5; cursor:not-allowed; pointer-events:none; }

.badge-count{ display:inline-flex; align-items:center; justify-content:center; min-width:18px; height:18px; padding:0 5px;
  border-radius:999px; background:var(--accent-soft); color:var(--accent-strong); font-size:10.5px; font-weight:700; }

.empty-state{ padding:48px 20px; text-align:center; color:var(--ink-muted); }
.empty-state svg{ width:34px; height:34px; margin-bottom:10px; stroke:var(--ink-muted); fill:none; stroke-width:1.6; }

.readonly-banner{
  display:flex; gap:10px; align-items:flex-start; background:var(--surface-2); color:var(--ink-secondary);
  border:1px solid var(--border); border-radius:var(--radius-md); padding:10px 14px; font-size:12.5px; margin-bottom:16px;
}

/* ============ Estilo Alegra (escritorio) ============ */
body{ font-size:14px; letter-spacing:.005em; }
h1,h2,h3,h4{ font-weight:800; }
.sidebar{ width:252px; }
.brand{ padding:18px 18px 14px; border-bottom:none; }
.brand-mark{ width:36px; height:36px; border-radius:10px; font-weight:800; font-size:14px; letter-spacing:.3px; }
.brand-name{ font-weight:800; font-size:16px; }
.brand-sub{ font-size:11.5px; }
.nav{ padding:4px 12px 14px; }
.nav-group-head{ padding:10px 12px; border-radius:10px; font-weight:700; color:var(--ink); }
.nav-item{ padding:9px 12px 9px 40px; border-radius:10px; font-weight:600; border:none; }
.nav-solo > .nav-item{ padding-left:12px; font-weight:700; color:var(--ink); }
.nav-item.active{ background:var(--sidebar-active-bg); color:var(--sidebar-active-ink); font-weight:800; }
.nav-item.active::before{ display:none; }
.nav-ico{ opacity:1; color:var(--ink-muted); }
.nav-item.active .nav-ico, .nav-group:not(.collapsed) > .nav-group-head .nav-ico{ color:var(--accent); }
.sidebar-foot{ border-top:1px solid var(--border); }
.sidebar-foot a{ text-decoration:none; font-weight:700; }
.sidebar-perfil{ color:var(--ink-secondary); }

.topbar{ height:62px; padding:0 28px; box-shadow:0 1px 0 var(--border); border-bottom:none; }
.page-title{ font-size:19px; font-weight:800; }
.crumb{ font-size:12px; font-weight:600; color:var(--ink-muted); }
.topbar-search input{ border-radius:10px; background:var(--surface-2); border-color:var(--border); padding-top:10px; padding-bottom:10px; }
.company-pill{ border-radius:10px; border-color:var(--border); background:var(--surface-2); }
.company-pill-dot{ background:var(--accent); color:#fff; border-radius:8px; width:24px; height:24px; }
.icon-btn{ border-radius:10px; background:var(--surface); }
.avatar{ background:var(--accent); color:#fff; border:none; font-weight:800; }

.content{ padding:26px 32px 90px; }

.btn{ border-radius:8px; font-weight:700; padding:9px 16px; border-color:var(--border-strong); }
.btn-primary{ box-shadow:0 1px 2px rgba(0,145,127,.25); }
.btn-primary:hover{ filter:brightness(.96); }
.btn-ghost{ color:var(--ink-secondary); }
.btn-ghost:hover{ color:var(--accent-strong); background:var(--accent-soft); }

.card{ border-radius:12px; border-color:var(--border); box-shadow:var(--shadow-sm); }
thead th{ text-transform:none; letter-spacing:0; font-size:12.5px; font-weight:800; color:var(--ink-secondary); background:var(--surface); border-bottom:1px solid var(--border-strong); padding:13px 16px; }
tbody td{ padding:14px 16px; }
tbody tr:hover{ background:var(--surface-2); }
.id-link{ font-family:var(--font-body); font-weight:800; color:var(--accent-strong); text-decoration:none; }
a.id-link:hover{ text-decoration:underline; }
.pill{ border-radius:6px; font-weight:800; font-size:11.5px; padding:4px 10px; }
.company-tag{ border-radius:6px; background:var(--surface-2); font-weight:700; }
.chip{ border-radius:8px; font-weight:700; padding:7px 14px; background:var(--surface); }
.chip.active{ background:var(--accent); border-color:var(--accent); color:#fff; }
.chip.active .badge-count{ background:rgba(255,255,255,.25); color:#fff; }
.chips-row{ margin-bottom:16px; }
.search input{ border-radius:8px; border-color:var(--border-strong); }
.field input, .field select, .field textarea{ border-radius:8px; border-color:var(--border-strong); padding:10px 12px; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus, .topbar-search input:focus{ outline:2px solid var(--accent-soft); border-color:var(--accent); }
.field label{ font-weight:700; color:var(--ink-secondary); }
.modal{ border-radius:14px; }
.modal-head h3{ font-weight:800; }
.draft-banner{ border-radius:10px; }
.flash{ border-radius:10px; font-weight:600; }
.err-list{ margin:4px 0 0; padding-left:18px; font-weight:500; }
.kpi{ padding:18px 20px; }
.kpi-label{ text-transform:none; letter-spacing:0; font-size:13px; font-weight:700; color:var(--ink-secondary); }
.kpi-value{ font-size:26px; font-weight:800; }

/* ---- Botón "+" flotante con acciones rápidas ---- */
.fab{ position:fixed; right:28px; bottom:26px; width:58px; height:58px; border-radius:50%; border:none; background:var(--accent); color:#fff; cursor:pointer;
  box-shadow:0 8px 22px rgba(0,145,127,.45); display:flex; align-items:center; justify-content:center; z-index:80; transition:transform .15s ease; }
.fab:hover{ transform:scale(1.06); }
.fab svg{ width:26px; height:26px; stroke-width:2.6; }
.quick-back{ position:fixed; inset:0; background:rgba(20,24,44,.42); z-index:130; display:none; align-items:flex-end; justify-content:flex-end; padding:0 28px 98px; }
.quick-back.open{ display:flex; }
.quick-menu{ width:290px; background:var(--surface); border-radius:14px; box-shadow:var(--shadow-md); padding:8px; border:1px solid var(--border); }
.quick-title{ font-size:11.5px; font-weight:800; color:var(--ink-muted); padding:8px 12px 4px; text-transform:uppercase; letter-spacing:.06em; }
.quick-item{ display:flex; align-items:center; gap:12px; padding:11px 12px; border-radius:10px; text-decoration:none; color:var(--ink); font-weight:700; font-size:14.5px; }
.quick-item:hover{ background:var(--accent-soft); color:var(--accent-strong); }
.quick-ico{ width:34px; height:34px; border-radius:10px; background:var(--accent-soft); color:var(--accent-strong); display:flex; align-items:center; justify-content:center; flex:none; }
.quick-ico svg{ width:18px; height:18px; }
.quick-ico.venta{ background:#E8F0FF; color:#2F6FE0; }
.quick-ico.compra{ background:#FFF1E2; color:#D9822B; }

/* ---- Formularios de documento (Compra / Venta) ---- */
.doc-grid{ display:grid; grid-template-columns:minmax(0,1fr) 340px; gap:18px; align-items:start; }
.doc-main{ display:flex; flex-direction:column; gap:16px; min-width:0; }
.doc-side{ position:sticky; top:82px; display:flex; flex-direction:column; gap:14px; }
.doc-section{ overflow:hidden; }
.doc-title{ font-size:15px; padding:16px 20px 0; }
.doc-section .form-grid{ padding:14px 20px 18px; }
.doc-body{ padding:14px 20px 18px; }
.doc-details{ border-top:1px solid var(--border); }
.doc-details summary{ cursor:pointer; padding:13px 20px; font-weight:800; font-size:13.5px; color:var(--accent-strong); list-style:none; }
.doc-details summary::-webkit-details-marker{ display:none; }
.doc-details summary::before{ content:"+ "; }
.doc-details[open] summary::before{ content:"− "; }
.input-con-boton{ display:flex; gap:8px; }
.input-con-boton input{ flex:1; min-width:0; }
.resumen{ margin:0; padding:10px 20px 4px; }
.resumen > div{ display:flex; justify-content:space-between; gap:12px; padding:7px 0; font-size:13.5px; color:var(--ink-secondary); }
.resumen dt{ font-weight:600; } .resumen dd{ margin:0; font-weight:700; color:var(--ink); }
.resumen .resumen-total{ border-top:1px dashed var(--border-strong); margin-top:6px; padding-top:12px; font-size:15px; }
.resumen .resumen-total dt{ font-weight:800; color:var(--ink); } .resumen .resumen-total dd{ font-size:20px; font-weight:800; color:var(--accent-strong); }
.doc-acciones{ display:flex; flex-direction:column; gap:8px; padding:12px 20px 20px; }
.doc-acciones .btn{ justify-content:center; width:100%; }
.nota-dgii{ font-size:12.5px; color:var(--ink-secondary); line-height:1.55; }
.file-drop{ display:flex; flex-direction:column; align-items:center; gap:4px; text-align:center; border:2px dashed var(--border-strong); border-radius:12px; padding:22px 16px; cursor:pointer; color:var(--ink-secondary); background:var(--surface-2); }
.file-drop:hover{ border-color:var(--accent); background:var(--accent-soft); }
.file-drop svg{ width:28px; height:28px; color:var(--accent); }
.file-drop b{ color:var(--accent-strong); } .file-drop small{ color:var(--ink-muted); }
.adj-nombres{ font-size:12.5px; color:var(--ink); font-weight:700; overflow-wrap:anywhere; }
.adj-list{ list-style:none; margin:0 0 12px; padding:0; display:flex; flex-direction:column; gap:6px; }
.adj-list li{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; padding:8px 12px; border:1px solid var(--border); border-radius:10px; background:var(--surface-2); }
.adj-list a{ font-weight:700; color:var(--accent-strong); text-decoration:none; overflow-wrap:anywhere; }
.adj-list .btn{ margin-left:auto; }
.visually-hidden{ position:absolute; width:1px; height:1px; margin:-1px; padding:0; border:0; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.lineas{ display:flex; flex-direction:column; gap:8px; margin-bottom:12px; }
.linea{ display:grid; grid-template-columns:minmax(0,1fr) 78px 118px 112px 100px 36px; gap:8px; align-items:center; }
.linea input, .linea select{ padding:9px 10px; border-radius:8px; border:1px solid var(--border-strong); background:var(--surface); color:var(--ink); font-size:13.5px; font-family:var(--font-body); min-width:0; width:100%; }
.linea-head{ font-size:12px; font-weight:800; color:var(--ink-muted); }
.linea-importe{ font-weight:700; text-align:right; }
.linea-quitar{ padding:6px; justify-content:center; }

/* ---- Mi perfil y Configuración ---- */
.perfil-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(340px,1fr)); gap:16px; align-items:start; }
.perfil-p{ margin:0 0 12px; color:var(--ink-secondary); line-height:1.55; }
.datos-lista{ margin:0; padding:12px 20px 18px; display:flex; flex-direction:column; gap:10px; }
.datos-lista > div{ display:flex; justify-content:space-between; gap:14px; font-size:13.5px; }
.datos-lista dt{ color:var(--ink-muted); font-weight:700; } .datos-lista dd{ margin:0; font-weight:700; text-align:right; }
.config-seccion{ margin:0 0 12px; font-size:15px; }
.config-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:14px; margin-bottom:26px; }
.config-card{ display:flex; gap:14px; align-items:flex-start; padding:18px; text-decoration:none; color:inherit; transition:box-shadow .15s ease, border-color .15s ease; }
.config-card:hover{ border-color:var(--accent); box-shadow:var(--shadow-md); }
.config-ico{ width:44px; height:44px; border-radius:12px; background:var(--accent-soft); color:var(--accent-strong); display:flex; align-items:center; justify-content:center; flex:none; }
.config-ico svg{ width:22px; height:22px; }
.config-card b{ display:block; font-size:15px; font-weight:800; margin-bottom:2px; }
.config-card span{ font-size:12.5px; color:var(--ink-secondary); line-height:1.45; }

/* ---- Resumen del negocio (inicio) ---- */
.dash-head{ display:flex; align-items:flex-end; justify-content:space-between; gap:16px; flex-wrap:wrap; margin-bottom:18px; }
.dash-head h2{ font-size:22px; } .dash-head p{ margin:3px 0 0; color:var(--ink-muted); font-weight:600; font-size:13px; }
.dash-actions{ display:flex; gap:10px; flex-wrap:wrap; }
.kpi-row{ grid-template-columns:repeat(3,minmax(0,1fr)); }
@media (max-width:980px){ .kpi-row{ grid-template-columns:repeat(2,minmax(0,1fr)); } }
.kpi-row.kpi-4{ grid-template-columns:repeat(4,minmax(0,1fr)); }
@media (max-width:980px){ .kpi-row.kpi-4{ grid-template-columns:repeat(2,minmax(0,1fr)); } }
.kpi-top{ display:flex; align-items:center; gap:12px; }
.kpi-ico.verde{ background:var(--accent-soft); color:var(--accent-strong); }
.kpi-ico.azul{ background:#E8F0FF; color:#2F6FE0; }
.kpi-ico.naranja{ background:#FFF1E2; color:#D9822B; }
.kpi-ico.morado{ background:#F0EAFE; color:#7A4FD6; }
.kpi-ico{ width:38px; height:38px; border-radius:50%; }
.kpi-ico svg{ width:18px; height:18px; stroke:currentColor; }
.kpi-hint{ font-size:12px; color:var(--ink-muted); font-weight:600; }

/* ---- Inicio de sesión ---- */
body.login-body{ min-height:100vh; min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:20px; background:var(--bg); }
.login-wrap{ width:100%; max-width:410px; }
.login-card{ background:var(--surface); border:1px solid var(--border); border-radius:16px; box-shadow:var(--shadow-md); padding:30px 28px 24px; }
.login-brand{ display:flex; align-items:center; gap:11px; margin-bottom:18px; }
.login-brand b{ font-size:17px; font-weight:800; display:block; } .login-brand span{ font-size:12px; color:var(--ink-muted); font-weight:600; }
.login-titulo{ font-size:23px; margin:0 0 16px; }
.login-error{ background:var(--crit-soft); color:var(--crit); padding:10px 12px; border-radius:10px; font-size:13px; font-weight:600; margin-bottom:14px; }
.login-aviso{ background:var(--good-soft); color:var(--good); padding:10px 12px; border-radius:10px; font-size:13px; font-weight:600; margin-bottom:14px; }
.login-card .field{ margin-bottom:14px; }
.login-check{ display:flex; gap:10px; align-items:flex-start; font-size:13.5px; font-weight:700; margin:2px 0 16px; cursor:pointer; }
.login-check small{ display:block; font-weight:500; color:var(--ink-muted); font-size:12px; margin-top:2px; line-height:1.4; }
.login-check input{ margin-top:3px; flex:none; }
.login-btn{ width:100%; justify-content:center; min-height:46px; font-size:15px; }
.login-sep{ display:flex; align-items:center; gap:12px; color:var(--ink-muted); font-size:12px; margin:14px 0; }
.login-sep::before, .login-sep::after{ content:""; flex:1; height:1px; background:var(--border); }
.login-faceid svg{ width:20px; height:20px; }
.login-hint{ margin-top:18px; font-size:12px; color:var(--ink-muted); text-align:center; }

@media (max-width:1100px){
  .doc-grid{ grid-template-columns:1fr; }
  .doc-side{ position:static; }
}

/* ============ Móvil / iPhone (≤ 860 px) ============ */
.menu-btn{ display:none; }
.nav-backdrop{ display:none; }
.bottom-nav{ display:none; }
.sidebar-foot{ display:flex; flex-direction:column; gap:6px; }
.sidebar-logout{ color:var(--accent-strong); font-weight:600; text-decoration:none; font-size:13px; }
.chips-row{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; }
a.chip{ text-decoration:none; display:inline-flex; align-items:center; gap:6px; }
.filter-form{ display:flex; gap:10px; flex-wrap:wrap; align-items:flex-end; }
.filter-form .field input, .filter-form .field select{ min-width:150px; }
.field textarea{ resize:vertical; line-height:1.45; }
.detalle-novedad{ padding:16px 20px; display:flex; flex-direction:column; gap:10px; }
.detalle-novedad p{ margin:0; }
.detalle-texto{ background:var(--surface-2); border:1px solid var(--border); border-radius:var(--radius-md); padding:12px 14px; font-size:14px; line-height:1.55; overflow-wrap:anywhere; }

@media (max-width:860px){
  html{ -webkit-text-size-adjust:100%; }
  body{ font-size:15px; -webkit-tap-highlight-color:transparent; }

  /* Menú lateral convertido en cajón deslizable */
  .sidebar{
    display:flex; position:fixed; left:0; top:0; bottom:0; height:100dvh; width:min(300px,86vw); z-index:120;
    transform:translateX(-102%); transition:transform .22s ease; box-shadow:var(--shadow-md);
    padding-top:env(safe-area-inset-top); padding-bottom:env(safe-area-inset-bottom);
  }
  body.nav-open .sidebar{ transform:none; }
  .nav-backdrop{ position:fixed; inset:0; background:rgba(10,16,18,.5); z-index:110; opacity:0; pointer-events:none; transition:opacity .2s ease; display:block; }
  body.nav-open .nav-backdrop{ opacity:1; pointer-events:auto; }
  body.nav-open{ overflow:hidden; }
  .nav-group-head, .nav-item{ padding-top:12px; padding-bottom:12px; font-size:15px; }
  .nav-group-body{ max-height:600px; }
  .sidebar-foot{ padding-bottom:18px; }
  .sidebar-logout{ font-size:15px; padding:6px 0; }

  /* Barra superior compacta */
  .topbar{ position:static; height:auto; min-height:56px; padding:calc(8px + env(safe-area-inset-top)) 12px 8px; gap:8px 10px; flex-wrap:wrap; }
  .menu-btn{ display:flex; width:40px; height:40px; }
  .icon-btn{ width:40px; height:40px; }
  .crumb{ display:none; }
  .topbar-left{ flex:1; min-width:0; }
  .page-title{ font-size:16.5px; line-height:1.2; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
  /* Fila 1: menú · título · tema. Fila 2: empresa activa (a todo lo ancho, para no registrar en la empresa equivocada). Fila 3: buscador. */
  .topbar-right{ display:contents; }
  .topbar-right .avatar{ display:none; }
  .menu-btn{ order:1; }
  .topbar-left{ order:2; }
  #themeBtn{ order:3; }
  .company-pill{ order:4; flex:1 0 100%; padding:7px 14px 7px 8px; min-height:44px; }
  .company-pill select{ flex:1; max-width:none; width:100%; font-size:15px; }
  .company-pill::after{ right:16px; }
  .topbar-search{ order:5; flex:1 0 100%; max-width:none; }
  .topbar-search input{ padding:11px 14px 11px 34px; }

  .content{ padding:14px 14px calc(96px + env(safe-area-inset-bottom)); }

  /* Barra inferior con acceso rápido + botón "+ Gasto" */
  .bottom-nav{
    display:grid; grid-template-columns:repeat(5,1fr); align-items:end; position:fixed; left:0; right:0; bottom:0; z-index:90;
    background:var(--surface); border-top:1px solid var(--border-strong);
    padding:6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .bn-item{
    display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; min-height:48px;
    color:var(--ink-secondary); text-decoration:none; font-size:11px; font-weight:600; background:none; border:none; cursor:pointer; font-family:var(--font-body);
  }
  .bn-item svg{ width:22px; height:22px; }
  .bn-item.active{ color:var(--accent-strong); }
  .bn-fab{
    display:flex; flex-direction:column; align-items:center; justify-content:center; gap:1px; text-decoration:none;
    width:62px; height:62px; margin:-26px auto 0; border-radius:50%; background:var(--accent); color:var(--accent-ink);
    box-shadow:0 6px 16px rgba(0,0,0,.28); border:4px solid var(--surface); font-size:10.5px; font-weight:700;
  }
  .bn-fab svg{ width:24px; height:24px; stroke-width:2.4; }
  button.bn-fab{ cursor:pointer; font-family:var(--font-body); }
  #toastHost{ bottom:calc(86px + env(safe-area-inset-bottom)) !important; }

  /* Formularios y botones fáciles de tocar (16 px evita el zoom automático de iOS) */
  input, select, textarea, .field input, .field select, .field textarea{ font-size:16px; }
  .field input, .field select{ min-height:46px; }
  .btn{ min-height:44px; padding:10px 16px; font-size:14px; }
  .btn-sm{ min-height:40px; padding:8px 12px; font-size:13.5px; }
  .chip{ padding:9px 14px; font-size:13px; }
  .toolbar{ flex-direction:column; align-items:stretch; }
  .toolbar-left, .search{ width:100%; }
  .search input{ width:100%; padding:11px 12px 11px 34px; font-size:16px; }
  .toolbar > .btn{ justify-content:center; }
  .filter-form{ width:100%; }
  .filter-form .field{ flex:1 1 40%; }
  .filter-form .field:first-child{ flex:1 0 100%; }
  .filter-form .field input, .filter-form .field select{ width:100%; min-width:0; }
  .chips-row{ flex-wrap:nowrap; overflow-x:auto; margin-left:-14px; margin-right:-14px; padding:0 14px 4px; scrollbar-width:none; }
  .chips-row::-webkit-scrollbar{ display:none; }
  .chips-row .chip{ flex:none; }

  /* Ventanas emergentes como hoja desde abajo */
  .modal-back{ align-items:flex-end; padding:0; }
  .modal{ width:100%; max-height:92dvh; border-radius:18px 18px 0 0; border-bottom:none; }
  .modal-head{ position:sticky; top:0; background:var(--surface); z-index:2; }
  .modal-close{ width:40px; height:40px; font-size:16px; }
  .form-grid{ grid-template-columns:minmax(0,1fr); padding:16px; }
  .form-grid .field{ grid-column:1/-1 !important; min-width:0; }
  .field input, .field select, .field textarea{ width:100%; min-width:0; max-width:100%; }
  .field input[type=file]{ min-height:0; padding:10px; }
  .field input[type=checkbox]{ width:18px; height:18px; min-height:0; }
  .toolbar-left .search{ display:none; }
  .toolbar-left:has(> .search:only-child){ display:none; }
  body.sin-tabla .topbar-search{ display:none; }
  .bn-item{ align-self:stretch; }
  .modal-foot{ position:sticky; bottom:0; background:var(--surface); padding:12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn{ flex:1; justify-content:center; }

  /* Tarjetas del dashboard */
  .kpi-row{ grid-template-columns:1fr 1fr; gap:10px; }
  .kpi{ padding:13px 14px; }
  .kpi-value{ font-size:18px; }
  .card-head{ padding:14px 14px 0; }
  .card-pad{ padding:14px; }
  .aging-row{ grid-template-columns:90px 1fr 80px; gap:8px; }
}

/* Tablas convertidas en tarjetas (una por fila) en pantallas de teléfono */
@media (max-width:700px){
  .table-wrap{ overflow:visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td{ display:block; width:100%; }
  .table-wrap thead{ display:none; }
  .table-wrap tbody tr{ padding:12px 14px; border-bottom:1px solid var(--border); }
  .table-wrap tbody tr:last-child{ border-bottom:none; }
  .table-wrap tbody tr:hover{ background:transparent; }
  .table-wrap tbody td{
    display:flex; justify-content:space-between; align-items:center; gap:14px; padding:5px 0; border:none;
    white-space:normal; text-align:right; min-width:0; overflow-wrap:anywhere;
  }
  .table-wrap tbody td::before{
    content:attr(data-label); flex:none; color:var(--ink-muted); font-size:11px; font-weight:600;
    text-transform:uppercase; letter-spacing:.05em; text-align:left;
  }
  .table-wrap tbody td:first-child{ justify-content:flex-start; font-size:15px; padding-bottom:7px; text-align:left; }
  .table-wrap tbody td:first-child::before, .table-wrap tbody td[colspan]::before, .table-wrap tbody td.td-sin-etiqueta::before, .table-wrap tbody td.td-acciones::before{ display:none; }
  .table-wrap tbody td.td-acciones{ justify-content:flex-start; flex-wrap:wrap; gap:8px; padding-top:10px; }
  .table-wrap tbody td.td-acciones form{ display:inline-flex !important; }
  .table-wrap td.wrap{ min-width:0; }
  .table-wrap tbody td .company-tag{ white-space:nowrap; }
  .table-wrap tbody td.td-acciones .btn{ flex:1 1 auto; justify-content:center; border-color:var(--border-strong); }
}

/* ============ Alegra · ajustes móviles ============ */
@media (max-width:860px){
  .content{ padding:14px 14px calc(96px + env(safe-area-inset-bottom)); }
  .fab{ display:none; }
  .quick-back{ padding:0; align-items:flex-end; justify-content:center; }
  .quick-menu{ width:100%; border-radius:18px 18px 0 0; padding:10px 10px calc(14px + env(safe-area-inset-bottom)); }
  .quick-item{ padding:14px 12px; font-size:16px; }
  .topbar{ box-shadow:none; border-bottom:1px solid var(--border); }
  .dash-head h2{ font-size:19px; }
  .dash-actions{ width:100%; } .dash-actions .btn{ flex:1; justify-content:center; }
  .kpi-value{ font-size:17px; }
  .doc-title{ padding:14px 16px 0; }
  .doc-section .form-grid{ padding:12px 16px 16px; }
  .doc-body{ padding:12px 16px 16px; }
  .resumen{ padding:8px 16px 2px; } .doc-acciones{ padding:12px 16px 18px; }
  .config-grid{ grid-template-columns:1fr; }
  .perfil-grid{ grid-template-columns:1fr; }
  .login-card{ padding:24px 20px 20px; }
  .login-btn{ min-height:50px; }
  .file-drop{ padding:20px 12px; }
  /* Líneas de venta: cada línea es una tarjeta con la descripción arriba */
  .linea-head{ display:none; }
  .linea{ grid-template-columns:1fr 1fr; gap:8px; padding:12px; border:1px solid var(--border); border-radius:12px; background:var(--surface-2); position:relative; }
  .linea input:first-child{ grid-column:1/-1; padding-right:46px; }
  .linea select{ grid-column:1/2; }
  .linea .linea-importe{ grid-column:2/3; align-self:center; font-size:15px; }
  .linea .linea-quitar{ position:absolute; top:6px; right:6px; }
  .linea input, .linea select{ min-height:46px; font-size:16px; }
  .adj-list .btn{ margin-left:0; }
  .input-con-boton .btn{ min-height:46px; }
}

/* ============ Activos Fijos: foto y selección para etiquetas ============ */
.af-thumb{ width:44px; height:44px; border-radius:8px; object-fit:cover; border:1px solid var(--border); background:var(--surface-2); display:inline-flex; align-items:center; justify-content:center; color:var(--ink-muted); vertical-align:middle; }
.selEtq, #selTodos{ width:18px; height:18px; accent-color:var(--accent, #00B19D); cursor:pointer; }
@media (max-width:700px){
  .table-wrap tbody tr{ position:relative; }
  .table-wrap tbody td.td-sel{ position:absolute; top:12px; right:14px; width:auto; padding:0; }
  .table-wrap tbody td.td-sel::before, .table-wrap tbody td.td-foto::before{ display:none; }
  .table-wrap tbody td.td-foto{ justify-content:flex-start; padding-bottom:4px; }
  .af-thumb{ width:76px; height:76px; border-radius:12px; }
  .selEtq{ width:24px; height:24px; }
}

@media (max-width:700px){
  .table-wrap tbody td.td-activo{ display:block; text-align:left; padding-top:2px; }
  .table-wrap tbody td.td-activo::before{ display:none; }
  .table-wrap tbody td.td-activo b{ font-size:16px; }
  .table-wrap tbody td.td-foto:has(.af-thumb-vacia){ display:none; }
}

.af-tabla th, .af-tabla td{ padding-left:10px; padding-right:10px; }
.af-tabla .company-tag{ white-space:nowrap; display:inline-block; margin-bottom:2px; }
.af-acc{ display:flex; flex-wrap:wrap; gap:2px 4px; justify-content:flex-end; max-width:150px; margin-left:auto; }
.af-acc form{ display:inline; }
@media (max-width:700px){ .af-acc{ max-width:none; margin-left:0; justify-content:flex-start; } }
@media (max-width:700px){ .af-acc{ width:100%; gap:8px; } .af-acc .btn{ flex:1 1 auto; justify-content:center; border-color:var(--border-strong); } .af-acc form{ display:inline-flex; flex:1 1 auto; } .af-acc form .btn{ width:100%; } }
@media (min-width:701px){
  .af-acc{ max-width:118px; }
  .af-acc .btn{ padding:3px 9px; min-height:0; font-size:12px; line-height:1.5; }
  .af-tabla th:first-child, .af-tabla td:first-child{ padding-left:14px; padding-right:2px; width:30px; }
}

/* ============ Actualizaciones / Desarrollo / Tareas ============ */
.act-desc{ margin-top:4px; font-size:13.5px; line-height:1.5; color:var(--ink-secondary); max-width:78ch; }
.fila-hecha .tarea-titulo{ text-decoration:line-through; color:var(--ink-muted); }
.tarea-check{ width:20px; height:20px; accent-color:var(--accent, #00B19D); cursor:pointer; }
.tarea-rapida{ display:flex; gap:8px; margin:0 0 14px; }
.tarea-rapida input{ flex:1; min-width:0; font:inherit; font-size:16px; padding:12px 14px; border:1px solid var(--border-strong); border-radius:10px; background:var(--surface); color:var(--ink); }
.tarea-rapida .btn{ min-height:46px; }
.inline-estado{ font:inherit; font-size:12.5px; font-weight:700; padding:4px 8px; border-radius:8px; border:1px solid var(--border-strong); background:var(--surface); color:var(--ink); max-width:150px; }
@media (min-width:701px){ .fila-vencida td:first-child{ box-shadow: inset 3px 0 0 var(--crit, #D64545); } }
@media (max-width:700px){
  .tarea-check{ width:26px; height:26px; }
  .table-wrap tbody td.td-sel-tarea{ position:absolute; top:12px; right:14px; width:auto; padding:0; }
  .table-wrap tbody td.td-sel-tarea::before{ display:none; }
  .table-wrap tbody td.td-titulo{ display:block; text-align:left; padding-right:44px; }
  .table-wrap tbody td.td-titulo::before{ display:none; }
  .table-wrap tbody td.td-titulo b{ font-size:16px; }
  .inline-estado{ max-width:none; min-height:40px; font-size:15px; }
}

/* Hora de registro (AM/PM) debajo de la fecha */
.fecha-hora{ display:block; font-size:11.5px; color:var(--ink-muted); margin-top:2px; letter-spacing:.01em; }
@media (max-width:700px){ .fecha-celda .fecha-hora{ display:inline; margin-left:6px; } }

/* Móvil: las celdas de texto largo (descripciones, detalles) van con la etiqueta arriba y el texto a lo ancho */
@media (max-width:700px){
  .table-wrap tbody td.wrap{ display:block; text-align:left; }
  .table-wrap tbody td.wrap::before{ display:block; margin-bottom:3px; }
}

/* Fotos de los pagos */
.pago-fotos{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; max-width:128px; }
.btn-fotos{ display:inline-flex; align-items:center; gap:5px; }
.btn-fotos .ico{ width:16px; height:16px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.pago-fotos .btn{ flex:none; }
.pago-foto{ display:inline-flex; flex:none; width:38px; height:38px; border-radius:8px; overflow:hidden; border:1px solid var(--border-strong); background:var(--surface-2); }
.pago-foto img{ width:100%; height:100%; object-fit:cover; display:block; }
.pago-foto-doc{ display:flex; align-items:center; justify-content:center; width:100%; height:100%; font-size:11px; font-weight:700; color:var(--accent-strong); }
.pago-foto-doc.grande{ width:120px; height:120px; border:1px solid var(--border-strong); border-radius:10px; background:var(--surface-2); font-size:14px; }
.fotos-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(120px,1fr)); gap:12px; margin-bottom:14px; }
.foto-item{ margin:0; display:flex; flex-direction:column; align-items:center; gap:4px; }
.foto-item img{ width:120px; height:120px; object-fit:cover; border-radius:10px; border:1px solid var(--border-strong); display:block; }
.foto-item figcaption{ font-size:11.5px; color:var(--ink-muted); }
.adj-nombres{ font-size:12px; color:var(--ink-secondary); overflow-wrap:anywhere; }
@media (max-width:700px){ .table-wrap tbody td .pago-fotos{ justify-content:flex-end; max-width:none; } .pago-foto{ width:44px; height:44px; } }

@media (min-width:701px){ .tabla-compacta th, .tabla-compacta td{ padding-left:10px; padding-right:10px; } }

/* ---- Inicio: tarjetas con gráficos (tooltip, pantalla completa, descargar) ---- */
.kpi-row.kpi-5{ grid-template-columns:repeat(6,minmax(0,1fr)); }
.kpi-row.kpi-5 > .card{ grid-column:span 2; }
.kpi-row.kpi-5 > .card:nth-child(n+4){ grid-column:span 3; }
@media (max-width:980px){ .kpi-row.kpi-5{ grid-template-columns:repeat(2,minmax(0,1fr)); } .kpi-row.kpi-5 > .card, .kpi-row.kpi-5 > .card:nth-child(n+4){ grid-column:span 1; } .kpi-row.kpi-5 > .card:nth-child(3){ grid-column:1/-1; } }
.kpi-value.pos{ color:var(--good); } .kpi-value.neg{ color:var(--crit); }
.grid-2.eq{ grid-template-columns:repeat(2,minmax(0,1fr)); }
@media (max-width:980px){ .grid-2.eq{ grid-template-columns:minmax(0,1fr); } }
.chart-card .card-head{ align-items:flex-start; gap:10px; }
.chart-tools{ display:flex; gap:6px; flex:none; }
.chart-btn{ width:34px; height:34px; border-radius:10px; border:1px solid var(--border); background:var(--surface); color:var(--ink-secondary); display:flex; align-items:center; justify-content:center; cursor:pointer; }
.chart-btn:hover, .chart-btn.on{ background:var(--accent-soft); color:var(--accent-strong); border-color:transparent; }
.chart-btn svg{ width:16px; height:16px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.chart-card .legend{ padding-top:8px; }
.legend-dot.azul{ background:var(--chart-ganancias); }
.chart-wrap{ position:relative; padding:6px 10px 12px; }
.chart-svg{ display:block; max-width:100%; overflow:visible; touch-action:pan-y; }
.chart-wrap .dc-hit{ cursor:crosshair; }
.chart-empty{ padding:46px 20px; text-align:center; color:var(--ink-muted); font-size:13px; }
.chart-tip{ position:absolute; z-index:5; pointer-events:none; min-width:190px; padding:10px 12px; border-radius:12px; background:var(--surface); border:1px solid var(--border-strong); box-shadow:var(--shadow-md); font-size:12.5px; color:var(--ink); }
.chart-tip[hidden]{ display:none; }
.tip-title{ font-weight:800; margin-bottom:6px; font-size:12.5px; }
.tip-row{ display:flex; align-items:center; gap:8px; padding:2px 0; }
.tip-row i{ width:9px; height:9px; border-radius:3px; flex:none; }
.tip-row span{ color:var(--ink-secondary); flex:1; }
.tip-row b{ font-variant-numeric:tabular-nums; }
.tip-row b.neg{ color:var(--crit); }
body.chart-lock{ overflow:hidden; }
.chart-card.is-full{ position:fixed; inset:0; z-index:150; margin:0; border-radius:0; display:flex; flex-direction:column; background:var(--surface); }
.chart-card.is-full .card-head{ padding:18px 22px 0; }
.chart-card.is-full .card-head h3{ font-size:18px; }
.chart-card.is-full .legend{ padding:10px 22px 0; font-size:13.5px; }
.chart-card.is-full .chart-wrap{ flex:1; min-height:0; padding:10px 18px 18px; }
.chart-card.is-full .chart-svg{ position:absolute; left:18px; top:10px; }

/* ============ Proveedores: lista compacta con iconos ============ */
.sub-linea{ display:block; font-size:12px; font-weight:400; color:var(--ink-muted); margin-top:2px; overflow-wrap:anywhere; }
.sub-linea a{ color:inherit; text-decoration:none; }
.sub-linea a:hover{ color:var(--accent-strong); text-decoration:underline; }
div > .sub-linea:only-child{ margin-top:0; }
span.sub-linea{ display:inline; margin:0; }
.acciones-iconos{ display:inline-flex; align-items:center; gap:4px; white-space:nowrap; }
.acciones-iconos form{ margin:0; }
.btn-icono{
  width:34px; height:34px; padding:0; border-radius:9px; border:1px solid transparent; background:transparent;
  color:var(--ink-secondary); display:inline-flex; align-items:center; justify-content:center; cursor:pointer; flex:none;
}
.btn-icono svg{ width:17px; height:17px; fill:none; stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; }
.btn-icono:hover{ color:var(--accent-strong); background:var(--accent-soft); }
.btn-icono-borrar:hover{ color:var(--crit); background:var(--crit-soft, rgba(220,38,38,.1)); }
.btn-icono:focus-visible{ outline:2px solid var(--accent); outline-offset:1px; }
.tabla-proveedores th.th-acciones, .tabla-proveedores td.td-acciones-iconos{ width:84px; text-align:right; padding-right:12px; }
.tabla-proveedores td.wrap{ white-space:normal; min-width:160px; }
@media (min-width:701px){
  .tabla-proveedores th, .tabla-proveedores td{ padding-left:10px; padding-right:10px; }
}
@media (max-width:700px){
  .table-wrap tbody td.td-acciones-iconos{ justify-content:flex-start; padding-top:6px; }
  .table-wrap tbody td.td-acciones .btn-icono{ flex:0 0 auto; width:42px; height:42px; border-color:var(--border-strong); }
  .tabla-proveedores td.td-acciones-iconos{ width:100%; text-align:left; }
  .tabla-proveedores td.wrap .sub-linea{ text-align:left; }
}

.sub-bloque{ display:block; font-size:12px; font-weight:400; color:var(--ink-muted); margin-top:3px; }
.tabla-facturas td.wrap{ min-width:120px; }
.tabla-facturas td.td-acciones-iconos{ width:112px; }
@media (max-width:700px){ .tabla-facturas td.td-acciones-iconos{ width:100%; } .table-wrap tbody td .sub-bloque{ text-align:left; } }
@media (min-width:701px){ .tabla-facturas .btn-icono{ width:30px; height:30px; } .tabla-facturas td.td-acciones-iconos{ width:106px; padding-right:8px; } }

/* ============ Logo de la empresa en el menú ============ */
.brand.brand-con-logo{ flex-direction:column; align-items:flex-start; gap:4px; padding:16px 18px 12px; }
.brand-logo-box{ display:flex; align-items:center; width:100%; max-width:190px; height:48px; overflow:hidden; }
.brand-logo{ display:block; max-width:100%; max-height:48px; width:auto; height:auto; object-fit:contain; }
:root[data-theme="dark"] .brand-logo{ background:#fff; padding:4px 8px; border-radius:8px; }
@media (prefers-color-scheme: dark){ :root:not([data-theme="light"]) .brand-logo{ background:#fff; padding:4px 8px; border-radius:8px; } }
.company-logo-img{ width:56px; height:56px; max-width:56px; max-height:56px; border-radius:10px; object-fit:contain; background:#fff; border:1px solid var(--border); padding:3px; flex:none; }
.color-swatch{ display:inline-block; width:14px; height:14px; border-radius:50%; border:1px solid var(--border-strong); vertical-align:-2px; margin-right:6px; }
.color-fila{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.color-fila input[type=color]{ width:52px; height:40px; padding:2px; border:1px solid var(--border-strong); border-radius:8px; background:var(--surface); cursor:pointer; }
.color-presets{ display:flex; gap:6px; flex-wrap:wrap; }
.color-presets button{ width:28px; height:28px; border-radius:50%; border:2px solid var(--surface); box-shadow:0 0 0 1px var(--border-strong); cursor:pointer; padding:0; }
.color-presets button:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }

/* ============ Empleados ============ */
.checks-fila{ display:flex; gap:22px; flex-wrap:wrap; }
.check-linea{ display:inline-flex; align-items:center; gap:8px; font-weight:600; font-size:14px; cursor:pointer; }
.check-linea input{ width:18px; height:18px; accent-color:var(--accent, #00B19D); }
.tss-montos[hidden]{ display:none; }
.tabla-empleados td.wrap{ white-space:normal; min-width:110px; }
.tabla-empleados td.td-acciones-iconos{ width:112px; }
@media (min-width:701px){ .tabla-empleados .btn-icono{ width:30px; height:30px; } .tabla-empleados td.td-acciones-iconos{ width:106px; padding-right:8px; } }
@media (max-width:700px){ .tabla-empleados td.td-acciones-iconos{ width:100%; } .table-wrap tbody td .sub-bloque{ text-align:left; } }

/* ============ Lista con buscador (select[data-buscable]) ============ */
.combo{ position:relative; }
.combo-oculto{ position:absolute !important; opacity:0; pointer-events:none; width:1px; height:1px; overflow:hidden; }
.combo-caja{ position:relative; }
.combo-input{ width:100%; padding-right:62px; text-overflow:ellipsis; font-size:16px; }
.combo-flecha{ position:absolute; right:12px; top:50%; transform:translateY(-50%); width:18px; height:18px; color:var(--ink-muted); display:flex; pointer-events:auto; cursor:pointer; }
.combo-flecha svg{ width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.combo-x{ position:absolute; right:34px; top:50%; transform:translateY(-50%); width:24px; height:24px; border:none; border-radius:50%; background:transparent; color:var(--ink-muted); font-size:12px; cursor:pointer; padding:0; }
.combo-x:hover{ background:var(--surface-hover); color:var(--ink); }
.combo-lista{
  position:absolute; z-index:60; left:0; right:0; top:calc(100% + 4px); margin:0; padding:4px; list-style:none;
  max-height:min(300px, 46vh); overflow-y:auto; overscroll-behavior:contain;
  background:var(--surface); border:1px solid var(--border-strong); border-radius:12px; box-shadow:var(--shadow-md);
}
.combo-lista[hidden]{ display:none; }
.combo-op{ padding:10px 12px; border-radius:8px; cursor:pointer; font-size:14.5px; line-height:1.3; color:var(--ink); }
.combo-op.activo{ background:var(--accent-soft); color:var(--accent-strong); }
.combo-op.elegido{ font-weight:700; }
.combo-op.combo-off{ opacity:.45; cursor:default; }
.combo-vacio{ padding:12px; color:var(--ink-muted); font-size:13.5px; }
.tss-montos > .form-grid{ padding:0; }

/* ============ Ganancias y Pérdidas (Finanzas) ============ */
.gp-filtros{ display:flex; flex-wrap:wrap; align-items:flex-end; gap:12px 14px; padding:14px 18px; margin-bottom:10px; }
.gp-filtros .field{ display:flex; flex-direction:column; gap:5px; min-width:160px; }
.gp-filtros .field label{ font-size:12px; font-weight:700; color:var(--ink-secondary); }
.gp-filtros .field[hidden], .gp-filtros .btn[hidden]{ display:none; }
.gp-check{ display:inline-flex; align-items:center; gap:8px; font-size:13px; font-weight:600; color:var(--ink-secondary); min-height:40px; cursor:pointer; }
.gp-check input[type=checkbox]{ width:17px; height:17px; accent-color:var(--accent); }
.gp-csv{ margin-left:auto; display:inline-flex; align-items:center; gap:6px; text-decoration:none; }
.gp-csv svg{ width:15px; height:15px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.gp-contexto{ font-size:12.5px; color:var(--ink-muted); margin:0 2px 12px; }
.gp-contexto b{ color:var(--ink-secondary); }
.gp-tabs{ margin-bottom:14px; }
.gp-panel[hidden]{ display:none; }
.gp-pad{ padding:10px 20px 18px; }
.tip-note{ margin-top:6px; font-size:11.5px; color:var(--ink-muted); }
.tip-row b.neg{ color:var(--crit); }
.kpi-delta.up, .kpi-delta.down{ font-size:12px; }
.kpi-delta:not(.up):not(.down){ color:var(--ink-muted); font-weight:600; }

.gp-lista{ display:flex; flex-direction:column; gap:14px; }
.gp-item-top{ display:flex; justify-content:space-between; gap:12px; align-items:baseline; font-size:13.5px; }
.gp-item-nombre{ font-weight:700; min-width:0; overflow-wrap:anywhere; }
.gp-item-monto{ font-weight:700; white-space:nowrap; }
.gp-barra{ height:8px; border-radius:99px; background:var(--surface-2); overflow:hidden; margin-top:6px; }
.gp-barra i{ display:block; height:100%; border-radius:99px; min-width:2px; }
.gp-item-sub{ display:flex; justify-content:space-between; font-size:11.5px; color:var(--ink-muted); margin-top:4px; font-weight:600; }
.gp-item-sub .up{ color:var(--good); } .gp-item-sub .down{ color:var(--crit); }

.tabla-gp td, .tabla-gp th{ vertical-align:middle; }
.tabla-gp tr.gp-sec td{ background:var(--surface-2); font-size:11.5px; font-weight:800; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-secondary); padding-top:9px; padding-bottom:9px; }
.tabla-gp td.gp-ind{ padding-left:26px; }
.tabla-gp tr.gp-tot td{ font-weight:800; border-top:1px solid var(--border-strong); }
.tabla-gp tr.gp-res td{ font-weight:800; font-size:14.5px; border-top:2px solid var(--border-strong); }
.tabla-gp td.pos, .tabla-gp td.neg, .tabla-gp td .pos{ font-weight:800; }
.tabla-gp td.pos{ color:var(--good); } .tabla-gp td.neg{ color:var(--crit); }
.gp-doble{ min-width:150px; }
.gp-doble .gp-barra{ margin-top:4px; max-width:220px; }

.gp-insights{ display:flex; flex-direction:column; padding:8px 20px 14px; }
.gp-insight{ display:flex; gap:12px; padding:13px 0; border-bottom:1px solid var(--border); }
.gp-insight:last-child{ border-bottom:none; }
.gp-insight-dot{ width:10px; height:10px; border-radius:50%; margin-top:6px; flex:none; background:var(--ink-muted); }
.gp-insight.good .gp-insight-dot{ background:var(--good-dot); }
.gp-insight.warn .gp-insight-dot{ background:var(--warn-dot); }
.gp-insight.crit .gp-insight-dot{ background:var(--crit-dot); }
.gp-insight.info .gp-insight-dot{ background:var(--chart-ganancias); }
.gp-insight-titulo{ font-weight:700; font-size:14px; }
.gp-insight-texto{ font-size:13px; color:var(--ink-secondary); margin-top:2px; line-height:1.45; }
.gp-nota{ font-size:12px; color:var(--ink-muted); margin:4px 2px 24px; line-height:1.5; }

@media (max-width:860px){
  .gp-filtros{ padding:12px 14px; }
  .gp-filtros .field{ flex:1 1 100%; min-width:0; }
  .gp-filtros .field select, .gp-filtros .field input{ width:100%; }
  .gp-csv{ margin-left:0; flex:1 1 100%; justify-content:center; }
  .gp-pad{ padding:8px 14px 16px; }
  .gp-insights{ padding:4px 14px 10px; }
  .gp-doble{ min-width:0; width:100%; }
  .tabla-gp tr.gp-sec td{ justify-content:flex-start; }
  .tabla-gp td.gp-ind{ padding-left:0; }
}
.gp-panel .kpi-value{ font-size:21px; white-space:nowrap; }
@media (max-width:860px){ .gp-panel .kpi-value{ font-size:17px; } }
.tabla-gp td.wrap{ white-space:normal; min-width:0; }

/* ---- Módulos por empresa (Empresas) ---- */
.company-modulos{ display:flex; gap:6px; flex-wrap:wrap; margin:10px 0 12px; }
.modulos-fila{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.modulo-op{ display:flex; gap:10px; align-items:flex-start; padding:10px 12px; border:1px solid var(--border); border-radius:12px; background:var(--surface-2); cursor:pointer; margin:0; font-weight:400; }
.modulo-op input{ width:auto; margin-top:3px; flex:none; }
.modulo-op span{ display:flex; flex-direction:column; gap:2px; }
.modulo-op small{ color:var(--ink-secondary); font-size:12.5px; line-height:1.4; }
@media (max-width:700px){ .modulos-fila{ grid-template-columns:1fr; } }
