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

:root {
  --blue:    #0066CC;
  --blue-dk: #004A99;
  --bg:      #F0F2F5;
  --bg-card: #FFFFFF;
  --border:  #E0E4EA;
  --text:    #1A1A2E;
  --muted:   #6B7280;
  --radius:  10px;
  --shadow:  0 2px 10px rgba(0,0,0,.08);

  --c-laboral:    #4CAF50;
  --c-sabado:     #8BC34A;
  --c-domingo:    #9E9E9E;
  --c-festivo:    #B0BEC5;
  --c-vacaciones: #FF9800;
  --c-baja:       #F44336;
  --c-formacion:  #2196F3;
  --c-descanso:   #78909C;
  --c-permisos:   #AB47BC;
  --c-maternidad: #E91E63;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--blue); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--blue);
  color: white;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.topbar-brand { display: flex; align-items: center; gap: .7rem; }
.brand-title { font-size: 1.1rem; font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: .8rem; opacity: .75; border-left: 1px solid rgba(255,255,255,.3); padding-left: .7rem; }
.back-btn { color: white; font-size: .9rem; opacity: .8; transition: opacity .2s; }
.back-btn:hover { opacity: 1; }

.topbar-nav { display: flex; gap: .25rem; }
.nav-btn {
  background: transparent; border: none; color: rgba(255,255,255,.75);
  padding: .4rem .9rem; border-radius: 6px; font-size: .875rem;
  transition: background .15s, color .15s;
}
.nav-btn:hover, .nav-btn.active {
  background: rgba(255,255,255,.15); color: white;
}
.nav-btn.active { font-weight: 600; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app-main { padding: 1.5rem; max-width: 1600px; margin: 0 auto; }
.section { display: none; }
.section.active { display: block; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; flex-wrap: wrap; gap: .75rem;
}
.section-header h2 { font-size: 1.4rem; font-weight: 700; }

.controls { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem;
}
.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 1.5rem; }

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

/* Stat card */
.stat-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem 1.25rem 1rem;
  display: flex; flex-direction: column; gap: .4rem;
}
.stat-card .stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-card .stat-sub   { font-size: .8rem; color: var(--muted); }
.stat-card.accent-blue  { border-top: 3px solid var(--blue); }
.stat-card.accent-green { border-top: 3px solid var(--c-laboral); }
.stat-card.accent-orange{ border-top: 3px solid var(--c-vacaciones); }
.stat-card.accent-red   { border-top: 3px solid var(--c-baja); }

/* ── Delegación card ──────────────────────────────────────────────────────── */
.deleg-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.25rem;
  border-left: 5px solid var(--blue);
}
.deleg-card h4 { font-size: .95rem; font-weight: 700; margin-bottom: .6rem; }
.deleg-stat { display: flex; justify-content: space-between; font-size: .82rem; padding: .2rem 0; border-bottom: 1px solid var(--border); }
.deleg-stat:last-child { border: none; }

/* ── Formularios / controles ──────────────────────────────────────────────── */
select, input[type="text"] {
  border: 1px solid var(--border); border-radius: 6px;
  padding: .4rem .75rem; font-size: .875rem; background: white;
  color: var(--text); outline: none;
}
select:focus, input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,102,204,.15); }

.search-input { min-width: 200px; }

