/* =========================================================
   Braindump - Nuage de tâches (TDAH friendly)
   Thème clair « premium » : verre dépoli, pastels, bulle de BD
   ========================================================= */

:root {
    --bg: #f7f6f3;
    --surface: rgba(255, 255, 255, 0.66);
    --border: rgba(18, 18, 32, 0.07);
    --border-strong: rgba(18, 18, 32, 0.12);

    --text: #15151d;
    --muted: #74747f;
    --muted-strong: #5d5d6a;
    --accent: #4f46e5;

    --urgency-3: #e2543c;
    --urgency-2: #d99a2b;
    --urgency-1: #1fa37b;

    --radius-cloud: 50%;
    --radius-pill: 999px;

    --shadow-card: 0 30px 70px -24px rgba(15, 15, 35, 0.3);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 34px 24px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 24px;
    font-family: "Segoe UI Variable Display", "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1100px 620px at 12% -12%, #ffe8dc 0%, rgba(255, 232, 220, 0) 62%),
        radial-gradient(950px 520px at 92% -6%, #e8e6ff 0%, rgba(232, 230, 255, 0) 58%),
        radial-gradient(1000px 620px at 60% 112%, #e2f6ee 0%, rgba(226, 246, 238, 0) 62%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- En-tête ---------- */

.app-header {
    text-align: center;
    max-width: 600px;
}

.app-header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 8px;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.brand-mark {
    display: inline-flex;
    width: 34px;
    height: 34px;
    filter: drop-shadow(0 8px 14px rgba(79, 70, 229, 0.3));
}

.brand-mark svg {
    width: 100%;
    height: 100%;
}

.app-header p {
    margin: 0;
    color: var(--muted-strong);
    font-size: 0.93rem;
    line-height: 1.55;
}

/* ---------- Installation PWA ---------- */

.install-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding: 9px 16px;
    border: 1px solid rgba(79, 70, 229, 0.22);
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.78);
    color: var(--accent);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 650;
    cursor: pointer;
    box-shadow: 0 10px 24px -16px rgba(79, 70, 229, 0.5);
    transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.install-btn svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

.install-btn:hover {
    background: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 14px 28px -16px rgba(79, 70, 229, 0.55);
}

.install-btn:active {
    transform: scale(0.98);
}

.install-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ---------- Structure : légende + nuage ---------- */

.app-shell {
    width: 100%;
    max-width: 1000px;
    display: grid;
    grid-template-columns: 244px minmax(0, 1fr);
    gap: 38px;
    align-items: center;
}

.app-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    min-width: 0;
}

/* ---------- Légende ---------- */

.legend {
    padding: 22px 20px;
    border: 1px solid rgba(255, 255, 255, 0.88);
    border-radius: 26px;
    background:
        linear-gradient(165deg, rgba(255, 255, 255, 0.86) 0%, rgba(255, 255, 255, 0.5) 100%);
    box-shadow:
        0 26px 54px -34px rgba(20, 20, 45, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
}

.legend-title {
    margin: 0 0 16px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--muted);
}

.legend-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.legend-list li {
    display: flex;
    align-items: center;
    gap: 12px;
}

.legend-dot {
    flex-shrink: 0;
    border-radius: 50%;
}

.dot-3 {
    width: 24px;
    height: 24px;
    background: linear-gradient(150deg, #ffe3dc, #ffd1c6);
    border: 1px solid rgba(226, 84, 60, 0.28);
    box-shadow: 0 7px 14px -7px rgba(226, 84, 60, 0.65);
}

.dot-2 {
    width: 19px;
    height: 19px;
    margin: 0 2.5px;
    background: linear-gradient(150deg, #fff0d3, #ffe4b5);
    border: 1px solid rgba(217, 154, 43, 0.3);
    box-shadow: 0 6px 12px -6px rgba(217, 154, 43, 0.6);
}

.dot-1 {
    width: 14px;
    height: 14px;
    margin: 0 5px;
    background: linear-gradient(150deg, #dff7ee, #c9f0e2);
    border: 1px solid rgba(31, 163, 123, 0.28);
    box-shadow: 0 5px 10px -5px rgba(31, 163, 123, 0.55);
}

.dot-info {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #8f5c0c;
    background: #fff4e0;
    border: 1.5px dashed rgba(143, 92, 12, 0.5);
}

.legend-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.legend-copy strong {
    font-size: 0.84rem;
    font-weight: 650;
    color: var(--text);
}

.legend-copy small {
    font-size: 0.71rem;
    color: var(--muted);
    line-height: 1.35;
}

.legend-actions {
    margin-top: 18px;
    padding-top: 15px;
    border-top: 1px solid rgba(21, 21, 29, 0.07);
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.legend-actions p {
    margin: 0;
    font-size: 0.76rem;
    line-height: 1.4;
    color: var(--muted);
}

.legend-actions strong {
    font-weight: 650;
    color: var(--text);
}

/* ---------- Nuage rond ---------- */

.cloud-wrap {
    position: relative;
    width: min(100%, 520px);
    aspect-ratio: 1 / 1;
}

.cloud {
    width: 100%;
    height: 100%;
    padding: 15%;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 16px;
    overflow: hidden;
    background:
        radial-gradient(120% 100% at 18% 0%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.5) 46%, rgba(255, 255, 255, 0.38) 100%),
        rgba(255, 255, 255, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow:
        0 34px 70px -34px rgba(20, 20, 45, 0.32),
        0 2px 0 rgba(255, 255, 255, 0.8) inset;
    backdrop-filter: blur(20px) saturate(125%);
    -webkit-backdrop-filter: blur(20px) saturate(125%);
}

.cloud:empty::after {
    content: 'Votre esprit est vide. Pour l\'instant. ☁️';
    max-width: 70%;
    color: #9b9ba6;
    font-size: 0.9rem;
    font-style: italic;
    text-align: center;
}

/* ---------- Bulles ---------- */

.task-bubble {
    display: inline-block;
    max-width: 100%;
    padding: 12px 22px;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -0.01em;
    text-align: center;
    overflow-wrap: break-word;
    cursor: pointer;
    user-select: none;
    animation: float 5.5s ease-in-out infinite alternate;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1), box-shadow 0.25s ease, opacity 0.2s ease;
    will-change: transform;
    -webkit-tap-highlight-color: transparent;
}

/* !important nécessaire : l'animation `float` contrôle déjà `transform` */
.task-bubble:hover {
    transform: translateY(-3px) scale(1.05) !important;
}

.task-bubble:active {
    transform: scale(0.94) !important;
    opacity: 0.6;
}

.task-bubble:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

/* Taille = urgence temporelle, couleur = teinte douce */
.urgency-3 {
    font-size: 27px;
    color: #a72f1b;
    background: linear-gradient(150deg, #ffe3dc, #ffd1c6);
    border-color: rgba(226, 84, 60, 0.22);
    box-shadow:
        0 16px 32px -16px rgba(226, 84, 60, 0.55),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.urgency-2 {
    font-size: 20px;
    color: #8f5c0c;
    background: linear-gradient(150deg, #fff0d3, #ffe4b5);
    border-color: rgba(217, 154, 43, 0.24);
    box-shadow:
        0 14px 28px -16px rgba(217, 154, 43, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.urgency-1 {
    font-size: 15px;
    color: #0f7458;
    background: linear-gradient(150deg, #dff7ee, #c9f0e2);
    border-color: rgba(31, 163, 123, 0.22);
    box-shadow:
        0 12px 24px -16px rgba(31, 163, 123, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

/* Beaucoup de billes : on réduit légèrement l'échelle */
.cloud.is-dense .task-bubble {
    padding: 10px 17px;
}

.cloud.is-dense .urgency-3 {
    font-size: 22px;
}

.cloud.is-dense .urgency-2 {
    font-size: 17px;
}

.cloud.is-dense .urgency-1 {
    font-size: 13px;
}

/* Bille en attente d'une information manquante */
.task-bubble.needs-info {
    border-style: dashed;
    border-width: 1.5px;
    border-color: rgba(143, 92, 12, 0.42);
    filter: saturate(0.82);
}

.task-bubble.needs-info::after {
    content: '❓';
    margin-left: 8px;
    font-size: 0.75em;
    vertical-align: middle;
}

/* Flottaison organique, volontairement discrète */
@keyframes float {
    0%   { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}

/* ---------- Mascotte ---------- */

.mascot {
    position: absolute;
    left: -12px;
    bottom: -4px;
    z-index: 3;
    width: 92px;
    animation: mascot-bob 3.4s ease-in-out infinite alternate;
    transform-origin: 50% 100%;
    filter: drop-shadow(0 16px 20px rgba(49, 46, 129, 0.18));
    pointer-events: none;
}

.mascot svg {
    display: block;
    width: 100%;
    height: auto;
}

@keyframes mascot-bob {
    0%   { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(-5px) rotate(-1.5deg); }
}

/* La mascotte s'anime quand elle « parle » */
.cloud-wrap:has(.detail-panel.is-open) .mascot svg {
    animation: mascot-talk 0.65s ease-out;
}

@keyframes mascot-talk {
    0%   { transform: translateY(0) scale(1); }
    35%  { transform: translateY(-7px) scale(1.04); }
    70%  { transform: translateY(0) scale(0.99); }
    100% { transform: translateY(0) scale(1); }
}

/* ---------- Contrôles ---------- */

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.mic-btn {
    width: 76px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: linear-gradient(150deg, #6c63ff, #4f46e5);
    color: #ffffff;
    cursor: pointer;
    box-shadow:
        0 18px 34px -14px rgba(79, 70, 229, 0.65),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: transform 0.2s ease, box-shadow 0.3s ease, background 0.3s ease;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.mic-btn svg {
    width: 28px;
    height: 28px;
    pointer-events: none;
}

.mic-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow:
        0 22px 40px -14px rgba(79, 70, 229, 0.7),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.mic-btn.recording {
    background: linear-gradient(150deg, #ff7a68, #e2543c);
    box-shadow: 0 18px 34px -14px rgba(226, 84, 60, 0.6);
    animation: pulse 1.6s ease-in-out infinite;
}

/* Analyse en cours */
.mic-btn:disabled {
    cursor: progress;
}

.mic-btn.processing {
    background: linear-gradient(150deg, #9a94ff, #7a71f0);
    opacity: 0.85;
    animation: pulse 1.3s ease-in-out infinite;
}

@keyframes pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.status {
    min-height: 20px;
    max-width: 420px;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.4;
    text-align: center;
    letter-spacing: 0.005em;
}

/* ---------- Accessibilité : mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
    .task-bubble,
    .mascot,
    .mic-btn.recording,
    .mic-btn.processing,
    .cloud-wrap:has(.detail-panel.is-open) .mascot svg {
        animation: none;
    }

    .task-bubble:hover,
    .task-bubble:active {
        transform: none !important;
    }
}

/* ---------- Bulle de BD (détails / question) ---------- */

[hidden] {
    display: none !important;
}

.detail-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(20, 20, 35, 0.04);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.detail-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.detail-panel {
    position: absolute;
    z-index: 30;
    left: 76px;
    bottom: 58px;
    width: min(72%, 360px);
    background: #fffdfb;
    border: 1px solid rgba(21, 21, 29, 0.09);
    border-radius: 22px;
    box-shadow:
        0 28px 56px -24px rgba(20, 20, 45, 0.38),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.96);
    transform-origin: 18% 100%;
    transition: opacity 0.22s ease, transform 0.24s cubic-bezier(0.2, 0.8, 0.3, 1), visibility 0.22s;
}

.detail-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Queue de la bulle, pointée vers la mascotte */
.detail-panel::after {
    content: '';
    position: absolute;
    left: 6px;
    bottom: -9px;
    width: 18px;
    height: 18px;
    background: #fffdfb;
    border-right: 1px solid rgba(21, 21, 29, 0.09);
    border-bottom: 1px solid rgba(21, 21, 29, 0.09);
    border-bottom-right-radius: 3px;
    transform: rotate(45deg);
}

.detail-panel:focus {
    outline: none;
}

.detail-content {
    max-height: min(72vh, 520px);
    overflow-y: auto;
    padding: 22px 24px 20px;
    border-radius: inherit;
}

.detail-content::-webkit-scrollbar {
    width: 6px;
}

.detail-content::-webkit-scrollbar-thumb {
    background: rgba(21, 21, 29, 0.16);
    border-radius: 999px;
}

.detail-close {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 2;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #8d8d99;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.detail-close:hover {
    background: #f1f0f5;
    color: var(--text);
}

.detail-title {
    margin: 0 34px 14px 0;
    font-size: 1.12rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.3;
    color: var(--text);
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 0.73rem;
    font-weight: 650;
    letter-spacing: 0.01em;
}

.badge-urgency-3 {
    background: #fdeae5;
    border-color: #f7d2c9;
    color: #a72f1b;
}

.badge-urgency-2 {
    background: #fdf2df;
    border-color: #f4e1c0;
    color: #8f5c0c;
}

.badge-urgency-1 {
    background: #e8f7f1;
    border-color: #cdeee1;
    color: #0f7458;
}

#detail-energy {
    background: #f3f2f6;
    border-color: #e6e5eb;
    color: #5d5d6a;
}

/* Urgence provisoire : ambre, quelle que soit la valeur estimée */
.badge.badge-provisional {
    background: #fff4e0;
    border-color: #f1dcb8;
    color: #8f5c0c;
}

.detail-reason {
    margin: 0 0 16px;
    color: #6c6c78;
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.5;
}

/* Question de précision */
.detail-question {
    margin: 0 0 12px;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 650;
    line-height: 1.45;
}

.detail-question.detail-error {
    color: #b3341f;
    font-size: 0.87rem;
    font-weight: 500;
}

.detail-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}

.detail-option {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e5e4ea;
    border-radius: 12px;
    background: #ffffff;
    color: #34343f;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.1s ease;
}

.detail-option:hover:not(:disabled) {
    background: #f8f7ff;
    border-color: #c9c4ff;
}

.detail-option:active:not(:disabled) {
    transform: scale(0.995);
}

.detail-option:disabled {
    opacity: 0.55;
    cursor: progress;
}

.detail-actions {
    display: flex;
    gap: 8px;
}

.detail-actions button {
    flex: 1;
    padding: 11px;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.87rem;
    font-weight: 650;
    cursor: pointer;
    transition: filter 0.18s ease, transform 0.1s ease, box-shadow 0.18s ease;
}

.detail-actions button:hover {
    filter: brightness(1.04);
}

.detail-actions button:active {
    transform: scale(0.985);
}

.btn-done {
    background: linear-gradient(150deg, #16a37f, #0d7a5f);
    color: #ffffff;
    box-shadow: 0 12px 24px -14px rgba(13, 122, 95, 0.8);
}

.btn-later {
    background: #f3f2f6;
    color: #4c4c58;
}

/* ---------- Tablette / mobile ---------- */

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 26px;
    }

    .app-main {
        order: 1;
        width: 100%;
    }

    .legend {
        order: 2;
        width: min(100%, 540px);
    }

    .legend-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 14px 20px;
    }

    .legend-actions {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px 18px;
    }

    /* Le panneau devient une feuille basse, sans queue */
    .detail-panel {
        position: fixed;
        left: 50%;
        bottom: 0;
        width: min(100%, 520px);
        border-radius: 24px 24px 0 0;
        transform: translate(-50%, 100%);
    }

    .detail-panel.is-open {
        transform: translate(-50%, 0);
    }

    .detail-panel::after {
        display: none;
    }

    .detail-content {
        max-height: 80vh;
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 560px) {
    body {
        padding: 26px 16px 24px;
        gap: 20px;
    }

    .app-header h1 {
        font-size: 1.7rem;
    }

    .app-header p {
        font-size: 0.88rem;
    }

    .cloud-wrap {
        width: min(100%, 360px);
    }

    .cloud {
        padding: 15%;
        gap: 9px;
    }

    .task-bubble {
        padding: 8px 15px;
    }

    .urgency-3 {
        font-size: 21px;
    }

    .urgency-2 {
        font-size: 16px;
    }

    .urgency-1 {
        font-size: 13px;
    }

    .cloud.is-dense {
        gap: 7px;
    }

    .cloud.is-dense .task-bubble {
        padding: 7px 13px;
    }

    .cloud.is-dense .urgency-3 {
        font-size: 19px;
    }

    .cloud.is-dense .urgency-2 {
        font-size: 14px;
    }

    .cloud.is-dense .urgency-1 {
        font-size: 12px;
    }

    .mascot {
        width: 74px;
        left: -6px;
        bottom: -2px;
    }

    .legend-list {
        grid-template-columns: 1fr;
    }

    .legend-actions {
        flex-direction: column;
    }
}

/* ---------- Mode installé (PWA standalone) ---------- */

@media (display-mode: standalone) {
    /* Respecte l'encoche et la barre gestuelle des téléphones récents. */
    body {
        padding-top: max(24px, env(safe-area-inset-top));
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    /* L'installation n'a plus de sens une fois l'app lancée depuis l'écran d'accueil. */
    .install-btn {
        display: none;
    }
}
