/**
 * TideTrack Frontend - Main Styles
 * Design System & Global Layout
 */

/* ============================================
   CSS VARIABLES - DESIGN SYSTEM
   ============================================ */

:root {
    /* Primary Colors - Ocean Blues */
    --color-primary: #0077BE;
    --color-primary-light: #4A9FD8;
    --color-primary-dark: #005A8F;

    /* Secondary Colors */
    --color-secondary: #FF6B35;
    --color-accent: #00C9A7;

    /* Neutrals */
    --color-bg-dark: #1A2332;
    --color-bg-medium: #2C3E50;
    --color-bg-light: #ECF0F1;
    --color-text-primary: #2C3E50;
    --color-text-secondary: #7F8C8D;
    --color-text-inverse: #FFFFFF;

    /* Status Colors */
    --color-success: #27AE60;
    --color-warning: #F39C12;
    --color-error: #E74C3C;
    --color-info: #3498DB;

    /* Environmental Data Colors */
    --color-wind-light: #A8E6CF;
    /* 0-5 kt - light green */
    --color-wind-moderate: #FFD93D;
    /* 5-12 kt - yellow */
    --color-wind-strong: #FF6B6B;
    /* 12-20 kt - red */
    --color-wind-very-strong: #C41E3A;
    /* 20-26 kt - dark red */
    --color-wind-severe: #4B0082;
    /* 26+ kt - deep purple/indigo */

    --color-current-very-light: #B3E5FC;
    --color-current-light: #8CC4D6;
    --color-current-medium: #6AADCA;
    --color-current-moderate: #4895B8;
    --color-current-strong: #2D7DA3;
    --color-current-very-strong: #18648D;

    /* Route Colors */
    --color-route-good: #27AE60;
    --color-route-moderate: #F39C12;
    --color-route-challenging: #E67E22;
    --color-route-difficult: #E74C3C;

    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Roboto Mono', 'Courier New', monospace;

    --text-xs: 0.75rem;
    /* 12px */
    --text-sm: 0.875rem;
    /* 14px */
    --text-base: 1rem;
    /* 16px */
    --text-lg: 1.125rem;
    /* 18px */
    --text-xl: 1.25rem;
    /* 20px */
    --text-2xl: 1.5rem;
    /* 24px */
    --text-3xl: 1.875rem;
    /* 30px */

    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.75;

    /* Spacing */
    --space-1: 0.25rem;
    /* 4px */
    --space-2: 0.5rem;
    /* 8px */
    --space-3: 0.75rem;
    /* 12px */
    --space-4: 1rem;
    /* 16px */
    --space-5: 1.25rem;
    /* 20px */
    --space-6: 1.5rem;
    /* 24px */
    --space-8: 2rem;
    /* 32px */
    --space-10: 2.5rem;
    /* 40px */
    --space-12: 3rem;
    /* 48px */

    /* Touch Targets */
    --touch-target-min: 44px;

    /* 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);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --panel-shadow: 0 0 20px rgba(0, 0, 0, 0.3);

    /* Layout */
    --header-height: 44px;
    --panel-width: 300px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg-light);
    overflow: hidden;
}

/* ============================================
   LAYOUT
   ============================================ */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: var(--color-bg-dark);
    color: var(--color-text-inverse);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-3);
    box-shadow: var(--shadow-md);
    z-index: 1000;
}

.app-header__logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
}

.app-header__logo-icon {
    font-size: var(--text-lg);
}

.app-header__status {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

.app-header__settings {
    display: flex;
    align-items: center;
}

/* Main Content Area */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    margin-bottom: var(--space-4);
}

h1 {
    font-size: var(--text-3xl);
}

h2 {
    font-size: var(--text-2xl);
}

h3 {
    font-size: var(--text-xl);
}

h4 {
    font-size: var(--text-lg);
}

h5 {
    font-size: var(--text-base);
}

h6 {
    font-size: var(--text-sm);
}

p {
    margin-bottom: var(--space-4);
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-light);
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    line-height: 1;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: var(--touch-target-min);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary Button */
.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--color-primary-light);
}

.btn-primary:active:not(:disabled) {
    background-color: var(--color-primary-dark);
}

/* Secondary Button */
.btn-secondary {
    background-color: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
}

/* Route Buttons Row */
.route-buttons {
    display: flex;
    gap: var(--space-2);
}

.route-buttons .btn-primary {
    flex: 1;
}

.route-buttons .btn-secondary {
    flex: 0 0 auto;
}

