:root {
  --bg: #f3eee4;
  --bg-2: #ebe4d6;
  --surface: #fffcf7;
  --ink: #1a1714;
  --ink-soft: #5c564e;
  --line: #e4dcd0;
  --brand: #e25b1a;
  --brand-dark: #b84410;
  --forest: #1f4d3a;
  --forest-2: #2d6a4f;
  --gold: #c9a227;
  --danger: #b42318;
  --ok: #1b7a4a;
  --warn: #b45309;
  --sidebar: #0b1220;
  --sidebar-2: #152033;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 12px 40px rgba(26, 23, 20, .08);
  --shadow-sm: 0 2px 8px rgba(26, 23, 20, .05);
  --font: "Manrope", system-ui, sans-serif;
  --nav: 280px;
  --top: 64px;
  --content-pad: clamp(14px, 2vw, 28px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; width: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 750; letter-spacing: -.02em; margin: 0; }
p { margin: 0; }

.app { display: flex; min-height: 100vh; width: 100%; }
.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; width: 100%; }

.sidebar {
  width: var(--nav);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar) 0%, #121a2c 100%);
  color: #f6efe4;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  padding: 6px 8px 18px;
}
.brand-logo {
  width: 100%;
  max-width: 168px;
  display: block;
  background: transparent;
}
.brand-copy { display: none; }
.brand strong { display: block; font-size: 1.15rem; }
.brand small { color: #cbbfae; font-size: .75rem; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--brand); color: #fff;
  box-shadow: 0 8px 20px rgba(226,91,26,.35);
}
.brand-mark.lg { width: 56px; height: 56px; border-radius: 18px; }
.brand-logo-lg {
  width: min(280px, 100%);
  display: block;
  background: transparent;
}
.nav-label {
  font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: #9c9082; padding: 8px 12px 6px; margin: 8px 0 0;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px; text-decoration: none;
  color: #d9cfc2; font-weight: 600;
}
.side-nav a:hover, .side-nav a.is-active {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.side-nav a.is-active { background: var(--brand); }
.side-user {
  display: flex; gap: 10px; align-items: center;
  padding: 12px; border-radius: 14px; background: var(--sidebar-2);
}
.side-user strong { display: block; font-size: .9rem; }
.side-user small { color: #b7aa9a; }

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: #3d342c; color: #f3e6d4; font-weight: 700; font-size: .8rem;
  flex-shrink: 0;
}
.avatar.sm { width: 32px; height: 32px; font-size: .72rem; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.2rem; background: var(--brand); color: #fff; }

.topbar {
  height: auto;
  min-height: 76px;
  display: flex; align-items: center; gap: 12px;
  padding: 16px var(--content-pad);
  background: rgba(243,238,228,.92);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--line);
  width: 100%;
}
.top-search { flex: 1; min-width: 0; padding: 4px 0; }
.top-search form {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 12px 16px; width: 100%; max-width: 640px; color: var(--ink-soft);
  min-height: 48px;
}
.top-search input { border: 0; outline: 0; background: transparent; width: 100%; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; font-weight: 650; padding: 4px 8px;
}

.icon-btn {
  width: 40px; height: 40px; border: 0; background: transparent;
  border-radius: 12px; cursor: pointer; position: relative;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--bg-2); }
.badge-dot {
  position: absolute; top: 4px; right: 4px;
  background: var(--brand); color: #fff; font-size: .65rem; font-weight: 800;
  min-width: 16px; height: 16px; border-radius: 99px; padding: 0 4px;
  display: grid; place-items: center;
}

