/* ═══════════════════════════════════════════
   Cards & Components
═══════════════════════════════════════════ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.card > * {
  min-width: 0;
  max-width: 100%;
}

.card-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 6px;
  overflow-wrap: break-word;
}

.card-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.25;
  overflow-wrap: break-word;
}

.card-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  overflow-wrap: break-word;
}

.card.danger .card-value { color: var(--danger); }
.card.warning .card-value { color: var(--warning); }
.card.success .card-value { color: var(--success); }

/* Icon-style KPI cards (resumen.js, analisis.js): label+value+trend on the
   left in .card-info, icon on the right — needs a row layout instead of the
   default stacked card, and truncates instead of wrapping since the icon
   constrains the available width. */
.card:has(.card-icon) {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px;
}

.card-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.card-info .card-label,
.card-info .card-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-info .card-label {
  font-size: 14px;
  margin-bottom: 8px;
}

.card-info .card-value {
  font-size: 28px;
  line-height: 1.2;
}

.card-trend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
}

.card-trend.up { color: var(--success); }
.card-trend.down { color: var(--danger); }

.card-trend-icon { font-size: 16px; }

.card-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

/* Colores DashStack (Pastel backgrounds) */
.card-blue .card-icon { background-color: rgba(67, 121, 238, 0.1); color: #4379EE; }
.card-orange .card-icon { background-color: rgba(255, 149, 0, 0.1); color: #FF9500; }
.card-green .card-icon { background-color: rgba(34, 197, 94, 0.1); color: #22C55E; }
.card-red .card-icon { background-color: rgba(239, 95, 95, 0.1); color: #EF5F5F; }

.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.chart-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.chart-block-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 24px;
}

.chart-canvas {
  width: 100%;
  height: 220px;
}

.chart-canvas-tall {
  height: 260px;
}

.donut-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 10px 4px 2px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.block-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 12px;
  border-bottom: 2px solid var(--border);
  font-weight: 700;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-soft);
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.table tr:hover td {
  background: rgba(0, 0, 0, 0.015);
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

.table .badge.success {
  background: var(--success-soft);
  color: var(--success);
}

.table .badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.table .badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.table .badge.muted {
  background: var(--bg-hover);
  color: #000;
}

/* Alerts list */
.alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  background: #fff;
  border-left: 4px solid var(--warning);
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 13px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.alert-item.danger {
  border-left-color: var(--danger);
  background: #fff5f5;
}

.alert-item.warning {
  border-left-color: var(--warning);
  background: #fffcf0;
}

.alert-item.success {
  border-left-color: var(--success);
  background: var(--success-soft);
}

/* Password field with toggle */
.field-password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.field-password-wrapper input {
  flex: 1;
  padding-right: 40px;
}

.btn-toggle-pass {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-toggle-pass:hover {
  color: #000;
}

/* Buttons */
.btn-primary {
  background: var(--arrenda-teal);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--arrenda-deep);
}

.btn-big {
  padding: 16px 24px;
  font-size: 14px;
}

.btn-row-quick {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

/* Welcome */
.welcome {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-card {
  background: var(--bg);
  padding: 40px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 400px;
}

/* Hamburger (mobile) */
.btn-menu {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  width: 40px;
  height: 40px;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.btn-menu span {
  display: block;
  width: 24px;
  height: 2px;
  background: #000;
}

@media (max-width: 768px) {
  .btn-menu {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 200;
  }

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

  /* FORZAR full-width en mobile — el sidebar position:fixed no debe contabilizar espacio */
  .sidebar {
    width: 240px; /* explicit, no usar var */
    flex: 0 0 auto;
  }

  .app-layout,
  .main-area,
  .content {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .content > .block {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

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

  .cards {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  .cards > .card {
    flex: 0 0 calc(50% - 5px) !important;
    width: calc(50% - 5px) !important;
    max-width: calc(50% - 5px) !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
}

@media (max-width: 480px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

.brand-logo {
  height: 56px;
  width: auto;
  display: block;
}

@media (max-width: 768px) {
  .brand-logo {
    height: 44px;
  }

  .header {
    padding: 8px 12px;
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .brand-logo {
    height: 36px;
  }

  .header {
    padding: 6px 10px;
    gap: 8px;
  }
}

.status-item.ok {
  color: var(--success);
}

.status-item.warn {
  color: var(--warning);
}

.status-item.error {
  color: var(--danger);
}

/* Tabs (en linea con el logo) */
.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1 1 auto;
  min-width: 0;
  scrollbar-width: thin;
}

.tabs::-webkit-scrollbar {
  height: 4px;
}

.tabs::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 2px;
}

@media (max-width: 768px) {
  .status {
    gap: 8px;
    font-size: 11px;
  }
}

/* Content */
.content {
  padding: 24px;
}

.content h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.content h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 20px 0 12px;
}

/* Section blocks */
.block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
  max-width: 100%;
}

.block-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-soft);
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.table tr:hover td {
  background: var(--bg-soft);
}

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

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.table .badge.success {
  background: var(--success-soft);
  color: var(--success);
}

.table .badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.table .badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.table .badge.muted {
  background: var(--bg-hover);
  color: var(--text-soft);
}

/* Responsive table scroll — aplicado via JS en renderView() */
.table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  /* contain: el padre no toma el tamaño intrínseco de la tabla */
  contain: inline-size;
}

.table-wrap .table {
  min-width: 500px; /* fuerza scroll si la pantalla es más angosta */
}

.table-wrap .table th,
.table-wrap .table td {
  white-space: nowrap;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

