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

:root {
    --color-blue: #6B7FFF;
    --color-green: #4CAF50;
    --color-orange: #FF9800;
    --color-purple: #9C27B0;
    --color-blue-light: rgba(107, 127, 255, 0.08);
    --color-green-light: rgba(76, 175, 80, 0.08);
    --color-orange-light: rgba(255, 152, 0, 0.08);
    --color-purple-light: rgba(156, 39, 176, 0.08);
    --color-blue-lighter: rgba(107, 127, 255, 0.04);
    --color-green-lighter: rgba(76, 175, 80, 0.04);
    --color-orange-lighter: rgba(255, 152, 0, 0.04);
    --color-purple-lighter: rgba(156, 39, 176, 0.04);
    --bg-light: #F5F7FA;
    --bg-dark: #4A5568;
    --text-dark: #2D3748;
    --text-light: #718096;
    --border-color: #CBD5E0;
}

html, body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Barre de titre */
.title-bar {
    background: #394355;
    width: 100%;
    height: 54px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.app-title {
    font-size: 26px;
    font-weight: 800;
    color: white;
    margin: 0;
    letter-spacing: -0.3px;
}

.title-bar-buttons {
    position: absolute;
    right: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.info-btn, .lang-btn {
    padding: 8px;
    min-width: 40px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.info-btn:active, .lang-btn:active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(0.97);
}

.info-btn:disabled, .lang-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.app-container {
    max-width: 480px;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    min-height: 0;
    overflow: hidden;
}

/* Zone scrollable : Cartes et bouton Ajouter */
.measured-scrollable-zone {
    flex: 0 1 auto;
    min-height: 0;
    max-height: calc(100vh - 420px); /* Hauteur maximale pour laisser place aux autres éléments */
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    background: white;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

#measurements-container {
    /* Les cartes seront ajoutées ici */
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    color: white;
    background: var(--bg-dark);
    padding: 10px 14px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon {
    width: 24px;
    height: 24px;
    fill: white;
    flex-shrink: 0;
}

/* Titre "Grandeurs mesurées" - fixe, arrondi seulement en haut */
.measured-title {
    flex-shrink: 0;
    border-radius: 10px 10px 0 0 !important;
    margin: 0 0 0 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.calculated-section .section-title {
    margin: -14px -14px 12px -14px;
    border-radius: 10px 10px 0 0;
}

/* Carte de mesure */
.measurement-card {
    border-radius: 0;
    padding: 12px;
    margin: 0;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border-color);
    position: relative;
}

.measurement-card.color-blue { background: var(--color-blue-light); }
.measurement-card.color-green { background: var(--color-green-light); }
.measurement-card.color-orange { background: var(--color-orange-light); }
.measurement-card.color-purple { background: var(--color-purple-light); }

.remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #718096;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.remove-btn:active {
    background: white;
    color: #E53E3E;
}

/* Nouvelle structure des champs de mesure */
.field-labels {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 3px;
    font-size: 10px;
    color: var(--text-light);
    font-weight: 500;
}

.field-labels .label-symbol {
    flex: 0 0 40px;
    text-align: center;
}

.field-labels .label-equals-spacer {
    width: 10px;
}

.field-labels .label-paren-spacer {
    width: 8px;
}

.field-labels .label-pm-spacer {
    width: 10px;
}

.field-labels .label-value {
    flex: 0 0 60px;
    text-align: center;
}

.field-labels .label-uncertainty {
    flex: 0 0 60px;
    text-align: center;
}

.measurement-fields {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}

.field-symbol {
    flex: 0 0 40px;
}

.field-equals {
    font-size: 16px;
    color: var(--text-dark);
    font-weight: 500;
}

.field-paren-open {
    font-size: 18px;
    color: var(--text-dark);
}

.field-value {
    flex: 0 0 60px;
}

.field-pm {
    font-size: 16px;
    color: var(--text-dark);
}

.field-uncertainty {
    flex: 0 0 60px;
}

.field-paren-close {
    font-size: 18px;
    color: var(--text-dark);
}

.field-exponent {
    flex: 1;
    min-width: 0;
}

input[type="text"],
input[type="number"],
select {
    border: 2px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dark);
    background: white;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: #6B7FFF;
}

.symbol-input {
    text-align: center;
    font-size: 20px;
    font-style: italic;
    font-weight: 600;
}

/* Couleurs pour les inputs */
.color-blue input,
.color-blue select {
    color: var(--color-blue);
    font-weight: 600;
    background: var(--color-blue-lighter);
}

.color-green input,
.color-green select {
    color: var(--color-green);
    font-weight: 600;
    background: var(--color-green-lighter);
}

.color-orange input,
.color-orange select {
    color: var(--color-orange);
    font-weight: 600;
    background: var(--color-orange-lighter);
}

.color-purple input,
.color-purple select {
    color: var(--color-purple);
    font-weight: 600;
    background: var(--color-purple-lighter);
}

/* Visualisation de la distribution */
.distribution-viz {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    position: relative;
}

.distribution-row {
    position: absolute;
    top: 16px;
    left: 8px;
    z-index: 5;
}

.distribution-row select {
    font-size: 11px;
    padding: 5px 8px;
    width: auto;
    min-width: 120px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: transparent;
    border: none;
}

.distribution-chart {
    width: 100%;
    height: 45px;
    margin-bottom: 0;
}

.distribution-labels {
    display: flex;
    font-size: 10px;
    color: var(--text-light);
    position: relative;
    margin-bottom: 8px;
}

.distribution-labels .label-left {
    position: absolute;
    transform: translateX(-50%);
}

.distribution-labels .label-center {
    position: absolute;
    transform: translateX(-50%);
}

.distribution-labels .label-right {
    position: absolute;
    transform: translateX(-50%);
}

.distribution-labels .label-exponent {
    position: absolute;
    right: 0;
}

/* Bouton ajouter */
.add-btn {
    width: 100%;
    padding: 12px;
    background: white;
    border: 2px dashed var(--border-color);
    border-radius: 0 0 10px 10px !important;
    color: var(--text-light);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
}

.add-btn:active:not(:disabled) {
    border-top-color: #6B7FFF;
    color: #6B7FFF;
}

.add-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Section calculée - Footer fixe */
.calculated-section {
    flex-shrink: 0;
    background: white;
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    margin-top: auto;
    margin-bottom: 12px;
}

.calculated-section .section-title {
    margin: -14px -14px 12px -14px;
    border-radius: 10px 10px 0 0;
}

.formula-input-group {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}

.formula-symbol {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.formula-symbol label {
    font-size: 10px;
    color: var(--text-light);
    font-weight: 500;
}

#calc-symbol {
    width: 60px;
    text-align: center;
    font-size: 18px;
    font-style: italic;
}

.formula-equals {
    font-size: 22px;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.formula-input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.formula-input-wrapper label {
    font-size: 10px;
    color: var(--text-light);
    font-weight: 500;
}

#calc-formula {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 18px;
}

.formula-preview {
    padding: 20px 0;
    margin-bottom: 0;
}

.preview-label {
    display: none;
}

.formula-display {
    text-align: center;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}

/* Conteneur des boutons d'action */
.action-buttons {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    gap: 8px;
}

.calculate-btn, .sensitivity-btn {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    color: white;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.1s;
    font-family: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    -webkit-tap-highlight-color: transparent;
    white-space: normal;
    text-align: center;
    line-height: 1.3;
}

.calculate-btn,
.sensitivity-btn {
    background: linear-gradient(180deg, #6B6B6B 0%, #4A4A4A 100%);
    border: 1px solid #3A3A3A;
}

.calculate-btn:active,
.sensitivity-btn:active {
    background: linear-gradient(180deg, #4A4A4A 0%, #5A5A5A 100%);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

.calculate-btn:disabled, .sensitivity-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Classes pour colorer les variables dans KaTeX */
.var-blue {
    color: var(--color-blue) !important;
}

.var-green {
    color: var(--color-green) !important;
}

.var-orange {
    color: var(--color-orange) !important;
}

.var-purple {
    color: var(--color-purple) !important;
}

/* Modal À propos */
.about-modal {
    position: fixed;
    top: 54px; /* Hauteur de la barre de titre */
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-light);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.about-modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    max-width: 400px;
    width: 100%;
    margin: auto;
}

.about-icon {
    width: 128px;
    height: 128px;
    margin-bottom: 16px;
}

.about-app-name {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.about-version {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 20px;
}

.about-author-info {
    text-align: center;
    margin-bottom: 30px;
}

.about-author-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.about-author-email {
    font-size: 14px;
    color: var(--text-light);
}

.about-desktop-link {
    font-size: 13px;
    color: var(--text-light);
    text-align: center;
    line-height: 1.5;
    margin: 20px 0;
    padding: 0 10px;
}

.about-desktop-link a {
    color: var(--color-blue);
    text-decoration: none;
}

.about-desktop-link a:hover,
.about-desktop-link a:active {
    text-decoration: underline;
}

.about-buttons-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
    margin-top: 10px;
}

.about-update-btn {
    padding: 10px 30px;
    background: linear-gradient(180deg, #FFFFFF 0%, #E5E5E5 100%);
    color: var(--text-dark);
    border: 1px solid #B8B8B8;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    -webkit-tap-highlight-color: transparent;
}

.about-update-btn:active {
    background: linear-gradient(180deg, #D0D0D0 0%, #E0E0E0 100%);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    transform: scale(0.98);
}

.about-update-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.about-ok-btn {
    padding: 12px 40px;
    background: linear-gradient(180deg, #6B6B6B 0%, #4A4A4A 100%);
    color: white;
    border: 1px solid #3A3A3A;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    -webkit-tap-highlight-color: transparent;
}

.about-ok-btn:active {
    background: linear-gradient(180deg, #4A4A4A 0%, #5A5A5A 100%);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
    transform: scale(0.98);
}

/* Sélecteur de langue (dropdown) */
.language-selector {
    position: fixed;
    top: 16px;
    right: 56px;
    z-index: 1000;
}

.language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid #B8B8B8;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: none;
}

.language-dropdown.show {
    display: block;
}

.language-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
}

.language-option:hover {
    background: #F3F2F1;
}

.language-option:active {
    background: #E1DFDD;
}

.flag-icon {
    width: 20px;
    height: 15px;
    border-radius: 2px;
    flex-shrink: 0;
}

.info-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Responsive adjustments */
@media (max-width: 375px) {
    .app-container {
        padding: 10px;
    }

    .section-title {
        font-size: 14px;
        padding: 9px 12px;
    }

    .field-value,
    .field-uncertainty {
        flex: 0 0 55px;
    }

    .field-labels .label-value,
    .field-labels .label-uncertainty {
        flex: 0 0 55px;
    }
}

/* Overlay Desktop : Bloquer l'accès sur ordinateur */
.desktop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #18AECB;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.desktop-overlay-content {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.desktop-overlay-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto 20px;
    display: block;
}

.desktop-overlay-title {
    font-size: 36px;
    font-weight: 800;
    color: #2D3748;
    margin-bottom: 8px;
}

.desktop-overlay-subtitle {
    font-size: 18px;
    color: #718096;
    margin-bottom: 30px;
}

.desktop-overlay-message {
    margin-bottom: 30px;
}

.desktop-overlay-message p {
    font-size: 16px;
    color: #4A5568;
    line-height: 1.6;
    margin-bottom: 12px;
}

.desktop-download-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    background: #18AECB;
    color: white;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(24, 174, 203, 0.4);
    margin-bottom: 40px;
}

.desktop-download-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(24, 174, 203, 0.5);
}

.desktop-qr-section {
    border-top: 2px solid #E2E8F0;
    padding-top: 30px;
}

.desktop-qr-section p {
    font-size: 14px;
    color: #718096;
    margin-bottom: 20px;
}

.desktop-qr-code {
    width: 200px;
    height: 200px;
    display: block;
    margin: 0 auto;
    border: 4px solid #E2E8F0;
    border-radius: 10px;
}

/* Banner d'installation mobile */
.mobile-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 9998;
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.close-install-banner {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #E2E8F0;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    color: #4A5568;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-install-banner:active {
    background: #CBD5E0;
    transform: scale(0.95);
}

.mobile-install-content {
    padding-right: 40px;
}

.mobile-install-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.mobile-install-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    flex-shrink: 0;
}

.mobile-install-title-group h3 {
    font-size: 18px;
    font-weight: 700;
    color: #2D3748;
    margin: 0 0 4px 0;
}

.mobile-install-title-group p {
    font-size: 14px;
    color: #718096;
    margin: 0;
}

.install-instructions {
    background: #F7FAFC;
    border-radius: 12px;
    padding: 16px;
}

.install-instructions p {
    font-size: 15px;
    color: #2D3748;
    margin: 0 0 12px 0;
    font-weight: 600;
}

.install-instructions ol {
    margin: 0;
    padding-left: 20px;
}

.install-instructions li {
    font-size: 14px;
    color: #4A5568;
    line-height: 1.8;
    margin-bottom: 8px;
}

.install-instructions strong {
    color: #2D3748;
    font-weight: 700;
}
