* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #0f1117;
  color: #c8ccd4;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  display: flex;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6,
.sidebar-header,
.stat-value,
thead th,
.data-table tfoot td {
  font-family: 'Cardo', serif;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: #1a1d27;
  border-right: 1px solid #2a2d3a;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #2a2d3a;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 28px;
  height: 28px;
  border-radius: 4px;
}

.sidebar-nav {
  list-style: none;
  padding: 8px 0;
  flex: 1;
}

.sidebar-nav li a {
  display: block;
  padding: 10px 16px;
  color: #8a8f9a;
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav li a:hover {
  background: #252830;
  color: #e0e0e0;
}

.sidebar-nav li.active a {
  color: #d8613c;
  background: #1e2230;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #2a2d3a;
}

.sidebar-footer a {
  color: #6a6f7a;
  text-decoration: none;
  font-size: 14px;
}

.sidebar-footer a:hover {
  color: #c8ccd4;
}

/* Content */
.content {
  flex: 1;
  padding: 24px;
  overflow-x: auto;
}

/* Controls */
.controls {
  margin-bottom: 20px;
}

.stats {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
}

.stat {
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  border-radius: 6px;
  padding: 16px 24px;
}

.stat-label {
  display: block;
  font-size: 12px;
  color: #6a6f7a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 600;
  color: #fff;
}

.stat-value-sm {
  font-size: 16px;
}

.filters {
  display: flex;
  gap: 12px;
}

.filters input,
.filters select {
  padding: 8px 12px;
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  border-radius: 4px;
  color: #c8ccd4;
  font-size: 14px;
}

.filters input {
  flex: 1;
  max-width: 400px;
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: #d8613c;
}

.filters select option {
  background: #1a1d27;
}

.btn-clear {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid #2a2d3a;
  border-radius: 4px;
  color: #6a6f7a;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-clear:hover {
  color: #c8ccd4;
  border-color: #d8613c;
}

/* Table */
.table-wrapper {
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  border-radius: 6px;
  max-height: 80vh;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 16px;
  font-weight: 600;
  color: #6a6f7a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #2a2d3a;
  white-space: nowrap;
  user-select: none;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  color: #c8ccd4;
}

th.active-sort {
  color: #d8613c;
}

.sort-arrow {
  font-size: 10px;
  margin-left: 4px;
}

tbody td {
  padding: 10px 16px;
  font-size: 15px;
  border-bottom: 1px solid #1e2130;
  white-space: nowrap;
}

tbody tr:hover {
  background: #1e2230;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.amount {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

td a.pdf-link {
  color: #d8613c;
  text-decoration: none;
}

td a.pdf-link:hover {
  text-decoration: underline;
}

/* Client links */
td a.client-link {
  color: #d8613c;
  text-decoration: none;
  cursor: pointer;
}

td a.client-link:hover {
  text-decoration: underline;
}

/* Client detail */
.client-header {
  margin-bottom: 20px;
}

.back-link {
  color: #6a6f7a;
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover {
  color: #d8613c;
}

.client-header h2 {
  color: #fff;
  font-size: 20px;
  margin-top: 8px;
}

.client-info {
  margin-bottom: 20px;
}

.fiscal-data {
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  border-radius: 6px;
  padding: 16px 20px;
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.fiscal-field {
  display: flex;
  flex-direction: column;
}

.fiscal-label {
  font-size: 12px;
  color: #6a6f7a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.fiscal-value {
  color: #e0e0e0;
  font-size: 15px;
}

/* Section blocks */
.section-block {
  margin-top: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h3 {
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}

.section-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.section-controls select {
  padding: 8px 12px;
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  border-radius: 4px;
  color: #c8ccd4;
  font-size: 14px;
}

.section-controls select:focus {
  outline: none;
  border-color: #d8613c;
}

.section-controls select option {
  background: #1a1d27;
}

.inline-stats {
  display: flex;
  gap: 16px;
}

.inline-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  color: #fff;
  font-weight: 600;
}

.inline-stat .stat-label {
  font-size: 12px;
  font-weight: 400;
  margin-bottom: 0;
}

/* Charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

.chart-box {
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  border-radius: 6px;
  padding: 16px;
  height: 280px;
}

/* Data tables */
.data-table {
  font-size: 15px;
  white-space: nowrap;
}

.data-table thead th {
  padding: 8px 12px;
  font-size: 16px;
  position: sticky;
  top: 0;
  background: #1a1d27;
  z-index: 2;
}

.data-table .group-header th {
  border-bottom: 2px solid #2a2d3a;
  text-align: center;
  font-size: 16px;
  letter-spacing: 1px;
  top: 0;
  background: #1a1d27;
}


.data-table .group-header + tr th {
  top: 30px;
  background: #1a1d27;
}

.group-ingresos { color: #4caf50; }
.group-gastos { color: #ff6b6b; }
.group-resultado { color: #d8613c; }

.data-table tbody td {
  padding: 9px 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.data-table tbody td:first-child,
.data-table tbody td:nth-child(2) {
  text-align: left;
}

.data-table tbody td.dim {
  font-size: 15px;
  color: #8a8f9a;
}

.data-table tfoot td {
  padding: 8px 12px;
  border-top: 2px solid #2a2d3a;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tfoot td:first-child {
  text-align: left;
}

.center { text-align: center !important; }
.err { color: #ff6b6b; }

.sep-left {
  border-left: 2px solid #444 !important;
}

.positive { color: #4caf50; }
.negative { color: #ff6b6b; }
.warning { color: #f0a030; }

/* API error */
.api-error {
  background: #3a1a1a;
  color: #ff6b6b;
  padding: 16px 24px;
  border-radius: 6px;
  text-align: center;
  font-size: 15px;
}

/* Mobile header (hidden on desktop) */
.mobile-header {
  display: none;
}
.refresh-btn { display: none; }

.sidebar-overlay {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  /* Mobile top bar */
  html, body { overflow-x: hidden; max-width: 100vw; }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #1a1d27;
    border-bottom: 1px solid #2a2d3a;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .mobile-title {
    font-family: 'Cardo', serif;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
  }

  .refresh-btn {
    display: block;
    background: none;
    border: none;
    color: #d8613c;
    font-size: 26px;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 10px;
    line-height: 1;
  }
  .refresh-btn:active { transform: rotate(180deg); transition: transform 0.4s; }

  /* Hamburger button */
  .hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    width: 32px;
    height: 24px;
    position: relative;
    flex-shrink: 0;
  }

  .hamburger span {
    display: block;
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: #c8ccd4;
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.25s;
  }

  .hamburger span:nth-child(1) { top: 2px; }
  .hamburger span:nth-child(2) { top: 11px; }
  .hamburger span:nth-child(3) { top: 20px; }

  .hamburger.active span:nth-child(1) {
    top: 11px;
    transform: rotate(45deg);
  }

  .hamburger.active span:nth-child(2) {
    opacity: 0;
  }

  .hamburger.active span:nth-child(3) {
    top: 11px;
    transform: rotate(-45deg);
  }

  /* Sidebar as slide-out drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: 1px solid #2a2d3a;
    flex-direction: column;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Overlay behind sidebar */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 150;
  }

  .sidebar-overlay.active {
    display: block;
  }

  /* Nav items stacked vertically */
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    overflow-y: auto;
  }

  .sidebar-nav li a {
    padding: 14px 20px;
    font-size: 16px;
  }

  .sidebar-footer {
    margin-top: auto;
  }

  /* Content adjustments */
  .stats {
    flex-direction: column;
    gap: 8px;
  }

  .filters {
    flex-direction: column;
  }

  .filters input {
    max-width: 100%;
  }

  .content {
    padding: 16px;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  /* === Tablas en móvil: card layout === */
  .table-wrapper {
    max-height: none;
    overflow: visible;
    border: none;
    background: transparent;
  }

  table.card-mobile { display: block; white-space: normal; }
  table.card-mobile thead { display: none; }
  table.card-mobile tbody, table.card-mobile tfoot { display: block; }
  table.card-mobile tbody tr,
  table.card-mobile tfoot tr {
    display: block;
    background: #1a1d27;
    border: 1px solid #2a2d3a;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 12px;
  }
  table.card-mobile tfoot tr { border-color: #d8613c; }
  table.card-mobile tbody td,
  table.card-mobile tfoot td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    padding: 9px 0;
    text-align: right;
    border: none;
    border-bottom: 1px solid #23262f;
    white-space: normal;
    word-break: break-word;
    font-size: 16px;
    font-weight: 600;
    color: #e8eaed;
    font-variant-numeric: tabular-nums;
  }
  table.card-mobile tbody tr td:last-child,
  table.card-mobile tfoot tr td:last-child { border-bottom: none; }
  table.card-mobile tbody td::before,
  table.card-mobile tfoot td::before {
    content: attr(data-label);
    color: #9aa0ab;
    font-size: 13px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    text-align: left;
    flex: 1 1 auto;
  }
  table.card-mobile tbody td:first-child,
  table.card-mobile tbody td:nth-child(2) { text-align: right; }
  /* Primera fila de cada card: destacar la etiqueta semana/mes */
  table.card-mobile tbody tr td:first-child {
    border-bottom: 1px solid #2a2d3a;
    padding-bottom: 10px;
    margin-bottom: 4px;
    font-size: 17px;
    color: #d8613c;
  }
  table.card-mobile tbody tr td:first-child::before { color: #9aa0ab; }
  /* Esconde celdas con colspan grande del tfoot (TOTAL row) en versión card */
  table.card-mobile tfoot td[colspan]:not([colspan="1"])::before { content: "TOTAL"; color: #d8613c; }

  /* === Clientes: tabla con columnas prioritarias === */
  table.cols-priority {
    font-size: 15px;
    width: 100%;
    table-layout: fixed;
  }
  table.cols-priority th:nth-child(2),
  table.cols-priority td:nth-child(2),
  table.cols-priority th:nth-child(3),
  table.cols-priority td:nth-child(3),
  table.cols-priority th:nth-child(4),
  table.cols-priority td:nth-child(4),
  table.cols-priority th:nth-child(6),
  table.cols-priority td:nth-child(6) { display: none; }
  table.cols-priority th:nth-child(1),
  table.cols-priority td:nth-child(1) {
    width: 65%;
    word-break: break-all;
    overflow-wrap: anywhere;
    white-space: normal;
    padding: 12px 8px;
  }
  table.cols-priority th:nth-child(5),
  table.cols-priority td:nth-child(5) {
    width: 35%;
    text-align: right;
    padding: 12px 8px;
  }

  /* === Filtros de Clientes: apilados === */
  .cliente-search {
    flex-direction: column;
    max-width: 100%;
    gap: 10px;
  }
  .cliente-search input,
  .cliente-search select,
  .cliente-search button { width: 100%; }

  /* Stats grid en móvil: 2 columnas en vez de 1 columna apilada */
  .stats { flex-direction: row; flex-wrap: wrap; }
  .stats .stat { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .stat-value { font-size: 18px; word-break: break-word; }
  .stat-label { font-size: 12px; }

  /* Ficha de cliente: evitar overflow horizontal */
  .cliente-card { overflow-x: hidden; }
  .cliente-card h2 { font-size: 20px; word-break: break-word; }
  .cliente-card .dim { word-break: break-word; }
  .cliente-header { flex-direction: column; align-items: flex-start !important; gap: 12px; }
  .cliente-header > div:last-child { text-align: left !important; }
  .fiscal-edit-grid { grid-template-columns: 1fr !important; }
  .fiscal-edit-grid input { width: 100%; box-sizing: border-box; }
  .pdf-link {
    display: inline-block;
    padding: 6px 14px;
    background: #d8613c;
    color: #1a1a1a !important;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none;
    font-size: 13px;
  }
  .groups-list { flex-wrap: wrap; }
}

/* === Section/subsection titles === */
.section-title {
  color: #e0e0e0;
  font-size: 18px;
  font-weight: 600;
  margin: 8px 0 14px;
  letter-spacing: -0.2px;
}
.subsection-title {
  color: #c0c4cc;
  font-size: 14px;
  font-weight: 600;
  margin: 22px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Clientes module === */
.cliente-search {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  max-width: 600px;
}
.cliente-search input {
  flex: 1;
  padding: 12px 16px;
  font-size: 16px;
  background: #1a1d24;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e0e0e0;
  font-family: inherit;
}
.cliente-search input:focus {
  outline: none;
  border-color: #d8613c;
}
.btn-primary {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 700;
  background: #d8613c;
  border: none;
  border-radius: 6px;
  color: #1a1a1a;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-primary:hover { background: #b8512f; }
.btn-secondary {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #c0c4cc;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: #d8613c; color: #d8613c; }
.origen-badge.origen-ads { background: rgba(255,211,89,0.18); color: #d8613c; }

.cliente-card {
  background: #15181f;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 24px;
}
.cliente-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #2a2f3a;
}
.cliente-section-title {
  color: #c0c4cc;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 24px 0 10px;
}
.origen-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: #2a2f3a;
  color: #c0c4cc;
}
.origen-badge.origen-ads { background: rgba(74,144,226,0.18); color: #6ab0f5; }
.origen-badge.origen-org { background: rgba(80,200,120,0.15); color: #80d09a; }
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge.status-active { background: rgba(80,200,120,0.15); color: #80d09a; }
.status-badge.status-inactive { background: rgba(220,80,80,0.15); color: #e88080; }
.groups-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.group-badge {
  display: inline-block;
  padding: 4px 10px;
  background: #1f232c;
  border: 1px solid #2a2f3a;
  border-radius: 4px;
  font-size: 12px;
  color: #c0c4cc;
}
.empty-state {
  text-align: center;
  padding: 40px;
  color: #6a6f7a;
  background: #15181f;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
}
.empty-state.err { color: #e88080; }
tr.inactive { opacity: 0.55; }

/* === Fiscal edit grid === */
.fiscal-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.fiscal-field-edit {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fiscal-field-edit label {
  font-size: 11px;
  color: #6a6f7a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.fiscal-field-edit input {
  padding: 8px 12px;
  font-size: 14px;
  background: #1a1d24;
  border: 1px solid #2a2f3a;
  border-radius: 4px;
  color: #e0e0e0;
  font-family: inherit;
}
.fiscal-field-edit input:focus {
  outline: none;
  border-color: #d8613c;
}

/* === Clientes table === */
.cliente-search select {
  padding: 12px 14px;
  font-size: 14px;
  background: #1a1d24;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e0e0e0;
  font-family: inherit;
}
.cliente-search select:focus { outline: none; border-color: #4a90e2; }
#clientesTable tr.clickable { cursor: pointer; transition: background 0.1s; }
#clientesTable tr.clickable:hover { background: #1f232c; }

/* ── Tabs alumnos ── */
.tab-btn {
  background: #1a1d27;
  border: 1px solid #2a2d3a;
  color: #6a6f7a;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}
.tab-btn:hover { border-color: #4a4f5a; color: #c0c4cf; }
.tab-btn.active { background: #2a2d3a; border-color: #6366f1; color: #fff; }
