@font-face {
    font-display: swap;
    font-family: Gilroy;
    font-style: normal;
    font-weight: 700;
    src: url("/fonts/gilroy-bold.woff") format("woff");
}

@font-face {
    font-display: swap;
    font-family: Gilroy;
    font-style: normal;
    font-weight: 800;
    src: url("/fonts/gilroy-extrabold.woff") format("woff");
}

:root {
    --ink: #333d42;
    --muted: #778a93;
    --paper: #ffffff;
    --paper-2: #f6f4f8;
    --line: #d4d4d6;
    --orange: #f7941d;
    --orange-dark: #de7f0c;
    --teal: #029ba1;
    --teal-dark: #007f7f;
    --teal-light: #20bdc3;
    --red: #f84425;
    --navy: #00667f;
    --shadow: 0 12px 40px rgba(51, 61, 66, 0.08);
    --radius: 18px;
    --header-h: 4.6rem;
    --danger: #b42318;
    --ok: #067647;
    --white: #fff;
    --bg: var(--paper);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--ink);
    background: var(--paper);
    font: 16px/1.5 Sen, "Helvetica Neue", Helvetica, Arial, sans-serif;
    letter-spacing: -0.02em;
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; }

a { color: var(--teal-dark); text-decoration: none; }
a:hover { color: var(--orange); }

h1, h2, .footer-title {
    font-family: Gilroy, Sen, "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: 800;
    letter-spacing: -0.02em;
}

h1 {
    margin: 0 0 .5rem;
    font-size: clamp(1.35rem, 2.2vw, 1.75rem);
    line-height: 1.25;
}

h2 { margin: 0 0 .35rem; font-size: 1.25rem; }

.container {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    min-height: var(--header-h);
}

.brand img {
    display: block;
    width: auto;
    height: 3.6rem;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .8rem 1.5rem;
    font-size: .95rem;
}

.nav a {
    color: var(--ink);
    font-weight: 600;
}

.nav a.is-active,
.nav a:hover { color: var(--orange); }

.brand-bar {
    height: 6px;
    background: linear-gradient(90deg, var(--navy) 0 25%, var(--orange) 25% 50%, var(--red) 50% 75%, var(--teal-light) 75% 100%);
}

.site-main {
    flex: 1;
    padding: 2.5rem 0 4rem;
}

.hero { padding: 1rem 0 2.5rem; }

.hero p,
.lede {
    margin: 0;
    max-width: 42rem;
    color: var(--muted);
    font-size: 1.05rem;
}

.hero-actions { margin-top: 1.4rem; }

.feature-list { display: grid; gap: 1.25rem; }

.feature-card,
.card,
.panel,
.auth-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.feature-card {
    display: grid;
    grid-template-columns: 5.5rem 1fr;
    gap: 1.25rem;
    align-items: center;
    padding: 1.4rem 1.6rem;
    transition: transform .2s ease, border-color .2s ease;
}

.feature-card:hover {
    transform: translateY(-2px);
    border-color: var(--orange);
}

.feature-card p:last-child { margin: 0; color: var(--muted); }

.step-badge {
    display: grid;
    place-items: center;
    min-height: 5.2rem;
    margin: 0;
    background: #fff8ee;
    border-radius: 14px;
    color: var(--orange);
    font-family: Gilroy, Sen, "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1;
}

.card, .panel { padding: 1.1rem 1.2rem; }

.auth-card {
    width: min(100%, 32rem);
    margin-inline: auto;
    padding: 1.6rem 1.6rem 1.3rem;
}

.page-texte { max-width: 42rem; }
.page-texte h2 { margin: 1.8rem 0 .5rem; font-size: 1.15rem; }
.page-texte p { margin: 0 0 .8rem; }

.site-footer {
    padding: 2.5rem 0 1.4rem;
    background: var(--paper-2);
    color: var(--ink);
}

.footer-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

.footer-title { margin: 0 0 .7rem; }

