/* Base */
:root {
  --z-bg: #f6f7fb;
  --z-surface: #ffffff;
  --z-surface-2: #f1f5f9;
  --z-border: #e5e7eb;
  --z-text: #0f172a;
  --z-muted: #64748b;
  --z-brand: #4f46e5;
  --z-brand-weak: #eef2ff;
  --z-brand-accent: #38bdf8;
  --z-brand-text: #ffffff;
  --z-sidebar-w: 16rem; /* 256px */
  --z-topbar-h: 3.75rem; /* 60px */
  --z-scroll-track: rgba(15, 23, 42, 0.08);
  --z-scroll-thumb: rgba(15, 23, 42, 0.28);
}

body {
  font-family: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
}

body.theme-light {
  background-color: var(--z-bg);
  color: var(--z-text);
}

body.theme-dark {
  --z-bg: #0b1220;
  --z-surface: #0f172a;
  --z-surface-2: #111827;
  --z-border: #1f2937;
  --z-text: #e2e8f0;
  --z-muted: #cbd5e1;
  --z-muted-2: #94a3b8;
  --z-brand: #6366f1;
  --z-brand-weak: rgba(99, 102, 241, 0.16);
  --z-brand-accent: #22d3ee;
  --z-brand-text: #ffffff;
  --z-scroll-track: rgba(148, 163, 184, 0.16);
  --z-scroll-thumb: rgba(148, 163, 184, 0.5);

  background-color: var(--z-bg);
  color: var(--z-text);
}

/* Sidebar en light mode (clara) */
body.theme-light aside {
  background-color: var(--z-surface) !important;
  border-color: var(--z-border) !important;
  color: var(--z-text);
}

body.theme-light aside .text-slate-100,
body.theme-light aside .text-slate-200,
body.theme-light aside .text-slate-300 {
  color: var(--z-text) !important;
}

body.theme-light aside .text-slate-400,
body.theme-light aside .text-slate-500 {
  color: var(--z-muted) !important;
}

body.theme-light aside .border-slate-800,
body.theme-light aside .border-slate-700 {
  border-color: var(--z-border) !important;
}

body.theme-light aside .bg-slate-900 {
  background-color: var(--z-brand-weak) !important;
  color: #4338ca !important;
}

body.theme-light aside button:hover {
  background-color: #f1f5f9 !important;
}

body.theme-light aside .rounded-full {
  background-color: var(--z-surface-2);
  color: var(--z-text);
  border-color: var(--z-border);
}

body.theme-light .brand-mark {
  background-color: var(--z-brand) !important;
  color: #ffffff !important;
  border-color: rgba(79, 70, 229, 0.9) !important;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.22);
}

/* Main / topbar en light mode */
body.theme-light main {
  background-color: var(--z-bg);
}

body.theme-light header {
  background-color: var(--z-surface) !important;
  border-color: var(--z-border) !important;
}

body.theme-light header .text-slate-100,
body.theme-light header .text-slate-200,
body.theme-light header .text-slate-300 {
  color: var(--z-text) !important;
}

body.theme-light header .text-slate-400,
body.theme-light header .text-slate-500 {
  color: var(--z-muted) !important;
}

body.theme-light header .bg-slate-900,
body.theme-light header .bg-slate-950 {
  background-color: var(--z-surface-2) !important;
  border-color: var(--z-border) !important;
  color: var(--z-text) !important;
}

body.theme-light .bg-brand {
  background-color: var(--z-brand) !important;
  color: var(--z-brand-text) !important;
}

/* Sidebar / header en dark mode */
body.theme-dark aside {
  background-color: var(--z-surface) !important;
  border-color: var(--z-border) !important;
  color: var(--z-text);
}

body.theme-dark aside .text-slate-100,
body.theme-dark aside .text-slate-200,
body.theme-dark aside .text-slate-300 {
  color: var(--z-text) !important;
}

body.theme-dark aside .text-slate-400,
body.theme-dark aside .text-slate-500 {
  color: var(--z-muted) !important;
}

body.theme-dark aside .border-slate-800,
body.theme-dark aside .border-slate-700 {
  border-color: var(--z-border) !important;
}

body.theme-dark aside .bg-slate-900 {
  background-color: var(--z-brand-weak) !important;
  color: #e0e7ff !important;
}

body.theme-dark aside button:hover,
body.theme-dark aside button:focus-visible {
  background-color: rgba(99, 102, 241, 0.18) !important;
  border-color: rgba(99, 102, 241, 0.35) !important;
}

body.theme-dark aside button:hover span,
body.theme-dark aside button:hover svg,
body.theme-dark aside button:focus-visible span,
body.theme-dark aside button:focus-visible svg {
  color: #e0e7ff !important;
}

