/* TocaYAvanza v2 — Attendance Module (Control Horario) */

/* ====== Widget de fichaje (barra superior) ====== */
#attendance-widget {
  display: flex;
  align-items: center;
  gap: 6px 14px;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  transition: all 0.4s ease;
  flex-wrap: wrap;
  border-left: 5px solid transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* State colors — fondo + borde izquierdo grueso */
#attendance-widget.state-idle {
  background: #f8fafc;
  border-left-color: #cbd5e1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
#attendance-widget.state-working {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  border-left-color: var(--success);
  box-shadow: 0 2px 12px rgba(16,185,129,0.15);
}
#attendance-widget.state-on_break {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-left-color: var(--warning);
  box-shadow: 0 2px 12px rgba(245,158,11,0.15);
}
#attendance-widget.state-done {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  border-left-color: var(--info);
  box-shadow: 0 2px 12px rgba(59,130,246,0.12);
}

/* Pulse dot (indicador "live") */
.att-pulse-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.att-pulse-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  animation: attPulse 2s ease-in-out infinite;
}
.att-pulse-dot.idle        { background: #94a3b8; }
.att-pulse-dot.idle::after { display: none; }
.att-pulse-dot.working     { background: var(--success); }
.att-pulse-dot.working::after  { border: 2px solid var(--success); }
.att-pulse-dot.on_break    { background: var(--warning); }
.att-pulse-dot.on_break::after { border: 2px solid var(--warning); }
.att-pulse-dot.done        { background: var(--info); }
.att-pulse-dot.done::after { display: none; }

@keyframes attPulse {
  0%   { opacity: 1; transform: scale(1); }
  50%  { opacity: 0; transform: scale(1.8); }
  100% { opacity: 0; transform: scale(1.8); }
}

.att-status-text { flex: 1; min-width: 0; }

.att-status-label {
  font-size: var(--text-md);
  font-weight: var(--fw-bold);
  color: var(--text);
}
.att-status-time {
  font-size: var(--text-lg);
  font-weight: var(--fw-bold);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  margin-top: 2px;
  line-height: 1;
}
.att-status-time:empty { display: none; }

.att-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }

