/* ==========================================================================
   Borbolla Control — Corporate Stylesheet
   "Mercury" reskin: Borbolla navy house format x Mercury Bank discipline.
   LIGHT theme. Design tokens drive every surface; a future tenant = a new
   [data-tenant="..."] variable layer, no markup change.
   ========================================================================== */

/* --------------------------------------------------------------------------
   DESIGN TOKENS
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;

  /* Brand + accent */
  --brand: #13294b;            /* Borbolla navy — topbar */
  --brand-contrast: #ffffff;   /* logo + topbar text */
  --accent: #3a5bd9;           /* navy-leaning indigo (Mercury #5266EB influence) */
  --accent-soft: rgba(58, 91, 217, 0.12);

  /* Lines + text */
  --border: #e6e8eb;           /* hairline */
  --text: #1a1d24;
  --text-muted: #6b7280;

  /* Status — functional color ONLY */
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --info: #0e7490;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Shadows — whisper only; separation comes from value + spacing */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-pop: 0 4px 16px rgba(16, 24, 40, 0.10);

  /* Spacing (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;
  --space-10: 64px;

  /* Type */
  --font-sans: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Archivo", var(--font-sans);
  --fs-display: 2.25rem;
  --fs-h1: 1.6rem;
  --fs-h2: 1.35rem;
  --fs-h3: 1.15rem;
  --fs-body: 0.9rem;
  --fs-caption: 0.8125rem;
  --fs-small: 0.75rem;

  /* Layout metrics */
  --topbar-height: 56px;
  --sidebar-width: 240px;

  /* ---- Legacy aliases (kept so no existing reference breaks) ---- */
  --topbar-bg: var(--brand);
  --sidebar-bg: var(--surface);
  --sidebar-border: var(--border);
  --sidebar-active-bg: var(--accent-soft);
  --sidebar-active-color: var(--brand);
  --sidebar-link-color: var(--text-muted);
  --sidebar-link-hover-bg: var(--surface-2);
  --body-bg: var(--bg);
  --card-shadow: var(--shadow-sm);
  --card-shadow-hover: var(--shadow);
  --corporate-blue: var(--brand);
  --corporate-accent: var(--accent);
}

/* --------------------------------------------------------------------------
   PER-TENANT LAYER — BODE (default tenant today).
   A future tenant adds its own [data-tenant="omicron"]{...} overriding these.
   -------------------------------------------------------------------------- */
[data-tenant="bode"] {
  --brand: #13294b;
  --accent: #3a5bd9;
  --accent-soft: rgba(58, 91, 217, 0.12);
}

/* --------------------------------------------------------------------------
   Base / Layout
   -------------------------------------------------------------------------- */
html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text);
}

a {
  color: var(--accent);
}

/* Alpine.js: hide cloaked nodes until the component initialises */
[x-cloak] { display: none !important; }

/* Money / figures read like a financial statement */
.tabular-nums,
.money,
td.money,
.kpi-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* --------------------------------------------------------------------------
   Top Navigation Bar
   -------------------------------------------------------------------------- */
#topbar,
.topbar {
  background-color: var(--brand) !important;
  height: var(--topbar-height);
  z-index: 1030;
  box-shadow: var(--shadow);
}

.topbar .navbar-brand .brand-logo,
.topbar .navbar-brand img.brand-logo {
  height: 28px;
  width: auto;
  color: var(--brand-contrast); /* SVG uses currentColor */
}

.header-menu {
  position: relative;
}

.header-menu__summary {
  list-style: none;
}

.header-menu__summary::-webkit-details-marker {
  display: none;
}

.header-menu__popover {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  z-index: 1100;
  overflow: hidden;
}

.header-menu__header {
  padding: 0.75rem 1rem;
}

.header-menu .dropdown-item {
  display: block;
  padding: 0.55rem 1rem;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  border: 0;
}

.header-menu .dropdown-item:hover {
  background: var(--surface-2);
}

