/* ==========================================================================
   AI Runcode — design system
   An AI workspace, not a document site: app shell, calm surfaces, one confident
   indigo accent, and type that stays out of the way while you work.
   Light and dark are both first-class.
   ========================================================================== */

:root {
    /* Brand — indigo/violet, the AI Runcode identity */
    --accent:        #6D5DF6;
    --accent-hi:     #8E7DFF;
    --accent-lo:     #5B4BE8;
    --accent-soft:   rgba(109, 93, 246, 0.10);
    --accent-line:   rgba(109, 93, 246, 0.28);
    --accent-glow:   rgba(109, 93, 246, 0.35);

    /* Surfaces — violet-biased neutrals so the accent feels native */
    --bg:            #F7F7FC;
    --surface:       #FFFFFF;
    --surface-2:     #FBFBFE;
    --surface-3:     #F2F2F9;
    --line:          #E7E6F2;
    --line-strong:   #D6D4E8;

    --text:          #16142B;
    --text-2:        #4A4767;
    --muted:         #6B6889;
    --faint:         #918EAC;

    --ok:            #12A87A;
    --warn:          #C98A00;
    --crit:          #E5484D;
    --ok-soft:       rgba(18, 168, 122, 0.12);
    --warn-soft:     rgba(201, 138, 0, 0.14);
    --crit-soft:     rgba(229, 72, 77, 0.12);

    --sh-1: 0 1px 2px rgba(22, 20, 43, .05), 0 1px 3px rgba(22, 20, 43, .04);
    --sh-2: 0 4px 14px rgba(22, 20, 43, .07), 0 2px 6px rgba(22, 20, 43, .04);
    --sh-3: 0 18px 48px rgba(22, 20, 43, .16);

    --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-xl: 22px;
    --sidebar-w: 264px;
    --topbar-h: 58px;

    --sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, Menlo, monospace;
    --ease: cubic-bezier(.2, .7, .3, 1);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:          #0D0C16;
        --surface:     #15142268;
        --surface:     #151422;
        --surface-2:   #1B1A2B;
        --surface-3:   #232235;
        --line:        #272639;
        --line-strong: #34324B;
        --text:        #ECEBF5;
        --text-2:      #B8B5D0;
        --muted:       #918EAC;
        --faint:       #6F6C8C;
        --accent-soft: rgba(142, 125, 255, 0.14);
        --accent-line: rgba(142, 125, 255, 0.32);
        --sh-1: 0 1px 2px rgba(0,0,0,.4);
        --sh-2: 0 4px 16px rgba(0,0,0,.45);
        --sh-3: 0 20px 50px rgba(0,0,0,.6);
    }
}
:root[data-theme="dark"] {
    --bg:#0D0C16; --surface:#151422; --surface-2:#1B1A2B; --surface-3:#232235;
    --line:#272639; --line-strong:#34324B;
    --text:#ECEBF5; --text-2:#B8B5D0; --muted:#918EAC; --faint:#6F6C8C;
    --accent-soft: rgba(142,125,255,.14); --accent-line: rgba(142,125,255,.32);
    --sh-1: 0 1px 2px rgba(0,0,0,.4); --sh-2: 0 4px 16px rgba(0,0,0,.45); --sh-3: 0 20px 50px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: var(--sans); font-size: 15px; line-height: 1.55;
    -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
svg { display: block; flex: none; }
button, input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ── App shell ─────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.shell.no-side { grid-template-columns: 1fr; }

.side {
    position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
    background: var(--surface); border-right: 1px solid var(--line); z-index: 30;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
    width: 32px; height: 32px; border-radius: 9px; flex: none; display: grid; place-items: center;
    background: linear-gradient(150deg, var(--accent-hi), var(--accent));
    box-shadow: 0 2px 10px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.35);
}
.brand-word b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.brand-word span { display: block; font-size: 9.5px; font-weight: 600; letter-spacing: .16em;
    text-transform: uppercase; color: var(--faint); margin-top: 2px; }

.side-scroll { flex: 1; overflow-y: auto; padding: 6px 10px 10px; }
.side-scroll::-webkit-scrollbar { width: 8px; }
.side-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

.side-label {
    font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
    color: var(--faint); padding: 14px 8px 6px;
}
.side-link {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
    color: var(--text-2); font-size: 13.5px; font-weight: 500; transition: background .14s var(--ease), color .14s;
}
.side-link:hover { background: var(--surface-3); color: var(--text); }
.side-link.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link .ic { color: currentColor; opacity: .85; }
.side-foot { padding: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }

.who { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; padding: 6px; border-radius: 9px; }
.who:hover { background: var(--surface-3); }
.avatar {
    width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
    background: linear-gradient(150deg, var(--accent-hi), var(--accent));
    color: #fff; font-weight: 700; font-size: 12.5px; box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.who-txt { min-width: 0; }
.who-txt b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-txt span { display: block; font-size: 11px; color: var(--faint); }

.icon-btn {
    width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: none;
    color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: all .14s var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--line); }

