/* ========================================
   FICHIER CSS - MOTOREX TURBO VOICE
   VERSION AVEC NAVBAR MODERNE (STYLE WHATSAPP)
   ======================================== */

/* ========== IMPORT POLICE INTER ========== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ========== STYLES GÉNÉRAUX ========== */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #f0f4f8;
    overflow: hidden;
    position: fixed;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== EN-TÊTE FIXE EN HAUT (STYLE iOS MODERNE) ========== */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(1, 144, 132, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    font-weight: 600;
    font-size: 1.1rem;
    z-index: 10;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.15);
}

/* Logo avec espacement */
header img[alt="Logo Motorex"] {
    height: 32px;
    transition: opacity 0.2s ease;
}

header img[alt="Logo Motorex"]:active {
    opacity: 0.7;
}

/* Container des boutons à droite */
.header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* Boutons d'action style iOS minimaliste */
.header-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease, transform 0.1s ease;
    min-width: 32px;
    min-height: 32px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    opacity: 0.9;
}

.header-button:hover {
    opacity: 1;
}

.header-button:active {
    opacity: 0.5;
    transform: scale(0.92);
}

.header-button svg {
    width: 24px;
    height: 24px;
    stroke: white;
    transition: none;
}

.header-button:active svg {
    transform: none;
}

/* ========== TOGGLE MODE ANALYSE ========== */
.analysis-toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.analysis-toggle-container input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    transition: background-color 0.3s ease;
    flex-shrink: 0;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.analysis-toggle-container input:checked + .toggle-slider {
    background: #ffd500; /* Jaune Motorex */
}

.analysis-toggle-container input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 14px;
    font-weight: 500;
    color: white;
    white-space: nowrap;
}

/* ========== CONTENEUR PRINCIPAL SPLIT VIEW ========== */
#main-container {
    display: flex;
    margin-top: 70px;
    height: calc(100vh - 120px);
    gap: 0;
    transition: all 0.3s ease;
}

/* Mode normal: chat pleine largeur */
#main-container:not(.split-mode) #chat-window {
    width: 100%;
}

#main-container:not(.split-mode) #analysis-panel {
    width: 0;
    overflow: hidden;
}

/* Mode split: 40% chat, 60% tableau */
#main-container.split-mode #chat-window {
    width: 40%;
    border-right: 1px solid #e0e0e0;
}

#main-container.split-mode #analysis-panel {
    width: 60%;
    opacity: 1;
    transform: translateX(0);
}

/* ========== FENÊTRE DE CHAT (MESSAGES) ========== */
#chat-window {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    flex-shrink: 0;
}

#chat-window::after {
    content: '';
    display: block;
    height: 70px;
    flex-shrink: 0;
}

/* ========== PANEL D'ANALYSE (TABLEAU) ========== */
.analysis-panel {
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateX(20px);
}

.analysis-panel.hidden {
    display: none;
}

.analysis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.analysis-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #26a89b;
}

.clear-table-btn {
    background: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-table-btn:hover {
    background: #f0f0f0;
    color: #26a89b;
}

#analysis-table {
    flex: 1;
    overflow: hidden;
    padding: 8px;
}

/* Personnalisation Tabulator */
#analysis-table .tabulator {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
}

#analysis-table .tabulator-header {
    background: #26a89b;
    color: white;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

#analysis-table .tabulator-header .tabulator-col {
    background: #26a89b;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

#analysis-table .tabulator-row:hover {
    background: #f0f8f7;
}

#analysis-table .tabulator-row.tabulator-selected {
    background: #e6f7f5;
}

/* ========== STYLES DES MESSAGES ========== */
.message {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 75%;
    word-break: break-word;
    animation: fadeIn 0.3s ease;
    font-size: 15px;
    line-height: 1.55;
    letter-spacing: -0.01em;
}

.user {
    background: #26a89b;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    margin-right: 8px;
    margin-left: 40px;
}

.assistant {
    background: white;
    color: #1a1a1a;
    align-self: flex-start;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    border-bottom-left-radius: 6px;
    margin-left: 8px;
    margin-right: 40px;
}

.assistant p {
    margin: 0 0 10px 0;
}

.assistant p:last-child {
    margin-bottom: 0;
}

.assistant strong {
    font-weight: 600;
    color: #111;
}

.assistant a {
    color: #26a89b;
    text-decoration: none;
    font-weight: 500;
}

.assistant a:hover {
    text-decoration: underline;
}

.assistant h3 {
    margin: 0 0 12px 0;
    font-size: 17px;
    font-weight: 600;
    color: #111;
}

.assistant img {
    border-radius: 8px;
}

/* ========== ZONE DE SAISIE EN BAS (FIXE) ========== */
#input-container {
    position: fixed;
    bottom: 0px;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 8px);
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 26px;
    padding: 8px 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.input-wrapper:has(#user-input:focus) {
    border-color: #26a89b;
    box-shadow: 0 0 0 3px rgba(38, 168, 155, 0.15);
}

.icon-button {
    border: none;
    background: transparent;
    font-size: 1.2rem;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    flex-shrink: 0;
}

#user-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    padding: 8px 0;
    caret-color: #26a89b;
    background: transparent;
}

#user-input::placeholder {
    color: #999;
}

#mic-button {
    position: relative;
    font-size: 26px;
    background: rgb(255, 204, 0);
    border: none;
    padding: 12px;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 1001;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: transform 0.2s ease;
}

