/* 
   Theme: Premium Nautical
   Colors: Navy Blue, Gold/Sand, Clean White
*/

:root {
    --color-navy: #0a192f;
    --color-navy-light: #172a45;
    --color-gold: #d4af37;
    --color-sand: #f3e5ab;
    --color-white: #ffffff;
    --color-text: #333333;
    --color-text-light: #8892b0;
    --color-bg-light: #f4f7f6;

    --font-heading: 'Playfair Display', serif;
    --font-body: 'Inter', sans-serif;

    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-card: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--color-bg-light);
    color: var(--color-text);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    /* App-like feel */
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
header {
    background-color: var(--color-navy);
    color: var(--color-white);
    padding: 1rem 2rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    padding-left: calc(2rem + env(safe-area-inset-left));
    padding-right: calc(2rem + env(safe-area-inset-right));
    display: flex;
    flex-wrap: nowrap;
    /* Forced one line */
    gap: 15px;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-soft);
    z-index: 1000;
}

header h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    letter-spacing: 1px;
    color: var(--color-gold);
    white-space: nowrap;
    /* Prevent title break */
}

header .user-select {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    /* Slightly smaller text */
}

select#user-picker {
    background: var(--color-navy-light);
    color: var(--color-white);
    border: 1px solid var(--color-gold);
    padding: 5px 10px;
    border-radius: 4px;
    font-family: var(--font-body);
}

/* --- Main Layout --- */
main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#sidebar {
    width: 400px;
    background: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e0e0;
    z-index: 900;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
    padding-left: env(safe-area-inset-left);
}

#map-container {
    flex: 1;
    background: #e5e5e5;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* --- Navigation Tabs --- */
.tabs {
    display: flex;
    flex-direction: column;
    background: var(--color-navy);
    padding: 10px;
    gap: 8px;
    border-bottom: 2px solid var(--color-gold);
}

.tab-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    background: var(--color-navy-light);
    border: 1px solid rgba(212, 175, 55, 0.2);
    padding: 12px 15px;
    color: var(--color-text-light);
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 8px;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.tab-btn small {
    font-size: 0.8rem;
    opacity: 0.7;
    font-weight: 400;
    margin-top: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: 10px;
}

.tab-btn:hover {
    color: var(--color-white);
    background: rgba(212, 175, 55, 0.05);
    border-color: var(--color-gold);
    transform: translateX(5px);
}

.tab-btn.active {
    color: var(--color-white);
    background: var(--color-navy-light);
    border-color: var(--color-gold);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tab-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--color-gold);
}

.tab-btn.btn-weather {
    border-color: #3498db;
}

.tab-btn.btn-weather.active {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
    border-color: #3498db;
}

/* --- Itinerary List --- */
#itinerary-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    background: var(--color-bg-light);
}

.itinerary-header {
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--color-navy);
}

.scenario-title {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--color-navy);
    margin-bottom: 5px;
}

.scenario-meta {
    font-size: 1rem;
    color: var(--color-text-light);
    font-style: italic;
    line-height: 1.4;
}

.step-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
    border-left: 6px solid var(--color-navy);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.step-card:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.step-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, transparent 50%, rgba(212, 175, 55, 0.05) 50%);
    pointer-events: none;
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.step-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.step-day {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--color-text-light);
    font-weight: 700;
}

.step-distance {
    background: var(--color-bg-light);
    color: var(--color-navy);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 800;
    border: 1px solid #e2e8f0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.icon-inline {
    font-size: 1.1em;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

.step-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    color: var(--color-navy);
    margin-top: 5px;
}

.step-number-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
}

.step-details {
    margin-top: 10px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #555;
    margin-bottom: 15px;
}

.step-meta {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    font-size: 0.85rem;
    color: #666;
}

.meta-icon {
    color: var(--color-gold);
    margin-right: 5px;
}

.tourisme-info,
.org-info,
.tech-fiche {
    margin-top: 15px;
    padding: 15px;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: transform 0.2s ease;
}

.tourisme-info {
    background: #ebf8ff;
    border: 1px solid #bee3f8;
    border-left: 5px solid #3182ce;
    color: #2c5282;
}

.org-info {
    background: #fffaf0;
    border: 1px solid #feebc8;
    border-left: 5px solid #dd6b20;
    color: #7b341e;
}

.tech-fiche {
    background: #f7fafc;
    border: 1px solid #edf2f7;
    border-left: 5px solid var(--color-navy);
}

