:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-hover: #f0f4f8;
    --text: #18202f;
    --text-soft: #667085;
    --text-faint: #98a2b3;
    --line: #e4e7ec;
    --line-strong: #d0d5dd;
    --blue: #356df3;
    --blue-dark: #2455d7;
    --blue-soft: #eef4ff;
    --violet: #8155e7;
    --violet-soft: #f3efff;
    --amber: #d78b18;
    --amber-soft: #fff7e6;
    --green: #16865d;
    --green-soft: #eaf8f2;
    --red: #c84855;
    --red-soft: #fff0f1;
    --shadow: 0 1px 2px rgb(16 24 40 / 4%), 0 8px 22px rgb(16 24 40 / 4%);
    --rail-width: 62px;
    --sidebar-width: 252px;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #11151d;
    --surface: #181e28;
    --surface-soft: #202734;
    --surface-hover: #252e3d;
    --text: #eef2f8;
    --text-soft: #aab4c5;
    --text-faint: #778397;
    --line: #2c3544;
    --line-strong: #3a4659;
    --blue: #6b93ff;
    --blue-dark: #8ba9ff;
    --blue-soft: #1d2c51;
    --violet: #a78bfa;
    --violet-soft: #302553;
    --amber: #f2b653;
    --amber-soft: #3b2d16;
    --green: #4ed0a0;
    --green-soft: #173c31;
    --red: #ff8994;
    --red-soft: #48232a;
    --shadow: 0 1px 2px rgb(0 0 0 / 12%), 0 12px 30px rgb(0 0 0 / 15%);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

button:focus-visible, a:focus-visible, textarea:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--blue) 28%, transparent);
    outline-offset: 2px;
}

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

.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;
}

.app-shell { min-height: 100vh; }

.global-loading {
    position: fixed;
    z-index: 100;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text-soft);
    font-size: 12px;
}

.global-loading span, .button-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--line-strong);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.icon-rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 32;
    width: var(--rail-width);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 13px 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.brand-mark {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--blue);
    color: white;
    box-shadow: 0 7px 16px color-mix(in srgb, var(--blue) 25%, transparent);
}

.brand-mark svg { width: 21px; height: 21px; stroke-width: 1.9; }
.rail-actions { display: grid; gap: 8px; margin-top: 20px; }
.rail-bottom { display: grid; justify-items: center; gap: 12px; margin-top: auto; }

.icon-button {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
}

.icon-button:hover { color: var(--text); background: var(--surface-hover); }

.avatar {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(145deg, #d8e5ff, #f1eaff);
    color: #374b75;
    font-size: 11px;
    font-weight: 750;
    border: 1px solid color-mix(in srgb, var(--blue) 16%, var(--line));
}

.avatar-small { width: 32px; height: 32px; font-size: 10px; }
.avatar-large { width: 46px; height: 46px; font-size: 13px; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 var(--rail-width);
    z-index: 30;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    padding: 19px 15px 14px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

.workspace-heading {
    min-height: 43px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 7px 15px;
    border-bottom: 1px solid var(--line);
}

.workspace-heading div { display: grid; gap: 3px; }
.workspace-heading strong { font-size: 13px; }
.micro-label, .eyebrow { color: var(--text-faint); font-size: 10px; font-weight: 700; letter-spacing: .075em; text-transform: uppercase; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.main-nav { display: grid; gap: 3px; margin-top: 15px; }
.main-nav a, .sidebar-section a {
    min-height: 39px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 570;
}

.main-nav a svg { width: 18px; height: 18px; }
.main-nav a:hover, .sidebar-section a:hover { background: var(--surface-hover); color: var(--text); }
.main-nav a.active { background: var(--blue-soft); color: var(--blue-dark); }
.nav-badge { margin-left: auto; padding: 2px 6px; border-radius: 999px; background: var(--surface-soft); color: var(--text-faint); font-size: 9px; }

.sidebar-section { margin-top: 26px; padding: 0 4px; }
.sidebar-section > .micro-label { display: block; padding: 0 7px 6px; }
.sidebar-section a { min-height: 34px; font-size: 12px; }
.collection-dot { width: 7px; height: 7px; border-radius: 50%; }
.collection-dot.blue { background: var(--blue); }
.collection-dot.violet { background: var(--violet); }
.collection-dot.amber { background: var(--amber); }

.credits-card {
    margin-top: auto;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface-soft);
}

.credits-title { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-soft); }
.credits-title strong { color: var(--text); }
.progress-track { height: 5px; margin: 9px 0; border-radius: 9px; overflow: hidden; background: var(--line); }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--blue); }
.credits-card p { margin: 0; color: var(--text-faint); font-size: 10px; }
.credits-card button { margin: 11px 0 0; padding: 0; border: 0; background: transparent; color: var(--blue-dark); font-size: 10px; font-weight: 650; cursor: pointer; }

