/**
 * Interactions - Styles de l'application
 * Design moderne avec thème violet
 */

/* ==================== VARIABLES ==================== */

:root {
    /* Couleurs principales - tons adoucis */
    --primary: #7e57a0;
    --primary-light: #b89dc9;
    --primary-dark: #5e4077;
    --primary-gradient: linear-gradient(135deg, #8e6aad 0%, #6a4d82 100%);

    /* Background & surfaces */
    --bg-color: #f9f7fa;
    --card-bg: #ffffff;
    --surface-elevated: #ffffff;

    /* Texte */
    --text-color: #2d2d3a;
    --text-secondary: #555568;
    --text-muted: #8a8a9a;

    /* Bordures & ombres */
    --border-color: #e5e0e8;
    --border-light: #f2eff4;
    --shadow-sm: 0 1px 3px rgba(100, 60, 120, 0.06);
    --shadow-md: 0 4px 12px rgba(100, 60, 120, 0.10);
    --shadow-lg: 0 8px 24px rgba(100, 60, 120, 0.14);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(100, 60, 120, 0.03);

    /* Rayons */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* ==================== DARK MODE ==================== */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f0a12;
        --card-bg: #1a1520;
        --surface-elevated: #221b28;
        --text-color: #f0ecf2;
        --text-secondary: #c4b8cc;
        --text-muted: #8a7d94;
        --border-color: #2d2535;
        --border-light: #241e2a;
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
        --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

/* ==================== RESET & BASE ==================== */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ==================== HEADER ==================== */

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--primary-gradient);
    color: white;
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 12px rgba(100, 60, 120, 0.25);
}

.app-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.01em;
    color: white;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Compteur de médicaments */
.med-counter {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    transition: var(--transition-normal);
}

.med-counter.has-items {
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary);
}

.med-counter .count {
    min-width: 1.25rem;
    text-align: center;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    font-size: 1rem;
}

.btn-icon:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.btn-icon:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ==================== MAIN ==================== */

.app-main {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 2rem;
}

/* ==================== LOADING OVERLAY ==================== */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, rgba(142, 106, 173, 0.95) 0%, rgba(106, 77, 130, 0.98) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-content {
    text-align: center;
    color: white;
    padding: 2rem;
}

.loading-logo {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.2));
    animation: float 2s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.loading-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    letter-spacing: -0.02em;
}

.loading-status {
    font-size: 0.9375rem;
    opacity: 0.9;
    margin: 0 0 1.5rem;
    min-height: 1.5em;
}

.loading-progress {
    width: 240px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress-bar {
    height: 100%;
    background: white;
    border-radius: 999px;
    transition: width 0.3s ease;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
}

/* ==================== SEARCH ==================== */

.search-section {
    margin-bottom: 1.5rem;
}

/* Algolia Autocomplete custom styles */
.aa-Autocomplete {
    width: 100%;
}

.aa-Form {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.aa-Form:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(126, 87, 160, 0.15);
}

.aa-InputWrapperPrefix {
    padding-left: 0.875rem;
}

.aa-InputWrapperPrefix .aa-Label,
.aa-InputWrapperPrefix .aa-LoadingIndicator {
    color: var(--text-muted);
}

.aa-Input {
    color: var(--text-color);
    font-size: 1rem;
    padding: 0.875rem 0;
    padding-inline-start: 0 !important;
    background: none !important;
    background-image: none !important;
}

.aa-SubmitButton {
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
}

.aa-SubmitButton:focus,
.aa-SubmitButton:focus-visible,
.aa-Label:focus,
.aa-Label:focus-within {
    outline: none !important;
    box-shadow: none !important;
}

.aa-Input::placeholder {
    color: var(--text-muted);
}

.aa-InputWrapperSuffix {
    padding-right: 0.75rem;
}

.aa-ClearButton {
    color: var(--text-muted);
}

.aa-ClearButton:hover {
    color: var(--primary);
}

/* Dropdown panel */
.aa-Panel {
    z-index: 200;
    margin-top: 0.5rem;
}

.aa-PanelLayout {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
}

.aa-List {
    padding: 0.375rem;
}

.aa-Item {
    padding: 0.75rem 0.875rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    transition: var(--transition-fast);
}

.aa-Item:last-child {
    margin-bottom: 0;
}

.aa-Item[aria-selected="true"] {
    background: var(--primary);
}

.aa-Item:not([aria-selected="true"]):hover {
    background: var(--border-light);
}

.aa-Item[aria-selected="true"] .autocomplete-result-name,
.aa-Item[aria-selected="true"] .autocomplete-result-substance {
    color: white;
}

.autocomplete-item {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.autocomplete-result-name {
    font-weight: 500;
    font-size: 0.9375rem;
    color: var(--text-color);
}

.autocomplete-result-substance {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ==================== SECTIONS ==================== */

.meds-section h2,
.interactions-section h2,
.food-section h2 {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin: 0 0 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-count {
    background: var(--border-color);
    color: var(--text-secondary);
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
}

/* ==================== MEDICATIONS LIST ==================== */

.meds-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.empty-message {
    color: var(--text-muted);
    font-size: 0.9375rem;
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border-color);
}

.empty-message i {
    display: block;
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

/* Medication card */
.med-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    position: relative;
    transition: var(--transition-normal);
    border: 1px solid var(--border-light);
}

.med-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.med-item.has-interaction {
    border-left: 4px solid var(--interaction-warning-border);
}

.med-item.has-danger {
    border-left-color: var(--interaction-danger-border);
}

.med-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.med-item.has-interaction .med-icon {
    background: linear-gradient(135deg, var(--interaction-warning) 0%, #d84315 100%);
}

.med-item.has-danger .med-icon {
    background: linear-gradient(135deg, #ef5350 0%, var(--interaction-danger) 100%);
}

.med-info {
    flex: 1;
    min-width: 0;
}

.med-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.med-substance {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.125rem;
}

.med-remove {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition-fast);
    font-size: 0.875rem;
}

.med-remove:hover {
    background: #ffebee;
    color: #c62828;
}

@media (prefers-color-scheme: dark) {
    .med-remove:hover {
        background: rgba(198, 40, 40, 0.2);
        color: #ef5350;
    }
}

/* Animation d'ajout */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-12px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.med-item.just-added {
    animation: slideIn 0.3s ease-out;
}

/* ==================== INTERACTIONS & FOOD SECTIONS ==================== */

.interactions-section,
.food-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.interactions-section h2 {
    color: var(--interaction-warning);
}

.interactions-section.has-danger h2 {
    color: var(--interaction-danger);
}

.food-section h2 {
    color: var(--interaction-warning);
}

.hidden {
    display: none !important;
}

/* ==================== DISCLAIMER ==================== */

.data-disclaimer {
    margin-top: 2rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

.data-disclaimer p {
    margin: 0 0 0.5rem;
}

.data-disclaimer p:last-child {
    margin-bottom: 0;
}

.data-disclaimer a {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.data-disclaimer a:hover {
    color: var(--primary-dark);
}

.data-disclaimer .disclaimer-warning {
    color: var(--text-secondary);
}

.data-disclaimer i {
    margin-right: 0.25rem;
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 480px) {
    .app-header {
        padding: 0.75rem;
    }

    .app-header h1 {
        font-size: 1.125rem;
    }

    .app-main {
        padding: 0.75rem;
    }

    .aa-Input {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .med-item {
        padding: 0.75rem;
    }

    .med-icon {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }
}

/* ==================== PRINT ==================== */

@media print {
    .app-header {
        background: #7e57a0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .search-section,
    .btn-icon,
    .med-remove {
        display: none;
    }
}
