/* =====================================================================
   Agentic Kernel — single-page chat
   Pure black canvas, one scarlet accent, everything else monochrome.
   Designed for the Chat.razor shell: .shell / .topbar / .stream /
   .msg / .bubble / .md / .composer.
   ===================================================================== */

:root {
    --bg:            #000000;
    --bg-elev-1:     #0b0b0c;
    --bg-elev-2:     #121214;
    --bg-elev-3:     #18181b;
    --line:          #1f1f23;
    --line-strong:   #2a2a2f;

    --ink:           #ededee;
    --ink-dim:       #b6b6bb;
    --ink-faint:     #7a7a82;
    --ink-ghost:     #4a4a52;

    --accent:        #ef3d3d;
    --accent-hot:    #ff5757;
    --accent-soft:   rgba(239, 61, 61, 0.14);
    --accent-line:   rgba(239, 61, 61, 0.35);
    --accent-glow:   rgba(239, 61, 61, 0.55);

    --radius-s: 8px;
    --radius-m: 14px;
    --radius-l: 20px;

    --shadow-card:    0 1px 0 rgba(255,255,255,0.03) inset,
                      0 18px 50px rgba(0,0,0,0.45);
    --shadow-pop:     0 0 0 1px var(--accent-line),
                      0 10px 28px var(--accent-glow);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: "Inter", ui-sans-serif, system-ui, -apple-system,
                 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Subtle radial vignette on the body so pure-black doesn't read as dead. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%,
                        rgba(239, 61, 61, 0.08), transparent 60%),
        radial-gradient(ellipse 60% 40% at 50% 110%,
                        rgba(255, 255, 255, 0.02), transparent 60%);
    z-index: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hot); text-decoration: underline; }

::selection { background: var(--accent); color: #000; }

/* =====================================================================
   Shell grid: topbar / stream / composer
   ===================================================================== */

.shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    max-width: 880px;
    margin: 0 auto;
    padding: 0 20px;
}

/* =====================================================================
   Topbar
   ===================================================================== */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 4px 14px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: linear-gradient(to bottom,
                                rgba(0,0,0,0.92) 60%,
                                rgba(0,0,0,0.0));
    backdrop-filter: blur(10px);
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft),
                0 0 16px var(--accent-glow);
    animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--accent-soft),
                          0 0 12px var(--accent-glow); }
    50%      { box-shadow: 0 0 0 5px rgba(239,61,61,0.08),
                          0 0 20px var(--accent-glow); }
}

.brand-name { color: var(--ink); }
.brand-name em {
    font-style: normal;
    color: var(--ink-faint);
    font-weight: 500;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ghost-link,
.ghost-btn {
    font: inherit;
    font-size: 13px;
    color: var(--ink-dim);
    background: transparent;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.ghost-link:hover,
.ghost-btn:hover:not(:disabled) {
    color: var(--ink);
    border-color: var(--accent-line);
    background: var(--accent-soft);
    text-decoration: none;
}

.ghost-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* =====================================================================
   Stream
   ===================================================================== */

.stream {
    overflow-y: auto;
    padding: 28px 4px 40px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}
.stream::-webkit-scrollbar          { width: 10px; }
.stream::-webkit-scrollbar-track    { background: transparent; }
.stream::-webkit-scrollbar-thumb    {
    background: var(--line-strong);
    border-radius: 999px;
    border: 3px solid transparent;
    background-clip: padding-box;
}
.stream::-webkit-scrollbar-thumb:hover { background: var(--ink-ghost);
                                         background-clip: padding-box; }

/* =====================================================================
   Welcome / empty state
   ===================================================================== */

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12vh 12px 6vh;
    gap: 8px;
}

.welcome .glyph {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 42px;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--accent);
    text-shadow: 0 0 24px var(--accent-glow);
    margin-bottom: 6px;
}

.welcome h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.welcome-sub {
    margin: 0 0 24px;
    color: var(--ink-faint);
    max-width: 46ch;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 620px;
}

.suggestions button {
    font: inherit;
    font-size: 13.5px;
    color: var(--ink-dim);
    text-align: left;
    background: var(--bg-elev-1);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.16s ease;
}
.suggestions button:hover {
    color: var(--ink);
    background: var(--bg-elev-2);
    border-color: var(--accent-line);
    transform: translateY(-1px);
}