.communes,
.footer-links {
    display: grid;
    gap: .25rem 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.communes { grid-template-columns: 1fr 1fr; }
.footer-links { grid-template-columns: 1fr; }

.footer-bottom {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: .85rem;
}

.footer-bottom p { margin: 0; }

label { display: block; font-weight: 650; margin: 1rem 0 .3rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea, select {
    width: min(100%, 36rem);
    padding: .6rem .9rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    font: inherit;
    color: inherit;
    background: var(--white);
}

textarea {
    width: min(100%, 46rem);
    border-radius: 16px;
}

.auth-card input[type="email"],
.auth-card input[type="password"] { width: 100%; }

.help-text { max-width: 46rem; margin: .35rem 0 0; color: var(--muted); font-size: .88rem; }

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.6rem;
    padding: .55rem 1.2rem;
    border: 0;
    border-radius: 999px;
    background: var(--orange);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

button:hover, .button:hover { background: var(--orange-dark); color: #fff; }

button.secondary, .button.secondary {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

button.secondary:hover, .button.secondary:hover {
    border-color: var(--orange);
    color: var(--orange);
    background: transparent;
}

button.quiet {
    background: transparent;
    color: var(--ink);
    font-weight: 600;
    min-height: 0;
    padding: .4rem .5rem;
}

button.quiet:hover { background: #fff8ee; color: var(--orange); }

.flash { padding: .7rem 1rem; border-radius: 12px; margin-bottom: 1rem; }
.flash.success { background: #e7f6ee; color: var(--ok); }
.flash.error { background: #fdeceb; color: var(--danger); }
.form-error { color: var(--danger); font-size: .9rem; }

.layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.25rem;
    width: min(1180px, calc(100% - 2rem));
    margin: 0 auto;
}

.side {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .9rem;
    align-self: start;
    position: sticky;
    top: calc(var(--header-h) + 1rem);
}

.side a, .side button.quiet {
    display: block;
    width: 100%;
    padding: .45rem .6rem;
    border-radius: 10px;
    text-align: left;
    text-decoration: none;
    color: var(--ink);
    font-weight: 600;
}

.side a.active, .side a:hover, .side button.quiet:hover {
    background: #fff8ee;
    color: var(--orange);
}

.side form select { width: 100%; margin-bottom: .6rem; border-radius: 12px; }
.side p { margin: .2rem .4rem .6rem; }

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: .1rem .5rem;
    font-size: .75rem;
    font-weight: 700;
    background: #e7f6ee;
    color: var(--ok);
}

.badge.off { background: #fde8e4; color: var(--red); }
.badge.wait, .badge.star { background: #fff4e0; color: #b56a00; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

th, td { text-align: left; padding: .65rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); background: var(--paper-2); }
td button, td .button { min-height: 2.15rem; padding: .35rem .85rem; font-size: .9rem; }
tr:last-child td { border-bottom: 0; }

.filters { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters a { font-weight: 600; color: var(--ink); }
.filters a.active, .filters a:hover { color: var(--orange); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-bottom: 1rem; }
.stat strong { display: block; font-size: 1.6rem; color: var(--teal-dark); font-family: Gilroy, Sen, sans-serif; }
.stat-note { display: block; color: var(--muted); font-size: .8rem; }
.journal-stats { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
.journal-stats strong { white-space: nowrap; font-size: 1.35rem; }

.snippet { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; border-radius: 16px; }
.bubble { max-width: 42rem; padding: .7rem .9rem; border-radius: 12px; margin: .4rem 0; }
.bubble.user { background: #e5f6f6; }
.bubble.assistant { background: var(--paper); border: 1px solid var(--line); }
.login-error { color: var(--danger); }

.side a.studio-link,
.side a.studio-link:hover,
.side a.studio-link.active {
    background: var(--orange);
    color: #fff;
    text-align: center;
    font-weight: 700;
    margin: .35rem 0 .7rem;
    border-radius: 999px;
}

.side a.studio-link:hover { background: var(--orange-dark); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.metrics {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-top: .55rem;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .72rem;
    line-height: 1.45;
    letter-spacing: .01em;
}

.metrics span {
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .12rem .5rem;
}

.metrics em { font-style: normal; color: var(--ink); font-weight: 650; }
.metrics-cost em { color: var(--teal-dark); }

body.studio-page { background: var(--paper-2); height: 100vh; overflow: hidden; }
body.studio-page .site-main { padding: .55rem 0; display: flex; min-height: 0; overflow: hidden; }
body.studio-page .site-footer { display: none; }

body.studio-page .layout {
    flex: 1;
    width: min(1240px, calc(100% - 1.25rem));
    height: auto;
    min-height: 0;
    margin: 0 auto;
    gap: .75rem;
    align-items: stretch;
}

body.studio-page .side { position: static; align-self: stretch; }
body.studio-page .layout > section {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.studio {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.studio-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .8rem 1rem;
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--line);
}

.studio-id { display: flex; align-items: center; gap: .7rem; min-width: 0; flex: 1; }
.studio-id > div { min-width: 0; }
.studio-id strong { display: block; line-height: 1.2; }
.studio-id p { margin: .1rem 0 0; color: var(--muted); font-size: .85rem; }

.studio-mark {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    flex: none;
    background: var(--orange);
    color: var(--white);
    font-weight: 700;
    font-size: .85rem;
}

.studio-mark.big { width: 3.2rem; height: 3.2rem; font-size: 1.25rem; }
.studio-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; justify-content: flex-end; }
.studio-actions a { font-size: .92rem; }

.pill {
    border-radius: 999px;
    padding: .15rem .6rem;
    font-size: .78rem;
    font-weight: 650;
}

.pill.on { background: #e7f6ee; color: var(--ok); }
.pill.off { background: #fff6e8; color: #7a4b00; }

.studio-banner {
    margin: 0;
    padding: .6rem 1rem;
    background: #fff6e8;
    color: #7a4b00;
    font-size: .9rem;
}

.studio-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 1rem;
    background:
        radial-gradient(900px 220px at 0% -10%, rgba(2, 155, 161, .1), transparent 60%),
        radial-gradient(680px 200px at 100% 0%, rgba(247, 148, 29, .14), transparent 55%),
        #fbfafc;
    scroll-behavior: smooth;
}

.studio-empty[hidden] { display: none; }

.studio-empty {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2.2rem 1.4rem 1.4rem;
    gap: .75rem;
}

.studio-empty h1 { margin: 0; font-size: 1.85rem; }
.studio-empty p { margin: 0; max-width: 34rem; color: var(--muted); }
.studio-suggestions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: .4rem; }

.studio-suggestions button {
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .5rem .85rem;
    box-shadow: 0 1px 0 rgba(51, 61, 66, .04);
    font-weight: 600;
    min-height: 0;
}

.studio-suggestions button:hover { border-color: var(--orange); color: var(--orange); background: var(--paper); }

.msg {
    display: flex;
    gap: .65rem;
    width: min(48rem, calc(100% - 2rem));
    margin: .9rem auto;
    animation: studio-in .28s ease;
}

.msg.user { justify-content: flex-end; }
.msg-main { min-width: 0; max-width: 100%; }
.msg-who { margin: 0 0 .25rem; font-size: .78rem; color: var(--muted); font-weight: 650; }

.msg-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.55;
}

.msg.assistant .msg-text {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 4px 18px 18px 18px;
    padding: .8rem .95rem;
    box-shadow: 0 8px 24px rgba(51, 61, 66, .04);
    white-space: normal;
}

.msg.assistant .msg-text a, .answer-html a { color: var(--teal-dark); text-decoration: underline; text-underline-offset: .12em; overflow-wrap: anywhere; }
.msg.assistant .msg-text p, .answer-html p { margin: 0 0 .55rem; }
.msg.assistant .msg-text p:last-child, .answer-html p:last-child { margin-bottom: 0; }
.msg.assistant .msg-text ul, .msg.assistant .msg-text ol, .answer-html ul, .answer-html ol { margin: .35rem 0 .35rem 1.15rem; padding: 0; }

.msg.user .msg-text {
    background: var(--teal-dark);
    color: var(--white);
    border-radius: 18px 18px 4px 18px;
    padding: .7rem .95rem;
    max-width: min(36rem, 100%);
}

.msg-text.caret::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    background: var(--orange);
    vertical-align: text-bottom;
    animation: studio-blink 1s steps(1) infinite;
}

.typing { display: inline-flex; gap: .28rem; align-items: center; min-height: 1.1rem; padding: .15rem 0; }

.typing i {
    width: .42rem;
    height: .42rem;
    border-radius: 999px;
    background: var(--muted);
    animation: studio-dot 1.05s infinite ease-in-out;
}

.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
.sources-panel { margin-top: .55rem; }

.sources-panel summary {
    cursor: pointer;
    width: fit-content;
    font-size: .82rem;
    font-weight: 650;
    color: var(--teal-dark);
    list-style: none;
}

.sources-panel summary::-webkit-details-marker { display: none; }

.sources-panel summary::before {
    content: "";
    display: inline-block;
    width: .38rem;
    height: .38rem;
    margin-right: .4rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg) translateY(-.05rem);
}

.sources-panel[open] summary::before { transform: rotate(45deg) translateY(-.12rem); }
.sources-list { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }

.sources-list a {
    font-size: .78rem;
    text-decoration: none;
    background: #fff8ee;
    color: var(--orange-dark);
    border-radius: 999px;
    padding: .18rem .6rem;
}

.sources-list a:hover { background: #ffe8c4; color: var(--orange-dark); }
.sources-empty { margin: .45rem 0 0; color: var(--muted); font-size: .82rem; }

.studio-composer {
    display: flex;
    align-items: flex-end;
    gap: .45rem;
    margin: .75rem 1rem .85rem;
    padding: .35rem .4rem .35rem .9rem;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--paper);
    box-shadow: 0 10px 30px rgba(51, 61, 66, .06);
}

.studio-composer:focus-within {
    border-color: var(--orange);
    box-shadow: 0 0 0 4px rgba(247, 148, 29, .16);
}

.studio-composer textarea {
    width: 100%;
    max-width: none;
    border: 0;
    border-radius: 0;
    padding: .5rem 0;
    resize: none;
    background: transparent;
    outline: none;
    box-shadow: none;
    line-height: 1.45;
    max-height: 10rem;
}

.studio-send {
    width: 2.55rem;
    height: 2.55rem;
    min-height: 0;
    border-radius: 999px;
    padding: 0;
    display: grid;
    place-items: center;
    flex: none;
    background: var(--orange);
}

.studio-send:hover { background: var(--orange-dark); }
.studio-send:disabled { opacity: .4; cursor: default; }
.studio-send.is-stop { background: var(--ink); }
.studio-send .icon-stop { display: none; }
.studio-send.is-stop .icon-send { display: none; }
.studio-send.is-stop .icon-stop { display: block; }

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

@keyframes studio-blink { 50% { opacity: 0; } }

@keyframes studio-dot {
    0%, 80%, 100% { transform: translateY(0); opacity: .35; }
    40% { transform: translateY(-3px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .msg, .typing i, .msg-text.caret::after, .feature-card { animation: none; transition: none; }
    .studio-thread { scroll-behavior: auto; }
}

@media (min-width: 720px) {
    .brand img { height: 4rem; }
    .footer-grid { grid-template-columns: 16rem minmax(0, 1fr) 14rem; }
    .communes { font-size: .95rem; }
}

@media (max-width: 800px) {
    .stats, .layout { grid-template-columns: 1fr; }
    .journal-stats { grid-template-columns: 1fr 1fr; }
    .feature-card { grid-template-columns: 4.2rem 1fr; padding: 1rem; }
    .side { position: static; }
    body.studio-page .studio { min-height: 78dvh; }
    .studio-top { align-items: flex-start; flex-direction: column; }
}