/* --------------------------------------------------------------------------
   Sidebar — Desktop (sticky, hairline, quiet labels)
   -------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1020;
}

.sidebar-link {
  position: relative;
  color: var(--sidebar-link-color);
  padding: 0.6rem 1.25rem;
  border-radius: 0;
  font-size: var(--fs-caption);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  transition: background 0.15s ease, color 0.15s ease;
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--sidebar-link-hover-bg);
  color: var(--text);
}

.sidebar-link.active,
.sidebar-link.active:hover {
  background: var(--accent-soft);
  color: var(--brand);
  font-weight: 600;
}

/* Mercury-style active marker: subtle surface + a quiet accent bar */
.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.35rem;
  bottom: 0.35rem;
  width: 3px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  background: var(--accent);
}

.sidebar-section-label {
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.75rem 1.25rem 0.25rem;
  font-weight: 600;
}

.sidebar-divider {
  border-color: var(--border);
  margin: 0.5rem 1.25rem;
}

/* --------------------------------------------------------------------------
   Main Content Area
   -------------------------------------------------------------------------- */
.main-content {
  margin-top: var(--topbar-height);
  padding-left: 0;
}

@media (min-width: 992px) {
  .main-content {
    margin-left: var(--sidebar-width);
  }
}

/* --------------------------------------------------------------------------
   Cards — separation by hairline + one tiny shadow step (no hover drama)
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
}

/* Keep Bootstrap's border-0 cards borderless but give them the hairline look */
.card.border-0 {
  border: 1px solid var(--border) !important;
}

