@property --angle {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

:root {
    --app-height: 100dvh;

    --ink: #07060A;
    --glass: rgba(255, 255, 255, 0.045);
    --glass-strong: rgba(255, 255, 255, 0.085);
    --border: rgba(255, 255, 255, 0.10);
    --text: #F5F4F8;
    --text-dim: #A7A2B2;
    --text-faint: #6E6878;
    --garnet: #C42B4D;
    --garnet-deep: #7A1830;
    --amber: #E0954A;
    --teal: #123B3F;

    --error-text: #ffb3b3;
}

html[data-theme="light"] {
    --ink: #F3F1F5;
    --glass: rgba(10, 8, 16, 0.04);
    --glass-strong: rgba(10, 8, 16, 0.07);
    --border: rgba(10, 8, 16, 0.10);
    --text: #15121C;
    --text-dim: #5B5566;
    --text-faint: #8B8594;
    --error-text: #b91c1c;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    margin: 0;
    background: var(--ink);
    transition: background 0.2s ease;
    overscroll-behavior: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}

.app {
    height: var(--app-height);
    max-width: 760px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    background: var(--ink);
}

.app-content {
    position: relative;
    z-index: 2;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ----- Fond aurora + grain ----- */

.aurora {
    position: absolute;
    inset: -15%;
    z-index: 0;
    filter: blur(85px);
    pointer-events: none;
}

.aurora-blob {
    position: absolute;
    border-radius: 50%;
    mix-blend-mode: screen;
    opacity: .5;
}

.aurora-blob.b1 {
    width: 320px;
    height: 320px;
    background: var(--garnet);
    top: -40px;
    left: -60px;
    animation: drift1 24s ease-in-out infinite alternate;
}

.aurora-blob.b2 {
    width: 300px;
    height: 300px;
    background: var(--amber);
    bottom: 0;
    right: -70px;
    opacity: .4;
    animation: drift2 28s ease-in-out infinite alternate;
}

.aurora-blob.b3 {
    width: 280px;
    height: 280px;
    background: var(--teal);
    top: 42%;
    left: 25%;
    opacity: .55;
    animation: drift3 32s ease-in-out infinite alternate;
}

@keyframes drift1 { from { transform: translate(0, 0) scale(1); } to { transform: translate(50px, 70px) scale(1.2); } }
@keyframes drift2 { from { transform: translate(0, 0) scale(1); } to { transform: translate(-40px, -50px) scale(1.15); } }
@keyframes drift3 { from { transform: translate(0, 0) scale(1); } to { transform: translate(30px, -40px) scale(1.1); } }

.noise {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: .05;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

html[data-theme="light"] .aurora-blob { opacity: .25; }
html[data-theme="light"] .noise { opacity: .035; }

/* ----- Orb (avatar animé) ----- */

.orb-wrap {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.orb-ring {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1px solid rgba(196, 43, 77, .4);
    animation: ring-pulse 2.6s ease-out infinite;
}

.orb-ring.d2 { animation-delay: 1.3s; }

@keyframes ring-pulse {
    0% { transform: scale(.78); opacity: .8; }
    100% { transform: scale(1.7); opacity: 0; }
}

.orb {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    animation: breathe 3.6s ease-in-out infinite;
    box-shadow: 0 0 22px rgba(196, 43, 77, .55);
}

.orb::before {
    content: "";
    position: absolute;
    inset: -40%;
    background: conic-gradient(from var(--angle), var(--garnet), var(--amber), var(--teal), var(--garnet));
    animation: spin 7s linear infinite;
}

.orb::after {
    content: "";
    position: absolute;
    inset: 2.5px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #1a1820, #0a090d 70%);
}

.orb-logo {
    position: absolute;
    inset: 2.5px;
    width: calc(100% - 5px);
    height: calc(100% - 5px);
    border-radius: 50%;
    object-fit: cover;
    z-index: 1;
    pointer-events: none;
}

@keyframes spin { to { --angle: 360deg; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* ----- Header ----- */

.app-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(18px + env(safe-area-inset-top)) 18px 14px;
    background: var(--glass);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    border-bottom: 1px solid var(--border);
    transition: background 0.2s ease, border-color 0.2s ease;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

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

.app-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
    color: var(--text);
}

.header-user {
    margin: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

.agent-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    background: var(--glass-strong);
    border: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace;
    font-size: 9.5px;
    letter-spacing: .08em;
    color: var(--text-dim);
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.dot.active {
    box-shadow: 0 0 8px currentColor;
}

.dot.email { background: var(--teal); color: var(--teal); }
.dot.calendar { background: var(--amber); color: var(--amber); }
.dot.task { background: var(--garnet); color: var(--garnet); }
.dot.memory { background: var(--garnet-deep); color: var(--garnet-deep); }
.dot.thinking { background: var(--garnet); color: var(--garnet); animation: dot-pulse 1s infinite ease-in-out; }

@keyframes dot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ----- Toolbar (actions secondaires) ----- */

.toolbar {
    flex-shrink: 0;
    display: flex;
    gap: 10px;
    padding: 14px 18px;
    background: var(--glass);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    border-bottom: 1px solid var(--border);
}

.tool-btn {
    width: 44px;
    height: 44px;
    border-radius: 15px;
    background: var(--glass-strong);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s ease, transform .1s ease, background .15s ease, box-shadow .15s ease;
}

.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:active { transform: scale(0.92); }
.tool-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.tool-btn[hidden] { display: none; }

.tool-btn.active {
    color: #fff;
    background: linear-gradient(145deg, rgba(196, 43, 77, .35), rgba(224, 149, 74, .18));
    border-color: rgba(196, 43, 77, .45);
    box-shadow: 0 0 16px rgba(196, 43, 77, .3);
}

/* ----- Zone de messages ----- */

.chat-window {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 86%;
    animation: message-in 0.35s ease-out;
}

@keyframes message-in {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    justify-content: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.avatar {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 14px rgba(196, 43, 77, .5);
    font-size: 0;
    line-height: 0;
    color: transparent;
}

.avatar::before {
    content: "";
    position: absolute;
    inset: -40%;
    background: conic-gradient(from var(--angle), var(--garnet), var(--amber), var(--teal), var(--garnet));
    animation: spin 7s linear infinite;
}

.avatar::after {
    content: "";
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #1a1820, #0a090d 70%);
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.message.assistant .message-content {
    align-items: flex-start;
}

.message.user .message-content {
    align-items: flex-end;
}

.bubble {
    position: relative;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.025));
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border-radius: 4px 20px 20px 20px;
    padding: 14px 16px;
    line-height: 1.55;
    font-size: 15px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 100%;
}

.bubble::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, rgba(255, 255, 255, .3), rgba(196, 43, 77, .45), rgba(224, 149, 74, .25));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

.message.user .bubble {
    border-radius: 20px 4px 20px 20px;
    background: linear-gradient(160deg, rgba(196, 43, 77, 0.32), rgba(122, 24, 48, 0.22));
}

.message.user .bubble::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, .35), rgba(224, 149, 74, .4), rgba(196, 43, 77, .3));
}

.bubble.error {
    background: rgba(196, 43, 77, 0.18);
}

.bubble.error::before {
    background: linear-gradient(135deg, var(--garnet), var(--garnet));
}

.timestamp {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    color: var(--text-faint);
    letter-spacing: .04em;
    padding: 0 3px;
}

.agent-tag {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-dim);
    margin-bottom: 5px;
}

/* ----- Indicateur "Agent réfléchit..." ----- */

.bubble.typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 13px 17px;
}