/* =====================================================================
   Messages
   ===================================================================== */

.msg {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 14px;
    padding: 10px 0;
    animation: rise 0.18s ease-out both;
}
@keyframes rise {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    flex-shrink: 0;
}

.msg.user .avatar {
    background: var(--bg-elev-2);
    color: var(--ink-dim);
    border: 1px solid var(--line-strong);
}

.msg.assistant .avatar {
    background: radial-gradient(circle at 30% 30%,
                                var(--accent-hot), var(--accent) 60%, #8a1f1f);
    color: #fff;
    box-shadow: 0 0 0 1px var(--accent-line),
                0 6px 18px var(--accent-glow);
}

.bubble {
    align-self: start;
    min-width: 0;
    padding: 12px 16px;
    border-radius: var(--radius-m);
    background: var(--bg-elev-1);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-card);
    max-width: 100%;
    overflow: hidden;
}

.msg.user .bubble {
    background: var(--bg-elev-2);
    border-color: #ef3d3d;
}

.msg.assistant .bubble {
    background: var(--bg-elev-1);
    border-color: var(--line);
}

/* =====================================================================
   Typing indicator
   ===================================================================== */

.bubble.typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 14px 16px;
}
.bubble.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.4;
    animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing span:nth-child(2) { animation-delay: 0.15s; }
.bubble.typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
    40%           { opacity: 1;   transform: scale(1); }
}

/* =====================================================================
   Markdown content (.md inside .bubble)
   ===================================================================== */

.md {
    color: var(--ink);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.md > *:first-child { margin-top: 0 !important; }
.md > *:last-child  { margin-bottom: 0 !important; }

.md p {
    margin: 0.55em 0;
    line-height: 1.6;
}

.md h1, .md h2, .md h3,
.md h4, .md h5, .md h6 {
    margin: 1.1em 0 0.45em;
    color: var(--ink);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.25;
}
.md h1 { font-size: 1.45em; }
.md h2 { font-size: 1.25em; }
.md h3 { font-size: 1.12em; }
.md h4 { font-size: 1.0em;  color: var(--ink-dim); }
.md h5, .md h6 { font-size: 0.95em; color: var(--ink-dim); }

.md h1, .md h2 {
    padding-bottom: 0.25em;
    border-bottom: 1px solid var(--line);
}

.md a {
    color: var(--accent);
    border-bottom: 1px dashed var(--accent-line);
}
.md a:hover {
    color: var(--accent-hot);
    border-bottom-style: solid;
    text-decoration: none;
}

.md strong { color: #fff; font-weight: 600; }
.md em     { color: var(--ink-dim); font-style: italic; }
.md del    { color: var(--ink-faint); }
.md mark   { background: var(--accent-soft); color: var(--ink); padding: 0 3px; border-radius: 3px; }

.md hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1.2em 0;
}

/* Lists */
.md ul, .md ol {
    margin: 0.5em 0;
    padding-left: 1.4em;
}
.md li { margin: 0.2em 0; }
.md li::marker { color: var(--accent); }
.md ul ul, .md ol ol, .md ul ol, .md ol ul { margin: 0.2em 0; }

/* Task list (GFM) */
.md li input[type="checkbox"] {
    accent-color: var(--accent);
    margin-right: 6px;
    transform: translateY(1px);
}

/* Inline code */
.md code {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas,
                 "Liberation Mono", monospace;
    font-size: 0.88em;
    background: var(--bg-elev-3);
    border: 1px solid var(--line);
    padding: 1px 6px;
    border-radius: 6px;
    color: #ffd1d1;
}

/* Fenced code blocks */
.md pre {
    margin: 0.7em 0;
    padding: 14px 16px;
    background: #0a0a0b;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    overflow-x: auto;
    line-height: 1.5;
    font-size: 13px;
    position: relative;
}
.md pre::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 2px;
    background: var(--accent);
    opacity: 0.85;
}
.md pre code {
    background: transparent;
    border: 0;
    padding: 0;
    color: #eaeaea;
    font-size: inherit;
    border-radius: 0;
}

