/* ===== VARIABLES GLOBALES ===== */
:root {
    --radius: 28px;
    --radius-sm: 16px;
    --transition: 0.2s cubic-bezier(0.2, 0.9, 0.4, 1.1);
    --shadow-sm: 0 1px 6px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
    --shadow-lg: 0 12px 28px rgba(0,0,0,0.18);
}

/* Mode clair */
body.light {
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --accent: #ff8c00;
    --line: rgba(0,0,0,0.08);
    --text: #202124;
    --text-mid: #5f6368;
    --text-light: #9aa0a6;
    --font: 'Montserrat', sans-serif;
    --background-image: none;
    --background-color: #ffffff;
    --input-bg: #ffffff;
    --input-border: #dfe1e5;
    --voice-glow: rgba(255,140,0,0.3);
    --sg-bg: #ffffff;
    --sg-hover: #f1f3f4;
    --sg-border: rgba(0,0,0,0.12);
    --sg-shadow: 0 4px 6px rgba(32,33,36,0.28);
    --sg-label-color: #70757a;
    --sg-title-color: #202124;
    --sg-desc-color: #70757a;
    --sg-icon-color: #9aa0a6;
    --sg-icon-hist: #70757a;
    --sg-remove-color: #9aa0a6;
}

/* Mode sombre */
body.dark {
    --bg: #1e1e2f;
    --bg-secondary: #2a2a3c;
    --accent: #ffaa33;
    --line: rgba(255,255,255,0.1);
    --text: #e8eaed;
    --text-mid: #bdc1c6;
    --text-light: #80868b;
    --background-color: #12121f;
    --input-bg: #2d2d3f;
    --input-border: #3c4043;
    --voice-glow: rgba(255,170,51,0.4);
    --sg-bg: #2d2d3f;
    --sg-hover: #3c3c50;
    --sg-border: rgba(255,255,255,0.1);
    --sg-shadow: 0 4px 6px rgba(0,0,0,0.5);
    --sg-label-color: #9aa0a6;
    --sg-title-color: #e8eaed;
    --sg-desc-color: #9aa0a6;
    --sg-icon-color: #70757a;
    --sg-icon-hist: #9aa0a6;
    --sg-remove-color: #70757a;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--background-color);
    background-image: var(--background-image);
    background-size: cover;
    background-position: center;
    font-family: var(--font);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - 120px);
    padding: 20px 0;
}

/* ===== HEADER ===== */
.main-header {
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 8px 24px;
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    backdrop-filter: blur(12px);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 800;
    font-size: 1.3rem;
    letter-spacing: -0.5px;
}
.logo-area img { height: 32px; }

.header-nav { display: flex; gap: 28px; list-style: none; }
.header-nav a {
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-mid);
    transition: color var(--transition);
    padding: 6px 0;
}
.header-nav a:hover, .header-nav a.active { color: var(--accent); }

.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-mid);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,0.05); color: var(--accent); }
body.dark .icon-btn:hover { background: rgba(255,255,255,0.1); }

/* Apps panel */
.apps-panel {
    display: none;
    position: absolute;
    top: 55px;
    right: 80px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 16px;
    gap: 12px;
    grid-template-columns: repeat(3, 70px);
    z-index: 500;
    box-shadow: var(--shadow-lg);
}
.apps-panel.show { display: grid; }
.app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-mid);
    font-size: 0.7rem;
    padding: 6px;
    border-radius: 12px;
    transition: all 0.2s;
}
.app-item:hover { background: var(--bg-secondary); color: var(--accent); }
.app-item img { width: 32px; height: 32px; margin-bottom: 4px; }

/* ===== HERO ===== */
.hero { text-align: center; padding: 20px 20px 16px; }
.hero h1 {
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--accent), #ffb347);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero p { font-size: 1rem; color: var(--text-mid); }

/* ===== SECTION RECHERCHE ===== */
.search-section {
    background: transparent;
    padding: 16px 20px;
    position: sticky;
    top: 57px;
    z-index: 50;
    /* IMPORTANT: NO z-index that creates stacking context above 9999 */
}

.search-container {
    max-width: 680px;
    margin: 0 auto;
    position: relative;
}

.search-input-group {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 48px;
    padding: 4px 8px 4px 16px;
    transition: border-color 0.3s, box-shadow 0.3s;
    box-shadow: var(--shadow-sm);
    position: relative;
    /* NO transform — breaks fixed children */
    animation: permanentBorderGlow 3s infinite ease-in-out;
}

.search-input-group:focus-within {
    animation: focusBorderGlow 1.5s infinite ease-in-out;
    border-radius: 24px 24px 0 0;
}