.info-content {
    line-height: 1.6;
    margin-top: 5px;
}

.step-info-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tech-fiche strong {
    display: block;
    margin-bottom: 5px;
    color: var(--color-navy);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tech-fiche ul {
    list-style: none;
    padding: 0;
}

.tech-fiche li {
    margin-bottom: 4px;
    line-height: 1.4;
}

.tech-fiche li span {
    font-weight: 700;
    color: #666;
    margin-right: 5px;
}

.tech-fiche a {
    color: #3498db;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed #3498db;
    transition: all 0.2s;
}

.tech-fiche a:hover {
    color: var(--color-navy);
    border-bottom-style: solid;
}

.tourisme-info a {
    color: #3498db;
    text-decoration: underline;
    font-weight: 600;
}

.tourisme-info a:hover {
    color: var(--color-navy);
}

.tourisme-info strong,
.org-info strong {
    display: block;
    margin-bottom: 3px;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

/* --- Comments Section --- */
.comments-section {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 6px;
    margin-top: 15px;
}

.comments-header {
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--color-navy);
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 8px;
}

.comment-list {
    margin-bottom: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.comment-item {
    font-size: 0.9rem;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.comment-user {
    font-weight: 700;
    color: var(--color-navy);
    font-size: 0.8rem;
}

.comment-text {
    display: block;
    margin-top: 2px;
}

.comment-form {
    display: flex;
    gap: 5px;
}

.comment-input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: var(--font-body);
}

.comment-submit {
    background: var(--color-navy);
    color: var(--color-gold);
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.comment-submit:hover {
    background: var(--color-navy-light);
}

.comment-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.btn-edit-comment {
    background: none;
    border: none;
    color: var(--color-navy);
    font-size: 0.75rem;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    opacity: 0.7;
}

.btn-edit-comment:hover {
    opacity: 1;
}

.edit-form {
    margin-top: 5px;
}

.edit-input {
    width: 100%;
    min-height: 60px;
    margin-bottom: 5px;
    padding: 8px;
    border: 1px solid var(--color-gold);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
}

.edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-cancel,
.btn-save {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: 600;
}

.btn-cancel {
    background: #eee;
    border: 1px solid #ddd;
    color: #666;
}

.btn-save {
    background: var(--color-navy);
    color: var(--color-gold);
    border: none;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    main {
        flex-direction: column-reverse;
        /* List on bottom for mobile */
    }

    #sidebar {
        width: 100%;
        flex: 65;
        /* Use flex ratio instead of vh to account for header */
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .tabs {
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding: 5px;
        gap: 5px;
        -webkit-overflow-scrolling: touch;
        border-bottom: 1px solid var(--color-gold);
    }

    .tab-btn {
        flex: 0 0 auto;
        padding: 8px 12px;
        font-size: 0.8rem;
        flex-direction: column;
        /* Stack icons above text on mobile */
        align-items: center;
        gap: 2px;
    }

    .tab-btn small {
        display: none;
        /* Hide small text on mobile tabs to save space */
    }

    #map-container {
        width: 100%;
        flex: 35;
        /* Use flex ratio instead of vh */
        position: relative;
    }

    header {
        padding: 0.6rem 0.8rem;
        /* Further reduced padding */
    }

    header h1 {
        font-size: 1.1rem;
        /* Slightly smaller */
    }

    header .user-select label {
        display: inline-block;
        font-size: 0.8rem;
        /* Slightly smaller to fit */
    }

    header .user-select {
        gap: 5px;
        /* Reduce gap to save space */
    }
}

/* --- POI & Anchor Markers --- */
.custom-poi-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.poi-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.poi-icon:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    z-index: 2000;
}

.port-icon {
    border-radius: 4px;
    /* Squares for ports */
}

.icon-sym {
    line-height: 1;
    pointer-events: none;
}

.poi-popup {
    min-width: 150px;
}

.poi-popup strong {
    color: var(--color-navy);
    display: block;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    margin-bottom: 5px;
}

.poi-popup p {
    color: #555;
    line-height: 1.4;
}

/* Ensure step markers are clearly distinct */
.marker-pin {
    z-index: 1000;
}

/* Marker Styles */
.custom-div-icon {
    border: none;
    background: none;
}

.marker-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    background: #c30b82;
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -15px 0 0 -15px;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
}

.marker-pin::after {
    content: '';
    width: 24px;
    height: 24px;
    margin: 3px 0 0 3px;
    background: #fff;
    position: absolute;
    border-radius: 50%;
}

