*, *::before, *::after {
    box-sizing: border-box;
}

/* ============================================================================
   Theme-aware semantic color tokens (light defaults + dark overrides).
   Inline styles across the app use these via var(--cg-*) so colors flip with
   the theme. Dark mode is signalled by `html.cg-dark` (set in App.razor before
   paint + by MainLayout's toggle). Inline `var()` resolves through this cascade,
   so a hardcoded hex swapped for the matching token adapts automatically.

   Roles:
     --cg-text-*        : text drawn directly on the page/surface (bg inherits)
     --cg-box-*-bg/-text/-border : a soft "status box" (set all three together)
     --cg-border / --cg-row-alt-bg / --cg-thead-* : tables & dividers
   ============================================================================ */
:root {
    /* Standalone text on page */
    --cg-text-success: #15803d;
    --cg-text-info:    #1d4ed8;
    --cg-text-danger:  #dc2626;
    --cg-text-warning: #b45309;
    --cg-text-purple:  #7c3aed;
    --cg-text-neutral: #374151;
    --cg-text-muted:   #6b7280;

    /* Soft status boxes (background + on-box text + accent border) */
    --cg-box-success-bg:     #f0fdf4;
    --cg-box-success-text:   #14532d;
    --cg-box-success-border: #86efac;

    --cg-box-warning-bg:     #fffbeb;
    --cg-box-warning-text:   #7c2d12;
    --cg-box-warning-border: #fcd34d;

    --cg-box-info-bg:        #eff6ff;
    --cg-box-info-text:      #1e3a8a;
    --cg-box-info-border:    #93c5fd;

    --cg-box-purple-bg:      #faf5ff;
    --cg-box-purple-text:    #4c1d95;
    --cg-box-purple-border:  #c4b5fd;

    --cg-box-danger-bg:      #fef2f2;
    --cg-box-danger-text:    #7f1d1d;
    --cg-box-danger-border:  #fca5a5;

    --cg-box-neutral-bg:     #f8fafc;
    --cg-box-neutral-text:   #374151;

    /* Tables, dividers, dark code/log panels */
    --cg-border:    #e5e7eb;
    --cg-row-alt-bg: #f8fafc;
    --cg-thead-bg:  #1e3a5f;
    --cg-thead-text: #ffffff;
    --cg-panel-dark-bg:     #111111;
    --cg-panel-dark-border: #333333;
}

html.cg-dark {
    --cg-text-success: #4ade80;
    --cg-text-info:    #60a5fa;
    --cg-text-danger:  #f87171;
    --cg-text-warning: #fbbf24;
    --cg-text-purple:  #c4b5fd;
    --cg-text-neutral: rgba(255,255,255,0.78);
    --cg-text-muted:   rgba(255,255,255,0.55);

    --cg-box-success-bg:     rgba(34,197,94,0.13);
    --cg-box-success-text:   #86efac;
    --cg-box-success-border: #16a34a;

    --cg-box-warning-bg:     rgba(245,158,11,0.13);
    --cg-box-warning-text:   #fcd34d;
    --cg-box-warning-border: #b45309;

    --cg-box-info-bg:        rgba(59,130,246,0.15);
    --cg-box-info-text:      #bfdbfe;
    --cg-box-info-border:    #3b82f6;

    --cg-box-purple-bg:      rgba(139,92,246,0.16);
    --cg-box-purple-text:    #ddd6fe;
    --cg-box-purple-border:  #8b5cf6;

    --cg-box-danger-bg:      rgba(239,68,68,0.15);
    --cg-box-danger-text:    #fca5a5;
    --cg-box-danger-border:  #ef4444;

    --cg-box-neutral-bg:     rgba(255,255,255,0.06);
    --cg-box-neutral-text:   rgba(255,255,255,0.80);

    --cg-border:    rgba(255,255,255,0.12);
    --cg-row-alt-bg: rgba(255,255,255,0.04);
    --cg-thead-bg:  #243b55;
    --cg-thead-text: rgba(255,255,255,0.92);
    /* dark code/log panels already dark — keep them dark in both themes */
}

html, body {
    font-family: 'Space Grotesk', 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 0;
    height: 100%;
}

