/* Popular Express — Sistema de Casilleros */
:root {
  --navy: #0d2d6e;
  --navy-2: #081e4e;
  --navy-soft: #e8edf8;
  --red: #cc1f2d;
  --red-2: #a81825;
  --red-soft: #fdecee;
  --green: #12805c;
  --green-soft: #e6f5ef;
  --amber: #a15c00;
  --amber-soft: #fff4e0;
  --gray-soft: #eef0f4;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --line: #e2e6ef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Montserrat', var(--font);
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy); }
h1, h2, h3 { font-family: var(--font-head); color: var(--navy); margin: 0; }
h1 { font-size: 22px; font-weight: 800; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 13px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1; }
.red { color: var(--red); }
.green { color: var(--green); }

/* ---------------------------------------------------------------- layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand img { width: 100%; max-width: 170px; filter: brightness(0) invert(1); display: block; }
.brand small { display: block; margin-top: 6px; color: rgba(255,255,255,.55); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,.78);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--red); }
.nav .sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 6px; }
.userbox {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: rgba(255,255,255,.7);
}
.userbox b { color: #fff; display: block; font-size: 13px; }
.userbox button { margin-top: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 24px 28px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow { min-width: 0; }
.page-head p { margin: 4px 0 0; }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card > h2, .card > h3 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 16px 18px; margin: 0; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat .value { font-family: var(--font-head); font-size: 24px; font-weight: 800; color: var(--navy); margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent .value { color: var(--red); }

/* ----------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: #344054; }
.field .hint { font-size: 11px; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid #cfd5e1;
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(13,45,110,.12); }
input:disabled, select:disabled { background: var(--gray-soft); color: var(--muted); }
input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(204,31,45,.12); }
input[type=checkbox] { width: 18px; height: 18px; padding: 0; accent-color: var(--navy); cursor: pointer; flex-shrink: 0; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
.input-big { font-size: 20px; font-weight: 600; padding: 12px 14px; letter-spacing: .5px; }
.join { display: flex; }
.join > *:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.join > *:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }

/* --------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  cursor: pointer;
  background: var(--navy);
  color: #fff;
  white-space: nowrap;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  line-height: 1.2;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.red { background: var(--red); }
.btn.red:hover { background: var(--red-2); }
.btn.green { background: var(--green); }
.btn.green:hover { background: #0d6649; }
.btn.ghost { background: #fff; color: var(--navy); border-color: #cfd5e1; }
.btn.ghost:hover { background: var(--navy-soft); }
.btn.ghost.danger { color: var(--red); }
.btn.ghost.danger:hover { background: var(--red-soft); }
.btn.light { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); }
.btn.light:hover { background: rgba(255,255,255,.18); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.btn.wa { background: #1f9d55; }
.btn.wa:hover { background: #17834a; }
.icon-btn { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--gray-soft); color: var(--red); }
.icon-btn svg { width: 16px; height: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: #f8f9fc; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.done td { color: var(--muted); }
tr.done td.mono { text-decoration: line-through; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--gray-soft); color: #475467;
}
.badge.pendiente { background: var(--amber-soft); color: var(--amber); }
.badge.pagada { background: var(--green-soft); color: var(--green); }
.badge.anulada { background: var(--red-soft); color: var(--red); }
.badge.navy { background: var(--navy-soft); color: var(--navy); }
.badge.odoo { background: #f3e8ff; color: #6b21a8; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

/* --------------------------------------------------------- client card */
.client {
  display: flex; gap: 14px; align-items: center;
  background: var(--navy-soft); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0;
}
.client .avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; font-family: var(--font-head); font-weight: 800; flex-shrink: 0;
}
.client .info { flex: 1; min-width: 0; }
.client .info b { font-size: 16px; color: var(--navy); display: block; }
.client .info span { color: var(--muted); font-size: 12px; margin-right: 10px; }
.code { font-family: var(--font-head); font-weight: 800; color: var(--red); letter-spacing: .5px; }
.total-box {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--navy); color: #fff; border-radius: var(--radius); margin-top: 12px;
}
.total-box b { font-family: var(--font-head); font-size: 26px; }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 10px 0; border: 1px solid; }
.alert.warn { background: var(--amber-soft); color: var(--amber); border-color: #f5d9a8; }
.alert.err { background: var(--red-soft); color: var(--red); border-color: #f4c2c7; }
.alert.ok { background: var(--green-soft); color: var(--green); border-color: #b8e2d2; }
.alert.info { background: var(--navy-soft); color: var(--navy); border-color: #c9d4ee; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12px; }
dl.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 90px 1fr 90px; gap: 10px; align-items: center; font-size: 12px; }
.bar .track { background: var(--gray-soft); border-radius: 4px; height: 10px; overflow: hidden; }
.bar .fill { background: var(--navy); height: 100%; border-radius: 4px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 12px; }
.timeline li:last-child { border-bottom: none; }
.address { background: var(--bg); border-radius: 8px; padding: 12px 14px; font-family: var(--mono); font-size: 13px; line-height: 1.7; }

/* ---------------------------------------------------------------- modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(8, 30, 78, .45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto;
  animation: fade .12s ease;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 480px; padding: 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); position: relative;
}
.modal.wide { max-width: 860px; }
.modal h2 { margin-bottom: 14px; padding-right: 30px; }
.modal .close { position: absolute; top: 14px; right: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------------------------------------------------------------- toast */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  font-size: 13px; max-width: 380px; animation: slide .18s ease;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------ auth pages */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(ellipse at 70% 30%, rgba(204,31,45,.25), transparent 60%), var(--navy);
}
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth img { width: 190px; display: block; margin: 0 auto 18px; }
.auth h1 { text-align: center; font-size: 19px; margin-bottom: 4px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.auth .btn { width: 100%; margin-top: 6px; }
.loading-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--navy); gap: 10px; }

/* ----------------------------------------------------------- responsive */
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 90; transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.menu-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.menu-open .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }
  .topbar {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 50;
  }
  .topbar img { height: 26px; filter: brightness(0) invert(1); }
  .topbar button { background: none; border: none; color: #fff; padding: 4px; cursor: pointer; display: flex; }
  .topbar svg { width: 24px; height: 24px; }
  .content { padding: 16px 16px 60px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 19px; }
  .stat .value { font-size: 20px; }
  .table-wrap { margin: 0 -18px; }
  .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .card { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .bar { grid-template-columns: 70px 1fr 70px; }
}

/* ---------------------------------------------------------------- print */
@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; padding: 0; }
}
