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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f0f2f5;
    color: #333;
}

/* Navbar */
.navbar {
    background: #2c3e50;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 50px;
}

.nav-brand {
    font-size: 18px;
    font-weight: bold;
    margin-right: 30px;
}

.nav-links a {
    color: #ecf0f1;
    text-decoration: none;
    margin-right: 20px;
    font-size: 14px;
}

.nav-links a:hover {
    color: #3498db;
}

/* Flash messages */
.flash-messages {
    padding: 0 20px;
}

.flash {
    padding: 10px 16px;
    margin: 10px 0;
    border-radius: 4px;
    font-size: 14px;
}

.flash-error {
    background: #fce4e4;
    color: #c0392b;
    border: 1px solid #e6b0aa;
}

.flash-success {
    background: #d5f5e3;
    color: #27ae60;
    border: 1px solid #a9dfbf;
}

/* Login */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    text-align: center;
}

.login-container h1 {
    margin-bottom: 30px;
    color: #2c3e50;
}

.login-form {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding-top: 20px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    background: white;
}

.btn:hover {
    background: #f5f5f5;
}

.btn-primary {
    background: #3498db;
    color: white;
    border-color: #2980b9;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-danger {
    background: #e74c3c;
    color: white;
    border-color: #c0392b;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.card h3 {
    margin-bottom: 16px;
    color: #2c3e50;
}

/* Map page */
.map-container {
    display: flex;
    height: calc(100vh - 50px);
}

.map-container.mobile-fullscreen {
    height: 100vh;
}

#map {
    flex: 1;
}

.map-sidebar {
    width: 280px;
    background: white;
    padding: 16px;
    overflow-y: auto;
    border-left: 1px solid #ddd;
}

.map-sidebar h3 {
    margin-bottom: 12px;
    color: #2c3e50;
    font-size: 14px;
}

.map-sidebar hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 16px 0;
}

.member-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    flex-wrap: wrap;
}

.member-entry:hover {
    background: #f5f5f5;
}

.member-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.member-name {
    font-size: 14px;
    font-weight: 500;
}

.member-time {
    font-size: 11px;
    color: #999;
    width: 100%;
    padding-left: 18px;
}

/* Geofence labels */
.geofence-label {
    background: transparent;
    border: none;
    box-shadow: none;
    color: #8e44ad;
    font-size: 12px;
    font-weight: 500;
}

/* User markers on map */
.user-marker div {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.marker-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* History controls */
.history-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-controls label {
    font-size: 12px;
    color: #666;
}

.history-controls select,
.history-controls input {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    width: 100%;
}

.history-controls .btn {
    width: 100%;
}

/* Admin page */
.admin-container {
    max-width: 900px;
    margin: 20px auto;
    padding: 0 20px;
}

.admin-container h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
}

.user-table th,
.user-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.user-table th {
    font-weight: 600;
    color: #666;
}

.user-table .actions {
    display: flex;
    gap: 8px;
}

/* Settings page */
.settings-container {
    max-width: 700px;
    margin: 20px auto;
    padding: 0 20px;
}

.settings-container h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.settings-form {
    max-width: 300px;
}

.avatar-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #3498db;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
}

.geofence-map {
    height: 350px;
    border-radius: 6px;
    margin-bottom: 16px;
    border: 1px solid #ddd;
}

.geofence-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.geofence-controls .form-row {
    gap: 12px;
}

.geofence-controls input[type="range"] {
    width: 100%;
    margin-top: 4px;
}

.geofence-controls input[readonly] {
    background: #f5f5f5;
    color: #666;
}

/* Workouts page */
.workouts-container {
    max-width: 900px;
    margin: 20px auto;
    padding: 0 20px;
}

.workouts-container h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

/* Workout detail page */
.workout-detail-container {
    max-width: 1100px;
    margin: 20px auto;
    padding: 0 20px;
}

.workout-detail-container h2 {
    margin-bottom: 4px;
    color: #2c3e50;
}

.workout-meta {
    color: #666;
    font-size: 14px;
    margin-bottom: 16px;
}

.workout-layout {
    display: flex;
    gap: 20px;
}

.workout-map-wrap {
    flex: 1;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#workoutMap {
    height: 500px;
}

.workout-stats {
    width: 280px;
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    align-self: flex-start;
}

.workout-stats h3 {
    margin-bottom: 12px;
    color: #2c3e50;
}

.stats-table {
    width: 100%;
}

.stats-table td {
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
}

.stat-label {
    color: #666;
}

.stat-value {
    text-align: right;
    font-weight: 500;
}

/* Events page */
.events-container {
    max-width: 700px;
    margin: 20px auto;
    padding: 0 20px;
}

.events-container h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.empty-msg {
    color: #999;
    font-size: 14px;
}

.timeline-date {
    font-size: 13px;
    font-weight: 600;
    color: #999;
    padding: 12px 0 4px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 4px;
}

.timeline-event {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 14px;
}

.event-time {
    color: #999;
    font-size: 13px;
    min-width: 60px;
}

.event-icon {
    font-size: 10px;
    min-width: 16px;
    text-align: center;
}

.event-enter .event-icon {
    color: #27ae60;
}

.event-exit .event-icon {
    color: #e74c3c;
}

.event-msg {
    flex: 1;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a2e;
        color: #e0e0e0;
    }

    .navbar {
        background: #16213e;
    }

    .card, .login-form, .map-sidebar, .workout-stats {
        background: #222244;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    }

    .form-group input[type="text"],
    .form-group input[type="password"],
    .history-controls select,
    .history-controls input {
        background: #2a2a4a;
        color: #e0e0e0;
        border-color: #444;
    }

    .btn {
        background: #2a2a4a;
        color: #e0e0e0;
        border-color: #555;
    }

    .btn:hover {
        background: #333366;
    }

    .btn-primary {
        background: #2980b9;
        border-color: #2471a3;
    }

    .btn-primary:hover {
        background: #2471a3;
    }

    .btn-danger {
        background: #c0392b;
        border-color: #a93226;
    }

    .map-sidebar {
        border-left-color: #333;
    }

    .member-entry:hover {
        background: #2a2a4a;
    }

    .member-time, .event-time, .stat-label {
        color: #888;
    }

    .user-table th {
        color: #aaa;
    }

    .user-table td, .user-table th {
        border-bottom-color: #333;
    }

    .flash-error {
        background: #3a1a1a;
        color: #e74c3c;
        border-color: #5a2a2a;
    }

    .flash-success {
        background: #1a3a1a;
        color: #2ecc71;
        border-color: #2a5a2a;
    }

    .timeline-date {
        border-bottom-color: #333;
    }

    .stats-table td {
        border-bottom-color: #333;
    }

    .card h3, h2, .login-container h1 {
        color: #e0e0e0;
    }

    .workout-meta, .empty-msg {
        color: #888;
    }

    a {
        color: #5dade2;
    }

    .geofence-map {
        border-color: #444;
    }

    .geofence-controls input[readonly] {
        background: #2a2a4a;
        color: #888;
    }
}
