/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg: #f0f2f5;
  --clr-surface: #ffffff;
  --clr-primary: #16213e;
  --clr-text: #1a1a2e;
  --clr-text-muted: #6b7280;
  --clr-success: #10b981;
  --clr-success-light: #d1fae5;
  --clr-warning: #f59e0b;
  --clr-warning-light: #fef3c7;
  --clr-danger: #ef4444;
  --clr-danger-light: #fee2e2;
  --clr-info: #3b82f6;
  --clr-info-light: #dbeafe;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

html {
  font-size: 18px;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100%;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* === PANTALLA LOGIN === */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  padding-top: calc(2rem + env(safe-area-inset-top));
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  gap: 1.5rem;
  background: var(--clr-bg);
}

.login-screen h1 {
  font-size: 1.8rem;
  color: var(--clr-primary);
  text-align: center;
}

.login-screen .subtitle {
  color: var(--clr-text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.login-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

.field-error {
  color: var(--clr-danger);
  font-size: 0.8rem;
  font-weight: 600;
  min-height: 0;
}

.form-group label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--clr-text-muted);
}

.form-group select,
.form-group input {
  padding: 1rem;
  border: 2px solid #e5e7eb;
  border-radius: var(--radius);
  font-size: 1.1rem;
  outline: none;
  transition: border-color 0.2s;
  background: var(--clr-surface);
}

.form-group select:focus,
.form-group input:focus {
  border-color: var(--clr-primary);
}

.pin-input {
  letter-spacing: 0.8rem;
  text-align: center;
  font-size: 1.6rem !important;
  font-weight: 700;
}

.btn {
  padding: 1rem 2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--clr-primary);
  color: white;
}

.btn-success {
  background: var(--clr-success);
  color: white;
}

.btn-warning {
  background: var(--clr-warning);
  color: white;
}

.btn-danger {
  background: var(--clr-danger);
  color: white;
}

.btn-info {
  background: var(--clr-info);
  color: white;
}

.btn-large {
  padding: 1.8rem 2rem;
  font-size: 1.5rem;
  border-radius: 24px;
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-error {
  color: var(--clr-danger);
  text-align: center;
  font-size: 0.9rem;
  min-height: 1.4rem;
}

/* === PANTALLA FICHAJE (EMPLEADO) === */
.app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--clr-primary);
  color: white;
  padding: 1.2rem 1.5rem;
  padding-top: calc(1.2rem + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h2 { font-size: 1.1rem; font-weight: 600; }

.header-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--clr-success);
}

.status-dot.offline { background: var(--clr-danger); }

.btn-logout {
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

.clock-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--clr-bg);
  gap: 1.5rem;
}

.current-time {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--clr-primary);
  font-variant-numeric: tabular-nums;
}

.current-date {
  font-size: 1rem;
  color: var(--clr-text-muted);
  margin-top: -1rem;
}

.greeting {
  font-size: 1.2rem;
  color: var(--clr-text-muted);
  text-align: center;
}

.clock-buttons {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.btn-clock {
  position: relative;
  overflow: hidden;
}

.btn-clock.done {
  opacity: 0.4;
  pointer-events: none;
}

.btn-clock .check-mark {
  position: absolute;
  right: 1.5rem;
  font-size: 1.5rem;
}

/* Barra de progreso de jornada */
.progress-bar-container {
  width: 100%;
  max-width: 400px;
  height: 12px;
  background: var(--clr-bg);
  border-radius: 6px;
  overflow: hidden;
  margin: 1rem auto 0.3rem;
}

.progress-bar {
  height: 100%;
  background: var(--clr-success);
  border-radius: 6px;
  transition: width 1s ease;
  min-width: 0;
}

.progress-bar.complete { background: var(--clr-info); }
.progress-bar.overtime { background: var(--clr-danger); }

.progress-label {
  font-size: 0.8rem;
  color: var(--clr-text-muted);
  text-align: center;
  margin-bottom: 0.5rem;
}

.fichaje-info {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 1.2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.fichaje-info h3 {
  font-size: 0.9rem;
  color: var(--clr-text-muted);
  margin-bottom: 0.8rem;
}

.fichaje-list { list-style: none; }

.fichaje-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.fichaje-list li:last-child { border-bottom: none; }

.fichaje-list .type { color: var(--clr-text-muted); }
.fichaje-list .time { font-weight: 700; }

.fichaje-list .pending {
  color: var(--clr-warning);
  font-size: 0.75rem;
}

.location-info {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--clr-text-muted);
}

.sync-banner {
  background: var(--clr-warning-light);
  color: #92400e;
  text-align: center;
  padding: 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.sync-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #92400e;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === PANEL ADMIN === */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 260px;
  background: var(--clr-primary);
  color: white;
  padding: 1.5rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 2rem;
  position: sticky;
  top: 0;
  align-self: stretch;
  max-height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.2);
  padding-bottom: 1rem;
}

