/* ==========================================
   FichajeGPS - Sistema de Fichaje
   Diseño profesional y corporativo
   ========================================== */

:root {
    --primary: #1a56db;
    --primary-dark: #1544b0;
    --primary-light: #e8effc;
    --success: #059669;
    --success-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --white: #ffffff;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.2s ease;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================
   Navbar
   ========================================== */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--primary);
    font-weight: 700;
    font-size: 1.15rem;
}

.navbar-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.navbar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    border-radius: 2px;
    transition: var(--transition);
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    color: var(--gray-600);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    white-space: nowrap;
}

.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-link-danger:hover { background: var(--danger-light); color: var(--danger); }
.nav-separator { width: 1px; height: 24px; background: var(--gray-200); margin: 0 0.5rem; }

/* ==========================================
   Bottom Nav (móvil)
   ========================================== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0.5rem 0;
    text-decoration: none;
    color: var(--gray-400);
    font-size: 0.7rem;
    font-weight: 500;
    transition: var(--transition);
}

.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:hover { color: var(--primary); }

/* ==========================================
   Main Content
   ========================================== */
.main-content { padding: 1.5rem 0 5rem; min-height: calc(100vh - 60px); }
.main-content-full { padding-top: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* ==========================================
   Cards
   ========================================== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.card-header h2 { font-size: 1.1rem; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 1.5rem; }
.card-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--gray-100); background: var(--gray-50); }

/* ==========================================
   Stat Cards
   ========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon-blue { background: var(--primary-light); color: var(--primary); }
.stat-icon-green { background: var(--success-light); color: var(--success); }
.stat-icon-red { background: var(--danger-light); color: var(--danger); }
.stat-icon-yellow { background: var(--warning-light); color: var(--warning); }

.stat-info h3 { font-size: 0.8rem; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-info .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); line-height: 1.2; }
.stat-info .stat-desc { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.15rem; }

/* ==========================================
   Page header
   ========================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }

.dashboard-date-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.btn-day-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--gray-500);
    text-decoration: none;
    transition: color var(--transition), background var(--transition);
}
.btn-day-nav:hover { color: var(--gray-800); background: var(--gray-100); }
.btn-day-nav.disabled { color: var(--gray-300); pointer-events: none; }
.btn-date-display {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--gray-700);
    font-size: 0.875rem;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
}
.btn-date-display:hover { border-color: var(--primary); color: var(--primary); }
.btn-date-display.is-today { color: var(--primary); border-color: var(--primary-light); background: var(--primary-light); }

/* ==========================================
   Buttons
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font);
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline { background: transparent; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover:not(:disabled) { background: var(--gray-100); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.875rem 2rem; font-size: 1rem; }

/* Botón fichaje grande */
.btn-fichaje {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-lg);
    margin: 0 auto;
    color: var(--white);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-fichaje-entrada { background: linear-gradient(135deg, #059669, #10b981); }
.btn-fichaje-entrada:hover { transform: scale(1.05); box-shadow: 0 12px 30px rgba(5,150,105,0.4); }
.btn-fichaje-salida { background: linear-gradient(135deg, #dc2626, #ef4444); }
.btn-fichaje-salida:hover { transform: scale(1.05); box-shadow: 0 12px 30px rgba(220,38,38,0.4); }
.btn-fichaje:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }
.btn-fichaje .btn-fichaje-icon { font-size: 2.5rem; }
.btn-fichaje .btn-fichaje-time { font-size: 0.75rem; font-weight: 400; opacity: 0.9; }

.btn-fichaje.processing {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

/* ==========================================
   Forms
   ========================================== */
.form-group { margin-bottom: 1.25rem; }

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.375rem;
}

.form-input, .form-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    font-family: var(--font);
    color: var(--gray-800);
    background: var(--white);
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    appearance: none;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.15);
}

.form-input::placeholder { color: var(--gray-400); }
.form-hint { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.25rem; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ==========================================
   Tables
   ========================================== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: none; }

/* ==========================================
   Badges
   ========================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    text-transform: capitalize;
}

.badge-entrada { background: var(--success-light); color: var(--success); }
.badge-salida { background: var(--danger-light); color: var(--danger); }
.badge-activo { background: var(--success-light); color: var(--success); }
.badge-inactivo { background: var(--gray-200); color: var(--gray-500); }
.badge-admin { background: var(--primary-light); color: var(--primary); }

/* ==========================================
   Alerts
   ========================================== */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; }

.alert span { flex: 1; }
.alert-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.5;
    line-height: 1;
    color: inherit;
}
.alert-close:hover { opacity: 1; }

