/* ── Reset & Variables ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:       #C41E3A;
  --red-dark:  #9B1729;
  --red-light: #F9E5E8;
  --orange:    #EA580C;
  --green:     #15803D;
  --green-bg:  #DCFCE7;
  --blue:      #1D4ED8;
  --blue-bg:   #DBEAFE;
  --gray-50:   #F9FAFB;
  --gray-100:  #F3F4F6;
  --gray-200:  #E5E7EB;
  --gray-400:  #9CA3AF;
  --gray-500:  #6B7280;
  --gray-700:  #374151;
  --gray-900:  #111827;
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.06);
}

html { font-size: 15px; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--red);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.brand-icon { font-size: 1.4rem; color: #fff; }
.brand-name { font-size: 1.2rem; font-weight: 700; color: #fff; letter-spacing: .04em; }

.sidebar-nav { flex: 1; padding: .5rem 0; }
.nav-link {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .65rem 1rem;
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .9rem;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-link.active { background: rgba(0,0,0,.2); color: #fff; font-weight: 600; }
.nav-icon { font-size: .55rem; opacity: .7; }

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.15);
  gap: .5rem;
}
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name { font-size: .82rem; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: .7rem; color: rgba(255,255,255,.6); }
.logout-btn {
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-size: 1.1rem;
  padding: .25rem;
  flex-shrink: 0;
  transition: color .15s;
}
.logout-btn:hover { color: #fff; }

/* Main wrapper */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.page-title { font-size: 1.05rem; font-weight: 700; color: var(--gray-900); }
.topbar-date { font-size: .8rem; color: var(--gray-500); }

.main-content { padding: 1.5rem; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: .75rem 1rem;
  font-size: .88rem;
  font-weight: 600;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.card-body { padding: 1rem; }
.card-body.p-0 { padding: 0; }
.mt-4 { margin-top: 1.25rem; }
.mt-2 { margin-top: .6rem; }

/* ── KPIs ────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi-grid-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1100px) { .kpi-grid-6 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px)  { .kpi-grid   { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 540px)  { .kpi-grid, .kpi-grid-6 { grid-template-columns: 1fr 1fr; } }

.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  border-top: 3px solid transparent;
}
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.kpi-label { font-size: .78rem; color: var(--gray-500); margin-top: .3rem; }
.kpi-green  { border-color: var(--green); }  .kpi-green  .kpi-value { color: var(--green); }
.kpi-blue   { border-color: var(--blue); }   .kpi-blue   .kpi-value { color: var(--blue); }
.kpi-red    { border-color: var(--red); }    .kpi-red    .kpi-value { color: var(--red); }
.kpi-gray   { border-color: var(--gray-400); } .kpi-gray  .kpi-value { color: var(--gray-500); }
.kpi-orange { border-color: var(--orange); } .kpi-orange .kpi-value { color: var(--orange); }

/* ── Charts ──────────────────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .charts-grid { grid-template-columns: 1fr; } }

/* ── Tables ──────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.table th {
  padding: .55rem .75rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
.table td {
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--gray-50); }
.table .nowrap { white-space: nowrap; }
.table .text-center { text-align: center; }
.text-muted { color: var(--gray-400); font-size: .82rem; }
.empty-row { text-align: center; padding: 2rem !important; color: var(--gray-400); font-style: italic; }
.row-inactive { opacity: .55; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-ok      { background: var(--green-bg); color: var(--green); }
.badge-deny    { background: var(--red-light); color: var(--red); }
.badge-alarm   { background: #FEF9C3; color: #854D0E; }
.badge-unknown { background: var(--gray-100); color: var(--gray-500); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .9rem;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1.4;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.btn-primary  { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-outline  { background: #fff; color: var(--gray-700); border-color: var(--gray-200); }
.btn-outline:hover { border-color: var(--gray-400); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger   { background: #FEE2E2; color: #B91C1C; border-color: #FECACA; }
.btn-danger:hover { background: #FECACA; }
.btn-sm   { padding: .28rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-badge { cursor: pointer; border: none; }
.inline-form { display: inline; }
.inline-reset-form { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; flex-wrap: wrap; }

/* ── Forms ───────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--gray-700); }
.form-control {
  padding: .45rem .7rem;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: .85rem;
  color: var(--gray-900);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(196,30,58,.12);
}
.form-control-inline { width: 200px; }
.filter-form { width: 100%; }
.filter-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-row .form-group { min-width: 140px; flex: 1; }
.form-actions { flex: 0 0 auto !important; display: flex; gap: .4rem; align-items: flex-end; padding-bottom: .02rem; }

/* ── Alerts ──────────────────────────────────────────────────────── */
.alert {
  padding: .7rem 1rem;
  border-radius: 6px;
  font-size: .85rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-error { background: var(--red-light); color: var(--red-dark); border-color: #FECACA; }
.alert-ok    { background: var(--green-bg); color: var(--green); border-color: #BBF7D0; }
.alert-warn  { background: #FEF9C3; color: #854D0E; border-color: #FDE68A; }

/* ── Utilities ───────────────────────────────────────────────────── */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.export-group { display: flex; gap: .4rem; }
.section-label { font-size: .8rem; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .75rem; }
.link-more { font-size: .8rem; color: var(--red); text-decoration: none; font-weight: 500; }
.link-more:hover { text-decoration: underline; }

/* ── Login page ──────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gray-100);
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}
.login-header { text-align: center; margin-bottom: 1.75rem; }
.login-logo {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--red);
  letter-spacing: .05em;
}
.logo-square { font-size: 1.5rem; }
.login-subtitle { font-size: .9rem; color: var(--gray-500); margin-top: .4rem; }
.login-card .form-group { margin-bottom: 1rem; }
.login-card .btn-block { margin-top: .5rem; padding: .65rem; }

/* ── Focus accessibility ─────────────────────────────────────────── */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* ── Reporte Empleado ────────────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.month-nav-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-700);
  min-width: 160px;
  text-align: center;
}
.btn-disabled { opacity: .4; pointer-events: none; }

.emp-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .25rem;
}
.emp-detail-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gray-900);
}
.emp-detail-meta {
  font-size: .82rem;
  color: var(--gray-500);
  margin-top: .15rem;
}

