/* STRATOS ONE: papel contable y tintas del contador. Ver DESIGN.md. */

:root {
  --paper: #EDF1EB; --sheet: #FAFBF8; --ink: #1A2836; --ink-blue: #1E4F8F; --ink-red: #A8231B; --rule: #C5D3C6;
  --muted: #56657A; --ok: #25643F; --warn: #8A5A00;
  --blue-wash: #E3EBF5; --red-wash: #F7E3E1; --ok-wash: #E1EFE6; --warn-wash: #F6ECD6; --line: #D9E1DA;
  --rail: #E3E9E2; --focus: #1E4F8F;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --figures: "IBM Plex Sans Condensed", "IBM Plex Sans", "Arial Narrow", sans-serif;
  --r-sheet: 10px; --r-ctl: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1820; --sheet: #142029; --ink: #E1E8EE; --ink-blue: #8FB5EA; --ink-red: #F08A80; --rule: #283A44;
    --muted: #93A2B3; --ok: #7CCB9B; --warn: #E9BF63;
    --blue-wash: #1A2D43; --red-wash: #3A1F1F; --ok-wash: #16302A; --warn-wash: #33291A; --line: #22323C;
    --rail: #111D26; --focus: #8FB5EA;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
a { color: var(--ink-blue); }
code, .code { font-family: var(--figures); font-variant-numeric: tabular-nums; letter-spacing: .01em; }

/* ---------------------------------------------------------------- estructura: índice + hoja */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--rail); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column;
        gap: 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 600; font-size: 17px; letter-spacing: .01em; padding: 0 8px; }
.brand span { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); letter-spacing: 0; }
.client { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 10px 12px; }
.client-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.client-rut { font-family: var(--figures); font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); }
.client select { width: 100%; margin-top: 6px; }
.modules { display: flex; flex-direction: column; gap: 14px; }
.group-name { font-size: 12.5px; color: var(--muted); padding: 0 8px 4px; }
.mod { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; background: none; border: 0;
       border-radius: var(--r-ctl); padding: 6px 8px; cursor: pointer; color: var(--ink); text-decoration: none; font-size: 14.5px; }
.mod:hover { background: var(--sheet); }
.mod[aria-current=page] { background: var(--sheet); color: var(--ink-blue); font-weight: 600; box-shadow: inset 3px 0 0 var(--ink-blue); }
.mod .count { font-family: var(--figures); font-variant-numeric: tabular-nums; font-size: 12.5px; min-width: 22px; text-align: center;
              padding: 0 6px; border-radius: 999px; background: var(--warn-wash); color: var(--warn); font-weight: 600; }
.who { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; font-size: 13.5px; }
.who .role { color: var(--muted); }
.who select { width: 100%; margin-top: 6px; }
.menu-btn { display: none; }

.main { min-width: 0; padding: 26px 32px 72px; max-width: 1320px; }
.demo-note { background: var(--warn-wash); color: var(--warn); border-radius: var(--r-ctl); padding: 8px 12px; font-size: 13.5px; margin-bottom: 18px; }