body.theme-dark aside .rounded-full {
  background-color: var(--z-surface-2);
  color: var(--z-text);
  border-color: var(--z-border);
}

body.theme-dark main {
  background-color: var(--z-bg);
}

body.theme-dark header {
  background-color: var(--z-surface) !important;
  border-color: var(--z-border) !important;
}

body.theme-dark header .text-slate-100,
body.theme-dark header .text-slate-200,
body.theme-dark header .text-slate-300 {
  color: var(--z-text) !important;
}

body.theme-dark header .text-slate-400,
body.theme-dark header .text-slate-500 {
  color: var(--z-muted) !important;
}

body.theme-dark header .bg-slate-900,
body.theme-dark header .bg-slate-950 {
  background-color: var(--z-surface-2) !important;
  border-color: var(--z-border) !important;
  color: var(--z-text) !important;
}

body.theme-dark .bg-brand {
  background-color: var(--z-brand) !important;
  color: var(--z-brand-text) !important;
}

/* =========================
   Topbar icon buttons
   ========================= */
.top-icon-btn {
  position: relative;
  height: 40px;
  width: 40px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.top-icon-btn:hover {
  border-color: rgba(99, 102, 241, 0.7);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

body.theme-light .top-icon-btn {
  background: #ffffff;
  color: #0f172a;
  border-color: rgba(226, 232, 240, 0.9);
}

body.theme-light .top-icon-btn:hover {
  border-color: rgba(79, 70, 229, 0.6);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* =========================
   Auth (Signin)
   ========================= */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f8fafc;
  color: #0f172a;
}

.auth-left {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: #ffffff;
}

.auth-left-inner {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand-badge {
  height: 40px;
  width: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--z-brand-weak);
  color: var(--z-brand);
  border: 1px solid rgba(79, 70, 229, 0.3);
}

.auth-brand-badge.auth-brand-badge-solid {
  background: rgba(99, 102, 241, 0.2);
  color: #e2e8f0;
  border-color: rgba(99, 102, 241, 0.4);
}

.auth-brand-title {
  font-size: 15px;
  font-weight: 700;
}

.auth-brand-sub {
  font-size: 12px;
  color: #64748b;
}

.auth-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-subtitle {
  font-size: 13px;
  color: #64748b;
}

.auth-social {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auth-social-btn {
  height: 40px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.auth-social-icon {
  height: 22px;
  width: 22px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #0f172a;
}

.auth-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 600;
}

.auth-sep::before,
.auth-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field label {
  font-size: 11px;
  color: #475569;
  font-weight: 600;
}

.auth-field input {
  height: 42px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  padding: 0 12px;
  font-size: 12px;
  background: #ffffff;
  color: #0f172a;
}

.auth-field input:focus {
  outline: none;
  border-color: rgba(79, 70, 229, 0.6);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.auth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
}

.auth-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #475569;
}

.auth-link {
  border: none;
  background: none;
  color: #4f46e5;
  font-weight: 600;
  cursor: pointer;
  font-size: 11px;
}

.auth-primary {
  height: 42px;
  border-radius: 10px;
  border: none;
  background: var(--z-brand);
  color: var(--z-brand-text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.auth-secondary {
  height: 40px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #0f172a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.auth-msg {
  font-size: 11px;
  padding: 8px 10px;
  border-radius: 8px;
}

.auth-msg-error {
  background: #fee2e2;
  color: #991b1b;
}

.auth-msg-success {
  background: #dcfce7;
  color: #166534;
}

.auth-right {
  position: relative;
  background: #0f1640;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.auth-right-inner {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-right-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 2;
}

.auth-right-title {
  font-size: 20px;
  font-weight: 700;
}

.auth-right-sub {
  font-size: 12px;
  color: rgba(226, 232, 240, 0.7);
}

.auth-right-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: 0.6;
}

@media (max-width: 980px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }
  .auth-right {
    display: none;
  }
}

/* =========================
   Datepicker (custom)
   ========================= */
.z-datepicker {
  position: fixed;
  z-index: 25;
  width: 17rem;
  border: 1px solid var(--z-border);
  background: var(--z-surface);
  color: var(--z-text);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  padding: 10px;
}

.z-datepicker.hidden {
  display: none;
}

.zdp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.zdp-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--z-text);
}

.zdp-nav {
  height: 30px;
  width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--z-border);
  background: var(--z-surface-2);
  color: var(--z-text);
}

.zdp-nav svg {
  height: 16px;
  width: 16px;
}

.zdp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.zdp-dow {
  font-size: 10px;
  color: var(--z-muted);
  text-align: center;
  padding: 2px 0;
}

.zdp-days {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.zdp-day {
  height: 28px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--z-text);
  font-size: 11px;
  text-align: center;
  cursor: pointer;
}

.zdp-day:hover {
  background: var(--z-brand-weak);
  border-color: var(--z-brand);
}