/* Icon Button */
.btn-icon {
    padding: var(--space-2);
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    background-color: transparent;
    color: var(--color-text-inverse);
}

.btn-icon:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    margin-bottom: var(--space-1);
    color: var(--color-text-primary);
}

.form-input,
.form-select {
    width: 100%;
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    line-height: var(--leading-tight);
    color: var(--color-text-primary);
    background-color: white;
    border: 1px solid var(--color-bg-medium);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition-fast);
    min-height: 40px;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-input::placeholder {
    color: var(--color-text-secondary);
}

.form-input.error {
    border-color: var(--color-error);
}

.form-error {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--text-sm);
    color: var(--color-error);
}

/* ============================================
   STATUS INDICATORS
   ============================================ */

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.status-dot.success {
    background-color: var(--color-success);
}

.status-dot.warning {
    background-color: var(--color-warning);
}

.status-dot.error {
    background-color: var(--color-error);
}

.status-dot.info {
    background-color: var(--color-info);
}

/* ============================================
   CARDS
   ============================================ */

.card {
    background-color: white;
    border: 1px solid var(--color-bg-medium);
    border-radius: var(--radius-sm);
    box-shadow: none;
    padding: var(--space-1);
    margin-bottom: var(--space-1);
}

.card-header {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-bg-light);
}

.card-body {
    font-size: var(--text-base);
}

/* ============================================
   LOADING STATES
   ============================================ */

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: var(--radius-full);
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.text-primary {
    color: var(--color-primary);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.text-success {
    color: var(--color-success);
}

.text-warning {
    color: var(--color-warning);
}

.text-error {
    color: var(--color-error);
}

.font-bold {
    font-weight: var(--font-bold);
}

.font-semibold {
    font-weight: var(--font-semibold);
}

.font-medium {
    font-weight: var(--font-medium);
}

.uppercase {
    text-transform: uppercase;
}

.mt-0 {
    margin-top: 0;
}

.mt-2 {
    margin-top: var(--space-2);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mb-0 {
    margin-bottom: 0;
}

.mb-2 {
    margin-bottom: var(--space-2);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles */
*:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --color-text-primary: #000000;
        --color-text-inverse: #FFFFFF;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   BOTTOM TIME BAR
   ============================================ */

.time-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    min-height: 36px;
    padding: 0 10px;
    background: var(--color-bg-dark);
    color: var(--color-text-inverse);
    z-index: 1001;
    flex-shrink: 0;
    overflow: visible;
}

.time-bar__display {
    white-space: nowrap;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 140px;
    text-align: left;
    color: rgba(255, 255, 255, 0.9);
}

.time-bar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--color-text-inverse);
    cursor: pointer;
    font-size: 0.65rem;
    flex-shrink: 0;
    transition: background 0.15s;
}

.time-bar__btn:hover:not(:disabled) {
    background: var(--color-primary);
    color: #fff;
}

.time-bar__btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.time-bar__btn--play {
    font-size: 0.6rem;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    background: transparent;
}

.time-bar__btn--play:hover:not(:disabled) {
    border-color: var(--color-primary);
    background: rgba(255, 255, 255, 0.1);
}

.time-bar__btn--play.playing {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.time-bar__btn--reset {
    width: auto;
    padding: 0 8px;
    font-size: 0.65rem;
    font-weight: 600;
}

.time-bar__slider-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    overflow: visible;
}

.time-bar__slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    position: relative;
    z-index: 2;
    /* above ticks so thumb is draggable */
}

.time-bar__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-primary);
    border: 2px solid #fff;
    cursor: pointer;
}

.time-bar__slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-primary);
    border: 2px solid #fff;
    cursor: pointer;
}

/* Tick marks overlaying the slider at midnight and hourly boundaries */
.time-bar__ticks {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
}

.time-bar__tick {
    position: absolute;
    top: -2px;
    width: 2px;
    height: calc(100% + 4px);
    background: rgba(255, 255, 255, 0.5);
    transform: translateX(-50%);
}

.time-bar__tick--hour {
    position: absolute;
    top: 30%;
    width: 1px;
    height: 40%;
    background: rgba(255, 255, 255, 0.25);
    transform: translateX(-50%);
}

.time-bar__tick-label {
    position: absolute;
    top: 1px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.55rem;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
    font-weight: 600;
    line-height: 1;
}

/* On small screens, shrink the time display */
@media (max-width: 480px) {
    .time-bar__display {
        min-width: 90px;
        font-size: 0.65rem;
    }

    .time-bar {
        gap: 4px;
        padding: 0 6px;
    }
}
