/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    max-width: 100%;
}

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --text-color: #4a5568;
    --bg-light: #f7fafc;
    --border-color: #e2e8f0;
    --white: #ffffff;
    --shadow-color: rgba(0,0,0,0.1);

    /* Fluid typography */
    --font-size-h1: clamp(2rem, 5vw, 3rem);
    --font-size-h3: clamp(1.1rem, 2.5vw, 1.3rem);
    --font-size-body: clamp(0.9rem, 2vw, 1rem);
    --font-size-small: clamp(0.8rem, 1.5vw, 0.9rem);

    /* Spacing */
    --spacing-xs: clamp(5px, 1vw, 10px);
    --spacing-sm: clamp(10px, 2vw, 15px);
    --spacing-md: clamp(15px, 3vw, 25px);
    --spacing-lg: clamp(20px, 4vw, 30px);
}

html, body {
    width: 100%;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    font-size: var(--font-size-body);
}

body {
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--spacing-lg);
    width: 100%;
}

/* Header */
header {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    color: var(--white);
}

header h1 {
    font-size: var(--font-size-h1);
    margin-bottom: var(--spacing-sm);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    opacity: 0.9;
}

/* Main content layout */
.main-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

/* Panels */
.controls-panel, .results-panel, .map-container, .info-panel {
    background: var(--white);
    border-radius: 15px;
    padding: var(--spacing-md);
    box-shadow: 0 10px 30px var(--shadow-color);
    height: fit-content;
}

.controls-panel h3, .results-panel h4, .maidenhead-section h4 {
    color: var(--text-color);
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-h3);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.controls-panel h3 i, .results-panel h4 i, .maidenhead-section h4 i {
    color: var(--primary-color);
}

.location-section, .destination-section, .radio-section, .radio-calculations {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.location-section:last-child, .destination-section:last-child, .radio-section:last-child, .radio-calculations:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* Form elements */
.coordinates, .manual-coords, .radio-controls {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.coord-input, .control-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.coord-input label, .control-group label {
    font-weight: 600;
    color: var(--text-color);
    font-size: var(--font-size-small);
}

input[type="number"], input[type="text"] {
    padding: var(--spacing-sm);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: var(--font-size-body);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input[type="number"]:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.search-box {
    display: flex;
}

.search-box input {
    flex: 1;
    min-width: 0; /* Prevents input from overflowing */
}

/* Buttons */
.btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-body);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

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

.btn-secondary:hover {
    background: var(--text-color);
    transform: translateY(-2px);
}

.coordinates .btn,
.search-container .btn {
    width: 100%;
}

.btn-small {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-small);
}

/* Compass */
.bearing-display {
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.compass-rose {
    position: relative;
    width: clamp(120px, 30vw, 200px);
    height: clamp(120px, 30vw, 200px);
    margin: 0 auto var(--spacing-md);
    border: 3px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-light);
}

.compass-needle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: clamp(3px, 0.8vw, 4px);
    height: 40%;
    transform: translate(-50%, -100%);
    transform-origin: 50% 100%;
}

.needle {
    width: 100%;
    height: 100%;
    background: linear-gradient(to top, #2d3748 0% 50%, #e53e3e 50% 100%);
    border-radius: 2px;
    transition: transform 0.5s ease;
    transform-origin: bottom center;
}

.compass-labels {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-size: var(--font-size-small);
}

.compass-labels span {
    position: absolute;
    font-weight: bold;
    color: var(--text-color);
}

.compass-labels .north { top: 5%; left: 50%; transform: translateX(-50%); }
.compass-labels .east { right: 5%; top: 50%; transform: translateY(-50%); }
.compass-labels .south { bottom: 5%; left: 50%; transform: translateX(-50%); }
.compass-labels .west { left: 5%; top: 50%; transform: translateY(-50%); }

/* Bearing info */
.bearing-info {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.bearing-value span:first-child {
    display: block;
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: bold;
    color: var(--primary-color);
}

.bearing-value span:last-child {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    color: #718096;
}

.distance {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    font-weight: bold;
    color: var(--text-color);
}

/* Radio calculations */
.calc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-sm);
}

.calc-item {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-sm);
    background: var(--bg-light);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.calc-item .label {
    font-weight: 600;
    color: var(--text-color);
}

.calc-item span:last-child {
    font-weight: bold;
    color: var(--primary-color);
}

/* Maidenhead section */
.grid-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.grid-item {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-sm);
    background: var(--bg-light);
    border-radius: 8px;
    border-left: 4px solid #38a169;
}

.grid-item .label {
    font-weight: 600;
    color: var(--text-color);
}

.grid-item span:last-child {
    font-weight: bold;
    color: #38a169;
}

/* Map container */
.map-container {
    overflow: hidden;
    margin-bottom: var(--spacing-lg);
}

#map {
    width: 100%;
    height: clamp(250px, 50vh, 500px);
    border-radius: 10px;
    margin-bottom: var(--spacing-md);
}

.map-controls {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
}

/* Info panel */
.info-tabs {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--border-color);
    flex-wrap: wrap;
}

.tab-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: none;
    cursor: pointer;
    font-size: var(--font-size-body);
    font-weight: 600;
    color: #718096;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-content {
    min-height: 150px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.tab-pane h4 {
    color: var(--text-color);
    margin-bottom: var(--spacing-sm);
}

.tab-pane ol, .tab-pane ul {
    padding-left: var(--spacing-md);
}

.tab-pane li, .tab-pane p {
    margin-bottom: var(--spacing-sm);
    color: var(--text-color);
    line-height: 1.7;
}

/* Responsive design */
@media (max-width: 768px) {
    .info-tabs {
        flex-direction: column;
        gap: var(--spacing-xs);
        border-bottom: none;
    }
    .tab-btn {
        text-align: left;
        border-bottom: none;
        border-left: 3px solid transparent;
    }
    .tab-btn.active {
        border-left-color: var(--primary-color);
        border-bottom-color: transparent;
    }
}

/* Leaflet map customizations */
.leaflet-container { font-family: inherit; }
.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 15px; font-size: var(--font-size-small); }
.leaflet-popup-tip { background: var(--white); }

/* Loading states */
.loading { opacity: 0.6; pointer-events: none; }
.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px; height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--primary-color);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Success/error states */
.success { border-color: #38a169 !important; background-color: #f0fff4; }
.error { border-color: #e53e3e !important; background-color: #fff5f5; }

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn { border: 2px solid currentColor; }
    .compass-rose { border-width: 4px; }
}
