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

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #3b82f6;
  --topbar-h: 60px;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

#app { display: flex; min-height: 100vh; }

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 16px;
  border-bottom: 1px solid #1e293b;
}

.sidebar-logo {
  background: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  display: inline-block;
}
.sidebar-logo img { height: 30px; width: auto; display: block; }

.brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 13px;
  flex-shrink: 0;
}

.brand-name { color: #fff; font-weight: 700; font-size: 16px; display: block; line-height: 1; }
.brand-sub { color: #64748b; font-size: 11px; display: block; margin-top: 2px; }

.sidebar-cuenta {
  padding: 16px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
}
.sidebar-cuenta-name { color: #e2e8f0; font-size: 16px; font-weight: 700; line-height: 1.25; }
.sidebar-cuenta-mail { color: #64748b; font-size: 11px; word-break: break-all; }
.sidebar-empresa { margin-top: 10px; padding-top: 10px; border-top: 1px solid #1e293b; display: flex; flex-direction: column; gap: 3px; }
.sidebar-empresa-name { color: #93c5fd; font-size: 12px; font-weight: 600; line-height: 1.3; }
.sidebar-empresa-link { color: #64748b; font-size: 11px; text-decoration: none; }
.sidebar-empresa-link:hover { color: #93c5fd; text-decoration: underline; }
.sidebar-periodo { color: #cbd5e1; font-size: 11.5px; font-weight: 600; margin-top: 6px; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.cal-head > div { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell { position: relative; min-height: 44px; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.cal-cell.cal-empty { border: none; background: transparent; }
.cal-cell.cal-rojo { background: #fde8e8; border-color: #f5b5b5; color: #b91c1c; }
.cal-fer { position: absolute; bottom: 4px; right: 6px; font-size: 9px; color: #dc2626; }
.cal-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
.cal-dot.cal-rojo, .cal-dot.rojo { background: #fde8e8; border: 1px solid #f5b5b5; }
.ip-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--primary); color: #fff;
  font-size: 12.5px; font-weight: 600; padding: 4px 6px 4px 10px; border-radius: 14px; }
.ip-chip button { background: rgba(255,255,255,.25); color: #fff; border: none; border-radius: 50%;
  width: 17px; height: 17px; line-height: 1; cursor: pointer; font-size: 13px; padding: 0; }
.ip-chip button:hover { background: rgba(255,255,255,.45); }

.sidebar-nav { padding: 12px 8px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  margin-bottom: 2px;
  transition: all .15s;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
}

.nav-item svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── MAIN ── */
#main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

#topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}

#page-title { font-size: 18px; font-weight: 600; color: var(--text); }

#topbar-actions { display: flex; gap: 8px; }

#content { padding: 24px; flex: 1; }

/* ── CARDS ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

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

.card-title { font-weight: 600; font-size: 15px; }
.card-body { padding: 20px; }

/* ── DASHBOARD STATS ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue { background: #eff6ff; }
.stat-icon.green { background: #f0fdf4; }
.stat-icon.yellow { background: #fffbeb; }
.stat-icon.purple { background: #faf5ff; }

.stat-value { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead { background: #f8fafc; }
th { padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ── FORMS ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }

.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── MODAL ── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}

#modal-overlay.hidden { display: none; }

#modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
#modal.modal-lg { max-width: 760px; }

/* ── Lista de empresas con checkbox (asignación a usuario) ── */
.emp-check-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.emp-check { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.emp-check:hover { background: var(--bg); }
.emp-check input { width: 16px; height: 16px; }

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--card);
}

#modal-title { font-size: 16px; font-weight: 600; }

#modal-close {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--text-muted); line-height: 1;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
}
#modal-close:hover { background: var(--bg); }

#modal-body { padding: 24px; }

/* ── TOASTS ── */
#toasts { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }

.toast {
  padding: 12px 16px;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 300px;
}

.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: var(--primary); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── LIQUIDACIÓN PREVIEW ── */
.liq-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.liq-section { padding: 12px 16px; }
.liq-section + .liq-section { border-top: 1px solid var(--border); }
.liq-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 10px; }

.liq-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; }
.liq-row.indent { padding-left: 12px; color: var(--text-muted); }
.liq-row.total { font-weight: 700; font-size: 15px; color: var(--text); }
.liq-row .amount { font-variant-numeric: tabular-nums; }
.liq-row .amount.green { color: #16a34a; }
.liq-row .amount.red { color: #dc2626; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; fill: var(--border); margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── LOADING ── */
.loading { display: flex; align-items: center; justify-content: center; padding: 48px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ── LOGIN ── */
.login-wrap {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 32px;
}

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

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
}

.login-error {
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 12px;
}

/* ── AUTH (registro / activación / recuperación) ── */
.login-card-wide { max-width: 560px; }

.auth-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: -12px 0 20px;
}

.auth-section {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin: 22px 0 12px;
  padding-top: 16px;
}

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.auth-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
  text-align: center;
}
.auth-links a {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
}
.auth-links a:hover { text-decoration: underline; }

.auth-id-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
}
.auth-id-label { color: var(--text-muted); font-size: 13px; }
.auth-badge {
  background: #e6f1fb;
  color: #185fa5;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}
.pwd-reqs { font-size: 11.5px; margin-top: 6px; line-height: 1.9; }
.field-error { color: #991b1b; font-size: 12px; margin-top: 4px; }
input.input-error { border-color: #dc2626 !important; background: #fef2f2; }
.field-hint { color: #185fa5; font-size: 12px; margin-top: 4px; }

/* ── Encabezado de sección (detalle de parámetros) ── */
/* ── Pestañas de la ficha de trabajador ── */
.ficha-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.ficha-tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; margin-bottom: -1px;
}
.ficha-tab-btn:hover { color: var(--text); }
.ficha-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.param-sec {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 6px;
  margin: 0 0 10px;
}
.input-invalid { border-color: #ef4444 !important; box-shadow: 0 0 0 3px rgba(239,68,68,.12) !important; }

/* ── CAJA DE ADVERTENCIA (acciones destructivas) ── */
.danger-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
}

/* ── SIDEBAR FOOTER ── */
.sidebar-footer {
  padding: 12px 8px 16px;
  border-top: 1px solid #1e293b;
}

#sidebar-user {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
}

.sidebar-user-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-user-name { color: #e2e8f0; font-size: 13px; font-weight: 600; display: block; }
.sidebar-user-perfil {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: none; border-radius: 7px;
  background: rgba(255,255,255,.06); color: #94a3b8; cursor: pointer; transition: all .15s;
}
.sidebar-user-perfil:hover { background: var(--primary); color: #fff; }
.sidebar-user-perfil svg { width: 16px; height: 16px; fill: currentColor; }
.sidebar-user-rol  { color: #94a3b8; font-size: 11px; display: block; margin-top: 2px; }
.sidebar-user-mail { color: #64748b; font-size: 11px; display: block; margin-top: 2px; word-break: break-all; }

/* ── ROL BADGES ── */
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── TABLA ACCIONES ── */
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── GRID 3 COLUMNAS STATS ── */
.stats-grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 24px; }