/* encabezado de módulo */
.mod-head { display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
.mod-head h1 { font-size: 26px; line-height: 1.15; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.mod-head p { margin: 4px 0 0; color: var(--muted); max-width: 68ch; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* hojas */
.sheet { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-sheet); padding: 18px 20px; min-width: 0; }
.sheet + .sheet, .cols + .sheet, .sheet + .cols, .cols + .cols { margin-top: 18px; }
.sheet-h { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.sheet-h h2 { font-size: 17px; margin: 0; font-weight: 600; }
.sheet-h .meta { color: var(--muted); font-size: 13.5px; }
h3 { font-size: 15px; font-weight: 600; margin: 18px 0 8px; }
.cols { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols.wide-left { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.scroll { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.empty { color: var(--muted); padding: 12px 0; }
.lead { max-width: 70ch; }

/* ---------------------------------------------------------------- controles */
.btn { background: var(--ink-blue); color: var(--sheet); border: 1px solid var(--ink-blue); border-radius: var(--r-ctl);
       padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn.quiet { background: var(--sheet); color: var(--ink-blue); border-color: var(--rule); }
.btn.danger { background: var(--sheet); color: var(--ink-red); border-color: var(--ink-red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.06); }
.linkbtn { background: none; border: 0; color: var(--ink-blue); cursor: pointer; padding: 0; text-decoration: underline;
           text-underline-offset: 2px; }
select, input[type=date], input[type=text], input[type=email], input[type=password], input[type=number], input:not([type]) {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-ctl); padding: 6px 9px; min-height: 34px; }
input[type=file] { max-width: 100%; }
.field { display: grid; gap: 4px; font-size: 13.5px; color: var(--muted); }
.field > select, .field > input { color: var(--ink); font-size: 15px; }
.form-grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); align-items: end; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: 10px; }

/* estado: timbre */
.st { display: inline-block; font-size: 12.5px; font-weight: 600; line-height: 1.6; padding: 0 7px; border-radius: 4px;
      border: 1px solid currentColor; white-space: nowrap; vertical-align: 1px; }
.st.ok { color: var(--ok); background: var(--ok-wash); }
.st.bad { color: var(--ink-red); background: var(--red-wash); }
.st.warn { color: var(--warn); background: var(--warn-wash); }
.st.na { color: var(--muted); background: transparent; }
.checks { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; font-size: 13.5px; }
.checks li { display: flex; gap: 8px; align-items: baseline; }

/* ---------------------------------------------------------------- tablas */
table { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 13px; font-weight: 600; color: var(--muted); }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td, .tbl tr.sel td { background: var(--blue-wash); }
td.n, th.n { text-align: right; white-space: nowrap; font-family: var(--figures); font-variant-numeric: tabular-nums; }

/* La firma visual: hoja columnar. Cifras condensadas, rayado verde entre columnas de montos,
   negativos en tinta roja, raya simple sobre subtotales y doble raya bajo los totales. */
.libro { font-size: 14px; line-height: 1.35; }
.libro th, .libro td { padding: 6px 10px; text-align: left; vertical-align: top; }
.libro thead th { font-size: 12.5px; font-weight: 600; color: var(--muted); border-bottom: 1.5px solid var(--ink); vertical-align: bottom; }
.libro td.n, .libro th.n { border-left: 1px solid var(--rule); font-family: var(--figures); font-variant-numeric: tabular-nums;
                           text-align: right; white-space: nowrap; min-width: 92px; }
.libro tr.hd td { font-weight: 600; padding-top: 14px; }
.libro tr.sub td { font-weight: 600; border-top: 1px solid var(--ink); }
.libro tr.tot td { font-weight: 700; border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); }
.libro td.indent { padding-left: 24px; }
.neg { color: var(--ink-red); }
.code-col { font-family: var(--figures); font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; padding-right: 4px; }

/* ---------------------------------------------------------------- piezas de módulos */
.todo { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.todo a, .todo button { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: baseline; width: 100%;
  text-align: left; padding: 12px 10px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink);
  text-decoration: none; cursor: pointer; border-radius: 0; }
.todo a:hover, .todo button:hover { background: var(--blue-wash); }
.todo .k { font-family: var(--figures); font-variant-numeric: tabular-nums; font-size: 21px; font-weight: 600; text-align: right; }
.todo .k.zero { color: var(--muted); font-weight: 400; }
.todo .k .st { font-family: var(--font); font-size: 12.5px; }
.todo .go { color: var(--ink-blue); font-size: 13.5px; }
.todo .what b { display: block; font-weight: 600; }
.todo .what span { color: var(--muted); font-size: 13.5px; }
.quote { border-left: 3px solid var(--ink-blue); padding: 6px 12px; background: var(--blue-wash); border-radius: 0 var(--r-ctl) var(--r-ctl) 0; }
pre.text { white-space: pre-wrap; font: 14px/1.6 var(--font); background: var(--paper); padding: 12px 14px; border-radius: var(--r-ctl);
           max-height: 420px; overflow: auto; }
.gate { display: inline-block; margin: 0 6px 6px 0; padding: 3px 9px; border-radius: 4px; background: var(--warn-wash); color: var(--warn); font-size: 13px; }
.warn-list { margin: 8px 0; padding-left: 18px; color: var(--warn); font-size: 13.5px; }
.map-grid { display: grid; gap: 8px 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 10px 0; }
.stick { position: sticky; bottom: 0; z-index: 2; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-ctl);
         padding: 10px 14px; margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.recon td:first-child { color: var(--ink); }
.post-sel { margin-top: 6px; width: 100%; max-width: 320px; font-size: 13.5px; }
.tbl td:first-child input[type=checkbox] { margin-top: 3px; }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: 440px; padding: 11px 15px; border-radius: var(--r-ctl); display: none;
         z-index: 20; font-size: 14px; border: 1px solid currentColor; }
#toast.ok { display: block; background: var(--ok-wash); color: var(--ok); }
#toast.err { display: block; background: var(--red-wash); color: var(--ink-red); }

/* ---------------------------------------------------------------- acceso */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: min(440px, 100%); }
.auth .brand { padding: 0; margin-bottom: 18px; }
.auth h1 { font-size: 21px; margin: 0 0 6px; }
.auth label { display: block; font-size: 13.5px; color: var(--muted); margin: 12px 0 4px; }
.auth input { width: 100%; }
.auth .btn { width: 100%; margin-top: 16px; padding: 9px; }
.auth .err { color: var(--ink-red); font-size: 14px; margin-top: 10px; min-height: 1em; }
.auth .qr { background: #fff; padding: 10px; border-radius: var(--r-sheet); width: fit-content; margin: 12px auto; }
.auth .qr svg { display: block; width: 240px; max-width: 70vw; height: auto; aspect-ratio: 1; }
.methods { display: grid; gap: 10px; margin: 14px 0; }
.method { text-align: left; width: 100%; padding: 12px 14px; background: var(--sheet); border: 1.5px solid var(--rule);
          border-radius: var(--r-ctl); cursor: pointer; }
.method[aria-checked=true] { border-color: var(--ink-blue); background: var(--blue-wash); }
.method b { display: block; }
.method span { color: var(--muted); font-size: 13.5px; }
.steps { margin: 10px 0 0 18px; padding: 0; font-size: 14px; color: var(--muted); }
.steps li { margin: 4px 0; }
.secret { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.secret code { font-size: 15px; letter-spacing: .05em; padding: 4px 8px; background: var(--paper); border-radius: var(--r-ctl); }
.auth input.code { font-family: var(--figures); font-size: 24px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.note { background: var(--warn-wash); color: var(--warn); border-radius: var(--r-ctl); padding: 8px 12px; font-size: 14px; margin-bottom: 10px; }

/* ---------------------------------------------------------------- pantallas angostas */
@media (max-width: 980px) {
  .cols, .cols.wide-left { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
          padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail .brand span { display: none; }
  .rail .client { flex: 1 1 160px; padding: 6px 10px; }
  .menu-btn { display: inline-block; }
  .rail .modules, .rail .who { display: none; flex-basis: 100%; }
  .rail.open .modules, .rail.open .who { display: flex; }
  .rail.open .who { display: block; }
  .main { padding: 18px 16px 64px; }
  .mod-head h1 { font-size: 22px; }
  .sheet { padding: 14px; }
}
