/* ============================================================
   LEDGER — Design system
   Palette: Forest Green | Typography: Epilogue + Figtree
   ============================================================ */

:root {
  /* Palette — Teal */
  --ink:             #0f172a;
  --muted:           #475569;
  --paper:           #f8fafc;
  --accent:          #0d9488;
  --accent-hover:    #0f766e;
  --accent-muted:    #f0fdfa;
  --card:            #ffffff;
  --line:            #e2e8f0;
  /* Sidebar */
  --sidebar-bg:      #0f3d38;
  --sidebar-text:    #a7d8d4;
  --sidebar-section: #4d9e96;
  --sidebar-active:  rgba(13, 148, 136, 0.28);
  --sidebar-hover:   rgba(255, 255, 255, 0.06);
  /* Shadows */
  --shadow:          0 4px 20px rgba(15, 61, 56, 0.12);
  --shadow-soft:     0 2px 8px  rgba(15, 61, 56, 0.07);
  --shadow-medium:   0 6px 20px rgba(15, 61, 56, 0.10);
  /* Radii */
  --radius:          8px;
  --radius-lg:       12px;
  --radius-xl:       16px;
  /* Finance colors */
  --debit:           #dc2626;
  --credit:          #0d9488;
  --debit-bg:        #fef2f2;
  --credit-bg:       #f0fdfa;
}

/* --- Reset --- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Figtree', "Avenir", "Gill Sans", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

h1, h2, h3, h4, .brand, .section h1, .section h2 {
  font-family: 'Epilogue', "Avenir", sans-serif;
}

/* --- Accessibility utilities --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  z-index: 200;
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
  transition: top 0.1s;
}
.skip-link:focus { top: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* --- Header (public) --- */
header {
  padding: 24px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--accent);
}

/* --- Public nav --- */
nav {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
nav a {
  text-decoration: none;
  color: var(--ink);
  padding: 6px 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
}
nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Main content --- */
main {
  padding: 24px 20px 64px;
  flex: 1;
}
.container {
  max-width: 1400px;
  margin: 0 auto;
}

/* --- Cards --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}
.card h3 { margin: 0 0 8px 0; }

.muted { color: var(--muted); }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-muted);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

footer {
  padding: 18px 28px 40px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

/* --- Hero (landing page) --- */
.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 28px;
  align-items: center;
  padding: 40px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, #ffffff, var(--accent-muted));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.hero h1 {
  margin: 0 0 14px 0;
  font-size: 40px;
  line-height: 1.15;
  color: var(--ink);
}
.hero p {
  margin: 0 0 18px 0;
  color: var(--muted);
  font-size: 16px;
}
.cta-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 0;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s;
  font-family: inherit;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary {
  background: var(--card);
  color: var(--accent);
  border-color: var(--accent);
}
.btn.secondary:hover {
  background: var(--accent-muted);
}
.btn.danger {
  background: var(--debit);
  border-color: transparent;
}
.btn.danger:hover { background: #991b1b; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.3px;
}

/* --- Sections & feature grid --- */
.section { margin-top: 40px; }
.section h1,
.section h2 { margin: 0 0 8px 0; }
.section h1 { font-size: 30px; font-weight: 800; }
.section h2 { font-size: 24px; font-weight: 700; }
.section > p { color: var(--muted); margin: 0; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.feature {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.feature strong {
  display: block;
  font-family: 'Epilogue', sans-serif;
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  margin: 4px 0 6px;
  font-variant-numeric: tabular-nums;
}

.kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
}
.feature-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 4px 0;
}
.chart-wrap {
  position: relative;
  width: 100%;
  height: 280px;
  margin-top: 10px;
}
.chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-soft);
}

/* --- Breakpoints base --- */
@media (max-width: 640px) {
  main { padding: 16px 14px 48px; }
  header { padding: 20px 16px; }
  .hero { padding: 24px; }
  .hero h1 { font-size: 28px; }
}

/* --- Utilities --- */
.centered  { margin: 0 auto; }
.max-520   { max-width: 520px; }
.mt-16     { margin-top: 16px; }
.mt-18     { margin-top: 18px; }
.mb-16     { margin-bottom: 16px; }
.hero-single  { grid-template-columns: 1fr; }
.hero-tight   { padding: 28px; }
.stack-12  { display: grid; gap: 12px; }
.alert {
  border: 1px solid #fecaca;
  background: var(--debit-bg);
  border-radius: var(--radius);
  padding: 12px 16px;
}

