/* Reset and Base Styles 1.0*/
:root {
    --primary-green: #2E7D32;
    --secondary-green: #1B5E20;
    --light-green: #C8E6C9;
    --gradient-green: linear-gradient(135deg, #2E7D32 0%, #388E3C 100%);
    --gradient-green-light: linear-gradient(135deg, #81C784 0%, #66BB6A 100%);
    --gradient-green-dark: linear-gradient(135deg, #1B5E20 0%, #2E7D32 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gradient-green-light);
    min-height: 100vh;
    height: 100%; /* Ensure body fills viewport for stable mobile layout */
    overflow-x: hidden;
    overflow-y: hidden; /* Use screen containers as the scroll areas to avoid iOS bounce issues */
    /* Improve iOS scrolling */
    -webkit-overflow-scrolling: touch;
}

/* Prevent body scrolling when modal is open */
body.modal-open {
    overflow: hidden;
}

html {
    /* Allow normal iOS scrolling behavior */
    -webkit-overflow-scrolling: touch;
    height: 100%;
    overscroll-behavior-y: none; /* avoid viewport bounce */
    overflow: hidden; /* prevent page-level scrollbar; only screens should scroll */
}

/* Screen Management */
.screen {
    display: none;
    /* Make each screen its own scroll container for mobile stability */
    height: 100%; /* tie to body/html height to avoid 1px dvh jitter */
    min-height: 100svh; /* modern unit avoids address bar jump */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none; /* completely stop scroll chaining/bounce */
    touch-action: pan-y; /* prioritize vertical scroll, avoid accidental horizontal capture */
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    box-sizing: border-box;
}

/* Timecard screen: let only the list (timecards-container) scroll */
#timecardScreen.screen {
    overflow: hidden; /* disable screen-level scroll for timecard screen */
}

/* Employee screen: add bottom filler space so content can scroll clear of address bar */
#employeeScreen.screen {
    padding-bottom: calc(120px + env(safe-area-inset-bottom));
}

.screen.active {
    display: block;
}

/* Login Screen */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Use modern viewport units to avoid mobile URL/nav bar issues */
    min-height: 100svh;
    height: 100svh;
    /* Where supported, prefer dynamic viewport to match visible area */
    height: 100dvh;
    text-align: center;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Keep content comfortably clear of bottom system UI (Android/iOS) */
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.login-container h1 {
    color: white;
    font-size: 2.5rem;
    margin-bottom: 40px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.pin-container {
    background: white;
    border-radius: 20px;
    /* Extra bottom padding so the last row of the pad never gets obscured */
    padding: 30px 30px calc(30px + env(safe-area-inset-bottom)) 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    max-width: 400px;
    width: 100%;
}

.login-logo {
    width: 96px;
    height: 96px;
    object-fit: contain;
    display: block;
    margin: 0 auto 12px auto;
}

.pin-container h2 {
    color: #333;
    margin-bottom: 30px;
    font-size: 1.5rem;
}

/* PIN Display */
.pin-feedback-area {
    min-height: 50px;
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pin-display {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.pin-message {
    display: none;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    padding: 10px 20px;
    border-radius: 8px;
}

.pin-message.error {
    color: #ff6b6b;
    background: #ffe0e0;
}

.pin-message.success {
    color: #51cf66;
    background: #e0ffe0;
}

.pin-dot {
    width: 20px;
    height: 20px;
    border: 3px solid #ddd;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: none; /* Hide by default */
}

.pin-dot.filled {
    display: block; /* Show when filled */
    background: var(--primary-green);
    border-color: var(--primary-green);
}

/* PIN Pad */
.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    max-width: 300px;
    margin: 0 auto;
}

.pin-btn {
    height: 60px;
    border: none;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: bold;
    background: #f8f9fa;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.pin-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.pin-btn:active {
    transform: translateY(0);
}

.pin-btn.clear {
    background: #ff6b6b;
    color: white;
}

.pin-btn.enter {
    background: #51cf66;
    color: white;
}

.error-message {
    color: #ff6b6b;
    margin-top: 20px;
    font-weight: 500;
    text-align: center;
    display: none; /* Hidden by default */
    min-height: 0;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 75px;
    margin-bottom: 20px;
    background: var(--gradient-green);
    padding: 0 20px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    position: relative;
    color: white;
}

.header-left {
    width: 60px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.header-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 10px;
}

.header-logo {
    height: 28px;
    width: auto;
    object-fit: contain;
    margin-bottom: 4px;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2));
}

.header-right {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 0;
}

.header-title {
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.header-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 2px;
}

.back-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.back-btn:hover {
    transform: scale(1.05);
    background: var(--secondary-green);
}

.sync-btn {
    background: var(--secondary-green);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    margin-right: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sync-btn:hover {
    background: #1a73e8;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sync-btn:active {
    opacity: 0.8;
}

.sync-btn.spinning {
    /* Use a rotation-only animation to avoid layout shifts from translate() in other spin keyframes */
    animation: spin-rotate 1s linear infinite;
    transform-origin: center center;
}

.config-btn {
    background: var(--secondary-green);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    margin-right: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.config-btn:hover {
    background: #1a73e8;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: scale(1.05);
}

.config-btn:active {
    opacity: 0.8;
    transform: scale(0.98);
}

/* Rotation-only keyframes for buttons/icons that should not move position */
@keyframes spin-rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.profile-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.profile-section:hover {
    transform: scale(1.05);
}

.profile-icon {
    background: var(--primary-green);
    color: white;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.profile-initials {
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
}

.logout-btn {
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    transform: scale(1.05);
}

/* Search */
.search-container {
    margin-bottom: 20px;
}

.search-box {
    position: relative;
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    overflow: hidden;
}

.search-box i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

.search-box input {
    width: 100%;
    padding: 15px 50px 15px 45px;
    border: none;
    outline: none;
    font-size: 1rem;
    background: transparent;
}

.search-box #clearSearch {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
}

.search-box #clearSearch:hover {
    background: #f0f0f0;
}

/* Timecard Tiles */
.timecards-container {
    display: grid;
    gap: 15px;
    /* Size relative to screen minus header/search chrome to avoid viewport bar jitter */
    max-height: calc(100% - 149px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    /* Keep minimal internal padding; spacer element will provide extra scroll room */
    padding-bottom: 16px;
}

/* Spacer appended at end of the list so last tile clears address bar/toolbars */
.timecards-filler {
    height: 120px; /* adjustable space */
    height: calc(120px + env(safe-area-inset-bottom));
    pointer-events: none; /* purely spacing */
}

.timecard-tile {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    border-left: 5px solid var(--primary-green);
}

.timecard-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.timecard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.timecard-number {
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

.timecard-date {
    color: var(--primary-green);
    font-weight: 600;
}

.timecard-details {
    color: #666;
    line-height: 1.5;
}

.timecard-farm {
    font-weight: 600;
    margin-bottom: 5px;
}

/* QR Scanner */
.qr-section {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.qr-scanner {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 auto 20px;
    border-radius: 15px;
    overflow: hidden;
    background: #f8f9fa;
}

#qrVideo {
    width: 100%;
    min-height: 300px;
    aspect-ratio: 1;
    object-fit: cover;
}

/* iOS-specific fixes for QR scanner */
@supports (-webkit-touch-callout: none) {
    #qrVideo {
        height: auto;
        min-height: 400px;
    }
    #qrVideo video {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }
}

.qr-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-frame {
    width: 200px;
    height: 200px;
    border: 3px solid var(--primary-green);
    border-radius: 15px;
    position: relative;
}

.scan-btn {
    flex: 1;
    min-width: calc(50% - 5px);
    padding: 15px;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0;
}

.scan-btn:not(.secondary) {
    background: #cf6d51;
    color: white;
}

.scan-btn.secondary {
    background: #ff6b6b;
    color: white;
}

.scan-btn:hover {
    transform: translateY(-2px);
}

/* Manual Entry */
.manual-entry {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.manual-entry h3 {
    margin-bottom: 15px;
    color: #333;
}

.manual-entry select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    background: white;
}

/* Employee Form */
.employee-form {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.employee-header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.employee-header h3 {
    color: #333;
    font-size: 1.3rem;
    margin-bottom: 5px;
}

.employee-header span {
    color: #667eea;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: 600;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary-green);
}

/* Activities */
.activities-section {
    margin-bottom: 20px;
}

.activity-group {
    margin-bottom: 15px;
    padding: 10px;  
    background: #ffffff;
    border: 2px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Header row: Description left, Container Weight right */
.activity-group .activity-row.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 45px;
    margin-bottom: 20px;
    padding: 0 20px;
    position: relative;
    color: #333;
    background: transparent;
    border: none;
    box-shadow: none;
}

.activity-group .activity-title {
    font-weight: 600;
    font-size: 1rem;
    color: #ffffff;
    background: linear-gradient(135deg, #2E7D32 0%, #1B5E20 100%);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.activity-group .container-info {
    font-size: 0.9rem;
    color: inherit;
    font-weight: 500;
    background: transparent;
    text-align: right;
    line-height: 1.3;
}

.activity-group .container-info .calc-method {
    display: block;
    margin-top: 2px;
    color: inherit;
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Inputs row: side-by-side boxes */
.activity-group .activity-row.inputs {
    display: grid;
    grid-template-columns: 0.5fr 0.5fr 0.5fr;
    gap: 10px;
    margin-bottom: 0;
}

/* Without containers: single column for entry input */
.activity-group .activity-row.inputs:has(> .calc-method) {
    grid-template-columns: 1fr;
}

.activity-group .activity-row.inputs input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.activity-group .activity-row.inputs input:focus {
    outline: none;
    border-color: var(--primary-green);
}

.activity-group .activity-row.inputs input[readonly] {
    background: #f0f0f0;
    color: #666;
    cursor: not-allowed;
}

/* Labels row: hidden/removed */
.activity-group .activity-row.labels {
    display: none;
}

/* Save Button */
.save-btn {
    width: 100%;
    padding: 15px;
    background: #51cf66;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-btn:hover {
    background: #40c057;
    transform: translateY(-2px);
}

/* History */
.history-section {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.history-section h3 {
    color: #333;
    margin-bottom: 15px;
    text-align: center;
}

.history-list {
    /* Let the parent modal handle all scrolling */
    padding-bottom: 10px;
}

.history-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    position: relative;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.history-time {
    color: var(--primary-green);
    font-weight: 600;
    font-size: 0.9rem;
}

.history-row {
    background: var(--light-green);
    color: var(--primary-green);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    margin: 5px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.history-entry-time {
    color: #999;
    font-size: 0.8rem;
}

.history-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    font-size: 0.9rem;
}

.history-detail {
    display: flex;
    flex-direction: column;
}

.history-detail span:first-child {
    color: #666;
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.history-detail span:last-child {
    color: #333;
    font-weight: 600;
}

/* Timecard Info */
.timecard-info {
    background: #f8f9fa;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 0.9rem;
    color: #333;
    max-width: 250px;
    text-align: center;
}

/* Flash Message */
.flash-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1rem;
    font-weight: 500;
    z-index: 10000;
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.3s ease;
}

.flash-message.show {
    transform: translateX(0);
    opacity: 1;
}

.flash-message.flash-success {
    border-left: 4px solid #27ae60;
    color: #27ae60;
}

.flash-message.flash-error {
    border-left: 4px solid #e74c3c;
    color: #e74c3c;
}

.flash-message i {
    font-size: 1.2rem;
}

/* Confirm Dialog */
.confirm-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.confirm-dialog-overlay.show {
    opacity: 1;
}

.confirm-dialog {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.confirm-dialog-overlay.show .confirm-dialog {
    transform: scale(1);
}

.confirm-dialog-icon {
    text-align: center;
    margin-bottom: 20px;
}

.confirm-dialog-icon i {
    font-size: 3rem;
    color: var(--primary-green);
}

.confirm-dialog-message {
    text-align: center;
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 25px;
    line-height: 1.5;
}

.confirm-dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-btn-cancel,
.confirm-btn-confirm {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.confirm-btn-cancel {
    background: #e0e0e0;
    color: #666;
}

.confirm-btn-cancel:hover {
    background: #d0d0d0;
}

.confirm-btn-confirm {
    background: var(--primary-green);
    color: white;
}

.confirm-btn-confirm:hover {
    background: var(--secondary-green);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.3);
}

/* Danger variant for confirm dialog */
.confirm-dialog.danger .confirm-dialog-icon i {
    color: #e74c3c;
}

.confirm-dialog.danger .confirm-btn-confirm {
    background: #dc3545;
}

.confirm-dialog.danger .confirm-btn-confirm:hover {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.3);
}

/* Danger zone styling for destructive actions */
.danger-zone {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border: 1px solid #ffcccc;
    background: #fff1f0;
    border-radius: 10px;
}

.danger-icon {
    color: #c0392b;
    font-size: 1.5rem;
    line-height: 1;
}

.danger-title {
    color: #b00020;
    font-weight: 700;
    margin-bottom: 6px;
}

.danger-text {
    color: #7f1d1d;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Responsive Design */
@media (max-width: 480px) {
    .screen {
        padding: 10px;
    }
    
    .header {
        height: 75px;
        padding: 0 15px;
        margin-bottom: 15px;
    }
    
    .header-title {
        font-size: 1.1rem;
    }
    
    .header-subtitle {
        font-size: 0.7rem;
    }
    
    .profile-icon {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }
    
    .profile-initials {
        color: white;
        font-size: 0.65rem;
    }
    
    .back-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    .activity-group .activity-row.inputs {
        grid-template-columns: 0.5fr 0.5fr 0.5fr;
        gap: 6px;
    }
    
    .activity-group .activity-row.inputs:has(> .calc-method) {
        grid-template-columns: 1fr;
    }
    
    .activity-group .activity-row.labels {
        display: none;
    }
    
    .history-details {
        grid-template-columns: 1fr;
    }
    
    .login-container h1 {
        font-size: 2rem;
    }
    
    .pin-container {
        padding: 20px;
    }
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top: 2px solid var(--primary-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Employee Selection Modal */
.employee-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile adjustments for employee modal */
@media (max-width: 768px) {
    .employee-modal {
        align-items: flex-start;
        padding: 10px;
        overflow-y: auto;
    }
}

.employee-modal.hidden {
    display: none;
}

.employee-modal-content {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    margin: 10px 0;
}

/* Mobile adjustments for employee modal content */
@media (max-width: 768px) {
    .employee-modal-content {
        max-height: calc(100vh - 40px);
        margin: 10px 0;
    }
}

/* Special styling for work session modal */
.employee-modal-content[style*="max-width: 600px"] {
    max-width: 600px;
    max-height: 85vh;
}

.employee-modal-content > div[style*="padding: 20px"] {
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.employee-modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.employee-modal-header h3 {
    margin: 0;
    color: #333;
}

/* Header buttons in employee-modal (light background) */
.employee-modal-header .header-cancel-btn {
    background: #6c757d;
    color: white;
}

.employee-modal-header .header-cancel-btn:hover {
    background: #5a6268;
}

.employee-modal-close {
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.employee-modal-footer {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    background: #f5f5f5;
    border-top: 1px solid #ddd;
    border-radius: 0 0 10px 10px;
}

.employee-modal-footer button {
    flex: 1;
}

/* Configuration Section Styles */
.config-section {
    margin-bottom: 20px;
}

.config-section h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-description {
    margin: 0 0 15px 0;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

.paytype-config-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.paytype-config-row {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
}

.paytype-config-row h5 {
    margin: 0 0 10px 0;
    color: #444;
    font-size: 1rem;
}

.paytype-config-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.config-input-group {
    display: flex;
    flex-direction: column;
    min-width: 0; /* Allow flex items to shrink below content size */
}

.config-input-group label {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.config-input-group input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    width: 100%;
    box-sizing: border-box;
    min-width: 0; /* Allow input to shrink */
}

.config-input-group input:focus {
    outline: none;
    border-color: var(--primary-green);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

/* Responsive layout for paytype config on mobile */
@media (max-width: 600px) {
    .paytype-config-inputs {
        grid-template-columns: 1fr;
    }
}

/* Settings (cog) button used in modal headers */
.settings-btn {
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.settings-btn:hover {
    background: #5a6268;
    transform: scale(1.05);
}

.print-label-btn {
    background: var(--primary-green);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.print-label-btn:hover {
    background: var(--secondary-green);
    transform: scale(1.05);
}

.new-entry-btn {
    background: var(--primary-green);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.new-entry-btn:hover {
    background: var(--secondary-green);
    transform: translateY(-1px);
}

/* Work Session Styles */
.work-session-section {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.work-session-section h4 {
    margin: 0 0 12px 0;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
}

.time-inputs-compact {
    margin-bottom: 15px;
}

.time-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

/* Ensure form-groups in time-row behave properly */
.time-row .form-group {
    margin-bottom: 0;
    flex: 1;
}

.time-row .form-group input {
    width: 100%;
    text-align: center; /* Center align all inputs in time-row */
}

/* iOS-specific time input fixes */
.time-row .form-group input[type="time"] {
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
    background: white;
    padding: 12px 8px; /* Reduce horizontal padding for better fit */
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    height: 48px; /* Fixed height for consistency */
    box-sizing: border-box;
    display: block;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-align: center; /* Center the time text */
}

.time-row .form-group input[type="time"]:focus {
    outline: none;
    border-color: var(--primary-green);
}

/* Ensure consistent sizing on all platforms */
.time-row .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 0; /* Prevent flex item overflow */
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .time-row .form-group input[type="time"] {
        /* Remove iOS default styling */
        -webkit-appearance: none;
        appearance: none;
        background: white;
        /* Ensure consistent text alignment */
        text-align: center;
        /* Fix iOS font rendering */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    /* Ensure proper flex behavior on iOS */
    .time-row {
        display: flex;
        align-items: stretch; /* Ensure equal height */
        gap: 15px;
    }
}

/* Activity Summary Styles */
.activity-summary {
    margin-top: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.activity-summary .summary-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 8px;
}

.summary-row {
    display: flex;
    gap: 15px;
    justify-content: space-between;
}

.activity-total {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    font-size: 0.8rem;
}

.activity-total .value {
    font-weight: 700;
    color: var(--primary-green);
    font-size: 1.1rem;
    line-height: 1;
}

.activity-total .label {
    color: #666;
    margin-top: 2px;
    text-align: center;
    line-height: 1.1;
}

.time-inputs-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.work-entries-section {
    padding: 20px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    position: relative;
    /* Removed fixed height - let content flow naturally and modal scrolls */
}

.work-entries-section h4 {
    margin: 0;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.work-entries-container {
    margin-top: 15px;
    position: relative;
    /* Remove overflow-y auto - let the parent modal content scroll */
}

@media (max-width: 768px) {
    /* Keep time inputs side by side on mobile */
    .time-row {
        display: flex;
        gap: 10px;
        flex-direction: row; /* Keep side by side */
    }
    
    .time-inputs-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* Better mobile time input styling */
    .time-row .form-group input[type="time"] {
        height: 50px; /* Slightly larger touch target on mobile */
        font-size: 0.95rem; /* Slightly smaller to fit better */
        min-width: 110px; /* Ensure minimum width for time inputs */
        padding: 12px 6px; /* Tighter padding for better fit */
    }
}

/* Very small screens - ensure time inputs still fit */
@media (max-width: 360px) {
    .time-row {
        gap: 8px; /* Reduce gap on very small screens */
    }
    
    .time-row .form-group input[type="time"] {
        font-size: 0.9rem;
        min-width: 100px;
        padding: 10px 4px;
    }
    
    .time-row .form-group label {
        font-size: 0.85rem;
    }
}

.employee-search {
    padding: 20px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.employee-search input {
    width: 100%;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
}

.employee-search input:focus {
    outline: none;
    border-color: var(--primary-green);
}

.employee-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
    /* Add padding for better iOS scroll interaction */
    padding-bottom: 30px;
}

.employee-tile {
    background: #f8f9fa;
    border: 2px solid #eee;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.employee-tile:hover {
    background: var(--primary-green);
    color: white;
    transform: translateY(-2px);
}

.employee-tile:active {
    transform: translateY(0);
}

.employee-name {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.employee-code {
    color: #666;
    font-size: 0.9rem;
}

.employee-tile:hover .employee-code {
    color: rgba(255, 255, 255, 0.8);
}

/* Employee Form Modal */
.employee-form-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1001;
    padding: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Generic Modal - Used for user management, etc. */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 10000 !important;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
}

.modal.hidden {
    display: none !important;
    pointer-events: none;
}

.modal-content,
.large-modal {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    pointer-events: auto;
}

.large-modal {
    max-width: 600px;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: var(--gradient-green);
    color: white;
    border-radius: 20px 20px 0 0;
}

.modal-header h2 {
    margin: 0;
    color: white;
    font-size: 1.3rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.modal-body form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-green);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-group small {
    font-size: 0.8rem;
    color: #666;
    margin-top: 3px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.primary-btn,
.secondary-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn {
    background: var(--primary-green);
    color: white;
}

.primary-btn:hover {
    background: var(--secondary-green);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

.secondary-btn {
    background: #f0f0f0;
    color: #333;
}

.secondary-btn:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
}

.error-message {
    padding: 12px;
    background: #ffe3e3;
    color: #d32f2f;
    border-radius: 8px;
    font-size: 0.9rem;
    border-left: 4px solid #d32f2f;
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal {
        padding: 10px;
        align-items: flex-start;
        justify-content: center;
        padding-top: 60px;
    }
    
    .modal-content {
        max-width: 95%;
        max-height: calc(100vh - 80px);
    }
    
    .modal-header h2 {
        font-size: 1.1rem;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .primary-btn,
    .secondary-btn {
        width: 100%;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    .employee-form-modal {
        align-items: flex-start;
        padding: 5px;
        /* On mobile, make sure we can scroll if keyboard shrinks viewport */
        height: 100vh;
        max-height: 100vh;
    }
    
    /* Make header buttons more prominent on mobile */
    .employee-form-header .header-buttons {
        gap: 8px;
    }
    
    .employee-form-header .header-save-btn,
    .employee-form-header .header-cancel-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
        min-width: 60px;
    }
}

.employee-form-modal.hidden {
    display: none;
}

/* Higher z-index for history and edit modals */
#employeeHistoryModal {
    z-index: 1002;
}

#editEntryModal {
    z-index: 1003;
}

/* Highest z-index for row selection modal to appear above all other modals */
#rowSelectionModal {
    z-index: 1004;
}

.employee-form-content {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: calc(100svh - 40px);
    min-height: 200px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    margin: 10px 0;
}

/* Mobile-specific modal content sizing */
@media (max-width: 768px) {
    .employee-form-content {
        margin: 5px 0;
        border-radius: 15px;
        /* Ensure modal doesn't exceed available space */
        max-height: calc(100svh - 20px);
        min-height: auto;
    }
}

.employee-form-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gradient-green);
    color: white;
    border-radius: 20px 20px 0 0;
    flex-shrink: 0;
}

.employee-form-header > div:first-child {
    text-align: left;
}

.employee-form-header h3 {
    margin: 0 0 5px 0;
    font-size: 1.3rem;
}

.employee-form-header span {
    font-size: 0.9rem;
    opacity: 0.9;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

.header-save-btn,
.header-cancel-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 15px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.header-save-btn {
    background: #28a745;
    color: white;
}

.header-save-btn:hover {
    background: #218838;
    transform: scale(1.05);
}

.header-cancel-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.header-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.modal-history-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.modal-history-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.delete-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 0 0 auto;
    min-width: 120px;
}

.delete-btn:hover {
    background: #c82333;
    transform: translateY(-2px);
}

.history-item-editable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item-editable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.edit-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--primary-green);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.history-item-editable:hover .edit-indicator {
    opacity: 1;
}

.employee-form-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    /* Allow flex child to shrink and scroll properly inside modal */
    min-height: 0;
    /* Add padding for better iOS scroll interaction */
    padding-bottom: 30px;
}

/* Mobile adjustments for form body */
@media (max-width: 768px) {
    .employee-form-body {
        padding: 15px;
        /* Allow more flexible sizing on mobile */
        flex-shrink: 1;
        min-height: 80px;
    }
}

.employee-form-buttons {
    display: flex;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid #eee;
    background: white;
    border-radius: 0 0 20px 20px;
    flex-shrink: 0;
}

/* Floating action buttons that appear at top of screen */
.floating-action-buttons {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    display: flex;
    gap: 15px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1002;
    transition: transform 0.3s ease;
    pointer-events: none; /* Don't interfere with scrolling when hidden */
}

.floating-action-buttons.hidden {
    transform: translateX(-50%) translateY(-100px);
    pointer-events: none;
}

.floating-action-buttons.show {
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.floating-action-buttons:not(.hidden) {
    transform: translateX(-50%) translateY(0);
    pointer-events: auto; /* Enable interactions when visible */
}

.floating-action-buttons .save-btn,
.floating-action-buttons .cancel-btn {
    padding: 8px 16px;
    margin: 0;
    font-size: 0.9rem;
    border-radius: 20px;
    pointer-events: auto; /* Ensure buttons are always clickable */
}

/* Ensure modal scrolling works properly */
.employee-form-modal {
    pointer-events: auto;
    z-index: 1000;
}

.employee-form-modal .employee-form-content {
    max-height: calc(100svh - 20px);
    overflow: hidden; /* only the body scrolls */
}

.employee-form-modal .employee-form-body {
    padding-bottom: 20px;
}

/* Keep footer buttons visible; make them stick to bottom within the modal */
.employee-form-buttons {
    position: sticky;
    bottom: 0;
    z-index: 1;
    background: white;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.employee-form-buttons .save-btn {
    flex: 1;
    margin: 0;
}

.cancel-btn {
    flex: 1;
    padding: 15px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.select-employee-btn {
    flex: 1;
    min-width: calc(50% - 5px);
    padding: 15px;
    background: #2e5c7d;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0;
}

.print-stickers-btn {
    width: 100%;
    padding: 15px;
    background: var(--secondary-green);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 20px;
}

.print-stickers-btn:hover {
    background: var(--primary-green);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(74, 144, 226, 0.3);
}

/* Timecard Summary */
.timecard-summary {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.summary-header h3 {
    color: #333;
    margin: 0;
}

.toggle-summary {
    background: none;
    border: none;
    color: var(--primary-green);
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.toggle-summary.collapsed {
    transform: rotate(-90deg);
}

.summary-content {
    display: block;
}

.summary-content.collapsed {
    display: none;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--gradient-green);
    color: white;
    padding: 15px;
    border-radius: 12px;
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.8rem;
    opacity: 0.9;
}

.best-picker {
    background: transparent;
    padding: 20px 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

/* Podium Container */
.podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 10px;
    min-height: 250px;
}

.podium-place {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 120px;
}

/* Empty podium state - muted appearance */
.podium-empty .podium-name,
.podium-empty .podium-score {
    opacity: 0.4;
    color: #999;
}

.podium-empty .podium-rank {
    opacity: 0.5;
}

.podium-empty .podium-base {
    opacity: 0.3;
}

/* First Place - Center - Gold - Tallest */
.podium-first {
    order: 2;
}

.podium-first .podium-rank {
    font-size: 1.5rem;
    font-weight: bold;
    color: #FFD700;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.podium-first .podium-name {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    text-align: center;
    word-wrap: break-word;
}

.podium-first .podium-score {
    font-size: 1.2rem;
    font-weight: bold;
    color: #FFD700;
    margin-bottom: 10px;
}

.podium-first .podium-base {
    width: 100%;
    height: 140px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    position: relative;
}

.podium-first .podium-base::before {
    content: '1';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.3);
}

/* Second Place - Left - Blue - Medium */
.podium-second {
    order: 1;
}

.podium-second .podium-rank {
    font-size: 1.2rem;
    font-weight: bold;
    color: #4A90E2;
    margin-bottom: 8px;
}

.podium-second .podium-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    text-align: center;
    word-wrap: break-word;
}

.podium-second .podium-score {
    font-size: 1rem;
    font-weight: bold;
    color: #4A90E2;
    margin-bottom: 10px;
}

.podium-second .podium-base {
    width: 100%;
    height: 100px;
    background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    position: relative;
}

.podium-second .podium-base::before {
    content: '2';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.3);
}

/* Third Place - Right - Green - Shortest */
.podium-third {
    order: 3;
}

.podium-third .podium-rank {
    font-size: 1.2rem;
    font-weight: bold;
    color: #2E7D32;
    margin-bottom: 8px;
}

.podium-third .podium-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    text-align: center;
    word-wrap: break-word;
}

.podium-third .podium-score {
    font-size: 1rem;
    font-weight: bold;
    color: #2E7D32;
    margin-bottom: 10px;
}

.podium-third .podium-base {
    width: 100%;
    height: 70px;
    background: linear-gradient(135deg, #2E7D32 0%, #1B5E20 100%);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    position: relative;
}

.podium-third .podium-base::before {
    content: '3';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.3);
}

/* Legacy styles - kept for backwards compatibility */
.best-picker-name {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.best-picker-value {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Chart Container */
.chart-container {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 15px;
    margin-top: 15px;
    height: 200px;
    position: relative;
    overflow: hidden;
}

.chart-title {
    text-align: center;
    color: #333;
    font-weight: 600;
    margin-bottom: 15px;
}

.chart-bars {
    display: flex;
    align-items: end;
    justify-content: space-around;
    height: 120px;
    position: relative;
}

.chart-bar {
    background: linear-gradient(to top, var(--primary-green), var(--secondary-green));
    border-radius: 4px 4px 0 0;
    min-width: 20px;
    max-width: 40px;
    flex: 1;
    margin: 0 2px;
    position: relative;
    transition: all 0.3s ease;
}

.chart-bar:hover {
    transform: scale(1.05);
}

.chart-bar-label {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: #666;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 60px;
}

.chart-bar-value {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: #333;
    font-weight: 600;
    white-space: nowrap;
}

/* Chart Carousel Styles */
.chart-carousel-container {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 15px;
    margin-top: 15px;
    height: 280px;
    position: relative;
    overflow: hidden;
}

.chart-carousel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    height: 40px;
}

.chart-nav-btn {
    background: var(--primary-green);
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.chart-nav-btn:hover {
    background: var(--secondary-green);
    transform: scale(1.1);
}

.chart-nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.chart-title-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    margin: 0 15px;
}

.chart-title {
    text-align: center;
    color: #333;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 1rem;
}

.chart-indicators {
    display: flex;
    gap: 8px;
}

.chart-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-indicator.active {
    background: var(--primary-green);
    transform: scale(1.3);
}

.chart-carousel-content {
    position: relative;
    height: 190px;
    overflow: hidden;
}

.chart-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.chart-slide.active {
    opacity: 1;
    transform: translateX(0);
}

.chart-slide.prev {
    transform: translateX(-100%);
}

/* Chart.js canvas styling */
.chart-slide canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: 190px;
}

/* Different colors for different chart types */
.chart-slide#activityTotalsChart .chart-bar {
    background: linear-gradient(to top, var(--primary-green), #51cf66);
}

.chart-slide#rowPiecesChart .chart-bar {
    background: linear-gradient(to top, var(--primary-orange), #ffa726);
}

/* Employee Summary Toggle */
.employee-summary-toggle {
    background: var(--primary-green);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 10px 15px;
    cursor: pointer;
    margin-bottom: 15px;
    transition: all 0.2s ease;
}

.employee-summary-toggle:hover {
    background: var(--secondary-green);
}

/* Row Selection Styles */
.row-selection {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.toolbox-description {
    background: white;
    border-radius: 15px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    text-align: center;
}

.toolbox-description-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--primary-green);
    font-size: 0.95rem;
    line-height: 1.5;
}

.toolbox-description-content i {
    color: var(--primary-green);
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toolbox-description-content span {
    font-weight: 500;
}

.row-selection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.row-selection-header h3 {
    color: var(--primary-green);
    font-size: 1.1rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.selected-row-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--light-green);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--primary-green);
}

.selected-row-display span {
    color: var(--primary-green);
    font-weight: 600;
    font-size: 0.9rem;
}

.change-row-btn {
    background: var(--primary-green);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.change-row-btn:hover {
    background: var(--secondary-green);
}

.row-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.row-tile {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.row-tile:hover {
    border-color: var(--primary-green);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.row-tile.selected {
    border-color: var(--primary-green);
    background: var(--light-green);
}

.row-tile .row-icon {
    font-size: 1.5rem;
    color: var(--primary-green);
    margin-bottom: 8px;
}

.row-tile .row-name {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.row-selection-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
}

.row-selection-tiles .row-tile {
    padding: 20px;
}

.row-selection-tiles .row-tile .row-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.row-selection-tiles .row-tile .row-name {
    font-size: 1rem;
}

/* Row selector in form */
.row-selector {
    display: flex;
    gap: 10px;
    align-items: center;
}

.row-selector input {
    flex: 1;
    background: #f8f9fa;
    cursor: pointer;
}

.row-change-btn {
    background: var(--primary-green);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 0.9rem;
}

.row-change-btn:hover {
    background: var(--secondary-green);
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .row-selection-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .selected-row-display {
        justify-content: center;
    }
    
    .row-tiles {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .row-selector {
        flex-direction: row;
        gap: 8px;
    }
    
    .row-selector input {
        flex: 1 1 auto;
        min-width: 0;
    }
    
    .row-change-btn {
        flex: 0 0 auto;
        padding: 10px 12px;
        font-size: 0.85rem;
    }
}

/* Welcome Splash */
.welcome-splash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.welcome-splash.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.welcome-splash.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.welcome-content {
    text-align: center;
    color: white;
    animation: welcomeIn 0.8s ease-out;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounceIn 1s ease;
}

.welcome-message {
    font-size: 2rem;
    font-weight: 300;
    margin-bottom: 0.5rem;
    animation: slideInUp 0.6s ease 0.2s both;
}

.welcome-name {
    font-size: 1.5rem;
    font-weight: 600;
    opacity: 0.9;
    animation: slideInUp 0.6s ease 0.4s both;
}

@keyframes welcomeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-180deg);
    }
    50% {
        transform: scale(1.05) rotate(-90deg);
    }
    70% {
        transform: scale(0.9) rotate(0deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile optimizations for welcome splash */
@media (max-width: 768px) {
    .welcome-icon {
        font-size: 3rem;
    }
    
    .welcome-message {
        font-size: 1.5rem;
    }
    
    .welcome-name {
        font-size: 1.2rem;
    }
}

/* Modal scroll management */
body.modal-open {
    overflow: hidden;
}

/* Improved scroll behavior for all scrollable containers */
.scrollable-container {
    -webkit-overflow-scrolling: touch;
}

/* Allow proper scrolling within modals */
.employee-modal-content,
.employee-form-content {
    /* Enable normal touch scrolling within modals */
    -webkit-overflow-scrolling: touch;
}

/* Modal overlays should allow content interaction */
.employee-modal,
.employee-form-modal {
    /* Allow normal touch interactions for scrolling */
    -webkit-overflow-scrolling: touch;
}

/* PWA Offline/Online Notifications */
.offline-notification,
.online-notification {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.offline-notification i,
.online-notification i {
    font-size: 16px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(-100%);
        opacity: 0;
    }
}

/* PWA Install Prompt */
.pwa-install-prompt {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideUpFromBottom 0.4s ease-out;
}

.pwa-install-prompt.hidden {
    display: none;
}

.pwa-install-prompt .icon {
    font-size: 32px;
    color: #667eea;
}

.pwa-install-prompt .content {
    flex: 1;
}

.pwa-install-prompt .content h4 {
    margin: 0 0 4px 0;
    color: #333;
    font-size: 16px;
}

.pwa-install-prompt .content p {
    margin: 0;
    color: #666;
    font-size: 13px;
}

.pwa-install-prompt .actions {
    display: flex;
    gap: 8px;
}

.pwa-install-prompt button {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pwa-install-prompt .install-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.pwa-install-prompt .dismiss-btn {
    background: #f0f0f0;
    color: #666;
}

.pwa-install-prompt button:active {
    transform: scale(0.95);
}

@keyframes slideUpFromBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .pwa-install-prompt {
        bottom: 10px;
        left: 10px;
        right: 10px;
        padding: 12px;
    }
    
    .pwa-install-prompt .actions {
        flex-direction: column;
    }
    
    .pwa-install-prompt button {
        width: 100%;
    }
}

/* ========================================
   MAIN MENU & MANAGEMENT SCREENS STYLES
   ======================================== */

/* Main Menu Container */
.main-menu-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Main Menu Item Tile */
.main-menu-item {
    background: white;
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
}

.main-menu-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border-color: #667eea;
}

.main-menu-item:active {
    transform: translateY(-2px);
}

.main-menu-item .menu-icon {
    font-size: 48px;
    color: #667eea;
    margin-bottom: 15px;
}

.main-menu-item .menu-title {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.main-menu-item .menu-description {
    font-size: 14px;
    color: #666;
}

/* Management Container */
.management-container {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.management-header {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: space-between;
}

.management-header .search-box {
    flex: 1;
    max-width: 500px;
}

.management-header .primary-btn {
    flex: 0;
    white-space: nowrap;
}

/* Management List */
.management-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.management-list-item {
    background: white;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.management-list-item:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.management-list-item .item-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    flex-shrink: 0;
}

.management-list-item .item-details {
    flex: 1;
    min-width: 0;
}

.management-list-item .item-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.management-list-item .item-subtitle {
    font-size: 14px;
    color: #666;
}

.management-list-item .item-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.management-list-item .action-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: #f0f0f0;
    color: #667eea;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.management-list-item .action-btn:hover {
    background: #667eea;
    color: white;
}

.management-list-item .action-btn:active {
    transform: scale(0.95);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    transition: bottom 0.3s ease;
    max-width: 90%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.toast.show {
    bottom: 30px;
}

.toast-success {
    background: #28a745;
}

.toast-error {
    background: #dc3545;
}

.toast-warning {
    background: #ffc107;
    color: #333;
}

.toast-info {
    background: #17a2b8;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .main-menu-container {
        grid-template-columns: 1fr;
        padding: 15px;
        gap: 15px;
    }
    
    .main-menu-item {
        padding: 25px;
    }
    
    .main-menu-item .menu-icon {
        font-size: 40px;
    }
    
    .main-menu-item .menu-title {
        font-size: 18px;
    }
    
    .management-container {
        padding: 15px;
    }
    
    .management-list-item {
        padding: 15px;
    }
    
    .management-list-item .item-icon {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    .management-list-item .item-title {
        font-size: 16px;
    }
    
    .management-list-item .item-subtitle {
        font-size: 13px;
    }
}