.btn-icon {
  background: white; border: 1px solid var(--border); border-radius: 6px;
  width: 32px; height: 32px; font-size: 1.2rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-icon:hover { background: var(--bg); }

.btn-sm {
  background: var(--blue); color: white; border: none;
  border-radius: 6px; padding: .35rem .8rem; font-size: .82rem;
}
.btn-sm:hover { background: var(--blue-dk); }

.month-label { font-weight: 600; min-width: 120px; text-align: center; }
.month-nav { display: flex; align-items: center; gap: .4rem; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  background: #F8F9FB; padding: .65rem 1rem;
  text-align: left; font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  border-bottom: 2px solid var(--border); white-space: nowrap;
  cursor: pointer;
}
thead th:hover { background: #EDF0F5; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #F5F7FA; }
tbody td { padding: .6rem 1rem; border-bottom: 1px solid var(--border); }
tfoot td { padding: .65rem 1rem; font-weight: 700; background: #EEF2F8; border-top: 2px solid var(--border); }

.badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
}
.badge-lleida     { background: #DBEAFE; color: #1D4ED8; }
.badge-tarragona  { background: #D1FAE5; color: #065F46; }
.badge-vilafranca { background: #FEF3C7; color: #92400E; }
.badge-barcelona  { background: #FCE7F3; color: #9D174D; }

.text-muted { color: var(--muted); font-size: .85rem; }
.text-right { text-align: right; }
.font-mono  { font-family: 'Consolas', monospace; }

/* ── Calendario visual ────────────────────────────────────────────────────── */
.cal-leyenda {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem;
  padding: .75rem 1.25rem; border-bottom: 1px solid var(--border);
  font-size: .78rem;
}
.cal-leyenda-item { display: flex; align-items: center; gap: .35rem; }
.cal-leyenda-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

.cal-wrap { overflow-x: auto; padding: 0; }
.cal-wrap.loading { display: flex; align-items: center; justify-content: center; min-height: 200px; }

.cal-table { border-collapse: collapse; font-size: .78rem; white-space: nowrap; width: 100%; }
.cal-table th { background: #F8F9FB; padding: .45rem .3rem; text-align: center; font-weight: 600; border: 1px solid var(--border); }
.cal-table th.col-tecnico { text-align: left; padding-left: .8rem; min-width: 170px; position: sticky; left: 0; background: #F8F9FB; z-index: 2; }
.cal-table th.col-dia { min-width: 28px; width: 28px; font-size: .7rem; color: var(--muted); }
.cal-table th.col-dia.weekend { color: #999; }
.cal-table th.col-dia.today { color: var(--blue); font-weight: 800; }

.cal-table td { border: 1px solid #E8EBF0; padding: 0; height: 30px; }
.cal-table td.col-tecnico {
  position: sticky; left: 0; background: white; z-index: 1;
  padding: .3rem .8rem; font-weight: 500;
}
.cal-table td.col-tecnico a { color: var(--text); font-size: .82rem; }
.cal-table td.col-tecnico a:hover { color: var(--blue); }

.cal-cell {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 600; color: white; opacity: .92;
  cursor: default;
}
.cal-cell:hover { opacity: 1; z-index: 10; position: relative; }
.cal-cell.empty { background: #F5F5F5; }
.cal-cell.no-data { background: #FAFAFA; }

.cal-cell.laboral    { background: var(--c-laboral); }
.cal-cell.sabado     { background: var(--c-sabado); }
.cal-cell.domingo    { background: var(--c-domingo); }
.cal-cell.festivo    { background: var(--c-festivo); color: #555; }
.cal-cell.vacaciones { background: var(--c-vacaciones); }
.cal-cell.baja       { background: var(--c-baja); }
.cal-cell.formacion  { background: var(--c-formacion); }
.cal-cell.descanso   { background: var(--c-descanso); }
.cal-cell.permisos   { background: var(--c-permisos); }
.cal-cell.maternidad { background: var(--c-maternidad); }
.cal-cell.desconocido{ background: #E0E0E0; color: #555; }

/* tooltip */
.cal-cell[title]:hover::after {
  content: attr(title);
  position: absolute; bottom: 120%; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.75); color: white;
  padding: .25rem .5rem; border-radius: 4px; font-size: .72rem;
  white-space: nowrap; pointer-events: none; z-index: 100;
}

/* ── Calendario individual técnico ────────────────────────────────────────── */
.cal-individual-wrap { padding: 1rem; }
.cal-individual-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: .3rem; margin-bottom: .75rem;
}
.cal-individual-grid .cal-day-header {
  text-align: center; font-size: .7rem; font-weight: 600;
  color: var(--muted); padding: .3rem 0;
}
.cal-day {
  border-radius: 6px; padding: .4rem .2rem; text-align: center;
  font-size: .75rem; min-height: 52px; display: flex;
  flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 2px; cursor: default;
}
.cal-day .cal-day-num { font-weight: 700; font-size: .8rem; }
.cal-day .cal-day-lbl { font-size: .6rem; opacity: .85; }
.cal-day.empty { background: transparent; }
.cal-day.laboral    { background: #E8F5E9; color: #2E7D32; }
.cal-day.sabado     { background: #F1F8E9; color: #33691E; }
.cal-day.domingo    { background: #F5F5F5; color: #757575; }
.cal-day.festivo    { background: #ECEFF1; color: #607D8B; }
.cal-day.vacaciones { background: #FFF3E0; color: #E65100; }
.cal-day.baja       { background: #FFEBEE; color: #C62828; }
.cal-day.formacion  { background: #E3F2FD; color: #1565C0; }
.cal-day.descanso   { background: #ECEFF1; color: #546E7A; }
.cal-day.permisos   { background: #F3E5F5; color: #6A1B9A; }
.cal-day.maternidad { background: #FCE4EC; color: #880E4F; }

/* ── Ficha técnico ────────────────────────────────────────────────────────── */
.card-tecnico-header {
  padding: 1.5rem; display: flex; gap: 1.5rem;
  align-items: flex-start; flex-wrap: wrap;
}
.tec-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--blue); display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 700; color: white; flex-shrink: 0;
}
.tec-info { flex: 1; min-width: 150px; }
.tec-info h2 { font-size: 1.35rem; margin-bottom: .25rem; }
.tec-contacto { flex: 2; min-width: 200px; font-size: .88rem; }
.tec-contacto p { margin-bottom: .35rem; }

.kpi-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: .3rem;
}
.kpi-card .kpi-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-card .kpi-value { font-size: 1.6rem; font-weight: 700; }
.kpi-card .kpi-bar-wrap { height: 4px; background: #E5E7EB; border-radius: 2px; margin-top: .3rem; }
.kpi-card .kpi-bar { height: 4px; border-radius: 2px; background: var(--blue); }

/* ── Grid técnicos ────────────────────────────────────────────────────────── */
.tec-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.tec-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.25rem;
  display: flex; flex-direction: column; gap: .5rem;
  transition: box-shadow .15s, transform .15s;
  cursor: pointer;
}
.tec-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.12); transform: translateY(-2px); }
.tec-card-top { display: flex; align-items: center; gap: .8rem; }
.tec-mini-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--blue); display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; color: white; flex-shrink: 0;
}
.tec-card-name { font-weight: 600; font-size: .95rem; }
.tec-card-code { font-size: .78rem; color: var(--muted); }
.tec-card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .5rem; font-size: .78rem; }
.tec-card-stat-label { color: var(--muted); }

/* ── Bar chart ────────────────────────────────────────────────────────────── */
.chart-container { padding: 1.25rem; overflow-x: auto; }
.bar-chart { display: flex; flex-direction: column; gap: .55rem; }
.bar-row { display: flex; align-items: center; gap: .75rem; }
.bar-label { min-width: 160px; font-size: .78rem; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 22px; background: #F0F2F5; border-radius: 4px; position: relative; }
.bar-fill { height: 100%; border-radius: 4px; display: flex; align-items: center; padding: 0 .4rem; }
.bar-fill span { font-size: .72rem; font-weight: 600; color: white; white-space: nowrap; }
.bar-val { min-width: 50px; font-size: .78rem; font-weight: 600; text-align: right; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem; color: var(--muted); font-size: .95rem; }
.cal-loading { text-align: center; padding: 2rem; color: var(--muted); }
.sort-indicator { font-size: .65rem; margin-left: .3rem; }

/* ── Formación ────────────────────────────────────────────────────────────── */
.trim-pill {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .7rem; font-weight: 600; background: #E3F2FD; color: #1565C0;
  white-space: nowrap;
}
.trim-pill.q1   { background: #E8F5E9; color: #2E7D32; }
.trim-pill.q2   { background: #FFF8E1; color: #F57F17; }
.trim-pill.q3   { background: #FFF3E0; color: #E65100; }
.trim-pill.q4   { background: #FCE4EC; color: #880E4F; }
.trim-pill.prl  { background: #F3E5F5; color: #6A1B9A; }
.trim-pill.anual{ background: #ECEFF1; color: #546E7A; }

.curso-row { padding: .6rem 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.curso-row:last-child { border-bottom: none; }
.curso-tipo { font-size: .72rem; color: var(--muted); min-width: 180px; }
.curso-nombre { flex: 1; font-size: .85rem; }
.curso-horas { font-weight: 700; font-size: .9rem; color: var(--blue); min-width: 50px; text-align: right; }

.form-stacked-bar { height: 20px; display: flex; border-radius: 4px; overflow: hidden; }
.form-stacked-bar .bar-tec   { background: var(--blue); height: 100%; }
.form-stacked-bar .bar-notec { background: #90CAF9; height: 100%; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar-nav { gap: 0; }
  .nav-btn { padding: .4rem .55rem; font-size: .78rem; }
  .brand-sub { display: none; }
  .app-main { padding: 1rem .75rem; }
  .section-header { flex-direction: column; align-items: flex-start; }
}
