:root {
    --dc-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --dc-bg: #ffffff;
    --dc-page: #f6f7f9;
    --dc-fg: #16181d;
    --dc-muted: #6b7280;
    --dc-line: #e5e7eb;
    --dc-accent: #2f6bff;
    --dc-accent-fg: #ffffff;
    --dc-bubble: #f1f3f7;
    --dc-error: #b42318;
    --dc-radius: 12px;
}

/* Deliberately light in every case. The widget is framed by dergosoft.com's white card, so
   following the visitor's OS dark mode made it a black rectangle in the middle of a light page. */

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    font: 15px/1.5 var(--dc-font);
    color: var(--dc-fg);
    background: var(--dc-bg);
    -webkit-text-size-adjust: 100%;
}

/* --- shell --- */

.chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--dc-bg);
}

.chat__header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--dc-line);
    flex: 0 0 auto;
}

.chat__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    flex: 0 0 auto;
}

.chat__title {
    font-weight: 600;
    font-size: .95rem;
}

/* --- messages --- */

.chat__log {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.msg {
    max-width: 85%;
    padding: .55rem .8rem;
    border-radius: var(--dc-radius);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    animation: dc-in .18s ease-out;
}

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

@media (prefers-reduced-motion: reduce) {
    .msg { animation: none; }
}

.msg--assistant {
    align-self: flex-start;
    background: var(--dc-bubble);
    border-bottom-left-radius: 4px;
}

.msg--user {
    align-self: flex-end;
    background: var(--dc-accent);
    color: var(--dc-accent-fg);
    border-bottom-right-radius: 4px;
}

.msg--system {
    align-self: center;
    max-width: 100%;
    text-align: center;
    font-size: .82rem;
    color: var(--dc-error);
    background: none;
    padding: .2rem .4rem;
}

/* --- typing indicator --- */

.typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 1.5em;
}

.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--dc-muted);
    animation: dc-blink 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }

@keyframes dc-blink {
    0%, 60%, 100% { opacity: .25; }
    30%           { opacity: 1; }
}

/* --- composer --- */

.chat__composer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .65rem .75rem .35rem;
    border-top: 1px solid var(--dc-line);
}

.chat__input {
    flex: 1 1 auto;
    resize: none;
    max-height: 8.5em;
    /* The box autosizes as you type; the scrollbar only appears past the max height and its
       spinner arrows were showing on an empty field. Keep it scrollable, keep it invisible. */
    overflow-y: auto;
    scrollbar-width: none;
    padding: .55rem .7rem;
    font: inherit;
    color: inherit;
    background: var(--dc-page);
    border: 1px solid var(--dc-line);
    border-radius: 10px;
    outline: none;
}

.chat__input::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.chat__input:focus {
    border-color: var(--dc-accent);
}

.chat__input:disabled {
    opacity: .6;
}

.chat__send {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 10px;
    background: var(--dc-accent);
    color: var(--dc-accent-fg);
    cursor: pointer;
}

.chat__send:disabled {
    opacity: .45;
    cursor: default;
}

.chat__footnote {
    flex: 0 0 auto;
    margin: 0;
    padding: 0 .75rem .55rem;
    font-size: .7rem;
    color: var(--dc-muted);
    text-align: center;
}

/* --- markdown-lite output inside assistant bubbles --- */

.msg--rich {
    white-space: normal;   /* the renderer emits real block elements */
}

.msg--rich > :first-child { margin-top: 0; }
.msg--rich > :last-child { margin-bottom: 0; }

.msg--rich p {
    margin: 0 0 .5em;
}

.msg--rich p.md-h {
    font-weight: 600;
    margin-top: .8em;
}

.msg--rich ul,
.msg--rich ol {
    margin: 0 0 .5em;
    padding-left: 1.25em;
}

.msg--rich li {
    margin: .15em 0;
}

.msg--rich strong {
    font-weight: 600;
}

.msg--rich code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9em;
    padding: .05em .3em;
    border-radius: 4px;
    background: rgba(127, 127, 127, .18);
}

.msg--rich hr {
    border: 0;
    border-top: 1px solid var(--dc-line);
    margin: .6em 0;
}