.main {
  padding: 24px var(--content-pad) 96px;
  width: 100%;
  max-width: none;
  flex: 1;
}

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; margin: 12px 0 22px; flex-wrap: wrap;
}
.page-head h1 { font-size: clamp(1.6rem, 2.4vw, 2.1rem); }
.eyebrow { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-dark); }
.lede { color: var(--ink-soft); margin-top: 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; border-radius: 12px; padding: 11px 16px;
  border: 1px solid transparent; font-weight: 700; text-decoration: none;
  cursor: pointer; background: var(--surface);
}
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 8px 18px rgba(226,91,26,.25); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: .82rem; border-radius: 10px; }
.btn-sm.danger { color: var(--danger); border-color: #f0d0cc; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }
.link, .link-btn, .link-danger {
  background: none; border: 0; cursor: pointer; font-weight: 700; text-decoration: none; padding: 0;
}
.link, .link-btn { color: var(--forest); }
.link-danger { color: var(--danger); }

.kpi-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 18px;
}
.kpi-grid.compact { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow-sm);
  border: 1px solid rgba(255,255,255,.7);
}
.kpi span { color: var(--ink-soft); font-size: .82rem; font-weight: 650; }
.kpi strong { display: block; font-size: 1.45rem; margin: 8px 0 4px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--ink-soft); }
.kpi.accent { background: linear-gradient(160deg, #1f4d3a, #163828); color: #f6efe4; }
.kpi.accent span, .kpi.accent small { color: #c9e6d6; }

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.card-head h2, .card h3 { font-size: 1.05rem; }
.grid-2 { display: grid; grid-template-columns: 1.1fr .9fr; gap: 16px; }
.grid-2.tight { grid-template-columns: 1fr 1fr; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td small { display: block; margin-top: 4px; }
.table tr:hover td { background: #faf6ef; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.mono { font-weight: 800; letter-spacing: .02em; text-decoration: none; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.totals-row td { background: #f7f1e6; font-weight: 800; }

.pill, .status {
  display: inline-flex; align-items: center; padding: 4px 10px;
  border-radius: 99px; font-size: .78rem; font-weight: 700;
  background: var(--bg-2); white-space: nowrap;
}
.status.activo { background: #e4f4ea; color: var(--ok); }
.status.cerrado { background: #ece7dc; color: #5c564e; }
.status.cancelado { background: #fde8e6; color: var(--danger); }
.pill.ok { background: #e4f4ea; color: var(--ok); }
.pill.warn { background: #fff1d6; color: var(--warn); }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; align-items: end; }
.filters.card { margin-top: 8px; margin-bottom: 22px; padding: 20px; }
.filters .grow { grid-column: 1 / -1; }
.filter-actions { display: flex; gap: 8px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 650; }
label span { color: var(--ink-soft); }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
  background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(226,91,26,.15); }
.has-error input, .has-error select { border-color: var(--danger); }
label em { color: var(--danger); font-style: normal; font-size: .78rem; font-weight: 650; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide, .inline-form .wide { grid-column: 1 / -1; }
.form-grid .wide h3 + .lede { margin-top: 8px; }
.form-actions { display: flex; gap: 8px; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 650; }
.check input { width: auto; }

.balance-hero {
  display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap;
  background: linear-gradient(135deg, #1a1714, #3a2c24 55%, #e25b1a);
  color: #fff; border-radius: 24px; padding: 28px; margin-bottom: 16px;
}
.balance-hero span { opacity: .8; font-weight: 650; }
.balance-hero strong { display: block; font-size: clamp(2rem, 4vw, 3rem); margin: 6px 0; font-variant-numeric: tabular-nums; }
.balance-hero ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; min-width: 200px; }
.balance-hero li { display: flex; justify-content: space-between; gap: 24px; background: rgba(255,255,255,.08); padding: 10px 12px; border-radius: 12px; }
.meta-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.ledger { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ledger li {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.ledger strong { display: block; }
.ledger small { color: var(--ink-soft); }
.ledger-side { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.icon-link { font-size: .8rem; font-weight: 700; color: var(--forest); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed button, .notify-item {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  display: flex; gap: 10px; padding: 10px 0; font: inherit;
}
.feed small, .notify-item small { display: block; color: var(--ink-soft); font-weight: 500; }
.unread, .is-unread { background: #fff6eb; margin: 0 -12px; padding-left: 12px; padding-right: 12px; border-radius: 10px; }
.n-type { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; background: var(--gold); flex-shrink: 0; }
.n-type.facturacion { background: var(--brand); }
.n-type.cobro { background: var(--forest-2); }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bar-meta { display: flex; justify-content: space-between; font-size: .86rem; margin-bottom: 4px; }
.bar { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--gold)); border-radius: 99px; }

.alert-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.mini-stat { padding: 14px; border-radius: 14px; background: var(--bg); }
.mini-stat strong { display: block; font-size: 1.4rem; }
.mini-stat.warn { background: #fff1d6; }
.mini-stat.info { background: #e7f3ec; }

.empty {
  display: grid; justify-items: center; gap: 14px;
  text-align: center; padding: 48px 28px; color: var(--ink-soft);
}
.empty h3 { margin: 0; color: var(--ink); }
.empty p { margin: 0; max-width: 440px; line-height: 1.55; }

.dropdown { position: relative; }
.dropdown-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  width: min(360px, 86vw); background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow); padding: 12px; z-index: 50; border: 1px solid var(--line);
}
.dropdown.open .dropdown-panel { display: block; }
.panel-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.empty-mini { color: var(--ink-soft); padding: 12px; }

.modal {
  position: fixed; inset: 0; background: rgba(26,23,20,.45);
  display: none; place-items: end center; z-index: 80; padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal:not([hidden]) { display: grid; }
.modal-card {
  background: var(--surface); width: min(480px, 100%);
  border-radius: 20px 20px 16px 16px; padding: 18px;
  box-shadow: var(--shadow); max-height: 90vh; overflow: auto;
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-card form { display: grid; gap: 12px; }

.toasts { position: fixed; top: 76px; right: 16px; z-index: 90; display: grid; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow); min-width: 240px; animation: in .25s ease;
}
.toast.is-success { background: var(--forest); }
.toast.is-error { background: var(--danger); }
@keyframes in { from { transform: translateY(-8px); opacity: 0; } }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; padding-top: 14px; }
.pager a { font-weight: 700; }

.user-cell { display: flex; gap: 10px; align-items: center; }
.user-cell small { display: block; color: var(--ink-soft); }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.profile-hero { display: flex; gap: 16px; align-items: center; }
.danger-zone { margin: 8px 0 40px; }
.module-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.module-switch.is-on { border: 1px solid #cfe8d8; }
.switch-form { display: grid; gap: 10px; }
.inline-form { display: grid; gap: 10px; }
.inline-form .btn { width: fit-content; }
.hint { color: var(--ink-soft); font-weight: 500; }
.form-section {
  margin: 8px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: .95rem;
  color: var(--brand-dark);
}
.detail-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  margin: 0;
}
.detail-list.cols-3 { grid-template-columns: repeat(3, 1fr); }
.detail-list dt {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  font-weight: 700;
}
.detail-list dd { margin: 2px 0 0; font-weight: 650; }
.notes-block {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg);
  border-radius: 12px;
  color: var(--ink-soft);
}
.alert-card { border: 1px solid #f3d7a5; }
.ficha-hero b.ok { color: #9be7c0; }
.ficha-hero b.warn { color: #ffd27a; }
.ficha-hero b.vencido { color: #ffb4a8; }

.bottom-nav { display: none; }
.menu-btn { display: none; }
.sidebar-backdrop { display: none; }

.auth-body { min-height: 100vh; width: 100%; }
.auth-wrap { display: grid; grid-template-columns: 1.15fr .85fr; min-height: 100vh; width: 100%; }
.auth-visual {
  background: linear-gradient(160deg, #0b1220 0%, #152033 48%, #e25b1a 140%);
  color: #f7efe4; padding: clamp(28px, 4vw, 56px); display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.visual-inner { max-width: 640px; width: 100%; }
.brand-lg { display: flex; gap: 14px; align-items: center; margin-bottom: 36px; }
.brand-lg span { color: #d9cfc2; display: block; font-size: .9rem; }
.auth-visual h1 { font-size: clamp(2rem, 4vw, 3.1rem); line-height: 1.1; margin-bottom: 14px; }
.auth-visual p { color: #e6d8c7; font-size: 1.05rem; }
.visual-points { margin: 28px 0 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.visual-points li { padding-left: 22px; position: relative; font-weight: 650; }
.visual-points li::before { content: ""; position: absolute; left: 0; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); }
.road {
  height: 90px; margin-top: 40px; border-radius: 20px;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.12) 0 40px, transparent 40px 70px);
  opacity: .5;
}
.auth-card-wrap { display: grid; place-items: center; padding: clamp(24px, 4vw, 40px); width: 100%; }
.auth-card { width: min(440px, 100%); background: var(--surface); padding: 32px; border-radius: 24px; box-shadow: var(--shadow); }
.auth-card h2 { font-size: 1.8rem; margin-bottom: 6px; }
.muted { color: var(--ink-soft); }
.stack { display: grid; gap: 14px; margin-top: 20px; }
.alert { padding: 10px 12px; border-radius: 12px; font-weight: 650; margin-top: 12px; }
.alert.error { background: #fde8e6; color: var(--danger); }
.alert.success { background: #e4f4ea; color: var(--ok); }
.demo-box { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--line); }
.demo-box p { font-size: .8rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 8px; }
.demo-creds { display: grid; gap: 8px; }
.ghost-chip {
  border: 1px dashed var(--line); background: var(--bg); border-radius: 12px;
  padding: 10px; text-align: left; cursor: pointer; font-weight: 650;
}
.auth-foot { text-align: center; color: var(--ink-soft); margin-top: 18px; font-size: .85rem; }
.auth-foot a { color: var(--brand-dark); font-weight: 700; }
.error-page { max-width: 520px; padding: 40px 8px; }
.error-page h1 { font-size: 2rem; margin: 8px 0 10px; }

@media (min-width: 1400px) {
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid .wide { grid-column: 1 / -1; }
}
@media (min-width: 861px) {
  .modal { place-items: center; }
  .modal-card { border-radius: 20px; }
}
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .module-switch, .filters { grid-template-columns: 1fr 1fr; }
  .detail-list, .detail-list.cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; transform: translateX(-105%);
    transition: transform .22s ease;
  }
  body.nav-open .sidebar { transform: none; }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35);
    opacity: 0; pointer-events: none; z-index: 30;
  }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .menu-btn { display: grid; }
  .hide-sm { display: none !important; }
  .topbar { flex-wrap: wrap; }
  .top-search.hide-sm {
    display: block !important;
    flex: 1 1 100%;
    order: 3;
    padding-top: 4px;
  }
  .top-search form { max-width: none; }
  .main { padding: 20px 14px 110px; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-visual { min-height: 280px; padding: 28px; }
  .form-grid, .grid-2, .filters, .kpi-grid, .module-switch, .alert-row, .detail-list, .detail-list.cols-3 { grid-template-columns: 1fr; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around; align-items: center;
    padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
    z-index: 25;
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    text-decoration: none; font-size: .68rem; font-weight: 700; color: var(--ink-soft); min-width: 56px;
  }
  .bottom-nav a.is-active { color: var(--brand); }
  .fab-link {
    width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: #fff !important;
    display: grid !important; place-items: center; margin-top: -22px;
    box-shadow: 0 10px 20px rgba(226,91,26,.35); font-size: 1.6rem;
  }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { background: #fff; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; padding: 8px 4px; }
  .table td { border: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; }
  .table td .row-actions { justify-content: flex-start; }
  .table td.num { text-align: right; }
  .totals-row { display: none; }
  .btn, .modal-card input, .modal-card select, .form-grid input, .form-grid select, .file-input {
    min-height: 44px;
  }
  .page-head { align-items: stretch; }
  .head-actions .btn { flex: 1 1 140px; justify-content: center; text-align: center; }
  .doc-row { flex-direction: column; align-items: stretch; }
  .doc-row .btn { width: 100%; }
}

.doc-list { list-style: none; margin: 0; padding: 0; display: grid; }
.doc-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.doc-row:last-child { border-bottom: 0; }
.doc-row small { display: block; color: var(--ink-soft); }
.doc-card { margin: 16px 0; }
.file-input { width: 100%; padding: 10px 0; }
