/* =============================================================================
   ROADBOOK MAP - Styles
   ============================================================================= */

:root {
    --primary-color: #487854;
    --primary-dark: #3a6344;
    --primary-light: #5a9468;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --success-color: #28a745;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;
    --sidebar-width: 380px;
    --header-height: 60px;
    --border-radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    color: var(--gray-800);
    background: var(--gray-100);
    overflow: hidden;
}

/* =============================================================================
   Header
   ============================================================================= */

.header {
    height: var(--header-height);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    box-shadow: var(--shadow);
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-left .logo {
    height: 40px;
    width: auto;
}

.header-left h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.header-left .subtitle {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-left: 0.5rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* API Status Indicator */
.api-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: help;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: background-color 0.3s;
}

.status-dot.checking {
    background: #fbbf24;
    animation: pulse 1.5s infinite;
}

.status-dot.online {
    background: #3b82f6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.status-dot.offline {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-text {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* =============================================================================
   Buttons
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: white;
    color: var(--primary-color);
}

.btn-primary:hover {
    background: var(--gray-100);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

/* Boutons dans le header (fond sombre) */
.header .btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.header .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-small {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-icon {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--gray-500);
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-icon:hover {
    color: var(--gray-700);
    background: var(--gray-200);
}

.btn-close:hover {
    color: var(--danger-color);
}

/* =============================================================================
   Main Layout
   ============================================================================= */

.main-container {
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* =============================================================================
   Sidebar
   ============================================================================= */

.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-300);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
}

/* Sidebar elargie quand le formulaire est ouvert */
.sidebar.editing {
    width: calc(var(--sidebar-width) * 2);
}

.panel {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel h2 .hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--gray-500);
}

/* Conteneur des etapes + formulaire (side by side) */
.stages-container {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    min-height: 0;
}

.panel-stages {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: none;
    border-right: 1px solid var(--gray-200);
}

.panel-stages .stages-list {
    flex: 1;
    overflow-y: auto;
}

.panel-form {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    border-bottom: none;
    background: var(--gray-50);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* =============================================================================
   Stats Row
   ============================================================================= */

.stats-row {
    display: flex;
    justify-content: space-around;
    background: var(--gray-100);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    margin-top: 0.75rem;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
}

/* =============================================================================
   Form Styles
   ============================================================================= */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(72, 120, 84, 0.15);
}

.form-group input[readonly] {
    background: var(--gray-100);
    color: var(--gray-600);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-actions {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.form-actions .btn-primary {
    background: var(--primary-color);
    color: white;
    flex: 1;
}

.form-actions .btn-primary:hover {
    background: var(--primary-dark);
}

/* =============================================================================
   Stages List
   ============================================================================= */

.stages-list {
    max-height: 250px;
    overflow-y: auto;
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--gray-500);
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.empty-state span {
    font-size: 0.8rem;
}

.stage-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--gray-100);
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.stage-item:hover {
    background: var(--gray-200);
}

.stage-item.active {
    border-color: var(--primary-color);
    background: rgba(72, 120, 84, 0.1);
}

.stage-number {
    width: 28px;
    height: 28px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.stage-info {
    flex: 1;
    min-width: 0;
}

.stage-info .title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stage-info .meta {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.stage-actions {
    display: flex;
    gap: 0.25rem;
}

/* =============================================================================
   Questions Section
   ============================================================================= */

.questions-section {
    background: var(--gray-100);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-top: 1rem;
}

.questions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.questions-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-700);
}

.question-item {
    background: white;
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--gray-300);
}

.question-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.question-number {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.85rem;
}

.btn-remove-question {
    color: var(--gray-400);
}

.btn-remove-question:hover {
    color: var(--danger-color);
    background: rgba(220, 53, 69, 0.1);
}

.choices-section {
    margin-bottom: 1rem;
}

.choices-section label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}

.choices-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.choices-list input {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
}

/* =============================================================================
   Map Container
   ============================================================================= */

.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

.map-instructions {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    z-index: 1000;
}

.map-instructions span {
    font-weight: 600;
    color: var(--warning-color);
}

/* =============================================================================
   Custom Leaflet Markers
   ============================================================================= */

.custom-marker {
    background: var(--primary-color);
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}