/* Blockquote */
.md blockquote {
    margin: 0.7em 0;
    padding: 4px 14px;
    border-left: 3px solid var(--accent);
    color: var(--ink-dim);
    background: var(--accent-soft);
    border-radius: 0 var(--radius-s) var(--radius-s) 0;
}
.md blockquote p { margin: 0.4em 0; }

/* Tables (GFM) */
.md table {
    border-collapse: collapse;
    margin: 0.7em 0;
    width: 100%;
    font-size: 0.95em;
    overflow: hidden;
    border-radius: var(--radius-s);
    border: 1px solid var(--line);
}
.md th, .md td {
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}
.md th {
    background: var(--bg-elev-2);
    color: var(--ink);
    font-weight: 600;
    border-bottom: 1px solid var(--line-strong);
}
.md tr:last-child td { border-bottom: 0; }
.md tr:hover td { background: rgba(239, 61, 61, 0.04); }

/* Images */
.md img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-s);
    border: 1px solid var(--line);
}

/* kbd */
.md kbd {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.82em;
    background: var(--bg-elev-3);
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--ink);
}

/* =====================================================================
   Composer
   ===================================================================== */

.composer {
    padding: 12px 4px 22px;
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top,
                                rgba(0,0,0,0.98) 40%,
                                rgba(0,0,0,0.70) 80%,
                                rgba(0,0,0,0.0));
    z-index: 5;
}

.composer-inner {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 10px;
    padding: 10px 10px 10px 16px;
    background: var(--bg-elev-1);
    border: 1px solid var(--line-strong);
    border-radius: 18px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer-inner:focus-within {
    border-color: var(--accent-line);
    box-shadow: 0 0 0 4px var(--accent-soft),
                0 10px 24px rgba(0,0,0,0.6);
}

.composer-input {
    font: inherit;
    color: var(--ink);
    background: transparent;
    border: 0;
    outline: none;
    resize: none;
    width: 100%;
    min-height: 24px;
    max-height: 220px;
    padding: 6px 2px;
    line-height: 1.55;
    overflow-y: auto;
}
.composer-input::placeholder { color: var(--ink-faint); }
.composer-input:disabled     { color: var(--ink-faint); cursor: wait; }

.send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: 0;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.send:hover:not(:disabled) {
    background: var(--accent-hot);
    box-shadow: 0 0 0 3px var(--accent-soft),
                0 6px 16px var(--accent-glow);
    transform: translateY(-1px);
}
.send:disabled {
    background: var(--bg-elev-3);
    color: var(--ink-ghost);
    cursor: not-allowed;
    box-shadow: none;
}
.send svg { display: block; }

.composer-hint {
    margin-top: 6px;
    text-align: center;
    font-size: 11.5px;
    color: var(--ink-faint);
    letter-spacing: 0.02em;
}

/* =====================================================================
   Toast notifications (app.js appNotify.show)
   ===================================================================== */

#toast-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 380px;
    background: var(--bg-elev-2);
    color: var(--ink);
    border: 1px solid var(--accent-line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-s);
    padding: 12px 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5),
                0 0 0 1px rgba(0,0,0,0.2);
    font-size: 13.5px;
    animation: toast-in 0.2s ease-out;
}
.toast-title {
    font-weight: 600;
    color: var(--accent-hot);
    margin-bottom: 4px;
}
.toast-body {
    color: var(--ink-dim);
    white-space: pre-wrap;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* =====================================================================
   Blazor error UI override
   ===================================================================== */

#blazor-error-ui {
    background: #1a0606;
    color: #ffd1d1;
    border-top: 1px solid var(--accent);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.8rem 1.25rem 0.8rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1001;
    font-size: 13px;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    color: var(--accent-hot);
}

/* =====================================================================
   Responsive
   ===================================================================== */

@media (max-width: 640px) {
    .shell            { padding: 0 12px; }
    .brand-name em    { display: none; }
    .welcome          { padding: 8vh 4px 4vh; }
    .welcome h1       { font-size: 26px; }
    .welcome .glyph   { font-size: 34px; }
    .suggestions      { grid-template-columns: 1fr; }
    .msg              { grid-template-columns: 28px 1fr; gap: 10px; }
    .avatar           { width: 28px; height: 28px; font-size: 10px; }
    .composer-inner   { padding: 8px 8px 8px 14px; border-radius: 16px; }
    .composer-hint    { display: none; }
}
