/* ============================================
   Dashboard — Analytics Layout
   ============================================ */

.db-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.db-greeting {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 var(--space-1) 0;
  letter-spacing: -0.02em;
}

.db-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
}

.db-kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.db-kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: box-shadow var(--transition-fast);
}

.db-kpi-card:hover {
  box-shadow: var(--shadow-sm);
}

.db-kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.db-kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.db-kpi-icon--blue {
  background: rgba(37, 99, 235, 0.1);
  color: var(--blue-600);
}

.db-kpi-icon--green {
  background: rgba(22, 163, 74, 0.1);
  color: var(--green-600);
}

.db-kpi-icon--emerald {
  background: rgba(5, 150, 105, 0.1);
  color: #059669;
}

.db-kpi-icon--amber {
  background: rgba(217, 119, 6, 0.1);
  color: var(--amber-600);
}

.db-kpi-icon--red {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
}

.db-kpi-icon--purple {
  background: rgba(124, 58, 237, 0.1);
  color: #7c3aed;
}

.db-type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  vertical-align: middle;
  margin-right: 2px;
}

.db-type-venta {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
}

.db-type-compra {
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}

.db-kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.db-kpi-value {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.1;
  min-height: 2rem;
}

.db-kpi-sub {
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 1rem;
}

.db-sub-green { color: var(--green-600); font-weight: 500; }
.db-sub-amber { color: var(--amber-600); font-weight: 500; }
.db-sub-red { color: var(--red-600); font-weight: 500; }
.db-sub-muted { color: var(--text-secondary); }

.db-kpi-skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: db-shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
  width: 80px;
  height: 1.6rem;
}

.db-kpi-skeleton-sm {
  width: 120px;
  height: 0.8rem;
}

@keyframes db-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.db-mid-row {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.db-chart-card,
.db-recent-card,
.db-table-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.db-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-color);
}

.db-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.db-card-badge,
.db-card-year {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: 99px;
}

.db-see-all {
  font-size: 12px;
  color: var(--blue-600);
  text-decoration: none;
  font-weight: 500;
}

.db-see-all:hover { text-decoration: underline; }

.db-chart-body {
  padding: var(--space-5);
  height: 260px;
  position: relative;
}

.db-chart-body canvas {
  width: 100% !important;
  height: 100% !important;
}

.db-recent-list {
  overflow-y: auto;
  max-height: 320px;
}

.db-recent-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.db-recent-item:last-child { border-bottom: none; }
.db-recent-item:hover { background: var(--gray-50); }

