.nx-md,
.nx-chat-content {
    line-height: 1.7;
    color: var(--nx-text-body, rgb(30, 41, 59));
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: var(--nx-text-base, 0.95rem);
}

.nx-md p,
.nx-chat-content p {
    margin: 0 0 var(--nx-space-3, 0.75rem) 0;
}

.nx-md p:last-child,
.nx-chat-content p:last-child {
    margin-bottom: 0;
}

.nx-md h1, .nx-md h2, .nx-md h3, .nx-md h4, .nx-md h5, .nx-md h6,
.nx-chat-content h1, .nx-chat-content h2, .nx-chat-content h3,
.nx-chat-content h4, .nx-chat-content h5, .nx-chat-content h6 {
    margin: var(--nx-space-4, 1rem) 0 var(--nx-space-2, 0.5rem) 0;
    font-weight: 600;
    color: var(--nx-text-heading, rgb(15, 23, 42));
    line-height: 1.4;
}

.nx-md h1, .nx-chat-content h1 { font-size: 1.5rem; }
.nx-md h2, .nx-chat-content h2 { font-size: 1.3rem; }
.nx-md h3, .nx-chat-content h3 { font-size: 1.15rem; }
.nx-md h4, .nx-chat-content h4 { font-size: 1.05rem; }
.nx-md h5, .nx-chat-content h5 { font-size: 0.95rem; }
.nx-md h6, .nx-chat-content h6 { font-size: 0.9rem; }

.nx-md ul, .nx-md ol,
.nx-chat-content ul, .nx-chat-content ol {
    margin: 0 0 var(--nx-space-3, 0.75rem) 0;
    padding-left: 1.5rem;
}

.nx-md li,
.nx-chat-content li {
    margin: 0.25rem 0;
}

.nx-md li > p,
.nx-chat-content li > p {
    margin: 0;
}

.nx-md a,
.nx-chat-content a {
    color: var(--nx-accent, rgb(79, 70, 229));
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color 0.15s;
}

.nx-md a:hover,
.nx-chat-content a:hover {
    color: var(--nx-accent-hover, rgb(67, 56, 202));
    text-decoration-thickness: 2px;
}

.nx-md blockquote,
.nx-chat-content blockquote {
    margin: var(--nx-space-3, 0.75rem) 0;
    padding: var(--nx-space-2, 0.5rem) var(--nx-space-4, 1rem);
    border-left: 3px solid var(--nx-border-strong, rgb(148, 163, 184));
    background: var(--nx-bg-subtle, rgb(241, 245, 249));
    color: var(--nx-text-muted, rgb(71, 85, 105));
    border-radius: 0 var(--nx-radius-sm, 0.375rem) var(--nx-radius-sm, 0.375rem) 0;
}

.nx-md blockquote p,
.nx-chat-content blockquote p {
    margin: 0;
}

.nx-md code,
.nx-chat-content code {
    padding: 0.125rem 0.375rem;
    background: var(--nx-bg-subtle, rgb(241, 245, 249));
    color: var(--nx-danger, rgb(190, 18, 60));
    border-radius: var(--nx-radius-sm, 0.375rem);
    font-family: 'SF Mono', Monaco, Inconsolata, 'Roboto Mono', 'Courier New', monospace;
    font-size: 0.875em;
    word-break: break-word;
}

.nx-md pre,
.nx-chat-content pre {
    margin: var(--nx-space-3, 0.75rem) 0;
    padding: var(--nx-space-4, 1rem);
    background: var(--nx-bg-code, rgb(30, 41, 59));
    border-radius: var(--nx-radius-md, 0.5rem);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.nx-md pre code,
.nx-chat-content pre code {
    padding: 0;
    background: transparent;
    color: rgb(226, 232, 240);
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: normal;
    white-space: pre;
}

.nx-md table,
.nx-chat-content table {
    width: 100%;
    margin: var(--nx-space-3, 0.75rem) 0;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--nx-border, rgb(226, 232, 240));
    border-radius: var(--nx-radius-sm, 0.375rem);
}

.nx-md th, .nx-md td,
.nx-chat-content th, .nx-chat-content td {
    padding: var(--nx-space-2, 0.5rem) var(--nx-space-3, 0.75rem);
    border: 1px solid var(--nx-border, rgb(226, 232, 240));
    text-align: left;
    white-space: nowrap;
}

.nx-md th,
.nx-chat-content th {
    background: var(--nx-bg-subtle, rgb(241, 245, 249));
    font-weight: 600;
    color: var(--nx-text-heading, rgb(15, 23, 42));
}

.nx-md td,
.nx-chat-content td {
    color: var(--nx-text-body, rgb(30, 41, 59));
}

.nx-md hr,
.nx-chat-content hr {
    margin: var(--nx-space-4, 1rem) 0;
    border: none;
    border-top: 1px solid var(--nx-border, rgb(226, 232, 240));
}

.nx-md img,
.nx-chat-content img {
    max-width: 100%;
    border-radius: var(--nx-radius-sm, 0.375rem);
    margin: var(--nx-space-2, 0.5rem) 0;
}

.nx-md del,
.nx-chat-content del {
    color: var(--nx-text-muted, rgb(148, 163, 184));
}