.card-header {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

/* --------------------------------------------------------------------------
   KPI / Stat Tiles — Mercury quiet tiles (no 4px colored left border)
   -------------------------------------------------------------------------- */
.kpi-card {
  border-left: none;
}

.kpi-card .kpi-value {
  font-size: var(--fs-display);
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.kpi-card .kpi-label {
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-card .kpi-icon {
  font-size: 2rem;
  opacity: 0.12;
}

/* Status accent reduced to a small top rule, functional color only */
.kpi-card.kpi-success { box-shadow: inset 0 2px 0 var(--ok), var(--shadow-sm); }
.kpi-card.kpi-warning { box-shadow: inset 0 2px 0 var(--warn), var(--shadow-sm); }
.kpi-card.kpi-danger  { box-shadow: inset 0 2px 0 var(--danger), var(--shadow-sm); }
.kpi-card.kpi-info    { box-shadow: inset 0 2px 0 var(--info), var(--shadow-sm); }

/* A quiet stat tile helper (Mercury "financial position first") */
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.stat-tile .stat-label {
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.stat-tile .stat-value {
  font-size: var(--fs-h1);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Tables — hairline separators, quiet uppercase headers, tabular figures
   -------------------------------------------------------------------------- */
.table {
  font-size: var(--fs-caption);
  color: var(--text);
  --bs-table-bg: var(--surface);
}

.table thead th,
.table > thead.table-light th,
.table .table-light th {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.table td,
.table th {
  border-color: var(--border);
}

.table-hover tbody tr:hover {
  background: var(--surface-2);
}

.table-clickable tbody tr {
  cursor: pointer;
}

/* Right-aligned money columns read like a statement */
.table td.money,
.table th.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Responsive stacked-table pattern (canonical — was inline in tesorería)
   On narrow screens each row becomes a stacked card, no horizontal scroll.
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .tes-stack thead {
    display: none;
  }
  .tes-stack tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0 0 0.6rem;
    padding: 0.35rem 0.6rem;
    background: var(--surface);
  }
  .tes-stack tbody td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border: 0;
    padding: 0.4rem 0.15rem;
    text-align: right;
  }
  .tes-stack tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    flex: 0 0 auto;
  }
  .tes-stack tfoot {
    display: block;
  }
  .tes-stack tfoot tr {
    display: block;
    text-align: left;
  }
  .tes-stack tfoot td {
    display: block;
    border: 0;
    padding: 0.2rem 0;
  }
  /* Fingers, not a mouse: taller touch targets inside tesorería */
  .tes .btn {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }
}

.tes .badge {
  white-space: normal;
  text-align: left;
  line-height: 1.3;
}

.tes .table-responsive {
  border-radius: var(--radius);
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-control,
.form-select {
  font-size: var(--fs-caption);
  border-radius: var(--radius-sm);
  border-color: var(--border);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-label {
  font-weight: 500;
  font-size: var(--fs-caption);
  color: var(--text);
  margin-bottom: 0.3rem;
}

.form-text {
  font-size: var(--fs-small);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Buttons — Mercury near-pill primary, flat accent
   -------------------------------------------------------------------------- */
.btn {
  font-size: var(--fs-caption);
  border-radius: var(--radius-pill);
  font-weight: 500;
}

.btn-sm {
  font-size: 0.8rem;
}

.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: #2f4bbf;
  --bs-btn-hover-border-color: #2f4bbf;
  --bs-btn-active-bg: #2a43ab;
  --bs-btn-active-border-color: #2a43ab;
  --bs-btn-disabled-bg: var(--accent);
  --bs-btn-disabled-border-color: var(--accent);
}

.btn-outline-primary {
  --bs-btn-color: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
  --bs-btn-active-bg: var(--accent);
  --bs-btn-active-border-color: var(--accent);
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  border-radius: var(--radius);
  font-size: var(--fs-caption);
}

/* --------------------------------------------------------------------------
   Status Badges — Invoice / Document states (functional color only)
   -------------------------------------------------------------------------- */
.badge-draft     { background-color: var(--text-muted); }
.badge-pending   { background-color: var(--warn); color: #fff; }
.badge-stamped   { background-color: var(--ok); color: #fff; }
.badge-cancelled { background-color: var(--danger); }
.badge-error     { background-color: var(--danger); }

/* Bootstrap-compatible status badge utility */
.status-badge {
  font-size: var(--fs-small);
  padding: 0.25em 0.65em;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-draft     { background: #e5e7eb; color: #374151; }
.status-pending   { background: #fef3c7; color: #92400e; }
.status-stamped   { background: #d1fae5; color: #065f46; }
.status-cancelled { background: #fee2e2; color: #991b1b; }
.status-error     { background: #fee2e2; color: #991b1b; }

/* --------------------------------------------------------------------------
   Environment Badge (FacturAPI mode)
   -------------------------------------------------------------------------- */
.env-test { background: #cffafe; color: #164e63; }
.env-live { background: #fee2e2; color: #991b1b; }

/* --------------------------------------------------------------------------
   Page Header — editorial, slight letter-spacing
   -------------------------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  font-size: var(--fs-h1);
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--text);
}

/* --------------------------------------------------------------------------
   Empty State — restrained
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
  opacity: 0.4;
}

/* --------------------------------------------------------------------------
   HTMX Loading Indicator
   -------------------------------------------------------------------------- */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* --------------------------------------------------------------------------
   Responsive adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  .main-content {
    margin-left: 0;
  }
}

@media (max-width: 575.98px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .table-responsive {
    font-size: 0.8rem;
  }
}

/* --------------------------------------------------------------------------
   Utility helpers
   -------------------------------------------------------------------------- */
.cursor-pointer { cursor: pointer; }
.font-monospace { font-family: 'Courier New', Courier, monospace; font-size: 0.85em; }
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ==========================================================================
   Tesorería — capa de diseño "profunda" (Mercury). Componentes tokenizados,
   se adaptan a tema claro/oscuro vía las variables. Scope: .tdeep
   ========================================================================== */
.tdeep { max-width: 880px; margin: 0 auto; }
.tdeep h1, .tdeep h2, .tdeep .tz-big, .tdeep .tz-total b { font-family: var(--font-display); letter-spacing: -0.01em; }

/* encabezado de pantalla */
.tz-head { display:flex; flex-wrap:wrap; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom:20px; }
.tz-eyebrow { font:700 11px/1 var(--font-sans); letter-spacing:.14em; text-transform:uppercase; color:var(--accent); }
.tz-head h1 { font-size:1.55rem; font-weight:800; margin:.3rem 0 .15rem; }
.tz-head .sub { color:var(--text-muted); font-size:.9rem; margin:0; }

/* hero con cifra protagonista */
.tz-hero { display:flex; flex-wrap:wrap; align-items:flex-end; justify-content:space-between; gap:16px;
           background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
           padding:22px 22px; box-shadow:var(--shadow-sm); margin-bottom:20px; }
.tz-hero .k { font:700 11px/1 var(--font-sans); letter-spacing:.12em; text-transform:uppercase; color:var(--text-muted); }
.tz-big { font-weight:800; font-size:clamp(1.9rem,6vw,2.7rem); line-height:1; margin:8px 0 5px; font-variant-numeric:tabular-nums; }
.tz-big .cur { font-size:1rem; color:var(--text-muted); font-weight:600; margin-left:6px; }
.tz-meta { color:var(--text-muted); font-size:.85rem; }

/* filtros tipo pill */
.tz-pills { display:flex; gap:7px; flex-wrap:wrap; margin-bottom:14px; }
.tz-pill { font:600 12.5px/1 var(--font-sans); padding:8px 14px; border-radius:999px; border:1px solid var(--border);
           color:var(--text-muted); background:var(--surface); text-decoration:none; display:inline-block; }
.tz-pill--on { background:var(--brand); border-color:var(--brand); color:#fff; }

/* grupos y filas de pago */
.tz-group { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
            box-shadow:var(--shadow-sm); overflow:hidden; margin-bottom:16px; }
.tz-seg { display:flex; justify-content:space-between; align-items:baseline; gap:10px;
          padding:14px 18px 10px; }
.tz-seg .lab { font:700 11px/1.1 var(--font-sans); letter-spacing:.06em; text-transform:uppercase; color:var(--faint,var(--text-muted)); }
.tz-seg .amt { font-weight:700; font-variant-numeric:tabular-nums; }
.tz-row { display:grid; grid-template-columns:1fr auto; gap:4px 14px; align-items:center;
          padding:13px 18px; border-top:1px solid var(--border); }
.tz-who { display:flex; align-items:center; gap:12px; min-width:0; }
.tz-mono { width:40px; height:40px; border-radius:11px; background:var(--surface-2); border:1px solid var(--border);
           display:grid; place-items:center; font-weight:700; color:var(--brand); flex:none; font-size:14px; font-family:var(--font-display); }
.tz-nm { font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.tz-sub { font-size:12px; color:var(--text-muted); display:flex; align-items:center; gap:7px; flex-wrap:wrap; }
.tz-amt { font-variant-numeric:tabular-nums; font-weight:700; text-align:right; white-space:nowrap; }
.tz-amt small { display:block; font-weight:500; font-size:11px; color:var(--text-muted); }
.tz-dot { width:7px; height:7px; border-radius:50%; display:inline-block; flex:none; }
.tz-dot--ok { background:var(--ok); } .tz-dot--flag { background:var(--danger); }
.tz-chip { font:600 11px/1 var(--font-sans); padding:3px 8px; border-radius:999px; }
.tz-chip--con { background:var(--ok-soft,#e6f4ec); color:var(--ok); }
.tz-chip--sin { background:var(--accent-soft); color:var(--accent); }

/* pie: fondeo/egreso + CTA */
.tz-foot { display:flex; flex-wrap:wrap; gap:12px 16px; justify-content:space-between; align-items:center;
           background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
           padding:16px 20px; box-shadow:var(--shadow-sm); margin-top:4px; }
.tz-total .k { font-size:12px; color:var(--text-muted); }
.tz-total b { font-size:1.3rem; font-variant-numeric:tabular-nums; }
.tz-cta { background:var(--accent); color:#fff; border:0; border-radius:10px; padding:11px 22px;
          font:700 14px/1 var(--font-sans); box-shadow:0 8px 18px -8px var(--accent); cursor:pointer; }
.tz-cta:hover { filter:brightness(1.07); color:#fff; }
.tz-cta--ghost { background:transparent; color:var(--text-muted); box-shadow:none; border:1px solid var(--border); }
.tz-note { font-size:.82rem; color:var(--text-muted); }

/* estados (aprobada/abierta/etc.) */
.tz-status { border-radius:var(--radius); padding:12px 15px; font-size:.9rem; margin-top:16px; border:1px solid transparent; }
.tz-status--ok { background:var(--ok-soft,#e6f4ec); color:var(--ok); border-color:color-mix(in srgb,var(--ok) 25%,transparent); }
.tz-status--wait { background:var(--warn-soft,#fbefdd); color:var(--warn); border-color:color-mix(in srgb,var(--warn) 25%,transparent); }
.tz-status--off { background:var(--surface-2); color:var(--text-muted); }

@media (max-width:560px){
  .tz-amt { text-align:left; }
  .tz-row { grid-template-columns:1fr; }
  .tz-row .tz-amt { padding-left:52px; }
}