.typing-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: .04em;
    color: var(--text-dim);
    white-space: nowrap;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    display: inline-block;
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ----- Barre d'input fixe en bas ----- */

.chat-input-area {
    flex-shrink: 0;
    background: var(--glass);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    border-top: 1px solid var(--border);
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
}

.input-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

#chat-input {
    flex: 1;
    resize: none;
    background: var(--glass-strong);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 16px;
    line-height: 1.4;
    font-family: 'Inter', sans-serif;
    max-height: 120px;
}

#chat-input::placeholder {
    color: var(--text-faint);
}

#chat-input:focus {
    outline: none;
    border-color: rgba(196, 43, 77, .45);
}

.icon-button {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--glass-strong);
    color: var(--text-dim);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: opacity 0.15s ease, transform 0.1s ease, background 0.15s ease, box-shadow .15s ease;
}

.icon-button svg { width: 18px; height: 18px; }

.icon-button:active {
    transform: scale(0.92);
}

.icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

#mic-button.listening,
#conversation-button.listening {
    background: linear-gradient(145deg, rgba(196, 43, 77, .45), rgba(122, 24, 48, .3));
    border-color: rgba(196, 43, 77, .5);
    color: #fff;
    box-shadow: 0 0 16px rgba(196, 43, 77, .4);
    animation: mic-pulse 1.2s infinite;
}