.nx-md kbd,
.nx-chat-content kbd {
    padding: 0.125rem 0.375rem;
    background: var(--nx-bg-subtle, rgb(241, 245, 249));
    border: 1px solid var(--nx-border, rgb(203, 213, 225));
    border-bottom-width: 2px;
    border-radius: var(--nx-radius-sm, 0.375rem);
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.85em;
    color: var(--nx-text-heading, rgb(15, 23, 42));
}

.nx-md mark,
.nx-chat-content mark {
    background: rgba(250, 204, 21, 0.3);
    color: inherit;
    padding: 0.05rem 0.2rem;
    border-radius: 2px;
}

.nx-md details,
.nx-chat-content details {
    margin: var(--nx-space-3, 0.75rem) 0;
    padding: var(--nx-space-2, 0.5rem) var(--nx-space-3, 0.75rem);
    border: 1px solid var(--nx-border, rgb(226, 232, 240));
    border-radius: var(--nx-radius-sm, 0.375rem);
    background: var(--nx-bg-subtle, rgb(241, 245, 249));
}

.nx-md summary,
.nx-chat-content summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--nx-text-heading, rgb(15, 23, 42));
    user-select: none;
}

.nx-md input[type="checkbox"],
.nx-chat-content input[type="checkbox"] {
    margin-right: 0.375rem;
    vertical-align: middle;
}

.nx-md-copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.625rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgb(226, 232, 240);
    border-radius: var(--nx-radius-sm, 0.375rem);
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    font-family: inherit;
}

.nx-md pre:hover .nx-md-copy,
.nx-chat-content pre:hover .nx-md-copy {
    opacity: 1;
}

.nx-md-copy:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nx-md-lang {
    position: absolute;
    top: 0.5rem;
    left: 0.75rem;
    font-size: 0.7rem;
    color: rgba(148, 163, 184, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: 'SF Mono', Monaco, monospace;
    pointer-events: none;
}

@media (max-width: 768px) {
    .nx-md, .nx-chat-content { font-size: 0.9rem; }
    .nx-md pre, .nx-chat-content pre { padding: var(--nx-space-3, 0.75rem); font-size: 0.8rem; }
    .nx-md pre code, .nx-chat-content pre code { font-size: 0.8rem; }
    .nx-md table, .nx-chat-content table { font-size: 0.85rem; }
    .nx-md h1, .nx-chat-content h1 { font-size: 1.3rem; }
    .nx-md h2, .nx-chat-content h2 { font-size: 1.15rem; }
    .nx-md h3, .nx-chat-content h3 { font-size: 1.05rem; }
    .nx-md-copy { opacity: 1; }
}

[data-theme="dark"] .nx-md,
[data-theme="dark"] .nx-chat-content {
    color: var(--nx-text-body-dark, rgb(226, 232, 240));
}

[data-theme="dark"] .nx-md h1, [data-theme="dark"] .nx-md h2, [data-theme="dark"] .nx-md h3,
[data-theme="dark"] .nx-md h4, [data-theme="dark"] .nx-md h5, [data-theme="dark"] .nx-md h6,
[data-theme="dark"] .nx-chat-content h1, [data-theme="dark"] .nx-chat-content h2,
[data-theme="dark"] .nx-chat-content h3, [data-theme="dark"] .nx-chat-content h4,
[data-theme="dark"] .nx-chat-content h5, [data-theme="dark"] .nx-chat-content h6 {
    color: var(--nx-text-heading-dark, rgb(248, 250, 252));
}

[data-theme="dark"] .nx-md code,
[data-theme="dark"] .nx-chat-content code {
    background: rgba(148, 163, 184, 0.18);
    color: rgb(252, 165, 165);
}

[data-theme="dark"] .nx-md blockquote,
[data-theme="dark"] .nx-chat-content blockquote {
    background: rgba(148, 163, 184, 0.1);
    color: var(--nx-text-muted-dark, rgb(148, 163, 184));
    border-left-color: rgb(100, 116, 139);
}

[data-theme="dark"] .nx-md th,
[data-theme="dark"] .nx-chat-content th {
    background: rgba(148, 163, 184, 0.15);
    color: var(--nx-text-heading-dark, rgb(248, 250, 252));
}

[data-theme="dark"] .nx-md td,
[data-theme="dark"] .nx-chat-content td {
    color: var(--nx-text-body-dark, rgb(226, 232, 240));
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .nx-md,
    :root:not([data-theme="light"]) .nx-chat-content {
        color: var(--nx-text-body-dark, rgb(226, 232, 240));
    }
    :root:not([data-theme="light"]) .nx-md h1,
    :root:not([data-theme="light"]) .nx-md h2,
    :root:not([data-theme="light"]) .nx-md h3,
    :root:not([data-theme="light"]) .nx-md h4,
    :root:not([data-theme="light"]) .nx-md h5,
    :root:not([data-theme="light"]) .nx-md h6,
    :root:not([data-theme="light"]) .nx-chat-content h1,
    :root:not([data-theme="light"]) .nx-chat-content h2,
    :root:not([data-theme="light"]) .nx-chat-content h3,
    :root:not([data-theme="light"]) .nx-chat-content h4,
    :root:not([data-theme="light"]) .nx-chat-content h5,
    :root:not([data-theme="light"]) .nx-chat-content h6 {
        color: var(--nx-text-heading-dark, rgb(248, 250, 252));
    }
    :root:not([data-theme="light"]) .nx-md code,
    :root:not([data-theme="light"]) .nx-chat-content code {
        background: rgba(148, 163, 184, 0.18);
        color: rgb(252, 165, 165);
    }
}