.marker-num {
    position: absolute;
    top: 11px;
    /* Center in the pin circle */
    left: 0;
    width: 30px;
    text-align: center;
    font-weight: 800;
    font-size: 13px;
    color: #1a202c;
    z-index: 1001;
    /* Must be higher than marker-pin (1000) */
    pointer-events: none;
}

/* --- Leaflet Layer Control Customization --- */
.leaflet-control-layers {
    border: none !important;
    box-shadow: var(--shadow-card) !important;
    border-radius: 8px !important;
    background-color: var(--color-navy) !important;
    color: var(--color-white) !important;
    padding: 5px !important;
}

.leaflet-control-layers-expanded {
    padding: 8px 12px !important;
}

.leaflet-control-layers label {
    font-family: var(--font-body);
    font-size: 0.85rem;
    margin-bottom: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.leaflet-control-layers-base label:last-child {
    margin-bottom: 0;
}

.leaflet-control-layers input[type="radio"] {
    accent-color: var(--color-gold);
}

/* Ensure Leaflet controls don't hit the notch/home bar */
.leaflet-bottom {
    margin-bottom: env(safe-area-inset-bottom);
}

.leaflet-right {
    margin-right: env(safe-area-inset-right);
}

.leaflet-left {
    margin-left: env(safe-area-inset-left);
}

/* --- Weather Synthesis Styles --- */
.weather-container {
    padding-bottom: 30px;
}

.weather-main-title {
    font-family: var(--font-heading);
    color: var(--color-navy);
    font-size: 1.6rem;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--color-gold);
    padding-bottom: 10px;
}

.weather-intro {
    font-size: 1rem;
    line-height: 1.6;
    color: #444;
    margin-bottom: 25px;
    font-style: italic;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.weather-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.weather-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow-card);
    border-top: 3px solid var(--color-navy);
}

.weather-card-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 12px;
}

.weather-icon {
    font-size: 2rem;
}

.weather-card-titles h3 {
    font-family: var(--font-heading);
    color: var(--color-navy);
    font-size: 1.2rem;
    margin: 0;
}

.weather-card-titles small {
    color: var(--color-text-light);
    font-weight: 600;
}

.weather-card p {
    font-size: 0.95rem;
    line-height: 1.5;
    color: #555;
}

.weather-details {
    margin-top: 15px;
    padding-left: 20px;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.weather-details li {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 5px;
}

.weather-risks {
    margin-top: 30px;
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 10px;
    padding: 20px;
}

.weather-risks h3 {
    color: #c53030;
    font-size: 1.1rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.weather-risks ul {
    padding-left: 20px;
}

.weather-risks li {
    font-size: 0.95rem;
    color: #742a2a;
    margin-bottom: 8px;
    line-height: 1.4;
}

/* Weather-specific button style */
.btn-weather.active {
    background: #2c3e50 !important;
    color: #3498db !important;
    border-bottom-color: #3498db !important;
}

.btn-weather {
    background: rgba(52, 152, 219, 0.1);
}

/* --- Weather View (Full Page) --- */
#weather-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: var(--color-bg-light);
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    /* Full bleed image */
    z-index: 950;
}

#weather-view img.meteo-map {
    width: 100%;
    height: auto;
    display: block;
    box-shadow: none;
    /* Removed for full bleed feel */
    border: none;
    border-radius: 0;
}

#weather-view .weather-container {
    max-width: 1000px;
    margin: 0 auto;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

#weather-view .weather-main-title {
    text-align: center;
    font-size: 2.2rem;
    margin-bottom: 20px;
}

#weather-view .weather-intro {
    text-align: center;
    max-width: 800px;
    margin: 0 auto 40px;
    font-size: 1.1rem;
}

/* Ensure synthesis text looks good in sidebar */
#itinerary-list .weather-container {
    padding: 10px 0;
}

#itinerary-list .weather-main-title {
    font-size: 1.4rem;
    margin-bottom: 20px;
    text-align: left;
    border-bottom: 2px solid var(--color-gold);
}

#itinerary-list .weather-intro {
    font-size: 0.95rem;
    margin-bottom: 20px;
    font-style: italic;
    color: #666;
}

#itinerary-list .weather-card {
    margin-bottom: 20px;
    padding: 15px;
}

@media (max-width: 768px) {
    #weather-view {
        padding: 10px;
        height: 100%;
        /* Fill the 35% flex container */
        /* Shorter image area on mobile */
    }
}