.attendance-bar-wrap {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: .75rem 0 0;
}
.attendance-bar-track {
  flex: 1;
  height: 10px;
  background: var(--gray-100);
  border-radius: 999px;
  overflow: hidden;
}
.attendance-bar-fill {
  height: 100%;
  background: var(--red);
  border-radius: 999px;
  transition: width .4s ease;
}
.attendance-bar-text {
  font-size: .78rem;
  color: var(--gray-500);
  white-space: nowrap;
}

.charts-col { display: flex; flex-direction: column; }
.chart-pie-wrap { display: flex; align-items: center; justify-content: center; min-height: 160px; }

/* Mini progress bar in table */
.pct-cell { display: flex; align-items: center; gap: .5rem; }
.pct-bar-mini {
  flex: 1;
  height: 7px;
  background: var(--gray-100);
  border-radius: 999px;
  overflow: hidden;
  min-width: 60px;
}
.pct-bar-fill-mini { height: 100%; border-radius: 999px; }
.pct-green { background: var(--green); }
.pct-blue  { background: var(--blue); }
.pct-red   { background: var(--red); }
.pct-label-mini { font-size: .78rem; color: var(--gray-700); white-space: nowrap; min-width: 38px; }

.row-active { background: var(--red-light) !important; }

/* ── Attendance Calendar ─────────────────────────────────────────── */
.att-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 1rem;
}
.att-cal-dow {
  text-align: center;
  font-size: .7rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  padding-bottom: .35rem;
}
.att-cal-cell {
  border-radius: 6px;
  padding: .35rem .3rem;
  min-height: 64px;
  border: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.att-cal-cell.att-empty   { background: transparent; border-color: transparent; }
.att-cal-cell.att-weekend { background: var(--gray-50); }
.att-cal-cell.att-absent  { background: #fff; }
.att-cal-cell.att-present { background: #F0FDF4; border-color: #86EFAC; }
.att-cal-cell.att-future  { background: #fff; opacity: .45; }
.att-cal-dn {
  font-size: .72rem;
  font-weight: 700;
  color: var(--gray-300);
  line-height: 1;
}
.att-cal-cell.att-present .att-cal-dn { color: var(--green); }
.att-cal-cell.att-weekend .att-cal-dn { color: var(--gray-400); }
.att-cal-entry, .att-cal-exit {
  font-size: .63rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
}
.att-cal-entry { color: var(--green); }
.att-cal-exit  { color: var(--red); }
.att-cal-bar-wrap {
  margin-top: auto;
  height: 4px;
  background: var(--gray-100);
  border-radius: 2px;
  overflow: visible;
  position: relative;
}
.att-cal-bar {
  position: absolute;
  top: 0;
  height: 4px;
  background: var(--green);
  border-radius: 2px;
  opacity: .75;
}
@media (max-width: 600px) {
  .att-cal-entry, .att-cal-exit { display: none; }
  .att-cal-cell { min-height: 36px; }
}

/* ── Responsive sidebar ──────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { width: 200px; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .topbar { padding: 0 1rem; }
  .main-content { padding: 1rem; }
}