/* --- Tables --- */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
}
.table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--ink);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:nth-child(even) td { background: var(--paper); }
.table tbody tr:hover td { background: var(--accent-muted); }

/* Numeric columns — right-aligned, tabular figures */
.table th.num,
.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: 0;
  white-space: nowrap;
}
/* Total / subtotal rows */
.table tbody tr.total td {
  font-weight: 700;
  border-top: 2px solid var(--ink);
  border-bottom: 3px double var(--ink);
  background: transparent !important;
}
/* Debit / credit coloring */
.text-debit  { color: var(--debit); }
.text-credit { color: var(--credit); }

/* --- Mobile responsive table --- */
@media (max-width: 768px) {
  .table { border-collapse: separate; border-spacing: 0; }
  .table thead { display: none; }
  .table tbody,
  .table tr,
  .table td { display: block; width: 100%; }
  .table tr {
    margin-bottom: 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--card);
  }
  .table tbody tr:nth-child(even) td { background: transparent; }
  .table tbody tr:nth-child(even) { background: transparent; }
  .table td {
    margin: 0;
    padding: 7px 0;
    border-bottom: 1px dashed var(--line);
    display: grid;
    grid-template-columns: minmax(110px, 42%) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    background: transparent !important;
  }
  .table td:last-child { border-bottom: none; }
  .table td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    font-weight: 700;
  }
  .table td[data-label=""]::before { content: ""; }
  .table td.num { text-align: left; }
  .table td .actions { justify-content: flex-start; }
  .table td .input,
  .table td .ts-wrapper,
  .table td .btn { width: 100%; min-width: 0; }
}

/* --- Actions row --- */
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* --- Form inputs --- */
.input {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
  outline: none;
}
select.input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--card);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230d9488' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  padding-right: 34px;
  cursor: pointer;
}
select.input option {
  background: var(--card);
  color: var(--ink);
}
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

/* --- Export dropdown --- */
.export-dropdown { position: relative; display: inline-block; }
.export-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-medium);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}
.export-menu a {
  display: block;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.1s;
}
.export-menu a:hover { background: var(--accent-muted); color: var(--accent); }
.export-dropdown.open .export-menu { display: block; }
.checkbox { transform: translateY(2px); }
.form-grid { display: grid; gap: 14px; }

/* --- App shell --- */
.layout {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

/* --- Sidebar wrapper (sticky container + fade overlay) --- */
.sidebar-wrap {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.sidebar-wrap::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72px;
  background: linear-gradient(to top, var(--sidebar-bg) 20%, transparent);
  pointer-events: none;
  z-index: 2;
}

/* --- Sidebar --- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 20px 14px 52px;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.2s ease;
  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: rgba(167, 216, 212, 0.18) transparent;
}
/* Webkit (Chrome, Safari, Edge) */
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(167, 216, 212, 0.22);
  border-radius: 99px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(167, 216, 212, 0.52);
}
.sidebar-backdrop { display: none; }

.sidebar .brand {
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 20px;
  padding: 0 6px;
  letter-spacing: 0.2px;
}

.sidebar nav { margin: 0; display: block; gap: 0; }

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: var(--radius);
  margin-bottom: 2px;
  min-height: 40px;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.sidebar a svg { flex-shrink: 0; }
.sidebar a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.sidebar a.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}
.sidebar a[aria-current="page"] {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.sidebar .section-title {
  font-size: 10px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--sidebar-section);
  margin: 18px 0 6px 10px;
  font-weight: 700;
}

/* --- Topbar --- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-company-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--accent-muted);
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.toggle-btn {
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  min-height: 40px;
  font-family: inherit;
  transition: background 0.15s;
}
.toggle-btn:hover { background: var(--accent); }

/* --- Sidebar collapsed state (desktop) --- */
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed a span,
.sidebar.collapsed .section-title,
.sidebar.collapsed .brand { display: none; }
.sidebar.collapsed a {
  justify-content: center;
  gap: 0;
  padding: 9px;
  position: relative;
}
.sidebar.collapsed a:hover::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--sidebar-bg);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