.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 14px;
    padding: 13px 5px 0;
    border-top: 1px solid var(--line);
}

.sidebar-profile div { min-width: 0; display: grid; }
.sidebar-profile strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-profile small { color: var(--text-faint); font-size: 9px; }
.sidebar-profile button { margin-left: auto; border: 0; background: transparent; color: var(--text-faint); cursor: pointer; }

.main-content { min-height: 100vh; margin-left: calc(var(--rail-width) + var(--sidebar-width)); }
.topbar {
    height: 58px;
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    padding: 0 26px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.mobile-menu { display: none; }
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-faint); }
.breadcrumb b { font-weight: 400; }
.breadcrumb strong { color: var(--text-soft); font-weight: 600; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

.quiet-button, .primary-button {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-soft);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.quiet-button:hover { border-color: var(--line-strong); color: var(--text); }
.primary-button { border-color: var(--blue); background: var(--blue); color: white; }
.primary-button svg { width: 16px; height: 16px; }
.icon-only { min-width: 34px; padding: 5px 8px; }

.page-wrap { width: min(1260px, 100%); margin: 0 auto; padding: 29px 30px 25px; }
.page-heading { display: flex; align-items: flex-start; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { max-width: 780px; margin: 7px 0 6px; font-size: clamp(22px, 2.2vw, 31px); line-height: 1.18; letter-spacing: -.035em; }
.page-heading p { max-width: 700px; margin: 0; color: var(--text-soft); font-size: 12px; }
.heading-actions { display: flex; gap: 7px; margin-left: auto; }

.prototype-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: -8px 0 19px;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--blue) 24%, var(--line));
    border-radius: 10px;
    background: var(--blue-soft);
}

.prototype-notice svg { flex: 0 0 auto; width: 17px; height: 17px; margin-top: 1px; color: var(--blue-dark); }
.prototype-notice strong { font-size: 11px; }
.prototype-notice p { margin: 2px 0 0; color: var(--text-soft); font-size: 10px; }
.prototype-notice code { padding: 1px 4px; border-radius: 4px; background: var(--surface); }

.hero-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 16px; }
.panel { border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.memory-overview { min-height: 468px; padding: 20px; }
.panel-toolbar, .panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.workspace-persona { display: flex; align-items: center; gap: 11px; }
.workspace-persona div { display: grid; gap: 2px; }
.workspace-persona strong { font-size: 12px; }
.workspace-persona span { color: var(--text-faint); font-size: 9px; }
.ai-label { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; background: var(--violet-soft); color: var(--violet); font-size: 9px; font-weight: 650; }
.ai-label i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.memory-score { display: flex; align-items: center; justify-content: space-between; gap: 30px; min-height: 205px; padding: 24px 24px 18px; }
.memory-score > div:first-child { max-width: 370px; }
.memory-score span { color: var(--text-soft); font-size: 10px; font-weight: 600; }
.memory-score strong { display: block; margin: 5px 0 4px; font-size: 42px; letter-spacing: -.055em; }
.memory-score p { margin: 0; color: var(--text-soft); font-size: 11px; }

.donut {
    --donut-color: var(--blue);
    position: relative;
    flex: 0 0 auto;
    width: 118px;
    height: 118px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: conic-gradient(var(--donut-color) calc(var(--value) * 1%), var(--line) 0);
}

.donut::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: var(--surface); }
.donut > span { position: relative; z-index: 1; color: var(--text); font-size: 25px; font-weight: 730; letter-spacing: -.04em; }
.donut small { margin-left: 1px; color: var(--text-faint); font-size: 10px; font-weight: 600; }