@keyframes mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(196, 43, 77, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(196, 43, 77, 0); }
    100% { box-shadow: 0 0 0 0 rgba(196, 43, 77, 0); }
}

/* Icône "égaliseur" du bouton micro */
.eq {
    display: flex;
    align-items: center;
    gap: 2.5px;
    height: 14px;
}

.eq span {
    width: 2.5px;
    border-radius: 2px;
    background: currentColor;
    animation: eq 1.1s ease-in-out infinite;
}

.eq span:nth-child(1) { height: 5px; animation-delay: 0s; }
.eq span:nth-child(2) { height: 11px; animation-delay: .15s; }
.eq span:nth-child(3) { height: 7px; animation-delay: .3s; }
.eq span:nth-child(4) { height: 13px; animation-delay: .45s; }

@keyframes eq {
    0%, 100% { transform: scaleY(.4); }
    50% { transform: scaleY(1); }
}

.send-button {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    border: none;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.send-button::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from var(--angle), var(--garnet), var(--amber), var(--garnet-deep), var(--garnet));
    animation: spin 5s linear infinite;
}

.send-button::after {
    content: "";
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--garnet), var(--garnet-deep));
}

.send-button svg {
    position: relative;
    z-index: 1;
    width: 18px;
    height: 18px;
    color: #fff;
}

.send-button:active { transform: scale(0.94); }

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

.send-button:disabled::before {
    animation-play-state: paused;
}

.chat-window::-webkit-scrollbar {
    width: 5px;
}

.chat-window::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ----- Desktop / écrans larges ----- */

@media (min-width: 760px) {
    .app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

/* ----- Écran de connexion ----- */

.login-screen {
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
    background: var(--ink);
}

.login-card {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 380px;
    background: var(--glass);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 44px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: login-card-in 0.45s ease-out;
}

@keyframes login-card-in {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-orb-wrap {
    position: relative;
    width: 72px;
    height: 72px;
    margin-bottom: 6px;
}

.login-orb-wrap .orb-ring { inset: -8px; }
.login-orb-wrap .orb { width: 72px; height: 72px; }

.login-title {
    font-size: 22px;
}

.login-subtitle {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--text-dim);
    font-family: 'Inter', sans-serif;
}

.login-error {
    margin: 0;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--garnet);
}

.google-signin-button {
    width: 100%;
    height: 46px;
    border-radius: 999px;
    background: #ffffff;
    color: #1f1f1f;
    border: none;
    font-size: 14.5px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    cursor: pointer;
    margin-top: 6px;
    transition: box-shadow 0.15s ease, transform 0.1s ease;
}

.google-signin-button:hover {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.google-signin-button:active {
    transform: scale(0.98);
}

.google-logo {
    flex-shrink: 0;
}

.install-app-button {
    width: 100%;
    height: 44px;
    border-radius: 999px;
    background: var(--glass-strong);
    color: var(--text-dim);
    border: 1px solid var(--border);
    font-size: 13.5px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.install-app-button:hover {
    background: var(--glass);
    color: var(--text);
}