#mic-button:hover {
    transform: scale(1.05);
}

#mic-button:active {
    transform: scale(0.95);
}

#mic-button img {
    pointer-events: none;
    display: block;
}

#send-button {
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    background: #26a89b;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    transition: transform 0.2s ease;
}

#send-button:hover {
    background: #1e8a7f;
    transform: scale(1.05);
}

#send-button:active {
    transform: scale(0.95);
}

#mic-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgb(255, 204, 0);
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

#mic-indicator.recording {
    opacity: 0.85;
    transform: translate(-50%, -50%) scale(1.1);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.3); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

.tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-left: 3px solid #26a89b;
    border-radius: 8px;
    margin: 8px 0;
    font-size: 14px;
    color: #495057;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.tool-indicator .spinner {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.tool-indicator .spinner circle {
    animation: spinner-rotate 1.4s linear infinite;
}

@keyframes spinner-rotate {
    0% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 89, 200;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 89, 200;
        stroke-dashoffset: -124;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== TABLEAUX DESKTOP (PAR DÉFAUT) ========== */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    font-size: 14px;
    border-radius: 12px;
    margin: 12px 0;
    overflow: hidden;
}

th, td {
    padding: 14px 18px;
    text-align: left;
    line-height: 1.5;
}

th {
    background: #26a89b;
    color: white;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

th:first-child {
    border-top-left-radius: 12px;
}

th:last-child {
    border-top-right-radius: 12px;
}

td {
    color: #333;
}

td strong {
    font-weight: 600;
    color: #111;
}

tbody tr:not(:last-child) td {
    border-bottom: 1px solid #f0f0f0;
}

tbody tr {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background: #f8fffe;
}

tbody tr:last-child td:first-child {
    border-bottom-left-radius: 12px;
}

tbody tr:last-child td:last-child {
    border-bottom-right-radius: 12px;
}

/* Images dans les tableaux */
table img {
    vertical-align: middle;
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
    header {
        font-size: 1rem;
        height: 54px;
        padding: 0 16px;
    }
    
    header img[alt="Logo Motorex"] {
        height: 28px;
    }
    
    .header-actions {
        gap: 20px;
    }
    
    .header-button {
        min-width: 28px;
        min-height: 28px;
    }
    
    .header-button svg {
        width: 22px;
        height: 22px;
    }

    /* Masquer le label du toggle sur mobile */
    .toggle-label {
        display: none;
    }

    /* Mode analyse mobile: empile verticalement */
    #main-container {
        margin-top: 60px;
        height: calc(100vh - 160px);
    }

    #main-container.split-mode {
        flex-direction: column;
    }

    #main-container.split-mode #chat-window {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
    }

    #main-container.split-mode #analysis-panel {
        width: 100%;
        height: 60%;
    }

    .analysis-header h3 {
        font-size: 14px;
    }
    
    .message {
        max-width: 85%;
    }
    
    #input-container {
        bottom: 10px;
        left: 5px;
        right: 5px;
    }
    
    #user-input {
        font-size: 16px;
    }
    
    /* TABLEAUX → CARTES STYLE MODERNE iOS */
    table {
        border: none;
        background: transparent;
        box-shadow: none;
    }

    thead { 
        display: none; 
    }

    tbody {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    tbody tr {
        display: block;
        background: linear-gradient(135deg, #ffffff 0%, #f8fffe 100%);
        border: none;
        border-left: 4px solid #26a89b;
        border-radius: 12px;
        padding: 12px 14px;
        box-shadow: 
            0 2px 8px rgba(38, 168, 155, 0.08),
            0 1px 3px rgba(0, 0, 0, 0.06);
        margin: 0;
        transition: all 0.2s ease;
    }

    tbody tr:active {
        background: linear-gradient(135deg, #e8f5f4 0%, #f0faf9 100%);
        transform: scale(0.98);
        box-shadow: 
            0 1px 4px rgba(38, 168, 155, 0.12),
            0 0px 2px rgba(0, 0, 0, 0.08);
    }

    tbody td {
        display: block;
        padding: 0;
        margin: 3px 0;
        font-size: 14px;
        border: none !important;
        color: #2d3748;
        line-height: 1.4;
        font-weight: 400;
    }

    tbody td:first-child {
        font-size: 15px;
        color: #1a202c;
        margin-bottom: 6px;
        padding-bottom: 6px;
        border-bottom: 1px solid rgba(38, 168, 155, 0.15) !important;
    }

    tbody td:first-child strong {
        font-weight: 600;
        color: #26a89b;
    }

    tbody td:nth-child(2) {
        font-size: 14px;
        color: #4a5568;
    }

    tbody td:last-child {
        font-style: italic;
        color: #718096;
        font-size: 13px;
        margin-top: 6px;
        padding-top: 6px;
        border-top: 1px solid rgba(38, 168, 155, 0.1) !important;
    }

    tbody td::before {
        content: none;
    }
}

/* ========== ACCESSIBILITÉ ========== */
*:focus-visible {
    outline: 2px solid #26a89b;
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

* {
    touch-action: manipulation;
}

#chat-window {
    -webkit-overflow-scrolling: touch;
}

#mic-button, #send-button, .icon-button, .header-button {
    -webkit-user-select: none;
    user-select: none;
}