/**
 * =============================================================================
 * M5Tracker - Stylesheet
 * =============================================================================
 * 
 * Professional, responsive design with dark/light mode support
 * Optimized for desktop split-view and mobile full-screen map
 * 
 * =============================================================================
 */

/* =============================================================================
   CSS VARIABLES - THEME COLORS
   ============================================================================= */

:root {
    /* Primary Colors */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #93c5fd;
    
    /* Status Colors */
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #06b6d4;
    
    /* Neutral Colors - Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --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);
    
    /* Layout */
    --sidebar-width: 320px;
    --header-height: 60px;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --card-bg: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: #334155;
        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    }
}

/* =============================================================================
   RESET & BASE STYLES
   ============================================================================= */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* =============================================================================
   BUTTONS
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.5;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-link {
    background: transparent;
    color: var(--primary-color);
    padding: 10px;
}

.btn-link:hover {
    text-decoration: underline;
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.875rem;
}

.btn-group {
    display: flex;
    gap: 10px;
}

/* =============================================================================
   FORMS
   ============================================================================= */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

input::placeholder {
    color: var(--text-muted);
}

/* =============================================================================
   LOGIN PAGE
   ============================================================================= */

.login-overlay,
.login-container {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 1000;
}

.login-overlay:not(.active) {
    display: none;
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo img {
    width: 80px;
    height: auto;
    margin-bottom: 15px;
}

.login-logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.login-logo p {
    color: var(--text-secondary);
    margin-top: 5px;
}

.login-form {
    margin-top: 20px;
}

.error-message {
    margin-top: 15px;
    padding: 10px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger-color);
    border-radius: var(--border-radius);
    color: var(--danger-color);
    font-size: 0.875rem;
    text-align: center;
}

.error-message:empty {
    display: none;
}

.result-message .success {
    color: var(--success-color);
}

.result-message .error {
    color: var(--danger-color);
}

/* =============================================================================
   LANDING PAGE
   ============================================================================= */

.landing-page {
    overflow: auto;
}

.landing-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.landing-logo img {
    width: 120px;
    margin-bottom: 20px;
}

.landing-logo h1 {
    font-size: 2.5rem;
    font-weight: 700;
}

.landing-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-top: 10px;
}

.landing-info {
    margin-top: 30px;
    color: var(--text-muted);
}

/* =============================================================================
   ERROR PAGE
   ============================================================================= */

.error-page {
    overflow: auto;
}

.error-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.error-container h1 {
    font-size: 3rem;
    color: var(--danger-color);
}

.error-container p {
    margin: 20px 0;
    color: var(--text-secondary);
}

/* =============================================================================
   MAP PAGE - MAIN LAYOUT
   ============================================================================= */

.map-page {
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* =============================================================================
   MOBILE HEADER
   ============================================================================= */

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    z-index: 1100;
    padding: 0 15px;
    align-items: center;
    gap: 15px;
}

.hamburger-btn {
    width: 40px;
    height: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    transition: transform var(--transition-fast);
}

.mobile-title {
    flex: 1;
    font-size: 1.125rem;
    font-weight: 600;
}

.mobile-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
}

.mobile-status.online {
    background: var(--success-color);
}

/* =============================================================================
   SIDEBAR
   ============================================================================= */

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    z-index: 1200;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* =============================================================================
   SIDEBAR CONTROLS
   ============================================================================= */

.user-info {
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    text-align: center;
}

.user-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.user-name {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-top: 4px;
}

.control-group {
    margin-bottom: 24px;
}

.control-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* Date Inputs */
.date-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.date-input {
    flex: 1;
    min-width: 0;
}

.date-separator {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Quick Date Buttons */
.quick-dates {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.quick-date-btn {
    padding: 8px 12px;
    font-size: 0.875rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.quick-date-btn:hover {
    background: var(--bg-tertiary);
}

.quick-date-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Toggle Switches */
.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.toggle input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    transition: background var(--transition-fast);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary-color);
}

.toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9375rem;
    color: var(--text-primary);
}

/* Status Info */
.status-info {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 12px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.status-row:last-child {
    border-bottom: none;
}

.status-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-value {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* =============================================================================
   MAP CONTAINER
   ============================================================================= */

.map-container {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
}

/* Map Controls */
.map-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 800;
}

.map-control-btn {
    width: 40px;
    height: 40px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
    color: var(--text-primary);
}

.map-control-btn:hover {
    background: var(--bg-secondary);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

@media (prefers-color-scheme: dark) {
    .loading-overlay {
        background: rgba(15, 23, 42, 0.8);
    }
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =============================================================================
   MODAL
   ============================================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
}

.modal h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
}

/* =============================================================================
   LEAFLET CUSTOMIZATION
   ============================================================================= */

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
    background: var(--card-bg) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.leaflet-control-zoom a:last-child {
    border-bottom: none !important;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius) !important;
    box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-content {
    margin: 12px 16px !important;
    font-size: 0.875rem;
}

/* Custom Markers */
.current-position-marker {
    background: var(--primary-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.track-point-marker {
    background: var(--text-muted);
    border: 2px solid white;
    border-radius: 50%;
}

/* =============================================================================
   ADMIN LOGIN PAGE
   ============================================================================= */

.admin-login-page {
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.admin-login-box {
    width: 90%;
    max-width: 400px;
    padding: 40px;
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.admin-login-box .login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.admin-login-box .login-form {
    margin-top: 0;
}

/* =============================================================================
   ADMIN PAGE STYLES
   ============================================================================= */

.admin-page {
    overflow: auto;
}

.section {
    margin-bottom: 30px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-header h2 {
    font-size: 1.25rem;
}

/* =============================================================================
   RESPONSIVE - TABLET
   ============================================================================= */

@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }
    
    .quick-dates {
        grid-template-columns: 1fr;
    }
}

/* =============================================================================
   RESPONSIVE - MOBILE
   ============================================================================= */

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        max-width: 320px;
        height: 100%;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
        box-shadow: var(--shadow-lg);
        z-index: 1200;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-close {
        display: block;
    }
    
    /* Sidebar backdrop overlay */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1150;
    }
    
    .sidebar-backdrop.active {
        display: block;
    }
    
    .map-container {
        padding-top: var(--header-height);
    }
    
    .map-controls {
        top: calc(var(--header-height) + 15px);
        right: 15px;
        z-index: 800;
    }
    
    #map {
        z-index: 0;
    }
    
    .login-box {
        margin: 20px;
        padding: 30px 20px;
    }
    
    .modal {
        padding: 20px;
    }
    
    /* Admin responsive */
    .users-table {
        display: block;
        overflow-x: auto;
    }
    
    .btn-group {
        flex-wrap: wrap;
    }
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
    .sidebar,
    .mobile-header,
    .map-controls,
    .modal-overlay {
        display: none !important;
    }
    
    .map-container {
        padding: 0 !important;
    }
}