.custom-marker span {
    transform: rotate(45deg);
}

.custom-marker.active {
    background: var(--warning-color);
    color: var(--gray-800);
}

/* Leaflet popup custom style */
.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius);
}

.leaflet-popup-content {
    margin: 0.75rem 1rem;
}

.popup-content {
    text-align: center;
}

.popup-content h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
}

.popup-content .popup-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}

.popup-content .btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

/* =============================================================================
   Toast Notifications
   ============================================================================= */

#toast-container {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 280px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* =============================================================================
   Modal
   ============================================================================= */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--primary-color);
    color: white;
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.modal-header .btn-close {
    color: white;
}

.modal-header .btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

.modal-intro {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

/* Checkbox Group */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.checkbox-label:hover {
    background: var(--gray-100);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* Generate Status */
.generate-status {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--gray-100);
    border-radius: var(--border-radius);
    margin-top: 1rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Accent Button */
.btn-accent {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border: none;
}

.btn-accent:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
}

.btn-generate {
    background: var(--primary-color);
    color: white;
}

.btn-generate:hover {
    background: var(--primary-dark);
}

.form-group small {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

/* Mini-map dans le formulaire d'edition */
.mini-map-container {
    width: 100%;
    height: 220px;
    border-radius: var(--border-radius);
    overflow: hidden;
    border: 2px solid var(--primary-color);
    background: var(--gray-100);
    position: relative;
}

.mini-map-container::after {
    content: 'Cliquez ou deplacez le marqueur pour ajuster la position';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(72, 120, 84, 0.9);
    color: white;
    font-size: 11px;
    padding: 4px 8px;
    text-align: center;
    z-index: 1000;
    pointer-events: none;
}

.mini-map-container #mini-map {
    width: 100%;
    height: 100%;
}

.mini-map-container .leaflet-control-zoom {
    margin-top: 5px;
    margin-left: 5px;
}

.mini-map-container .leaflet-control-zoom a {
    width: 26px;
    height: 26px;
    line-height: 26px;
    font-size: 14px;
}

.mini-map-container .leaflet-control-attribution {
    font-size: 8px;
    background: rgba(255,255,255,0.7);
}

/* Style pour le marqueur draggable dans la mini-map */
.mini-marker.draggable {
    background: transparent !important;
    border: none !important;
    width: 24px !important;
    height: 24px !important;
    cursor: grab !important;
}

.mini-marker.draggable:active {
    cursor: grabbing !important;
}

.mini-marker .marker-inner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    z-index: 2;
}

.mini-marker .marker-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: rgba(72, 120, 84, 0.3);
    border-radius: 50%;
    animation: pulse-ring 1.5s ease-out infinite;
    z-index: 1;
}

@keyframes pulse-ring {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

/* Tooltip sur mini-map */
.mini-map-tooltip {
    background: var(--primary-color) !important;
    border: none !important;
    color: white !important;
    font-weight: 500;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.mini-map-tooltip::before {
    border-top-color: var(--primary-color) !important;
}

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 1200px) {
    /* Sur ecrans moyens, reduire l'expansion de la sidebar */
    .sidebar.editing {
        width: calc(var(--sidebar-width) * 1.6);
    }
}

@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 50%;
        border-right: none;
        border-bottom: 1px solid var(--gray-300);
    }

    .sidebar.editing {
        width: 100%;
        height: 60%;
    }

    /* Sur mobile, empiler verticalement les panels */
    .stages-container {
        flex-direction: column;
    }

    .panel-stages {
        flex: 0 0 auto;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--gray-200);
    }

    .panel-form {
        flex: 1;
    }

    .map-container {
        height: 50%;
    }

    .sidebar.editing + .map-container {
        height: 40%;
    }

    .header-left .subtitle {
        display: none;
    }
}

@media (max-width: 600px) {
    .header {
        padding: 0 1rem;
    }

    .header-left h1 {
        font-size: 1.2rem;
    }

    .btn span {
        display: none;
    }

    :root {
        --sidebar-width: 100%;
    }

    .mini-map-container {
        height: 150px;
    }

    .mini-map-container::after {
        font-size: 9px;
        padding: 3px 6px;
    }
}