.zdp-day.zdp-today {
  border-color: var(--z-brand);
}

.zdp-day.zdp-selected {
  background: var(--z-brand);
  color: var(--z-brand-text);
  border-color: var(--z-brand);
}

.zdp-day.zdp-out {
  opacity: 0.25;
  cursor: default;
}

/* Dashboard empleados: hover legible en dark mode */
body.theme-dark #dash-table-emps tr:hover {
  background-color: rgba(99, 102, 241, 0.14) !important;
}

body.theme-dark #dash-table-emps tr:hover td,
body.theme-dark #dash-table-emps tr:hover .text-slate-500,
body.theme-dark #dash-table-emps tr:hover .text-slate-600,
body.theme-dark #dash-table-emps tr:hover .text-slate-700 {
  color: #e0e7ff !important;
}

body.theme-dark #dash-table-emps tr:hover .text-slate-400 {
  color: #c7d2fe !important;
}

/* Attendance: hover legible en dark mode */
body.theme-dark #attendance-body tr:hover {
  background-color: #111827 !important;
}

body.theme-dark #attendance-body tr:hover td {
  color: #e2e8f0 !important;
}

body.theme-dark #attendance-body tr:hover .text-slate-400 {
  color: #cbd5e1 !important;
}

/* Employees: hover legible en dark mode */
body.theme-dark #employees-table-body tr:hover {
  background-color: rgba(99, 102, 241, 0.14) !important;
}

body.theme-dark #employees-table-body tr:hover td {
  color: #e0e7ff !important;
}

body.theme-dark #employees-table-body tr:hover .text-slate-400 {
  color: #c7d2fe !important;
}

/* Nomina: hover legible en dark mode */
body.theme-dark #trend-chips button:hover,
body.theme-dark #trend-chips button:focus-visible {
  background-color: rgba(99, 102, 241, 0.22) !important;
  border-color: rgba(99, 102, 241, 0.55) !important;
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25) inset;
}

body.theme-dark #trend-chips button:hover .text-slate-500,
body.theme-dark #trend-chips button:hover .text-slate-400,
body.theme-dark #trend-chips button:focus-visible .text-slate-500,
body.theme-dark #trend-chips button:focus-visible .text-slate-400 {
  color: #c7d2fe !important;
}

body.theme-dark #closed-tbody .open-closed-run:hover,
body.theme-dark #closed-tbody .open-closed-run:focus-visible {
  background-color: rgba(99, 102, 241, 0.22) !important;
  border-color: rgba(99, 102, 241, 0.6) !important;
  color: #e0e7ff !important;
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25) inset;
}

/* App shell layout: fixed sidebar + topbar */
#app-shell > .flex {
  min-height: 100vh;
}

#app-shell aside {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--z-sidebar-w);
  height: 100vh;
  z-index: 40;
}

#app-shell aside nav {
  overflow-y: auto;
}

#app-shell aside .sidebar-footer {
  margin-top: auto;
}

#app-shell main {
  margin-left: var(--z-sidebar-w);
  width: calc(100% - var(--z-sidebar-w));
  min-height: 100vh;
}

#app-shell main > header {
  position: fixed;
  top: 0;
  left: var(--z-sidebar-w);
  right: 0;
  height: var(--z-topbar-h);
  z-index: 30;
}

#app-shell main > section {
  height: calc(100vh - var(--z-topbar-h));
  margin-top: var(--z-topbar-h);
  overflow-y: auto;
}

.topbar-sidebar-toggle {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 1024px) {
  .topbar-sidebar-toggle {
    display: inline-flex;
  }

  #app-shell aside {
    width: min(86vw, 18rem);
    transform: translateX(-100%);
    transition: transform 220ms ease;
    z-index: 60;
  }

  #app-shell main {
    margin-left: 0;
    width: 100%;
  }

  #app-shell main > header {
    left: 0;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  body.sidebar-open #app-shell aside {
    transform: translateX(0);
    box-shadow: 0 18px 36px rgba(2, 6, 23, 0.35);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.5);
    z-index: 50;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }
}

@media (max-width: 640px) {
  #header-org-select {
    min-width: 150px !important;
    max-width: 62vw;
  }

  #app-shell main > header {
    gap: 0.5rem;
  }
}