@keyframes permanentBorderGlow {
    0%   { box-shadow: 0 0 0 2px rgba(255,140,0,0.2), var(--shadow-sm);   border-color: #ff8c00; }
    33%  { box-shadow: 0 0 0 2px rgba(0,150,255,0.2), var(--shadow-sm);   border-color: #0096ff; }
    66%  { box-shadow: 0 0 0 2px rgba(0,255,100,0.2), var(--shadow-sm);   border-color: #00ff64; }
    100% { box-shadow: 0 0 0 2px rgba(255,140,0,0.2), var(--shadow-sm);   border-color: #ff8c00; }
}
@keyframes focusBorderGlow {
    0%   { box-shadow: 0 0 0 4px rgba(255,140,0,0.3), var(--shadow-md);   border-color: #ff8c00; }
    33%  { box-shadow: 0 0 0 4px rgba(0,150,255,0.3), var(--shadow-md);   border-color: #0096ff; }
    66%  { box-shadow: 0 0 0 4px rgba(0,255,100,0.3), var(--shadow-md);   border-color: #00ff64; }
    100% { box-shadow: 0 0 0 4px rgba(255,140,0,0.3), var(--shadow-md);   border-color: #ff8c00; }
}

.adm-search-bar {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 1.2rem;
    padding: 14px 8px;
    outline: none;
    font-family: var(--font);
    color: var(--text);
}
.adm-search-bar::placeholder { color: var(--text-light); font-weight: 400; }

.search-icons { display: flex; gap: 6px; align-items: center; }
.search-icons button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-mid);
    font-size: 1.3rem;
    padding: 8px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.search-icons button:hover { background: var(--bg-secondary); color: var(--accent); }

.search-plus-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-mid);
    cursor: pointer;
    padding: 8px;
    margin-right: 4px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.search-plus-btn:hover { background: var(--bg-secondary); color: var(--accent); }

/* =====================================================================
   DROPDOWN SUGGESTIONS — STYLE GOOGLE
   Positionné par JS en position:fixed — CSS = pure apparence
   ===================================================================== */
#suggestions {
    /* JS gère display:block / display:none via style inline */
    display: none;
    position: fixed;       /* set by JS too, just in case */
    z-index: 2147483647;   /* Max z-index */
    background: var(--sg-bg);
    border: 1px solid var(--sg-border);
    border-top: none;
    border-radius: 0 0 24px 24px;
    box-shadow: var(--sg-shadow);
    overflow: hidden;
    max-height: 520px;
    overflow-y: auto;
    /* Scrollbar fine à la Google */
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
    /* Animation d'ouverture */
    animation: sgFadeIn 0.12s ease-out;
}
#suggestions::-webkit-scrollbar { width: 6px; }
#suggestions::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

@keyframes sgFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Label de section (style Google : "Récents" / "Suggestions") */
.sg-section-label {
    padding: 8px 16px 4px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sg-label-color);
    border-top: 1px solid var(--sg-border);
    background: var(--sg-bg);
}
.sg-section-label:first-child { border-top: none; }

/* Item suggestion */
.sg-item {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0;
    cursor: pointer;
    transition: background 0.08s ease;
    min-height: 48px;
    position: relative;
    user-select: none;
}
.sg-item:hover,
.sg-item--active {
    background: var(--sg-hover);
}

/* Colonne gauche : icône ou miniature */
.sg-left {
    width: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: stretch;
}

/* Icône générique (loupe ou historique) */
.sg-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sg-icon-color);
    font-size: 0.85rem;
}
.sg-icon--hist { color: var(--sg-icon-hist); }
.sg-icon--hist i { font-size: 0.8rem; }

/* Miniature wikipedia */
.sg-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--sg-hover);
    flex-shrink: 0;
}