.admin-sidebar h1 {
  font-size: 1.2rem;
}

.sidebar-logout {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}

.sidebar-logout:hover {
  color: white;
  background: rgba(255,255,255,0.1);
}

.admin-nav { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }

.admin-nav li a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  display: block;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.admin-nav li a:hover,
.admin-nav li a.active {
  background: rgba(255,255,255,0.1);
  color: white;
}

.admin-main {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  background: var(--clr-bg);
}

.admin-main h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

/* Tarjetas de estadísticas */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.stat-card-link {
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}

.stat-card-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(0,0,0,0.12);
}

.stat-card-link:active {
  transform: translateY(0);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0.3rem;
}

/* Búsqueda y filtros */
.search-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.search-bar input,
.search-bar select {
  padding: 0.8rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
  background: var(--clr-surface);
}

.search-bar input { flex: 1; min-width: 200px; }
.search-bar input:focus { border-color: var(--clr-primary); }

.date-range-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.date-range-picker select {
  padding: 0.8rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
  background: var(--clr-surface);
  cursor: pointer;
}

.date-range-picker select:focus { border-color: var(--clr-primary); }

.date-range-custom {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.date-range-custom input {
  padding: 0.8rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
  background: var(--clr-surface);
}

.date-range-custom input:focus { border-color: var(--clr-primary); }

.date-range-sep {
  color: var(--clr-text-muted);
  font-size: 0.9rem;
}

/* Tabla de registros */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--clr-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.data-table th {
  background: var(--clr-primary);
  color: white;
  padding: 1rem;
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: #f8fafc; }

.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: var(--clr-success-light); color: #065f46; }
.badge-warning { background: var(--clr-warning-light); color: #92400e; }
.badge-danger { background: var(--clr-danger-light); color: #991b1b; }
.badge-info { background: var(--clr-info-light); color: #1e40af; }

/* Exportar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.btn-export {
  background: var(--clr-surface);
  border: 2px solid #e5e7eb;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}

.btn-export:hover { border-color: var(--clr-primary); }

/* Detalle empleado */
.employee-detail-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.employee-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--clr-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.employee-meta { flex: 1; }
.employee-meta h3 { font-size: 1.3rem; }
.employee-meta p { color: var(--clr-text-muted); font-size: 0.9rem; }

/* Toast notification */
.toast {
  position: fixed;
  bottom: calc(2rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--clr-primary);
  color: white;
  padding: 1rem 2rem;
  border-radius: var(--radius);
  font-weight: 600;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  transition: transform 0.3s ease;
  z-index: 1000;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* Tarjetas de dia (vista empleado) */
.fichaje-day-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
}

.fichaje-day-review {
  border-left: 4px solid var(--clr-danger);
}

/* Badges de auditoria */
.badge-edited {
  background: var(--clr-warning-light);
  color: #92400e;
  font-size: 0.65rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

.badge-autoclosed {
  background: var(--clr-danger-light);
  color: #991b1b;
  font-size: 0.65rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* Fila que necesita revision */
tr.needs-review td {
  border-left: 3px solid var(--clr-danger);
}

tr.needs-review td:first-child {
  font-weight: 700;
}

/* Boton de edicion en tabla */
.btn-edit {
  background: none;
  border: 1.5px solid var(--clr-info);
  color: var(--clr-info);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-edit:hover {
  background: var(--clr-info);
  color: white;
}

.btn-delete {
  background: none;
  border: 1.5px solid var(--clr-danger);
  color: var(--clr-danger);
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  line-height: 1;
  vertical-align: middle;
}

.btn-delete:hover {
  background: var(--clr-danger);
  color: white;
}

/* === BREADCRUMB NAVEGACION === */
.detail-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.2rem;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.detail-breadcrumb a {
  color: var(--clr-primary);
  text-decoration: none;
  font-weight: 500;
}

.detail-breadcrumb a:hover { text-decoration: underline; }

.detail-breadcrumb span:last-child {
  color: var(--clr-text-muted);
  font-weight: 400;
}

.breadcrumb-sep { color: var(--clr-text-muted); }

/* === HISTORIAL EMPLEADO === */
.history-days { display: flex; flex-direction: column; gap: 0.75rem; }

.history-day-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.history-day-card.needs-review { border-left: 3px solid var(--clr-danger); }

.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  background: var(--clr-primary);
  color: white;
}

.history-day-date { font-weight: 700; font-size: 0.9rem; }
.history-day-hours { font-size: 0.85rem; display: flex; align-items: center; gap: 0.5rem; }

.history-day-entries { padding: 0.5rem 1rem; }

.history-entry {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f0f2f5;
  font-size: 0.9rem;
}

.history-entry:last-child { border-bottom: none; }
.history-entry-time { font-weight: 600; min-width: 50px; }
.history-entry-loc { margin-left: auto; font-size: 0.8rem; }

.bottom-bar { display: none; }

/* Responsive: móvil */
@media (max-width: 768px) {
  html { font-size: 16px; }

  .admin-layout { flex-direction: column; }

  .admin-sidebar { display: none; }

  .bottom-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--clr-surface);
    border-top: 1px solid #e5e7eb;
    z-index: 1000;
    padding: 0.4rem 0;
    padding-bottom: calc(0.4rem + env(safe-area-inset-bottom));
  }

  .bottom-bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0;
    text-decoration: none;
    color: var(--clr-text-muted);
    font-size: 0.65rem;
    font-weight: 500;
    transition: color 0.15s;
    position: relative;
  }

  .bottom-bar-item.active {
    color: var(--clr-primary);
  }

  .bottom-bar-item.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background: var(--clr-primary);
    border-radius: 1px;
  }

  .bottom-bar-item svg {
    width: 22px;
    height: 22px;
  }

  .bottom-menu {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0.5rem;
    background: var(--clr-surface);
    border-radius: var(--radius);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
    min-width: 180px;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
  }

  .bottom-menu.visible { display: block; }

  .bottom-menu a {
    display: block;
    padding: 0.8rem 1.2rem;
    text-decoration: none;
    color: var(--clr-text);
    font-size: 0.9rem;
  }

  .bottom-menu a:last-child {
    color: var(--clr-danger);
    border-top: 1px solid #f0f2f5;
  }

  .bottom-menu a:active { background: var(--clr-bg); }

  .admin-main {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .admin-main h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-card .value {
    font-size: 1.5rem;
  }

  .toolbar {
    flex-direction: column;
    gap: 0.8rem;
    align-items: stretch;
  }

  .search-bar {
    flex-direction: column;
    gap: 0.6rem;
  }

  .search-bar input {
    min-width: 0;
    width: 100%;
  }

  .date-range-picker {
    width: 100%;
  }

  .date-range-picker select {
    width: 100%;
    font-size: 0.85rem;
    padding: 0.7rem 0.6rem;
  }

  .date-range-custom {
    width: 100%;
  }

  .date-range-custom input {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    padding: 0.7rem 0.6rem;
  }

  .data-table-wrap {
    overflow-x: visible;
    margin: 0;
    padding: 0;
  }

  .data-table {
    font-size: 0.85rem;
    min-width: 0;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
  }

  .data-table thead { display: none; }

  .data-table tbody tr {
    display: block;
    background: var(--clr-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 0.75rem;
  }

  .data-table tbody tr:hover td { background: transparent; }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid #f0f2f5;
    white-space: normal;
  }

  .data-table td:last-child { border-bottom: none; }

  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--clr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    margin-right: 1rem;
  }

  .data-table .total-row {
    border-radius: var(--radius);
    padding: 0.8rem 1rem;
  }

  .data-table .total-row td[colspan] { justify-content: flex-end; }

  tr.needs-review {
    border-left: 3px solid var(--clr-danger);
  }

  tr.needs-review td { border-left: none; }

  .employee-detail-header {
    flex-direction: column;
    text-align: center;
    gap: 0.8rem;
  }

  .employee-meta p {
    font-size: 0.8rem;
  }

  .btn-large {
    padding: 1.4rem 1.5rem;
    font-size: 1.3rem;
  }

  .clock-container {
    padding: 1.5rem 1rem;
    gap: 1rem;
  }

  .current-time {
    font-size: 2.8rem;
  }

  .fichaje-info {
    max-width: 100%;
  }

  .btn-export {
    width: 100%;
    text-align: center;
  }

  .data-table .btn-export {
    width: auto;
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
  }

  .btn-edit {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
  }

  .btn-delete {
    padding: 0.25rem 0.4rem;
    font-size: 0.75rem;
  }

  .modal {
    padding: 1.5rem;
    margin: 0.5rem;
  }

  .badge-edited,
  .badge-autoclosed {
    display: inline-block;
    margin-top: 0.2rem;
  }
}

@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .admin-nav {
    flex-direction: column;
  }

  .data-table {
    min-width: 0;
    font-size: 0.8rem;
  }

  .badge-edited,
  .badge-autoclosed {
    display: block;
    margin-left: 0;
    margin-top: 0.2rem;
  }
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1rem;
}

.modal {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}

.modal h3 { margin-bottom: 1rem; }
.modal p { color: var(--clr-text-muted); margin-bottom: 1.5rem; font-size: 0.95rem; }

.modal-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
}