/* Dark mode normalization for Tailwind utility colors */
body.theme-dark .bg-white {
  background-color: var(--z-surface) !important;
}
body.theme-dark .bg-slate-50 {
  background-color: var(--z-surface-2) !important;
}
body.theme-dark .bg-slate-100 {
  background-color: #0b1325 !important;
}
body.theme-dark .text-slate-900,
body.theme-dark .text-slate-800 {
  color: var(--z-text) !important;
}
body.theme-dark .text-slate-700,
body.theme-dark .text-slate-600 {
  color: var(--z-muted) !important;
}
body.theme-dark .text-slate-500,
body.theme-dark .text-slate-400 {
  color: var(--z-muted-2) !important;
}
body.theme-dark .text-slate-300,
body.theme-dark .text-slate-200 {
  color: #e2e8f0 !important;
}
body.theme-dark .border-slate-200,
body.theme-dark .border-slate-300,
body.theme-dark .border-slate-400 {
  border-color: var(--z-border) !important;
}
body.theme-dark .divide-slate-200 > :not([hidden]) ~ :not([hidden]),
body.theme-dark .divide-slate-300 > :not([hidden]) ~ :not([hidden]) {
  border-color: var(--z-border) !important;
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea {
  background-color: var(--z-surface-2);
  color: var(--z-text);
  border-color: var(--z-border);
}

/* Scrollbar themed (light + dark) */
.scrollbar-themed {
  scrollbar-color: var(--z-scroll-thumb) var(--z-scroll-track);
  scrollbar-width: thin;
}

.scrollbar-themed::-webkit-scrollbar {
  width: 8px;
}

.scrollbar-themed::-webkit-scrollbar-track {
  background: var(--z-scroll-track);
  border-radius: 999px;
}

.scrollbar-themed::-webkit-scrollbar-thumb {
  background: var(--z-scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* ApexCharts (tendencia) - mejorar contraste en dark mode */
body.theme-dark .apexcharts-text,
body.theme-dark .apexcharts-xaxis text,
body.theme-dark .apexcharts-yaxis text,
body.theme-dark .apexcharts-xaxis-title text,
body.theme-dark .apexcharts-yaxis-title text,
body.theme-dark .apexcharts-legend-text {
  fill: #e2e8f0 !important;
}
body.theme-dark .apexcharts-gridline {
  stroke: rgba(148, 163, 184, 0.35) !important;
}
body.theme-dark #dash-cost-chart .apexcharts-datalabel,
body.theme-dark #dash-cost-chart .apexcharts-datalabels text,
body.theme-dark #dash-cost-day-chart .apexcharts-datalabel,
body.theme-dark #dash-cost-day-chart .apexcharts-datalabels text {
  fill: #e2e8f0 !important;
  stroke: rgba(2, 6, 23, 0.95);
  stroke-width: 3px;
  paint-order: stroke;
}

/* Dashboard charts (Costos): labels visibles en light mode */
body.theme-light #dash-cost-chart .apexcharts-text,
body.theme-light #dash-cost-chart .apexcharts-xaxis text,
body.theme-light #dash-cost-chart .apexcharts-yaxis text,
body.theme-light #dash-cost-day-chart .apexcharts-text,
body.theme-light #dash-cost-day-chart .apexcharts-xaxis text,
body.theme-light #dash-cost-day-chart .apexcharts-yaxis text {
  fill: #0f172a !important;
}

body.theme-light #dash-cost-chart .apexcharts-datalabel,
body.theme-light #dash-cost-chart .apexcharts-datalabels text,
body.theme-light #dash-cost-day-chart .apexcharts-datalabel,
body.theme-light #dash-cost-day-chart .apexcharts-datalabels text {
  fill: #0f172a !important;
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 3px;
  paint-order: stroke;
}

/* Dashboard charts (Costos): labels visibles en dark mode */
body.theme-dark #dash-cost-chart .apexcharts-text,
body.theme-dark #dash-cost-chart .apexcharts-xaxis text,
body.theme-dark #dash-cost-chart .apexcharts-yaxis text,
body.theme-dark #dash-cost-day-chart .apexcharts-text,
body.theme-dark #dash-cost-day-chart .apexcharts-xaxis text,
body.theme-dark #dash-cost-day-chart .apexcharts-yaxis text {
  fill: #e2e8f0 !important;
}

/* Helpers */
.hidden { display: none !important; }

/* Theme switch */
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--z-border);
  background: var(--z-surface-2);
  color: var(--z-text);
  font-size: 11px;
  line-height: 1;
}

.theme-switch .switch-track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #e2e8f0;
  border: 1px solid var(--z-border);
  display: inline-block;
}

.theme-switch .switch-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
  transition: transform .2s ease, background .2s ease;
}

.theme-switch--sm {
  padding: 4px;
}

.theme-switch--sm .switch-track {
  width: 32px;
  height: 18px;
}

.theme-switch--sm .switch-thumb {
  width: 14px;
  height: 14px;
}

body.theme-dark .theme-switch .switch-track {
  background: var(--z-brand);
  border-color: var(--z-brand);
}

body.theme-dark .theme-switch .switch-thumb {
  transform: translateX(16px);
  background: #0f172a;
}

body.theme-dark .theme-switch--sm .switch-thumb {
  transform: translateX(14px);
}