/* Corps central : titre + description */
.sg-body {
    flex: 1;
    min-width: 0;
    padding: 10px 8px 10px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.sg-title {
    display: block;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--sg-title-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.sg-title strong {
    font-weight: 700;
    color: var(--accent);
}

.sg-desc {
    display: block;
    font-size: 0.72rem;
    color: var(--sg-desc-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

/* Colonne droite : bouton supprimer ou flèche auto-complétion */
.sg-right {
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: stretch;
    opacity: 0;
    transition: opacity 0.1s;
}
.sg-item:hover .sg-right,
.sg-item--active .sg-right {
    opacity: 1;
}

.sg-remove, .sg-arrow {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--sg-remove-color);
    font-size: 0.75rem;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    width: 32px;
    height: 32px;
}
.sg-remove:hover  { color: #d93025; background: rgba(217,48,37,0.08); }
.sg-arrow:hover   { color: var(--accent); background: rgba(255,140,0,0.08); }

/* Chips affichées depuis le bouton + */
.input-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; align-items: center; }
.input-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-secondary);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 3px 10px 3px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.input-chip:hover { border-color: var(--accent); color: var(--accent); }
.input-chip i { font-size: 0.7rem; }
.input-chip .chip-close { margin-left: 4px; opacity: 0.5; font-style: normal; font-size: 0.9rem; line-height: 1; }
.input-chip .chip-close:hover { opacity: 1; }

/* Zone chips au dessus de l'input */
.chips-bar { max-width: 680px; margin: 0 auto 8px; display: none; flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.chips-bar.visible { display: flex; }

/* ===== HISTORIQUE ===== */
.section { max-width: 680px; margin: 20px auto; padding: 0 20px; }
.section-label { font-size: 0.7rem; letter-spacing: 2px; font-weight: 700; color: var(--accent); text-transform: uppercase; margin-bottom: 12px; display: block; }
.history-actions { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.clear-btn { background: none; border: 1px solid var(--line); padding: 4px 14px; border-radius: 40px; font-size: 0.7rem; font-weight: 600; cursor: pointer; color: var(--text-mid); transition: all 0.2s; }
.clear-btn:hover { border-color: var(--accent); color: var(--accent); }
.history-tags { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.history-tag {
    background: var(--bg-secondary);
    padding: 8px 18px;
    border-radius: 40px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    border: 1px solid transparent;
}
.history-tag:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); }
.empty-history { color: var(--text-mid); text-align: center; font-style: italic; }

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    padding: 20px 16px;
    border-top: 1px solid var(--line);
    background: var(--bg);
    font-size: 0.75rem;
    color: var(--text-mid);
    margin-top: auto;
}
.social-links { display: flex; justify-content: center; gap: 18px; margin-bottom: 12px; flex-wrap: wrap; }
.social-links a { color: var(--text-mid); font-size: 1.2rem; transition: color 0.2s; }
.social-links a:hover { color: var(--accent); }
.legal-links { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.legal-links a, .legal-links button { background: none; border: none; color: var(--text-mid); text-decoration: none; font-size: 0.7rem; cursor: pointer; }
.legal-links a:hover, .legal-links button:hover { color: var(--accent); }
.location-badge { background: var(--bg-secondary); padding: 2px 8px; border-radius: 40px; font-size: 0.7rem; font-weight: 500; }

/* ===== PANNEAU PARAMÈTRES ===== */
.settings-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.25); z-index: 1999; display: none; }
.settings-overlay.active { display: block; }
.settings-panel {
    position: fixed; top: 0; right: -420px; width: 380px; max-width: 90vw;
    height: 100vh; background: var(--bg); box-shadow: var(--shadow-lg);
    z-index: 2000; transition: right 0.35s cubic-bezier(0.4,0,0.2,1);
    padding: 24px; overflow-y: auto; border-left: 1px solid var(--line);
    display: flex; flex-direction: column;
}
.settings-panel.open { right: 0; }
.settings-panel h3 { font-weight: 700; font-size: 1.1rem; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; }
.close-panel { position: absolute; top: 16px; right: 16px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-mid); }
.setting-group { margin-bottom: 24px; }
.setting-group h4 { font-size: 0.7rem; letter-spacing: 2px; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; font-weight: 700; }
.setting-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.setting-item:last-child { border-bottom: none; }
.setting-item label { font-weight: 500; flex: 1; }
.setting-item input[type="checkbox"] { accent-color: var(--accent); transform: scale(1.2); margin-left: 12px; }
.setting-item select, .setting-item input[type="text"], .setting-item input[type="color"] {
    border: 1px solid var(--line); background: var(--bg-secondary);
    padding: 4px 8px; border-radius: var(--radius-sm);
    font-family: var(--font); font-size: 0.85rem; color: var(--text);
}
.panel-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.panel-actions button {
    background: var(--bg); border: 1px solid var(--line);
    padding: 8px 14px; font-size: 0.75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer;
    color: var(--text-mid); border-radius: var(--radius-sm);
    transition: all var(--transition); font-family: var(--font);
}
.panel-actions .btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.panel-actions button:hover { border-color: var(--accent); color: var(--accent); }
.panel-actions .btn-primary:hover { opacity: 0.9; color: white; }