/* --- Mobile sidebar --- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-wrap {
    position: static;
    height: 0;
    overflow: visible;
  }
  .sidebar-wrap::after { display: none; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 30;
    width: 256px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(13, 38, 24, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .app-shell { min-height: 100vh; }
  .topbar { flex-wrap: wrap; }
  .topbar-right { gap: 8px; }
  .topbar-company-name { max-width: 40vw; }
  .topbar-right .muted {
    flex: 0 0 auto;
    max-width: 30vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
  }
}

/* --- Auth/guest visibility --- */
body.guest .sidebar-wrap,
body.guest .sidebar,
body.guest .sidebar-backdrop,
body.guest .topbar { display: none; }
body.guest .layout { grid-template-columns: 1fr; }
body.auth .public-header { display: none; }
body.guest .public-header {
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

/* --- Journal entry (líneas) table --- */
.lineas-table td { vertical-align: middle; padding: 5px 4px; }
.lineas-table .input { padding: 7px 10px; border-radius: 6px; font-size: 13px; min-width: 0; }
.lineas-table select.input { padding-right: 28px; background-position: right 8px center; }

/* --- Sidebar collapsed layout --- */
body.sidebar-collapsed .layout { grid-template-columns: 60px 1fr; }

/* --- Custom select (company picker in dashboard) --- */
.company-selector-form {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}
.company-selector-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.custom-select {
  position: relative;
  max-width: 360px;
  width: 100%;
}
.custom-select-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  min-height: 44px;
  transition: border-color 0.15s;
}
.custom-select-btn:hover { border-color: var(--accent); }
.custom-select-btn:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
  outline: none;
}
.custom-select-btn svg { flex-shrink: 0; color: var(--muted); transition: transform 0.15s; }
.custom-select-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.custom-select-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-medium);
  z-index: 50;
  overflow: hidden;
}
.custom-select-option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.1s;
}
.custom-select-option:hover { background: var(--accent-muted); }
.custom-select-option.active {
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-muted);
}

@media (max-width: 900px) {
  .company-selector-form { flex-direction: column; align-items: flex-start; gap: 6px; }
  .custom-select { max-width: 100%; }
}

/* --- Dark mode --- */
@media (prefers-color-scheme: dark) {
  :root {
    --ink:             #e2e8f0;
    --muted:           #64748b;
    --paper:           #0d1f1e;
    --accent:          #2dd4bf;
    --accent-hover:    #14b8a6;
    --accent-muted:    #042f2e;
    --card:            #132726;
    --line:            #1e3836;
    --sidebar-bg:      #071412;
    --sidebar-text:    #7ecfc9;
    --sidebar-section: #2d7d77;
    --debit:           #f87171;
    --debit-bg:        #1f0a0a;
    --credit-bg:       #042f2e;
  }
  body { background: var(--paper); }
  .topbar-company-name { color: var(--accent); }
}

/* --- Django messages --- */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.message {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 500;
}
.message-error   { background: #7f1d1d; color: #fca5a5; }
.message-success { background: #14532d; color: #86efac; }
.message-warning { background: #78350f; color: #fde68a; }
.message-info    { background: #1e3a5f; color: #93c5fd; }

/* --- Subscription banners --- */
.suscripcion-banner {
  padding: 10px 24px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}
.banner-gracia {
  background: #7f1d1d;
  color: #fca5a5;
}
.banner-proximo {
  background: #78350f;
  color: #fde68a;
}

/* --- Dashboard layout --- */
.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  margin-top: 24px;
}
.dash-header-left { flex: 1; min-width: 0; }
.dash-header-company {
  font-family: 'Epilogue', sans-serif;
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-header-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}
.dash-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-muted);
  color: var(--accent);
}
.dash-badge.closed {
  background: #fef2f2;
  color: #dc2626;
}

.dash-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}
@media (max-width: 640px) {
  .dash-kpis { grid-template-columns: 1fr 1fr; }
}
.dash-kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}
.dash-kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 6px 0;
}
.dash-kpi-value {
  font-family: 'Epilogue', sans-serif;
  font-size: 30px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin: 0 0 4px 0;
  font-variant-numeric: tabular-nums;
}
.dash-kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* Charts */
.dash-charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-top: 14px;
}
@media (max-width: 900px) {
  .dash-charts-row { grid-template-columns: 1fr; }
}
.dash-charts-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.chart-year-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chart-year {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.chart-year:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.chart-year.is-active {
  background: var(--accent-muted);
  border-color: transparent;
  color: var(--accent);
}

.dash-chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 20px;
}
.dash-chart-card h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.dash-chart-card .chart-sub {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px 0;
}
.dash-chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
}
.dash-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.dash-chart-full {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 20px;
  margin-top: 14px;
}
.dash-chart-full h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.dash-chart-full .chart-sub {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px 0;
}
.dash-chart-full .dash-chart-wrap { height: 220px; }

