/* =========================================================
   V3 — Dashboard CSS
   Ordenado por:
   1) Tokens
   2) Reset / base
   3) Layout
   4) Forms / buttons
   5) Components
   6) Tables
   7) Continuidad / estados
   8) Responsive
========================================================= */

/* =========================================================
   1) TOKENS
========================================================= */

:root {
  /* surfaces */
  --bg: #fda4c7;
  --surface: #f8deeb;
  --surface-2: #fffaf6;
  --border: #fffaf6;

  /* text */
  --text: #1c1c1c;
  --muted: #666f7c;
  --link: #f8deeb;

  /* brand */
  --primary: #f43175;
  --primary-hover: #c91554;

  /* semantic */
  --success: #22c55e;
  --success-dark: #16a34a;
  --danger: #e53935;
  --danger-dark: #c62828;
  --warn: #facc15;
  --info: #34b7f1;
  --neutral: #94a3b8;
  --accent: #d946ef;

  /* misc */
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-xl: 999px;

  --space-1: 6px;
  --space-2: 8px;
  --space-3: 10px;
  --space-4: 12px;
  --space-5: 14px;

  --font-xs: 11px;
  --font-sm: 12px;
  --font-md: 14px;
  --font-lg: 16px;

  --transition: background-color .05s ease, color .05s ease, border-color .05s ease, box-shadow .05s ease, transform .05s ease;
}

[data-theme="dark"] {
  --bg: #5b5b5b;
  --surface: #5c626b;
  --surface-2: #40444b;
  --border: #6c7075;

  --text: #f3f4f6;
  --muted: #cbd5e1;
  --link: #f3f4f6;

  --primary: #f43175;
  --primary-hover: #e11d68;

  --success: #22c55e;
  --success-dark: #16a34a;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --warn: #facc15;
  --info: #34b7f1;
  --neutral: #94a3b8;
  --accent: #d946ef;

  --shadow: 0px 5px 10px rgba(0, 0, 0, 0.35)
}

/* =========================================================
   2) RESET / BASE
========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 14px;
  font-family: system-ui, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a,
button,
input,
select,
textarea,
div,
span,
.card,
.box,
.pill {
  transition: var(--transition);
}

a {
  color: var(--link);
  text-decoration: none;
}

[data-theme="dark"] a {
    color: var(--link);
}

button {
  cursor: pointer;
  font: inherit;
}

input,
select,
textarea,
button {
  font: inherit;
}

input::placeholder {
  color: var(--surface);
  font-style: italic;
  font-size: var(--font-xs);
  opacity: 1;
}

/* =========================================================
   3) LAYOUT
========================================================= */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.box,
.card,
.tablewrap,
.rank-wrap {
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.card {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.tablewrap,
.rank-wrap {
  overflow: auto;
  border-radius: var(--radius-md);
}

.switch-box,
.cont-actions,
.actions,
.chips,
.heat-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.actions {
  justify-content: flex-end;
  margin-top: var(--space-3);
}

.chips {
  justify-content: center;
}

/* =========================================================
   4) FORMS / BUTTONS
========================================================= */

input,
select,
textarea,
button,
.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
}

input,
select,
textarea {
  background: var(--surface-2);
  color: var(--txt);
}

input::placeholder {
    color: var(--neutral);
}

button,
.btn {
  background: var(--primary);
  color: var(--surface);
  font-size: var(--font-md);
}

[data-theme="dark"] button,
[data-theme="dark"] .btn {
    color: #fff;
}

button:hover,
.btn:hover {
  background: var(--primary-hover);
}

.btn-accept,
.btn-reject {
  border-radius: var(--radius-xl);
  padding: 6px 10px;
  font-size: var(--font-sm);
}

.btn-accept {
  background: var(--success);
  color: var(--text);
}

.btn-accept:hover {
  background: var(--success-dark);
}

.btn-reject {
  background: var(--danger);
  color: #fff;
}

.btn-reject:hover {
  background: var(--danger-dark);
}

.danger {
  border-color: #7a2730;
}

/* =========================================================
   5) COMPONENTS
========================================================= */

.muted {
  color: var(--muted);
  margin-bottom: var(--space-3);
}

.pill,
.badge {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  font-size: var(--font-sm);
}

.pill {
  padding: 5px 10px;
  background: var(--primary);
  color: var(--surface);
  vertical-align: middle;
}

[data-theme="dark"] .pill {
    color: #fff;
}

.pill a {
  display: inline-block;
}

.pill-ok {
  background: var(--success);
  border-color: var(--success-dark);
  color: var(--text);
}

.pill-rejected {
  background: var(--danger);
  border-color: var(--danger-dark);
  color: var(--text);
}

.pill.is-active {
  background: var(--primary-hover);
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18) inset;
  font-weight: 900;
}

