:root {
  --navy: #17233d;
  --ink: #0e1e38;
  --teal: #58c9b9;
  --teal-dark: #0e7c72;
  --teal-bright: #58c9b9;
  --paper: #f4f7f9;
  --card: #ffffff;
  --line: #d7e0e6;
  --muted: #4a5568;
  --warn: #8a4b12;
  --warn-bg: #f6e7d4;
  --danger: #c23b4a;
  --danger-bg: #fdecee;
  --ok: #0e7c72;
  --error: #c23b4a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(23, 35, 61, 0.08);
  --side-w: 200px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--teal-dark); }
a:hover { color: var(--ink); }

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  background: var(--ink);
  color: #f6f3ec;
  padding: 0.7rem 1.25rem;
}

.marca, .marca-sola {
  color: #f6f3ec;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -0.03em;
}

.marca-sola { color: var(--ink); font-size: 1.1rem; margin: 0; }

.top nav { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; }
.top nav a { color: #d7deea; text-decoration: none; font-weight: 500; }
.top nav a[aria-current="page"] { color: var(--teal-bright); }
.salir { margin-left: auto; display: flex; gap: 0.6rem; align-items: center; }
.salir span { color: #c5cedd; font-size: 0.85rem; }
button, .boton {
  font: inherit;
  font-weight: 600;
  border: 0;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .boton:hover { background: var(--teal-dark); color: #fff; }
button.primario, .boton.primario { background: var(--navy); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
h1 { font-size: 1.55rem; letter-spacing: -0.03em; margin: 0.2rem 0 0.6rem; color: #4a6578; font-weight: 400; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 0.4rem; color: #4a6578; font-weight: 400; }

.nota, .aviso, .error, .flash {
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
}
.nota { background: var(--card); border: 1px solid var(--line); }
.nota p { margin: 0.3rem 0; }
.aviso { background: var(--warn-bg); color: var(--warn); }
.flash { background: #e9f8f5; border: 1px solid #b8e8e1; color: var(--ok); }
.error { border-color: #f3c4c9; background: var(--danger-bg); color: var(--error); }
.ayuda { color: var(--muted); font-size: 0.92rem; }
.muted { color: var(--muted); }
.miga { margin: 0; color: #4d5870; }
.cabeza, .acciones, .linea { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.cabeza { justify-content: space-between; align-items: baseline; }
.estado { margin: 0; color: #4d5870; }
.pill {
  display: inline-block;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.75rem;
  margin-right: 0.35rem;
}

table { width: 100%; border-collapse: collapse; background: var(--card); margin: 0.8rem 0 1rem; border-radius: var(--radius); box-shadow: var(--shadow); }
th, td { text-align: left; padding: 0.45rem 0.65rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 0.92rem; }
th { font-size: 0.78rem; letter-spacing: 0.03em; text-transform: uppercase; color: #4d5870; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; }
.sub { display: block; color: #4d5870; font-size: 0.78rem; }
.tabla-scroll { overflow-x: auto; max-width: 100%; }
.tabla-scroll table { min-width: 640px; }
.tabla-scroll input { width: 6.5rem; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; font-weight: 500; }
input, select, textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
}
.grilla { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem 1rem; align-items: start; }
.ancho { grid-column: 1 / -1; }
.grilla button, .linea button { justify-self: start; }
.login { max-width: 26rem; margin: 8vh auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.3rem; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.liquido { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.03em; }
.totales { font-variant-numeric: tabular-nums; }
pre { background: var(--ink); color: #f6f3ec; padding: 1rem; overflow: auto; border-radius: 12px; font-size: 0.82rem; }
details { margin-top: 1rem; }
.side details { margin-top: 0; }

.wordmark { display: block; line-height: 0; }
.wordmark img { display: block; height: 26px; width: auto; }
.wordmark .wm-dark { display: none; }
.side .wordmark .wm-light { display: none; }
.side .wordmark .wm-dark { display: block; }

body.staff-shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
  align-items: start;
}
html.nav-ready body.staff-shell { transition: grid-template-columns 0.22s ease; }
html.nav-collapsed body.staff-shell { grid-template-columns: 0 minmax(0, 1fr); }
html.nav-collapsed body.staff-shell > .side {
  width: 0;
  max-width: 0;
  min-width: 0;
  overflow: hidden;
  visibility: hidden;
}
.side {
  background: var(--navy);
  color: #fff;
  min-height: 100vh;
  width: var(--side-w);
  max-width: var(--side-w);
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 2;
}
html.nav-ready .side { transition: width 0.22s ease, max-width 0.22s ease; }
.side .brand {
  display: flex;
  align-items: center;
  color: #fff;
  text-decoration: none;
  padding: 1rem 0.85rem 0.8rem;
}
.side nav { padding: 0 0.35rem 1rem; flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.side-link {
  display: block;
  padding: 0.28rem 0.4rem;
  border-radius: 6px;
  color: rgba(255,255,255,0.78);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.3;
}
.side-link:hover { color: #fff; background: rgba(255,255,255,0.06); }
.side-link.on { background: rgba(88, 201, 185, 0.18); color: var(--teal); }
.side-fold { margin: 0.15rem 0 0.35rem; }
.side-fold summary {
  list-style: none;
  cursor: pointer;
  padding: 0.34rem 0.4rem;
  border-radius: 6px;
  color: rgba(255,255,255,0.92);
  font-size: 0.78rem;
  font-weight: 600;
}
.side nav .side-fold > summary {
  color: var(--teal);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.side-fold summary::-webkit-details-marker { display: none; }
.side-fold summary::marker { content: ""; }
.side-fold summary::after {
  content: "";
  float: right;
  margin-top: 0.45rem;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 4px 0 4px;
  border-color: rgba(255,255,255,0.55) transparent transparent transparent;
}
.side nav .side-fold > summary::after {
  border-color: var(--teal) transparent transparent transparent;
}
.side nav .side-fold[open] > summary::after,
.side-fold[open] summary::after {
  margin-top: 0.2rem;
  border-width: 0 4px 5px 4px;
  border-color: transparent transparent var(--teal) transparent;
}
.side-fold summary:hover { background: rgba(255,255,255,0.06); }
.side nav .side-fold > summary:hover { background: rgba(22, 184, 166, 0.14); color: #7ee8db; }
.side-fold .side-link { margin-left: 0.2rem; font-size: 0.76rem; }
.side-user {
  flex: 0 0 auto;
  border-top: 2px solid var(--teal);
  padding: 0.4rem 0.35rem 0.65rem;
  background: var(--navy);
}
.side-user .side-fold > summary {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  position: relative;
  padding: 0.4rem 1.15rem 0.4rem 0.45rem;
  color: #fff;
  font-weight: 700;
}
.side-user .side-user-name {
  display: block;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.side-user .side-fold > summary::after {
  float: none;
  position: absolute;
  right: 0.4rem;
  top: 0.72rem;
  margin-top: 0;
  border-color: #fff transparent transparent transparent;
}
.side-user .side-fold[open] > summary::after {
  top: 0.85rem;
  margin-top: 0;
  border-width: 0 4px 5px 4px;
  border-color: transparent transparent #fff transparent;
}
.side-user .side-fold summary:hover { background: rgba(255, 255, 255, 0.08); }
.side-user .side-link { color: rgba(255, 255, 255, 0.9); }
.role-chip {
  display: inline-block;
  margin: 0;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(88, 201, 185, 0.28);
  color: #fff;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  line-height: 1.3;
}
.side-logout {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  border: 0;
  border-radius: 6px;
  padding: 0.32rem 0.5rem;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
}
.side-logout:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1.1rem;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}
.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  margin: 0;
  color: #fff;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 6px;
  padding: 0;
}
.menu-btn svg { display: block; }
.buscar { flex: 1 1 auto; margin: 0; }
.buscar input {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: #fff;
  border-color: rgba(255,255,255,0.18);
}
.buscar input::placeholder { color: rgba(255,255,255,0.55); }
body.staff-shell main { margin: 0; max-width: 1100px; }
.resultados form { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: 0.7rem 1rem; align-items: flex-end; margin: 0.6rem 0 1rem; }
.filters label { margin: 0; min-width: 0; }
.filters input:not([type="checkbox"]):not([type="radio"]),
.filters select { width: auto; min-width: 8rem; max-width: 18rem; }
.filters .ancho { flex: 1 1 100%; }
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.25rem 0.85rem;
  margin: 0.5rem 0 1rem;
  max-height: 14rem;
  overflow: auto;
  padding: 0.5rem 0.65rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.pick-grid label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
}
.pick-grid input { width: auto; min-width: 0; }
.user-actions { white-space: nowrap; }
.user-actions > button,
.user-actions form.inline { vertical-align: middle; }
.user-actions > button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.user-actions form.inline { display: inline-flex; margin: 0 0 0 0.35rem; }
tr.user-edit td { background: #fbfcfd; }
.user-edit-panel { display: flex; flex-direction: column; gap: 0.85rem; }
.user-edit-panel form.inline { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: flex-end; }
.user-edit-panel form.inline label { margin: 0; }
details.disclose { margin: 0.2rem 0 1rem; }
details.disclose > summary {
  display: inline-block;
  width: auto;
  list-style: none;
  background: var(--navy);
  color: #fff;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary::marker { content: ""; }
details.disclose > summary:hover { background: var(--teal-dark); }
details.disclose[open] > summary { margin-bottom: 0.85rem; }
details.disclose:not([open]) > .disclose-body { display: none; }
.resultados { list-style: none; padding: 0; }
.resultados li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
fieldset { border: 1px solid var(--line); border-radius: 12px; }
legend { font-size: 0.82rem; padding: 0 0.3rem; }
body.solo-lectura form[method="post"]:not(.salir) button,
body.solo-lectura form[method="post"]:not(.salir) input[type="submit"] { display: none; }
textarea { width: 100%; }

@media (max-width: 800px) {
  .grilla, .dos { grid-template-columns: 1fr; }
  .salir { margin-left: 0; width: 100%; }
  .top { padding: 0.7rem; }
  main { padding: 1rem 0.7rem 2rem; }
  h1 { font-size: 1.3rem; }
}

@media (max-width: 960px) {
  body.staff-shell,
  html.nav-collapsed body.staff-shell { grid-template-columns: 1fr; }
  html.nav-ready body.staff-shell > .side,
  body.staff-shell > .side,
  html.nav-collapsed body.staff-shell > .side {
    display: flex;
    position: fixed;
    z-index: 20;
    width: var(--side-w);
    max-width: var(--side-w);
    min-width: 0;
    visibility: visible;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    top: 3.25rem;
    height: calc(100vh - 3.25rem);
    min-height: 0;
    max-height: none;
  }
  html.nav-open body.staff-shell > .side { transform: none; }
  .topbar { z-index: 30; }
  html.nav-collapsed .side nav,
  html.nav-collapsed .side .side-user { display: block; }
}

.menu-btn:hover { background: transparent; color: var(--teal); border-color: var(--teal); }

body.login-page { background: var(--card); }
body.login-page main { max-width: none; margin: 0; padding: 0; }
.login-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}
.login-form {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 4rem;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}
.login-form .brand { display: flex; align-items: center; text-decoration: none; margin-bottom: 2.2rem; }
.login-form .wordmark img { height: 42px; }
.login-form h1 { font-size: 1.8rem; margin: 0 0 0.35rem; color: var(--ink); font-weight: 600; }
.login-form .lead { margin: 0 0 0.4rem; color: var(--muted); }
.login-form .ayuda { margin: 0 0 1.2rem; }
.login-form label { margin: 0.8rem 0 0.25rem; }
.login-form input { width: 100%; max-width: none; }
.login-form button { width: 100%; padding: 0.7rem 1rem; margin-top: 0.8rem; }
.login-panel { position: relative; background: var(--navy); overflow: hidden; }
.login-panel::before,
.login-panel::after { content: ""; position: absolute; pointer-events: none; }
.login-panel::before {
  width: 140%;
  height: 90%;
  right: -35%;
  top: -10%;
  background: linear-gradient(160deg, rgba(88, 201, 185, 0.62) 0%, rgba(88, 201, 185, 0.22) 48%, transparent 62%);
  clip-path: polygon(28% 0, 100% 0, 100% 100%, 0 72%);
}
.login-panel::after {
  width: 48%;
  aspect-ratio: 1;
  right: 8%;
  bottom: 16%;
  background: rgba(255, 255, 255, 0.08);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
.login-copy {
  position: absolute;
  z-index: 1;
  left: 2.6rem;
  right: 2.6rem;
  bottom: 2.8rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.7rem;
  max-width: 24rem;
}
.login-panel .motto {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin: 0;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  line-height: 1.5;
}
.login-panel .motto span + span::before {
  content: "·";
  margin: 0 0.95rem;
  letter-spacing: 0;
  color: #fff;
}
.login-panel .caption {
  margin: 0;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 500;
  line-height: 1.5;
  max-width: 17rem;
}
@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-panel { min-height: 300px; }
  .login-form { padding: 2rem 1.4rem; }
  .login-copy { left: 1.4rem; right: 1.4rem; bottom: 1.6rem; gap: 1.05rem; }
  .login-panel .caption { font-size: 1.05rem; }
}

.sumi { position: fixed; right: 0.85rem; bottom: 0.85rem; z-index: 40; }
.sumi.placed { right: auto; bottom: auto; }
.sumi-open, .sumi-open:hover {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  background: transparent;
  color: var(--navy);
  border: 0;
  border-radius: 0;
  padding: 0;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.sumi.dragging .sumi-open { cursor: grabbing; }
.sumi-open:focus-visible { outline: 2px solid var(--teal-dark); outline-offset: 3px; border-radius: 12px; }
.sumi-open img {
  display: block;
  width: 5.6rem;
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(23, 35, 61, 0.22));
}
.sumi-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.45rem);
  width: min(28rem, 92vw);
  padding: 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.sumi.panel-below .sumi-panel { top: calc(100% + 0.45rem); bottom: auto; }
.sumi.panel-left .sumi-panel { left: 0; right: auto; }
.sumi-head { display: flex; align-items: center; gap: 0.75rem; }
.sumi-head img { width: 4.4rem; height: auto; flex: none; }
.sumi-panel[hidden] { display: none; }
.sumi-panel button { margin-top: 0.6rem; }
.sumi-title { margin: 0 0 0.2rem; color: var(--navy); font-weight: 600; }
.sumi-head .muted { margin: 0; }
.sumi-log { max-height: 22rem; overflow: auto; margin: 0.6rem 0; }
.sumi-log p { margin: 0.35rem 0; }
.sumi-log .sumi-go { display: block; width: fit-content; margin: 0.45rem 0 0.15rem; }
.sumi-panel textarea { width: 100%; max-width: none; }

@media print {
  .sumi, .side, .topbar, .menu-btn { display: none !important; }
  body.staff-shell { display: block; }
  main { max-width: none; }
  main::before {
    content: "Sumify  |  REM";
    display: block;
    margin: 0 0 0.8rem;
    color: #0e1e38;
    font-weight: 700;
    letter-spacing: -0.03em;
  }
}