/* ── Estado de carga del anio ─────────────────────────────────────── */
.carga-panel { margin-top: 14px; }
.carga-meses {
  list-style: none;
  margin: 0 0 16px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
}
@media (max-width: 900px) {
  .carga-meses { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 480px) {
  .carga-meses { grid-template-columns: repeat(4, 1fr); }
}
.carga-mes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  text-align: center;
}
.carga-mes-nombre {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.carga-mes-dato {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.carga-mes-leyenda { font-size: 10px; color: var(--muted); }
.carga-mes.es-cargado {
  border-color: transparent;
  background: var(--accent-muted);
}
.carga-mes.es-cargado .carga-mes-nombre,
.carga-mes.es-cargado .carga-mes-dato,
.carga-mes.es-cargado .carga-mes-leyenda { color: var(--accent); }
.carga-mes.es-vacio {
  background: #fffbeb;
  border-color: #fde68a;
}
.carga-mes.es-vacio .carga-mes-nombre,
.carga-mes.es-vacio .carga-mes-dato,
.carga-mes.es-vacio .carga-mes-leyenda { color: #a16207; }
.carga-mes.es-sin-periodo {
  background: transparent;
  border-style: dashed;
}

.carga-resumen {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
}
.carga-resumen .punto {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 8px;
}
.carga-resumen .punto.es-cargado { background: var(--accent); }
.carga-resumen .punto.es-vacio { background: #f59e0b; }
.carga-resumen .punto.es-sin-periodo {
  background: transparent;
  border: 1px dashed var(--muted);
}

.carga-aviso {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-xl);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #7c2d12;
  font-size: 13px;
  overflow-x: auto;
}
.carga-aviso p { margin: 0 0 8px 0; }
.carga-aviso-titulo { font-weight: 700; }
.carga-tabla {
  border-collapse: collapse;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.carga-tabla th,
.carga-tabla td {
  padding: 5px 14px 5px 0;
  text-align: left;
  font-weight: 400;
}
.carga-tabla thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 700;
}
.carga-tabla tbody th { font-weight: 700; }

.chart-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 260px;
  color: var(--muted);
  text-align: center;
  gap: 8px;
}
.chart-empty-state p { margin: 0; font-size: 13px; }
.dash-chart-full .chart-empty-state { height: 220px; }
/* --- Info Box --- */
.info-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  margin-right: 8px;
}

.info-box .muted {
  color: var(--muted);
  font-size: 13px;
}

.info-box strong {
  color: var(--accent);
  font-weight: 600;
}

/* --- List toolbar (empresa + filtros + acciones) --- */
.list-toolbar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.list-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.list-toolbar-empresa {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.list-toolbar-empresa-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}
.list-toolbar-empresa-nombre {
  font-weight: 700;
  color: var(--text);
  font-size: 15px;
}
.list-toolbar-empresa-sep {
  color: var(--line);
  font-size: 18px;
  line-height: 1;
}
.list-toolbar-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.list-toolbar-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.list-toolbar-filters .input {
  width: auto;
  min-width: 180px;
}
.list-toolbar-filters select.input {
  min-width: 200px;
}
/* Los selectores con buscador (Tom Select) no pueden medir segun su contenido: al escribir
   se ensanchaban y empujaban el boton Ver; al hacer clic el selector perdia el foco, volvia
   a su ancho y el boton se movia antes de soltar el mouse, asi que el primer clic se perdia. */
.list-toolbar-filters .ts-wrapper { flex: 0 1 320px; width: 320px; min-width: 200px; max-width: 100%; }
.list-toolbar-filters .ts-wrapper .ts-control { flex-wrap: nowrap; overflow: hidden; }
.list-toolbar-filters .ts-wrapper .ts-control > .item {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 700px) {
  .list-toolbar-filters .input,
  .list-toolbar-filters select.input { min-width: 0; width: 100%; }
  .list-toolbar-filters .ts-wrapper { flex-basis: 100%; width: 100%; }
}

/* --- Cliente/Proveedor toggle (existente / nuevo) --- */
.nuevo-tercero-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  letter-spacing: 0.2px;
  white-space: nowrap;
  line-height: 1;
}
.nuevo-tercero-link:hover { text-decoration: underline; text-underline-offset: 2px; }