.mini-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-metrics > div { min-width: 0; display: flex; align-items: center; gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.metric-icon { flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; font-weight: 750; }
.metric-icon.blue { background: var(--blue-soft); color: var(--blue); }
.metric-icon.amber { background: var(--amber-soft); color: var(--amber); }
.metric-icon.violet { background: var(--violet-soft); color: var(--violet); }
.mini-metrics p { min-width: 0; display: grid; margin: 0; }
.mini-metrics strong { font-size: 13px; }
.mini-metrics small { overflow: hidden; color: var(--text-faint); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }

.trust-note { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px 14px; border-radius: 9px; background: var(--green-soft); color: var(--green); }
.trust-note svg { flex: 0 0 auto; width: 20px; height: 20px; }
.trust-note p { display: grid; gap: 1px; margin: 0; }
.trust-note strong { font-size: 10px; }
.trust-note span { color: var(--text-soft); font-size: 9px; }

.chat-panel { min-height: 468px; display: flex; flex-direction: column; overflow: hidden; }
.chat-heading { min-height: 68px; display: flex; align-items: center; gap: 10px; padding: 14px 15px; border-bottom: 1px solid var(--line); }
.ai-orb { flex: 0 0 auto; width: 37px; height: 37px; display: grid; place-items: center; border-radius: 10px; background: linear-gradient(145deg, var(--blue-soft), var(--violet-soft)); color: var(--blue); }
.ai-orb svg { width: 21px; height: 21px; }
.chat-heading > div:nth-child(2) { display: grid; gap: 2px; }
.chat-heading strong { font-size: 11px; }
.provider-status { display: flex; align-items: center; gap: 5px; color: var(--text-faint); font-size: 8px; }
.provider-status i { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.provider-status.online i { background: var(--green); }
.chat-reset { margin-left: auto; }
.chat-reset svg { width: 17px; height: 17px; }

.chat-messages { flex: 1 1 auto; height: 244px; display: flex; flex-direction: column; gap: 11px; padding: 15px; overflow-y: auto; scroll-behavior: smooth; }
.chat-message { max-width: 91%; display: flex; align-items: flex-start; gap: 7px; }
.chat-message.user { align-self: flex-end; }
.message-avatar { flex: 0 0 auto; width: 25px; height: 25px; display: grid; place-items: center; border-radius: 8px; background: var(--blue-soft); color: var(--blue); font-size: 7px; font-weight: 800; }
.message-content { min-width: 0; padding: 9px 10px; border-radius: 4px 11px 11px; background: var(--surface-soft); }
.user .message-content { border-radius: 11px 4px 11px 11px; background: var(--blue); color: white; }
.error .message-content { background: var(--red-soft); color: var(--red); }
.blocked .message-content { background: var(--amber-soft); color: var(--amber); }
.message-content p { margin: 0; font-size: 10px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.model-label { display: block; margin-top: 6px; color: var(--text-faint); font-size: 7px; }
.user .model-label { color: rgb(255 255 255 / 70%); }

.chat-data-card { display: grid; gap: 5px; margin-top: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.chat-data-card > strong { padding-bottom: 4px; color: var(--text-soft); font-size: 8px; }
.chat-data-card span { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-data-card small { color: var(--text-soft); font-size: 8px; }
.chat-data-card b { font-size: 9px; }

.thinking .message-content { display: flex; align-items: center; gap: 8px; }
.thinking small { color: var(--text-faint); font-size: 8px; }
.typing-dots { display: flex; gap: 3px; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--blue); animation: bounce 1s infinite alternate; }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { to { transform: translateY(-3px); opacity: .45; } }

.clarification-options, .chat-suggestions { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 15px 9px; }
.clarification-options button, .chat-suggestions button { padding: 6px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--blue-dark); font-size: 8px; cursor: pointer; }
.clarification-options button:hover, .chat-suggestions button:hover { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 35%, var(--line)); }

.chat-composer { display: flex; align-items: flex-end; gap: 7px; margin: 0 14px; padding: 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); transition: border-color .2s, box-shadow .2s; }
.chat-composer:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 13%, transparent); }
.chat-composer textarea { flex: 1; min-height: 36px; max-height: 90px; resize: none; padding: 5px 6px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 10px; line-height: 1.45; }
.chat-composer textarea::placeholder { color: var(--text-faint); }
.chat-composer button { flex: 0 0 auto; width: 31px; height: 31px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; background: var(--blue); color: white; cursor: pointer; }
.chat-composer button:hover { background: var(--blue-dark); }
.chat-composer button svg { width: 16px; height: 16px; }
.field-error { margin: 5px 17px 0; color: var(--red); font-size: 8px; }
.chat-disclaimer { display: flex; align-items: center; justify-content: center; gap: 5px; padding: 9px 12px 11px; color: var(--text-faint); font-size: 7px; text-align: center; }
.chat-disclaimer svg { flex: 0 0 auto; width: 11px; height: 11px; }