/* ===== OVERLAY MOBILE ===== */
.search-overlay {
    display: none; position: fixed; top: 0; left: 0;
    width: 100%; height: 100%; background: var(--bg);
    z-index: 300; padding: 20px; flex-direction: column;
}
.search-overlay.active { display: flex; animation: overlayFadeIn 0.2s ease; }
@keyframes overlayFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.overlay-header {
    display: flex; gap: 12px; align-items: center; margin-bottom: 24px;
    background: var(--bg-secondary); padding: 8px 16px;
    border-radius: 48px; border: 1px solid var(--line);
}
.back-btn { background: none; border: none; font-size: 1.4rem; color: var(--text-mid); cursor: pointer; padding: 6px; }
.overlay-search-input { flex: 1; border: none; background: transparent; padding: 12px 0; font-size: 1rem; outline: none; color: var(--text); }
.overlay-icon-btn { background: none; border: none; font-size: 1.2rem; padding: 6px; border-radius: 50%; cursor: pointer; color: var(--text-mid); }
.overlay-icon-btn:hover { background: var(--bg); }
.overlay-history-label { font-size: 0.65rem; text-transform: uppercase; color: var(--accent); margin: 16px 0 8px; font-weight: 600; }
.overlay-history-item, .overlay-suggestion-item {
    padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
    display: flex; align-items: center; gap: 12px; border-radius: 12px;
    margin: 2px 0; transition: background 0.1s;
}
.overlay-history-item:hover, .overlay-suggestion-item:hover { background: var(--bg-secondary); }
.overlay-suggestion-img { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.overlay-suggestion-item div strong { font-size: 0.9rem; }
.overlay-suggestion-item div small { font-size: 0.7rem; color: var(--text-mid); }

/* ===== ANIMATION VOCALE ===== */
.voice-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(12px); z-index: 400;
    justify-content: center; align-items: center; flex-direction: column;
}
.voice-overlay.active { display: flex; animation: voicePulse 1.2s infinite alternate; }
@keyframes voicePulse {
    0%   { background: rgba(0,0,0,0.6); backdrop-filter: blur(8px); }
    100% { background: var(--voice-glow); backdrop-filter: blur(16px); }
}
.voice-visualizer { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.bar { width: 8px; height: 30px; background: var(--accent); border-radius: 4px; animation: soundWave 0.6s infinite alternate; box-shadow: 0 0 8px var(--accent); }
.bar:nth-child(2) { animation-delay: 0.1s; background: #00aaff; box-shadow: 0 0 8px #00aaff; }
.bar:nth-child(3) { animation-delay: 0.2s; background: #00ff88; box-shadow: 0 0 8px #00ff88; }
.bar:nth-child(4) { animation-delay: 0.3s; background: #ffaa00; box-shadow: 0 0 8px #ffaa00; }
.bar:nth-child(5) { animation-delay: 0.4s; }
@keyframes soundWave {
    from { height: 20px; opacity: 0.7; transform: scaleY(0.8); }
    to   { height: 70px; opacity: 1;   transform: scaleY(1.2); }
}
.interim-text { color: white; margin: 20px; font-size: 1.3rem; text-align: center; font-weight: 500; animation: textGlow 1s infinite alternate; }
@keyframes textGlow {
    from { text-shadow: 0 0 5px var(--accent); }
    to   { text-shadow: 0 0 20px var(--accent); }
}
.voice-stop-btn { background: white; border: none; padding: 12px 32px; border-radius: 50px; font-weight: 700; cursor: pointer; font-family: var(--font); font-size: 1rem; transition: transform 0.1s; }
.voice-stop-btn:active { transform: scale(0.96); }

/* ===== ANIMATIONS ===== */
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.search-section, .history-section { animation: fadeSlideUp 0.4s ease-out; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
    .header-nav { display: none; }
    .main-header { padding: 8px 16px; }
    .hero h1 { font-size: 2rem; }
    .search-section { top: 57px; padding: 12px 16px; }
    .adm-search-bar { font-size: 1rem; padding: 12px 4px; }
    .search-icons button { font-size: 1.2rem; padding: 6px; }
    .search-plus-btn { display: none; }
    .history-tags { gap: 8px; }
    .history-tag { font-size: 0.8rem; padding: 6px 14px; }
    .legal-links { gap: 8px; }
    .settings-panel { width: 85vw; right: -85vw; }
    .overlay-header { padding: 6px 12px; }
    .overlay-search-input { font-size: 0.95rem; }
    .overlay-history-item, .overlay-suggestion-item { padding: 10px 12px; }
    /* Sur mobile le dropdown est dans l'overlay — masquer le PC */
    #suggestions { display: none !important; }
}

/* ===== ACCESSIBILITÉ ===== */
button { cursor: pointer; }
a { text-decoration: none; }
input, select, textarea { font-family: inherit; }

/* ===== RTL (Arabe) ===== */
[dir="rtl"] .sg-body { padding: 10px 0 10px 8px; }
[dir="rtl"] .sg-left { order: 2; }
[dir="rtl"] .sg-body { order: 1; }
[dir="rtl"] .sg-right { order: 0; }