/* ==========================================
   Fichaje Page
   ========================================== */
.fichaje-container {
    text-align: center;
    padding: 2rem 0;
}

.fichaje-clock {
    font-size: 3rem;
    font-weight: 700;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
    margin-bottom: 0.25rem;
}

.fichaje-date {
    font-size: 1rem;
    color: var(--gray-500);
    margin-bottom: 2rem;
}

.fichaje-status {
    font-size: 0.9rem;
    color: var(--gray-600);
    margin-top: 1.5rem;
}

.fichaje-gps-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--gray-100);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--gray-600);
}

.gps-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.gps-dot-active { background: var(--success); animation: blink 1.5s infinite; }
.gps-dot-inactive { background: var(--danger); }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.fichajes-hoy-list {
    margin-top: 2rem;
    text-align: left;
}

.fichaje-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-100);
}

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

.fichaje-item-time {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
    min-width: 70px;
}

/* ==========================================
   Login Page
   ========================================== */
.login-wrapper {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo svg { color: var(--primary); }
.login-logo h1 { font-size: 1.5rem; color: var(--gray-900); margin-top: 0.75rem; }
.login-logo p { color: var(--gray-500); font-size: 0.9rem; margin-top: 0.25rem; }

.login-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.login-card .btn { width: 100%; margin-top: 0.5rem; }

.login-legal {
    margin-top: 1.25rem;
    text-align: center;
}
.login-legal p {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-bottom: 0.5rem;
}
.login-legal-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem 0.75rem;
}
.login-legal-links a {
    font-size: 0.7rem;
    color: var(--gray-400);
    text-decoration: none;
    transition: color var(--transition);
}
.login-legal-links a:hover { color: var(--primary); text-decoration: underline; }

/* ==========================================
   Empty state
   ========================================== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
}

.empty-state svg { margin-bottom: 1rem; opacity: 0.5; }
.empty-state p { font-size: 0.95rem; }

/* ==========================================
   Utilidades
   ========================================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--gray-500); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.hidden { display: none !important; }

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
    .navbar-toggle { display: flex; }

    .navbar-menu {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--white);
        border-bottom: 1px solid var(--gray-200);
        flex-direction: column;
        padding: 0.5rem;
        box-shadow: var(--shadow-md);
    }

    .navbar-menu.open { display: flex; }
    .nav-separator { width: 100%; height: 1px; margin: 0.25rem 0; }

    .bottom-nav { display: flex; }
    .main-content { padding-bottom: 5rem; }

    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }

    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header .btn { width: 100%; }

    .fichaje-clock { font-size: 2.5rem; }

    .table th, .table td { padding: 0.5rem 0.75rem; }

    .card-header { padding: 1rem; }
    .card-body { padding: 1rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .btn-fichaje { width: 160px; height: 160px; }
    .fichaje-clock { font-size: 2rem; }
}

/* ==========================================
   Map Panel (Leaflet sidebar)
   ========================================== */
.map-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 900;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.map-overlay.open { display: block; opacity: 1; }

.map-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 100vw;
    height: 100vh;
    background: var(--white);
    z-index: 901;
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
.map-panel.open { transform: translateX(0); }

.map-panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
}
.map-panel-info { flex: 1; min-width: 0; }
.map-panel-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.map-panel-meta {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.15rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.map-panel-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    line-height: 1;
    flex-shrink: 0;
    transition: color var(--transition), background var(--transition);
}
.map-panel-close:hover { color: var(--gray-700); background: var(--gray-100); }

.map-panel-address {
    padding: 0.65rem 1.25rem;
    font-size: 0.8rem;
    color: var(--gray-600);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}
.map-panel-address svg { flex-shrink: 0; color: var(--primary); }

#map-container {
    flex: 1;
    min-height: 300px;
    height: 100%;
}

.map-panel-coords {
    padding: 0.5rem 1.25rem;
    font-size: 0.72rem;
    color: var(--gray-400);
    border-top: 1px solid var(--gray-200);
    text-align: center;
    flex-shrink: 0;
}

.btn-map {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    padding: 0.25rem 0.4rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-family: var(--font);
    transition: color var(--transition), background var(--transition);
    vertical-align: middle;
}
.btn-map:hover { color: var(--primary-dark); background: var(--primary-light); }
.btn-map-nocoords {
    color: var(--gray-400);
    cursor: default;
    font-size: 0.8rem;
}

@media (max-width: 768px) {
    .map-panel { width: 100vw; }
}

/* ==========================================
   Print
   ========================================== */
@media print {
    .navbar, .bottom-nav, .btn, .alert { display: none !important; }
    .main-content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}
