/* CSS Variables */
:root {
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --secondary-color: #4CAF50;
    --danger-color: #f44336;
    --warning-color: #FF9800;
    --background-dark: #1a1a2e;
    --background-card: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #2d3a5a;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-small: 8px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-dark);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
#app {
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--background-card);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

#header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-small);
    transition: background-color 0.2s;
}

.btn-icon:hover,
.btn-icon:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Map */
#map {
    flex: 1;
    width: 100%;
    z-index: 1;
}

/* Stats Panel */
#stats-panel {
    display: flex;
    justify-content: space-around;
    padding: 12px 8px;
    background: var(--background-card);
    border-top: 1px solid var(--border-color);
    z-index: 100;
}

#stats-panel.hidden {
    display: none;
}

.stat {
    text-align: center;
    padding: 4px 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* GPS Status */
.gps-status {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 20px;
    font-size: 0.875rem;
    z-index: 500;
    backdrop-filter: blur(4px);
}

.gps-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning-color);
    animation: pulse 2s infinite;
}

.gps-dot.active {
    background: var(--secondary-color);
}

.gps-dot.error {
    background: var(--danger-color);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Control Buttons */
#controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    background: var(--background-card);
    border-top: 1px solid var(--border-color);
    z-index: 100;
}

.btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px 32px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 100px;
}

.btn-icon-large {
    font-size: 1.5rem;
}

.btn-start {
    background: var(--secondary-color);
    color: white;
}

.btn-start:hover,
.btn-start:active {
    background: #43A047;
    transform: scale(1.02);
}

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

.btn-stop:hover,
.btn-stop:active {
    background: #E53935;
    transform: scale(1.02);
}

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

.btn-pause:hover,
.btn-pause:active {
    background: #FB8C00;
    transform: scale(1.02);
}

.btn.hidden {
    display: none;
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: 85%;
    max-width: 350px;
    height: 100%;
    background: var(--background-card);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
}

.side-menu.visible {
    transform: translateX(0);
}

.side-menu.hidden {
    transform: translateX(100%);
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.menu-header h2 {
    font-size: 1.125rem;
}

/* Traces List */
.traces-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.empty-message {
    text-align: center;
    color: var(--text-secondary);
    padding: 32px 16px;
}

.trace-item {
    background: var(--background-dark);
    border-radius: var(--radius-small);
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
}

.trace-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.trace-name {
    font-weight: 600;
    font-size: 1rem;
    word-break: break-word;
}

.trace-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.trace-stats {
    display: flex;
    gap: 16px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

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

.trace-actions button {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius-small);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.btn-export {
    background: var(--secondary-color);
    color: white;
}

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

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 900;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Dialog */
.dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1100;
    padding: 20px;
}

.dialog.hidden {
    display: none;
}

.dialog-content {
    background: var(--background-card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 320px;
    box-shadow: var(--shadow);
}

.dialog-content h3 {
    margin-bottom: 16px;
    text-align: center;
}

.dialog-content input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-small);
    background: var(--background-dark);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 16px;
}

.dialog-content input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.dialog-buttons {
    display: flex;
    gap: 12px;
}

.dialog-buttons .btn {
    flex: 1;
    padding: 12px;
}

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

.btn-secondary {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 0.875rem;
    z-index: 1200;
    opacity: 0;
    transition: opacity 0.3s;
    max-width: 90%;
    text-align: center;
}

.toast.visible {
    opacity: 1;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Leaflet Customization */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
    background: var(--background-card) !important;
    color: var(--text-primary) !important;
    border: none !important;
}

.leaflet-control-zoom a:hover {
    background: var(--background-dark) !important;
}

.leaflet-control-attribution {
    background: rgba(0, 0, 0, 0.6) !important;
    color: var(--text-secondary) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

/* Current Position Marker */
.current-position-marker {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
}

.accuracy-circle {
    fill: rgba(33, 150, 243, 0.15);
    stroke: rgba(33, 150, 243, 0.4);
    stroke-width: 1;
}

/* Measure distance tooltip */
.measure-tooltip {
    background: rgba(0, 0, 0, 0.55);
    border: none;
    border-radius: 6px;
    padding: 3px 8px;
    color: #FF9800;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-shadow: none;
    box-shadow: none;
    white-space: nowrap;
}

.measure-tooltip::before {
    display: none;
}

/* Recording indicator */
.recording-indicator {
    position: absolute;
    top: 70px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(244, 67, 54, 0.9);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 500;
    animation: recording-pulse 1.5s infinite;
}

.recording-indicator.hidden {
    display: none;
}

.recording-dot {
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
}

@keyframes recording-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Media Queries */
@media (min-width: 768px) {
    .side-menu {
        width: 350px;
    }
    
    #controls {
        padding: 20px;
    }
    
    .btn {
        padding: 20px 48px;
        min-width: 140px;
    }
}

/* Safe area for notched devices */
@supports (padding-top: env(safe-area-inset-top)) {
    #header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
    
    #controls {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}