.nuevo-panel {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 14px 16px 16px;
  background: var(--accent-muted);
}
.nuevo-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.nuevo-panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  font-weight: 700;
  margin: 0;
}
.nuevo-panel-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px 3px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.13s, color 0.13s, border-color 0.13s;
  white-space: nowrap;
}
.nuevo-panel-back:hover {
  background: var(--card);
  color: var(--ink);
  border-color: var(--muted);
}
.nuevo-panel-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.nuevo-panel-fields .span-full { grid-column: 1 / -1; }
@media (max-width: 600px) {
  .nuevo-panel-fields { grid-template-columns: 1fr; }
  .nuevo-panel-fields .span-full { grid-column: 1; }
}

/* --- Segmented tipo control --- */
.tipo-segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  width: 100%;
  height: 38px;
}
.tipo-seg-opt {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
  border-right: 1px solid var(--line);
}
.tipo-seg-opt:last-child { border-right: none; }
.tipo-seg-opt.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tipo-seg-opt:hover:not(.active) { background: var(--paper); color: var(--ink); }

.rif-display {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 5px 10px;
  background: var(--accent-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.rif-display-label {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}
.rif-display--vacio { color: var(--muted); background: var(--paper); }
.field-span-2 { grid-column: span 2; }
@media (max-width: 600px) { .field-span-2 { grid-column: span 1; } }
.field-full { grid-column: 1 / -1; }
.field-error { color: #dc2626; font-size: 12px; margin-top: 4px; }
.field-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* --- IVA badges (gravada / no gravada) --- */
.tipo-venta-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}
.badge-gravada {
  background: rgba(16, 185, 129, 0.12);
  color: #065f46;
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge-no-gravada {
  background: rgba(245, 158, 11, 0.10);
  color: #92400e;
  border: 1px solid rgba(245, 158, 11, 0.28);
}

/* --- Tabla totales footer --- */
tfoot .totals-row td {
  border-top: 2px solid var(--accent);
  padding-top: 10px;
  padding-bottom: 10px;
  background: var(--accent-muted);
  font-size: 13px;
  color: var(--accent);
}

/* --- Encabezado fiscal del libro contable --- */
.libro-encabezado {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  background: var(--bg);
}
.libro-encabezado-rif-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}
.libro-encabezado-subtitle {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.libro-encabezado-body {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 32px;
  align-items: start;
}
.libro-encabezado-field {
  margin-bottom: 10px;
}
.libro-encabezado-field:last-child {
  margin-bottom: 0;
}
.libro-encabezado-field-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 3px;
}
.libro-encabezado-field-value {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.libro-encabezado-field-note {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.libro-encabezado-right {
  text-align: right;
  min-width: 200px;
  flex-shrink: 0;
}
.libro-encabezado-rif {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.libro-encabezado-periodo {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}
.libro-encabezado-periodo-val {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}
.libro-encabezado-tipo-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 2px;
}
.libro-encabezado-tipo-val {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  letter-spacing: 0.4px;
}

/* --- Panel resumen declaración --- */
.declaracion-resumen {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-soft);
}
.declaracion-titulo {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}
.declaracion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.declaracion-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.declaracion-item--total {
  background: var(--accent-muted);
  border-color: var(--accent);
}
.declaracion-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.declaracion-valor {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.declaracion-item--total .declaracion-label { color: var(--accent); }
.declaracion-item--total .declaracion-valor { color: var(--accent); font-size: 22px; }
@media print {
  .nav, .sidebar, .actions, .export-dropdown, .list-toolbar, .btn { display: none !important; }
  .container { max-width: 100% !important; padding: 0 !important; }
  .section { padding: 0 !important; }
  .panel { border: none !important; padding: 4px 0 !important; box-shadow: none !important; }
  .table td, .table th { padding: 3px 6px !important; font-size: 9px !important; line-height: 1.2 !important; }
  .table { border-collapse: collapse !important; }
  body { font-size: 10px !important; }
  h2 { font-size: 14px !important; margin-bottom: 6px !important; }
  .kicker { font-size: 9px !important; }
  tr { page-break-inside: avoid; }
}