.analytics-grid { display: grid; grid-template-columns: 1.12fr .88fr; gap: 16px; margin-top: 16px; }
.chart-panel { min-height: 245px; padding: 18px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 13px; }
.trend { padding: 4px 7px; border-radius: 999px; font-size: 9px; font-weight: 700; }
.trend.positive { background: var(--green-soft); color: var(--green); }
.bar-chart { height: 126px; display: flex; align-items: flex-end; gap: clamp(4px, 1.1vw, 10px); margin-top: 22px; padding: 0 6px; border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to bottom, transparent 0 31px, var(--line) 32px); }
.bar-chart span { flex: 1; min-width: 5px; max-width: 18px; border-radius: 4px 4px 0 0; background: linear-gradient(to top, var(--blue), color-mix(in srgb, var(--blue) 55%, var(--violet))); opacity: .78; }
.bar-chart span:hover { opacity: 1; }
.chart-labels { display: flex; justify-content: space-between; margin-top: 8px; color: var(--text-faint); font-size: 8px; }

.source-chart { min-height: 175px; display: flex; align-items: center; justify-content: center; gap: clamp(25px, 4vw, 55px); }
.source-donut { --donut-color: var(--blue); width: 116px; height: 116px; }
.source-donut::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: conic-gradient(var(--blue) 0 72%, var(--violet) 72% 93%, var(--line-strong) 93% 100%); }
.source-donut::after { inset: 13px; }
.source-donut span { display: grid; justify-items: center; font-size: 18px; }
.source-donut small { display: block; margin: 0; font-size: 7px; }
.legend { min-width: 180px; display: grid; gap: 13px; }
.legend p { display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 7px; margin: 0; color: var(--text-soft); font-size: 8px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; }
.legend-blue { background: var(--blue); }
.legend-violet { background: var(--violet); }
.legend-gray { background: var(--line-strong); }
.legend strong { color: var(--text); font-size: 9px; }

.prototype-footer { padding: 17px 0 0; color: var(--text-faint); font-size: 9px; text-align: center; }

@media (max-width: 1080px) {
    :root { --sidebar-width: 225px; }
    .page-wrap { padding-inline: 20px; }
    .hero-grid { grid-template-columns: minmax(0, 1fr); }
    .chat-panel { min-height: 500px; }
    .chat-messages { height: 280px; }
}

@media (max-width: 820px) {
    .icon-rail { display: none; }
    .sidebar { left: 0; transform: translateX(-103%); width: min(285px, 88vw); box-shadow: 18px 0 40px rgb(15 23 42 / 18%); transition: transform .22s ease; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open::after { content: ""; position: fixed; z-index: 25; inset: 0; background: rgb(15 23 42 / 38%); }
    .main-content { margin-left: 0; }
    .mobile-menu { width: 35px; height: 35px; display: grid; place-items: center; margin-right: 10px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
    .analytics-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .topbar { height: 54px; padding: 0 14px; }
    .breadcrumb span, .breadcrumb b, .top-actions .quiet-button { display: none; }
    .primary-button { padding: 7px 9px; font-size: 0; }
    .primary-button svg { margin: 0; }
    .page-wrap { padding: 21px 13px; }
    .page-heading { display: block; }
    .page-heading h1 { font-size: 24px; }
    .heading-actions { margin-top: 15px; }
    .memory-overview { min-height: 0; padding: 15px; }
    .panel-toolbar { align-items: center; }
    .ai-label { max-width: 130px; text-align: center; }
    .memory-score { padding: 25px 5px; gap: 15px; }
    .memory-score strong { font-size: 34px; }
    .donut { width: 93px; height: 93px; }
    .donut::after { inset: 9px; }
    .donut > span { font-size: 20px; }
    .mini-metrics { grid-template-columns: 1fr; }
    .mini-metrics small { white-space: normal; }
    .trust-note { align-items: flex-start; }
    .chat-panel { min-height: 510px; }
    .chat-messages { height: 290px; }
    .source-chart { align-items: flex-start; flex-direction: column; padding-top: 22px; }
    .source-donut { align-self: center; }
    .legend { width: 100%; }
    .bar-chart { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