/* ── Main column ───────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar {
    position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px; padding: 0 20px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.topbar .sub { font-size: 12.5px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.burger { display: none; }

.content { flex: 1; padding: 26px 24px 60px; }
.wrap { max-width: 1180px; margin: 0 auto; }
.wrap-narrow { max-width: 860px; margin: 0 auto; }

/* ── Portal ────────────────────────────────────────────────────────────── */
.hero { margin-bottom: 26px; }
.hero h2 { margin: 0; font-size: 27px; font-weight: 700; letter-spacing: -.03em; text-wrap: balance; }
.hero h2 em { font-style: normal; color: var(--accent); }
.hero p { margin: 7px 0 0; color: var(--muted); font-size: 14.5px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 14px; }
.card {
    position: relative; display: flex; align-items: flex-start; gap: 13px; padding: 16px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    box-shadow: var(--sh-1); overflow: hidden;
    transition: transform .16s var(--ease), box-shadow .16s, border-color .16s;
}
.card::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
    background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 0%), var(--accent-soft), transparent 42%);
    opacity: 0; transition: opacity .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--sh-3); border-color: var(--accent-line); }
.card:hover::after { opacity: 1; }
.card .ic {
    width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); transition: transform .18s var(--ease);
}
.card:hover .ic { transform: scale(1.07) rotate(-3deg); }
.card b { display: block; font-size: 14px; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }
.card span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.sec { display: flex; align-items: center; gap: 12px; margin: 30px 0 13px; }
.sec h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: -.01em; }
.sec .line { flex: 1; height: 1px; background: var(--line); }
.sec .count { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 15px; border-radius: 10px; border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
    transition: all .16s var(--ease);
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 10px var(--accent-glow); }
.btn-primary:hover { background: var(--accent-lo); transform: translateY(-1px); box-shadow: 0 8px 20px var(--accent-glow); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-danger { background: transparent; color: var(--crit); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--crit-soft); border-color: var(--crit); }

/* ── Chat ──────────────────────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); }
.chat-scroll { flex: 1; overflow-y: auto; padding: 26px 20px 8px; }
.chat-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.msg { display: flex; gap: 13px; animation: rise .3s var(--ease); }
.msg .who-ic {
    width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center;
    font-size: 12px; font-weight: 700;
}
.msg.user .who-ic { background: var(--surface-3); color: var(--text-2); }
.msg.ai .who-ic { background: linear-gradient(150deg, var(--accent-hi), var(--accent)); color: #fff; }
.msg .body { min-width: 0; flex: 1; padding-top: 3px; }
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }

.prose { font-size: 14.7px; line-height: 1.68; color: var(--text); }
.prose p { margin: 0 0 .85em; }
.prose h1,.prose h2,.prose h3 { margin: 1.3em 0 .5em; font-weight: 680; letter-spacing: -.015em; line-height: 1.3; }
.prose h1 { font-size: 1.32em; } .prose h2 { font-size: 1.18em; } .prose h3 { font-size: 1.05em; }
.prose ul, .prose ol { margin: 0 0 .9em; padding-left: 1.35em; }
.prose li { margin: .3em 0; }
.prose strong { font-weight: 660; }
.prose code {
    font-family: var(--mono); font-size: .88em; background: var(--surface-3);
    border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.prose pre {
    background: var(--surface-3); border: 1px solid var(--line); border-radius: var(--r);
    padding: 13px 15px; overflow-x: auto; margin: 0 0 1em; line-height: 1.5;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: 13px; }
.prose blockquote {
    margin: 0 0 1em; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent-line); color: var(--text-2);
}
.prose table { width: 100%; border-collapse: collapse; margin: 0 0 1em; font-size: .93em; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.prose th { background: var(--surface-3); font-weight: 650; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Composer */
.composer { padding: 12px 20px 20px; background: linear-gradient(to top, var(--bg) 62%, transparent); }
.composer-inner { max-width: 820px; margin: 0 auto; }
.composer-box {
    display: flex; align-items: flex-end; gap: 9px; padding: 9px 9px 9px 14px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-xl);
    box-shadow: var(--sh-2); transition: border-color .16s, box-shadow .16s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--sh-2); }
.composer-box textarea {
    flex: 1; border: 0; background: none; resize: none; outline: none; font-size: 14.6px;
    line-height: 1.55; max-height: 220px; padding: 6px 0; min-height: 26px;
}
.composer-box textarea::placeholder { color: var(--faint); }
.send {
    width: 36px; height: 36px; border-radius: 50%; border: 0; flex: none; cursor: pointer;
    background: var(--accent); color: #fff; display: grid; place-items: center;
    transition: all .16s var(--ease); box-shadow: 0 2px 8px var(--accent-glow);
}
.send:hover:not(:disabled) { background: var(--accent-lo); transform: scale(1.06); }
.send:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.composer-hint { text-align: center; font-size: 11.5px; color: var(--faint); margin-top: 8px; }