.badge {
  padding: 2px 8px;
  background: var(--surface-2);
  font-size: var(--font-xs);
  font-weight: 800;
}

.kpis {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.box.kpi {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 90px;
}

.kpiN {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: .5px;
  text-align: center;
}

.card .title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.kv {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 5px 6px;
  font-size: var(--font-xs);
}

.kv div:nth-child(odd) {
  color: var(--muted);
}

/* =========================================================
   6) TABLES
========================================================= */

table,
.rank-table {
  width: 100%;
  border-collapse: collapse;
}

th,
td,
.rank-table th,
.rank-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  vertical-align: top;
}

th {
  color: #b9c7d8;
  text-align: left;
}

[data-theme="dark"] th {
    color: var(--mut);
}

.rank-table th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  font-size: var(--font-xs);
}

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

.rank-table td.num {
  font-weight: 800;
}

tbody tr:hover,
.rank-table tbody tr:hover {
  background: var(--muted);
  color: var(--surface);
}

[data-theme="dark"] tbody tr:hover,
[data-theme="dark"] .rank-table tbody tr:hover {
    background: #fda4c7;
    color: var(--txt);
}

/* =========================================================
   7) CONTINUIDAD / ESTADOS
========================================================= */

.dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid var(--border);
  border-radius: 50%;
  vertical-align: middle;
}

.dot.green { background: var(--success); }
.dot.yellow { background: var(--warn); }
.dot.gray { background: var(--neutral); }
.dot.red { background: var(--danger); }
.dot.blue { background: var(--info); }

/* doble check estilo WhatsApp */
.checks {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--font-lg);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -2px;
}

.checks.blue { color: var(--info); }
.checks.gray { color: var(--neutral); }
.checks.magenta { color: var(--accent); }

/* switch */
.switch,
.theme-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.theme-switch {
  width: 64px;
  height: 34px;
}

.switch input,
.theme-switch input,
.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.slider,
.theme-toggle-ui {
  position: absolute;
  inset: 0;
  cursor: pointer;
  border-radius: 999px;
}

/* switch simple */
.slider {
  background: #ccc;
}

.slider::before {
  content: "";
  position: absolute;
  left: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  transition: .05s ease;
}

.switch input:checked + .slider {
  background: #25D366;
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

/* switch visual de tema */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.theme-toggle-ui {
  background: linear-gradient(135deg, #ffd36b, #f43175);
  box-shadow: inset 0 1px 3px rgba(255,255,255,.15), 0 4px 12px rgba(0,0,0,.18);
  position: relative;
  width: 64px;
  height: 34px;
  border-radius: 999px;
  transition: all .05s ease;
}

[data-theme="dark"] .theme-toggle-ui {
  background: linear-gradient(135deg, #2a2f3a, #111827);
}

.theme-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  font-size: 14px;
  line-height: 1;
  pointer-events: none;
}

.theme-icon.sun { left: 10px; }
.theme-icon.moon { right: 10px; }

.theme-knob {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 2;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.22);
  transition: transform .05s ease, background .05s ease;
}

#themeToggle:checked + .theme-toggle-ui .theme-knob {
  transform: translateX(30px);
}

[data-theme="dark"] .theme-knob {
  background: #e5e7eb;
}

/* heatmap */
.heatwrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.heat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12px, 12px));
  align-content: start;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.cell {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.20);
  transform: translateZ(0);
}

.cell:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px rgba(255,255,255,.35);
}

.c-green { background: var(--success); }
.c-red { background: var(--danger); }
.c-yellow { background: var(--warn); }
.c-gray { background: var(--neutral); }

.heat-note {
  font-size: var(--font-sm);
  color: var(--muted);
}

/* =========================================================
   8) RESPONSIVE
========================================================= */

@media (min-width: 720px) {
  .kpis {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 720px) {
  table thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
  }

  tr {
    margin: 10px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
  }

  td {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0;
    border: none;
  }

  td::before {
    content: attr(data-label);
    color: var(--txt);
    font-weight: 600;
  }
}

@media (max-width: 520px) {
  .heat-grid {
    grid-template-columns: repeat(auto-fit, minmax(16px, 16px));
    gap: 8px;
  }

  .cell {
    width: 16px;
    height: 16px;
    border-radius: 5px;
  }
}