.md-content h1 { font-size: 1.1rem; font-weight: 700; margin: 0.6rem 0 0.3rem; }
.md-content h2 { font-size: 1rem; font-weight: 700; margin: 0.5rem 0 0.25rem; }
.md-content h3 { font-size: 0.9rem; font-weight: 700; margin: 0.4rem 0 0.2rem; }
.md-content p  { margin: 0.3rem 0; }
.md-content ul, .md-content ol { margin: 0.3rem 0 0.3rem 1.2rem; padding: 0; }
.md-content li { margin: 0.15rem 0; }
.md-content hr { border: none; border-top: 1px solid var(--cg-border); margin: 0.5rem 0; }
.md-content table { border-collapse: collapse; width: 100%; font-size: 0.78rem; margin: 0.4rem 0; }
.md-content th { background: var(--cg-thead-bg); color: var(--cg-thead-text); padding: 4px 8px; text-align: left; }
.md-content td { border: 1px solid var(--cg-border); padding: 3px 8px; color: var(--mud-palette-text-primary); }
.md-content tr:nth-child(even) td { background: var(--cg-row-alt-bg); }
/* Inline/block code — theme-agnostic so it stays readable on both light pages and dark dialogs
   (color: inherit + translucent grey bg → contrast in either theme; fixes white-on-white). */
.md-content code { background: rgba(128,128,128,0.22); color: var(--mud-palette-text-primary, inherit) !important; padding: 0.05em 0.35em; border-radius: 4px; font-size: 0.85em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md-content pre { background: rgba(128,128,128,0.18); color: var(--mud-palette-text-primary, inherit) !important; padding: 0.6em 0.8em; border-radius: 6px; overflow-x: auto; }
.md-content pre code { background: none; padding: 0; }

.listing-kb-focus > .mud-expand-panel {
    outline: 2px solid #3b82f6;
    border-radius: 4px;
}

#blazor-error-ui {
    background: var(--cg-box-warning-bg);
    color: var(--cg-box-warning-text);
    border-top: 1px solid var(--cg-box-warning-border);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Blazor reconnection overlay — calm, theme-aware bottom banner instead of the default full-screen
   dim. Only surfaces once a drop persists; brief blips recover before it appears (see App.razor). The
   default modal is hidden until the framework adds a state class. */
#components-reconnect-modal {
    display: none;
}
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    max-width: 92vw;
    z-index: 2000;
    padding: 12px 18px;
    border-radius: 10px;
    background: var(--cg-box-info-bg);
    color: var(--cg-box-info-text);
    border: 1px solid var(--cg-box-info-border);
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.20);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
}
/* A failed/rejected (terminal) state reads as a warning — the page is about to reload itself. */
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    background: var(--cg-box-warning-bg);
    color: var(--cg-box-warning-text);
    border-color: var(--cg-box-warning-border);
}

.mic-listening { animation: cg-mic-pulse 1s ease-in-out infinite; }
@keyframes cg-mic-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .mic-listening { animation: none; } }
/* NoteEditor scoped styles */

.note-editor-textarea {
    width: 100%;
    min-height: 420px;
    font-family: monospace;
    font-size: 0.9rem;
    padding: 8px;
    box-sizing: border-box;
    resize: vertical;
    /* Theme-aware: use MudBlazor surface/text tokens so it reads on both light and dark */
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 4px;
    outline: none;
}

.note-editor-textarea:focus {
    border-color: var(--mud-palette-primary);
}

/* Rendered Markdown preview — must read on both themes */
.note-rendered {
    color: var(--mud-palette-text-primary);
    line-height: 1.6;
    overflow-wrap: break-word;
}

.note-rendered h1,
.note-rendered h2,
.note-rendered h3,
.note-rendered h4 {
    margin-top: 1rem;
    margin-bottom: 0.4rem;
    color: var(--mud-palette-text-primary);
}

.note-rendered p {
    margin-bottom: 0.6rem;
}

.note-rendered code {
    font-family: monospace;
    font-size: 0.88em;
    background-color: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    padding: 1px 4px;
    border-radius: 3px;
}

.note-rendered pre {
    background-color: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 0.8rem;
}

.note-rendered pre code {
    background: none;
    padding: 0;
}

.note-rendered blockquote {
    border-left: 3px solid var(--mud-palette-primary);
    margin-left: 0;
    padding-left: 12px;
    color: var(--mud-palette-text-secondary);
}

.note-rendered a {
    color: var(--mud-palette-primary);
}

.note-rendered ul,
.note-rendered ol {
    padding-left: 1.5rem;
    margin-bottom: 0.6rem;
}