.attach-btn {
    width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2);
    color: var(--muted); display: grid; place-items: center; cursor: pointer; flex: none; transition: all .15s;
}
.attach-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
.chip {
    display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; font-size: 12px; font-weight: 550;
    background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); border-radius: 20px;
}
.chip button { background: none; border: 0; color: inherit; cursor: pointer; display: grid; place-items: center; opacity: .7; }
.chip button:hover { opacity: 1; }

/* Typing dots */
.dots { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .45; animation: blink 1.3s infinite; }
.dots i:nth-child(2) { animation-delay: .18s; } .dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity:.25; transform: translateY(0); } 30% { opacity:1; transform: translateY(-3px); } }

/* Empty state */
.empty { text-align: center; padding: 46px 20px; max-width: 560px; margin: 0 auto; }
.empty .ic {
    width: 56px; height: 56px; border-radius: 17px; margin: 0 auto 16px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent);
}
.empty h3 { margin: 0 0 6px; font-size: 19px; font-weight: 680; letter-spacing: -.02em; }
.empty p { margin: 0; color: var(--muted); font-size: 14px; }
.suggests { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.suggest {
    padding: 8px 13px; font-size: 13px; background: var(--surface); border: 1px solid var(--line);
    border-radius: 20px; cursor: pointer; color: var(--text-2); transition: all .15s var(--ease);
}
.suggest:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }

/* ── Panels / forms ────────────────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 17px; border-bottom: 1px solid var(--line); }
.panel-head .ic { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.panel-head h3 { margin: 0; font-size: 14px; font-weight: 680; letter-spacing: -.01em; }
.panel-head .n { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.panel-body { padding: 17px; }

.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, .field input[type=text], .field input[type=email], .field input[type=password], .field textarea, .field select {
    width: 100%; padding: 10px 12px; font-size: 14.5px; background: var(--surface-2);
    border: 1px solid var(--line-strong); border-radius: 10px; transition: all .15s var(--ease);
}
.input:focus, .field input:focus, .field textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface);
}
.field textarea { resize: vertical; min-height: 92px; line-height: 1.55; }

/* Dropzone */
.drop {
    border: 1.6px dashed var(--line-strong); border-radius: var(--r-lg); padding: 34px 20px; text-align: center;
    cursor: pointer; transition: all .18s var(--ease); background: var(--surface-2);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .ic { width: 46px; height: 46px; border-radius: 14px; margin: 0 auto 12px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); }
.drop b { display: block; font-size: 14.5px; font-weight: 620; }
.drop span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ── Gallery ───────────────────────────────────────────────────────────── */
.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; }
.gal figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    overflow: hidden; box-shadow: var(--sh-1); transition: transform .16s var(--ease), box-shadow .16s; }
.gal figure:hover { transform: translateY(-3px); box-shadow: var(--sh-3); }
.gal img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface-3); }
.gal figcaption {
    padding: 10px 12px; font-size: 12px; color: var(--muted); line-height: 1.45;
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; max-height: calc(1.45em * 2 + 20px);
}

/* ── Notices ───────────────────────────────────────────────────────────── */
.notice { display: flex; gap: 11px; padding: 13px 15px; border-radius: var(--r); font-size: 13.5px; margin-bottom: 16px; align-items: flex-start; }
.notice .ic { flex: none; margin-top: 1px; }
.notice-warn { background: var(--warn-soft); color: #7A5B00; border: 1px solid rgba(201,138,0,.3); }
.notice-crit { background: var(--crit-soft); color: var(--crit); border: 1px solid rgba(229,72,77,.3); }
.notice-info { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
@media (prefers-color-scheme: dark) { .notice-warn { color: #E9C46A; } }

.meta-line { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 11.5px; color: var(--faint);
    margin-top: 9px; font-family: var(--mono); }
.meta-line .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
        radial-gradient(900px circle at 12% -10%, var(--accent-soft), transparent 55%),
        radial-gradient(700px circle at 108% 108%, var(--accent-soft), transparent 52%),
        var(--bg);
}
.login-card { width: 100%; max-width: 396px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 13px; margin-bottom: 26px; }
.login-brand .brand-mark { width: 50px; height: 50px; border-radius: 15px; }
.login-brand b { font-size: 21px; font-weight: 700; letter-spacing: -.03em; }
.login-brand span { font-size: 10px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--faint); }

/* ── Utility ───────────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.hidden { display: none !important; }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.rise { animation: rise .35s var(--ease) both; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .side {
        position: fixed; inset: 0 auto 0 0; width: 84%; max-width: var(--sidebar-w);
        transform: translateX(-100%); transition: transform .26s var(--ease); box-shadow: var(--sh-3);
    }
    .side.open { transform: none; }
    .burger { display: grid; }
    .content { padding: 20px 16px 48px; }
    .scrim { position: fixed; inset: 0; background: rgba(13,12,22,.5); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .2s; }
    .scrim.on { opacity: 1; pointer-events: auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