.db-recent-dot {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.db-recent-dot.status-paid {
  background: #f0fdf4;
  color: #16a34a;
}

.db-recent-dot.status-unpaid {
  background: #fffbeb;
  color: #b45309;
}

.db-recent-dot.status-draft {
  background: #f3f4f6;
  color: #6b7280;
}

.db-recent-arrow {
  color: var(--gray-300);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  transition: color var(--transition-fast);
}

.db-recent-item:hover .db-recent-arrow { color: var(--gray-500); }

.db-recent-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.db-recent-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-recent-client {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-recent-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.db-recent-amount {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.db-recent-amount--pending { color: var(--red-600); }
.db-recent-amount--paid    { color: var(--green-600); }
:root[data-theme='dark'] .db-recent-amount--pending { color: #fca5a5; }
:root[data-theme='dark'] .db-recent-amount--paid    { color: #86efac; }

.db-recent-date {
  font-size: 11px;
  color: var(--text-secondary);
}

.db-table-card { margin-bottom: var(--space-4); }
.db-table-wrap { overflow-x: auto; }

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

.db-monitoring-table thead th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--gray-50);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.db-th-right { text-align: right !important; }
.db-monitoring-table thead th:first-child { padding-left: var(--space-5); }
.db-monitoring-table thead th:last-child { padding-right: var(--space-5); }

.db-table-row { cursor: pointer; }

.db-table-row td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
  transition: background var(--transition-fast);
}

.db-table-row:last-child td { border-bottom: none; }
.db-table-row:hover td { background: var(--gray-50); }

.db-table-row td:first-child { padding-left: var(--space-5); border-left: 3px solid transparent; }
.db-table-row td:last-child { padding-right: var(--space-5); }

/* row tint + border + number color by status */
.db-row--paid td    { background: rgba(22, 163, 74, 0.04); }
.db-row--unpaid td  { background: rgba(220, 38, 38, 0.04); }

.db-row--paid td:first-child    { border-left-color: var(--green-600); }
.db-row--unpaid td:first-child  { border-left-color: var(--red-600); }
.db-row--draft td:first-child   { border-left-color: var(--gray-400); }

.db-row--paid:hover td    { background: rgba(22, 163, 74, 0.09) !important; }
.db-row--unpaid:hover td  { background: rgba(220, 38, 38, 0.08) !important; }

.db-num--paid    { color: var(--green-600) !important; }
.db-num--unpaid  { color: var(--red-600)   !important; }
.db-num--draft   { color: var(--text-secondary) !important; }

.db-total--pos { color: var(--green-600); font-weight: 600; }
.db-total--neg { color: var(--red-600);   font-weight: 600; }
.db-table-row td.db-total--pos { color: var(--green-600); font-weight: 600; }
.db-table-row td.db-total--neg { color: var(--red-600);   font-weight: 600; }

:root[data-theme='dark'] .db-row--paid td    { background: rgba(34, 197, 94, 0.07); }
:root[data-theme='dark'] .db-row--unpaid td  { background: rgba(220, 38, 38, 0.07); }
:root[data-theme='dark'] .db-row--paid:hover td   { background: rgba(34, 197, 94, 0.13) !important; }
:root[data-theme='dark'] .db-row--unpaid:hover td { background: rgba(220, 38, 38, 0.12) !important; }
:root[data-theme='dark'] .db-row--paid td:first-child   { border-left-color: #86efac; }
:root[data-theme='dark'] .db-row--unpaid td:first-child { border-left-color: #fca5a5; }
:root[data-theme='dark'] .db-num--paid   { color: #86efac !important; }
:root[data-theme='dark'] .db-num--unpaid { color: #fca5a5 !important; }
:root[data-theme='dark'] .db-total--pos  { color: #86efac; }
:root[data-theme='dark'] .db-total--neg  { color: #fca5a5; }
:root[data-theme='dark'] .db-table-row td.db-total--pos { color: #86efac; }
:root[data-theme='dark'] .db-table-row td.db-total--neg { color: #fca5a5; }

.db-cell-num {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}

.db-cell-client {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-cell-right { text-align: right; }
.db-remain-due   { color: var(--red-600); font-weight: 600; }
.db-remain-ok    { color: var(--green-600); }
.db-remain-muted { color: var(--text-secondary); }

.db-date--overdue { color: var(--red-600);   font-weight: 600; }
.db-date--soon    { color: var(--amber-600); font-weight: 500; }

.db-table-loading {
  text-align: center;
  padding: var(--space-8) !important;
  color: var(--text-secondary);
  font-size: 13px;
}

.db-loading-inner,
.db-no-data,
.db-error {
  text-align: center;
  padding: var(--space-6);
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0;
}

.db-error { color: var(--red-600); }
.db-td-center { text-align: center; }

.db-recent-skeleton { pointer-events: none; }

.db-skel-icon,
.db-skel-lines span,
.db-skel-right span {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: db-shimmer 1.4s infinite;
}

.db-skel-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.db-skel-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.db-skel-lines span {
  display: block;
  height: 10px;
  border-radius: var(--radius-sm);
}

.db-skel-lines span:first-child { width: 70%; }
.db-skel-lines span:last-child { width: 50%; }

.db-skel-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.db-skel-right span {
  display: block;
  height: 10px;
  border-radius: var(--radius-sm);
}

.db-skel-right span:first-child { width: 60px; }
.db-skel-right span:last-child { width: 44px; }

@media (max-width: 1400px) {
  .db-kpi-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1100px) {
  .db-kpi-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .db-mid-row { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .db-kpi-row { grid-template-columns: 1fr; }
  .db-greeting { font-size: 1.1rem; }
}

/* ── Large / Presentation Displays ── */
@media (min-width: 1600px) {
  .db-kpi-row {
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-6);
  }
  .db-kpi-value { font-size: 2rem; }
  .db-kpi-label { font-size: 12px; }
  .db-greeting { font-size: 1.75rem; }
  .db-subtitle { font-size: 15px; }
  .db-card-title { font-size: 15px; }
  .db-chart-body { height: 340px; }
  .db-recent-list { max-height: 400px; }
  .dashboard-subtitle { font-size: 15px; }
}

@media (min-width: 2200px) {
  .db-kpi-value { font-size: 2.5rem; }
  .db-greeting { font-size: 2rem; }
  .db-kpi-card { padding: var(--space-6); }
  .db-card-header { padding: var(--space-5) var(--space-6); }
  .db-chart-body { height: 420px; }
}

.dashboard-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin: var(--space-1) 0 0 0;
}

/* Logout button with icon */
.logout-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background-color: transparent;
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
}

.logout-button:hover {
  color: var(--danger);
  border-color: var(--danger);
  background-color: var(--red-50);
}

.logout-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.logout-button svg {
  flex-shrink: 0;
}

/* Dark mode UX tune */
:root[data-theme='dark'] .db-kpi-card,
:root[data-theme='dark'] .db-chart-card,
:root[data-theme='dark'] .db-recent-card,
:root[data-theme='dark'] .db-table-card {
  background: #081226;
  border-color: #1e2f4d;
}

:root[data-theme='dark'] .db-card-year,
:root[data-theme='dark'] .db-card-badge,
:root[data-theme='dark'] .db-kpi-icon {
  background: rgba(30, 41, 59, 0.8);
}

:root[data-theme='dark'] .db-recent-item,
:root[data-theme='dark'] .db-table-row td {
  background: transparent;
}

:root[data-theme='dark'] .db-recent-item:hover,
:root[data-theme='dark'] .db-table-row:hover td {
  background: rgba(30, 58, 110, 0.24);
}

:root[data-theme='dark'] .db-recent-dot.status-paid {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

:root[data-theme='dark'] .db-recent-dot.status-unpaid {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

:root[data-theme='dark'] .db-recent-dot.status-draft {
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
}

:root[data-theme='dark'] .db-kpi-icon--blue {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}

:root[data-theme='dark'] .db-kpi-icon--green {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

:root[data-theme='dark'] .db-kpi-icon--emerald {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

:root[data-theme='dark'] .db-kpi-icon--amber {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

:root[data-theme='dark'] .db-kpi-icon--red {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

:root[data-theme='dark'] .db-kpi-icon--purple {
  background: rgba(167, 139, 250, 0.15);
  color: #c4b5fd;
}

:root[data-theme='dark'] .logout-button {
  background-color: transparent;
  border-color: rgba(148, 163, 184, 0.2);
}

:root[data-theme='dark'] .logout-button:hover {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}