.att-btn {
  padding: 10px var(--space-5);
  border: none;
  border-radius: 24px;
  font-size: var(--text-base);
  font-weight: var(--fw-bold);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  min-width: 48px;
  justify-content: center;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.att-btn:hover  { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.att-btn:active { transform: scale(0.97) translateY(0); box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
.att-btn-checkin  { background: var(--success); color: white; }
.att-btn-checkin:hover  { background: #059669; }
.att-btn-break    { background: var(--warning); color: white; }
.att-btn-break:hover    { background: #d97706; }
.att-btn-checkout { background: var(--danger); color: white; }
.att-btn-checkout:hover { background: #dc2626; }

/* Toggle timeline */
.att-timeline-toggle {
  background: none;
  border: none;
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  width: 100%;
  text-align: center;
  margin-top: var(--space-1);
}
.att-timeline-toggle:hover { background: rgba(0,0,0,0.05); }

/* ====== Timeline desplegable ====== */
.att-timeline {
  display: none;
  margin-top: var(--space-2);
  padding: var(--space-2) 0;
  border-top: 1px solid rgba(0,0,0,0.08);
  width: 100%;
}
.att-timeline.open { display: block; }

.att-timeline-event {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--space-1) 0;
  font-size: var(--text-sm);
}
.att-timeline-hour {
  font-weight: var(--fw-semibold);
  color: var(--text);
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.att-timeline-icon  { font-size: var(--text-base); }
.att-timeline-label { color: var(--text-muted); }
.att-timeline-manual {
  font-size: 10px;
  color: var(--warning);
  font-weight: var(--fw-semibold);
}
.att-timeline-total {
  padding-top: 6px;
  margin-top: var(--space-1);
  border-top: 1px solid rgba(0,0,0,0.06);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

/* ====== Seccion admin: Control horario ====== */
.att-admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: var(--space-4);
}
.att-month-nav { display: flex; align-items: center; gap: var(--space-2); }
.att-month-nav button {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-md);
  display: flex; align-items: center; justify-content: center;
}
.att-month-nav button:hover { background: var(--bg); }
.att-month-label {
  font-size: var(--text-md);
  font-weight: var(--fw-bold);
  min-width: 160px;
  text-align: center;
}
.att-prof-filter {
  padding: 7px var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--card);
}

/* Tabla resumen diario */
.att-day-table td.att-events-cell { font-size: var(--text-xs); color: var(--text-muted); }

.att-event-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  margin-right: var(--space-1);
}
.att-event-tag.check_in    { background: #d1fae5; color: #065f46; }
.att-event-tag.break_start { background: #fef3c7; color: #92400e; }
.att-event-tag.break_end   { background: #e0f2fe; color: #0c4a6e; }
.att-event-tag.check_out   { background: #dbeafe; color: #1e40af; }
.att-manual-badge { font-size: 10px; color: var(--warning); cursor: help; }

/* Informe mensual */
.att-report-table th, .att-report-table td { text-align: center; }
.att-report-table td:first-child, .att-report-table th:first-child { text-align: left; }
.att-report-total { font-weight: var(--fw-bold); background: #f8fafc; }

/* CRUD buttons in report */
.att-row-actions { white-space: nowrap; }
.att-crud-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
  opacity: 0.5;
  transition: opacity 0.15s;
}
.att-crud-btn:hover { opacity: 1; }
.att-crud-del:hover { opacity: 1; background: var(--danger-subtle); }

/* Contract hours diff */
.att-diff-positive { color: #059669; font-weight: var(--fw-semibold); }
.att-diff-negative { color: #dc2626; font-weight: var(--fw-semibold); }

/* Signature canvas */
#att-sig-canvas {
  background: #fff;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: crosshair;
  touch-action: none;
}

/* Location icon */
.att-location-icon { font-size: var(--text-xs); margin-left: 2px; cursor: help; }

/* Weekly summary */
.att-weekly-table th, .att-weekly-table td {
  text-align: center;
  padding: 6px var(--space-2);
  font-size: var(--text-sm);
}
.att-weekly-table td:first-child, .att-weekly-table th:first-child { text-align: left; }
.att-weekly-ok    { background: #d1fae5; }
.att-weekly-under { background: #fee2e2; }
.att-weekly-none  { color: var(--text-muted); }

/* Audit log */
.att-audit-table td { font-size: var(--text-sm); }
.att-audit-table .att-audit-action { font-weight: var(--fw-semibold); }

/* ====== Responsive ====== */
@media (max-width: 768px) {
  #attendance-widget { padding: var(--space-3) 14px; gap: 10px; }
  .att-status-label  { font-size: var(--text-sm); }
  .att-status-time   { font-size: var(--text-md); }
  .att-btn { padding: 10px 14px; font-size: var(--text-xs); min-height: 48px; }
  .att-btn .att-btn-text { display: none; }
  .att-btn .att-btn-icon { display: inline; font-size: 18px; }
  .att-admin-header { flex-direction: column; align-items: stretch; }
  .att-month-nav    { justify-content: center; }
  .att-report-table { font-size: var(--text-xs); }
}
@media (min-width: 769px) {
  .att-btn .att-btn-icon { display: none; }
}

/* ====== DASHBOARD — Tarjetas y gráficos ====== */
.att-dashboard { padding-bottom: var(--space-5); }

.att-stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.att-stats-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
  border-left: 5px solid;
}
.att-stats-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.att-stats-card.card-hours { border-left-color: var(--success); }
.att-stats-card.card-avg   { border-left-color: var(--info); }
.att-stats-card.card-days  { border-left-color: var(--warning); }
.att-stats-card.card-profs { border-left-color: #8b5cf6; }

.att-stats-card-value {
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  color: var(--text);
  margin-bottom: var(--space-1);
}
.att-stats-card-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.att-stats-card-icon { font-size: 24px; margin-bottom: var(--space-2); opacity: 0.8; }

/* Chart containers */
.att-charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}
.att-chart-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.att-chart-title {
  font-size: var(--text-md);
  font-weight: var(--fw-semibold);
  color: var(--text);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.att-chart-wrapper { position: relative; height: 300px; min-height: 250px; }

.att-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 250px;
  color: var(--text-muted);
  font-size: var(--text-base);
  background: var(--bg);
  border-radius: var(--radius-md);
}

/* Loading & error */
.att-dashboard-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10);
  color: var(--text-muted);
  font-size: var(--text-base);
}
.att-dashboard-error {
  background: var(--danger-subtle);
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
}

@media (min-width: 1024px) {
  .att-charts-row { grid-template-columns: 1fr 1fr; }
  .att-charts-row .att-chart-container:nth-child(1) { grid-column: 1 / -1; }
}
@media (max-width: 768px) {
  .att-stats-cards   { grid-template-columns: 1fr 1fr; }
  .att-chart-wrapper { height: 250px; }
}
@media (max-width: 480px) {
  .att-stats-cards      { grid-template-columns: 1fr; }
  .att-stats-card       { padding: var(--space-4); }
  .att-stats-card-value { font-size: var(--text-lg); }
}

/* ====== Dropdown "Mas opciones" ====== */
.att-dropdown { position: relative; display: inline-block; }
.att-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: var(--space-1) 0;
  margin-top: var(--space-1);
}
.att-dropdown-menu.open { display: block; }
.att-dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text);
  white-space: nowrap;
}
.att-dropdown-menu button:hover { background: #f1f5f9; }

/* ====== Modal editar dia ====== */
.att-day-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}
.att-day-edit-row:last-of-type { border-bottom: none; }
.att-day-edit-row select,
.att-day-edit-row input[type="time"] {
  padding: 6px var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}
.att-day-edit-row input[type="time"] { width: 110px; }
.att-day-edit-row select { flex: 1; min-width: 100px; }
.att-day-edit-delete {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: #dc2626;
  cursor: pointer;
  white-space: nowrap;
}
.att-day-edit-delete input[type="checkbox"] { accent-color: #dc2626; }

/* ====== Subline compacta del widget (horario de hoy + aviso) ====== */
.att-subline {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.att-subline:empty { display: none; }

.att-sched-chip {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.att-sched-chip.att-sched-holiday { color: #b45309; }
.att-sched-chip.att-sched-muted   { color: var(--text-muted); }

/* Botón secundario: acción de menor peso que att-btn */
.att-btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.att-btn-secondary:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-muted);
}

/* ====== Detalle plegable del widget (timeline + horas extra) ====== */
.att-detail-empty {
  padding: var(--space-2) 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.att-detail-ot {
  margin-top: var(--space-3);
  padding-top: var(--space-2);
  border-top: 1px solid rgba(0,0,0,0.08);
}
.att-detail-ot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-sm);
  margin-bottom: var(--space-1);
}
.att-ot-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 0;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
}
.att-ot-row:last-child { border-bottom: none; }
.att-ot-auto { color: var(--text-muted); font-size: 11px; }
.att-btn-xs { padding: 3px var(--space-2); font-size: var(--text-xs); }

/* Botón "Horas extra" de la subline: acción siempre visible, alineada a la derecha */
.att-subline-ot-btn { margin-left: auto; }

/* ====== Aviso compacto de fichajes incompletos (chip de la subline) ====== */
.att-forgotten-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  background: #fff8e1;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
}
.att-forgotten-icon { font-size: var(--text-sm); flex-shrink: 0; }
.att-forgotten-text {
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  color: #92400e;
}
.att-forgotten-history-link { font-size: var(--text-xs); color: #b07d1a; }
.att-forgotten-btn {
  background: #f5a623;
  color: white;
  border: 0;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: var(--fw-semibold);
  font-size: var(--text-xs);
  white-space: nowrap;
}
.att-forgotten-btn:hover { filter: brightness(0.95); }

/* Sub-form por día dentro del modal olvidos */
.att-forgotten-subform {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}
.att-forgotten-subform:last-of-type { border-bottom: none; }
.att-forgotten-subform-header {
  font-size: var(--text-md);
  margin-bottom: var(--space-1);
  text-transform: capitalize;
}
.att-forgotten-submit-btn { margin-top: var(--space-2); }

/* Pills de estado para mis solicitudes */
.att-pending-status-pending,
.att-pending-status-approved,
.att-pending-status-rejected {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-lg);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.att-pending-status-pending  { background: #fef3c7; color: #92400e; }
.att-pending-status-approved { background: #d1fae5; color: #065f46; }
.att-pending-status-rejected { background: #fee2e2; color: #991b1b; }
