/* Stratum AI — Precision Design System (Chainlit overrides) */

/* ===== FIX 1: User message bubble — ensure readable text on teal background ===== */
/* Chainlit user messages use bg-accent (teal) bubble. Force white text for contrast. */
[data-step-type="user_message"] .bg-accent .prose,
[data-step-type="user_message"] .bg-accent .prose *,
[data-step-type="user_message"] .bg-accent .message-content,
[data-step-type="user_message"] .bg-accent .message-content * {
    color: #fff !important;
}
[data-step-type="user_message"] .bg-accent a {
    text-decoration: underline !important;
}

/* ===== FIX 2: Dark-mode variable fallbacks ===== */
/* Ensure key CSS vars resolve correctly in dark mode */
html.dark {
    --paper: #1a1a2e;
    --fog: #222236;
    --carbon: #e2e2e8;
    --midnight: #f0f0f5;
    --silver: #3a3a50;
}

/* ===== FIX 3: Header bar — subtle bottom border ===== */
.flex.h-\[60px\].items-center {
    border-bottom: 1px solid hsl(var(--border)) !important;
}

/* ===== Login page styling — adapts to light/dark theme ===== */
.cl-login-page {
    background-color: hsl(var(--background)) !important;
}

/* Login page logo: Stratum icon (stratified A) */
img.logo[alt="logo"] {
    width: 64px !important;
    height: 64px !important;
    object-fit: contain;
    border-radius: 12px;
}

/* Login page — branded image panel (right side on desktop, hidden on mobile) */
@media (min-width: 1024px) {
    .grid.min-h-svh.lg\:grid-cols-2 > .relative.bg-muted.overflow-hidden {
        background: linear-gradient(
            160deg,
            hsl(181 35% 42%) 0%,
            hsl(181 38% 50%) 40%,
            hsl(181 40% 58%) 100%
        ) !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    /* Keep the image centered and reasonably sized instead of stretched */
    .grid.min-h-svh.lg\:grid-cols-2 > .relative.bg-muted.overflow-hidden > img {
        position: relative !important;
        width: 200px !important;
        height: 200px !important;
        object-fit: contain !important;
        border-radius: 24px;
        filter: drop-shadow(0 8px 32px rgba(0, 0, 0, 0.15));
    }

    /* Dark mode: deeper teal gradient */
    html.dark .grid.min-h-svh.lg\:grid-cols-2 > .relative.bg-muted.overflow-hidden {
        background: linear-gradient(
            160deg,
            hsl(220 47% 7%) 0%,
            hsl(219 41% 11%) 40%,
            hsl(181 38% 25%) 100%
        ) !important;
    }
}

/* ===== Scrollbar styling — theme-aware ===== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: hsl(var(--background));
}
::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--primary));
}

/* ===== FIX 5: Sidebar footer — nav links at bottom of left pane ===== */
.stratum-sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 8px;
    border-top: 1px solid hsl(var(--sidebar-border));
}
.stratum-sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--sidebar-foreground));
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
    min-height: 40px;
}
.stratum-sidebar-link:hover {
    background-color: hsl(var(--sidebar-accent));
    color: hsl(var(--sidebar-accent-foreground));
}
.stratum-sidebar-link:focus-visible {
    outline: 2px solid hsl(var(--primary));
    outline-offset: -2px;
    border-radius: 8px;
}
/* Active state — highlight the current page link */
.stratum-sidebar-link[aria-current="page"],
.stratum-sidebar-link.active {
    background-color: hsl(var(--primary) / 0.12);
    color: hsl(var(--primary));
}
.stratum-sidebar-link svg {
    flex-shrink: 0;
    color: hsl(var(--muted-foreground));
}
.stratum-sidebar-link:hover svg {
    color: hsl(var(--primary));
}
.stratum-sidebar-link[aria-current="page"] svg,
.stratum-sidebar-link.active svg {
    color: hsl(var(--primary));
}

/* ===== FIX 4: Composer input box — refined styling ===== */
.bg-accent.rounded-3xl.min-h-24 {
    background-color: hsl(var(--primary) / 0.06) !important;
    border: 1.5px solid hsl(var(--primary) / 0.25) !important;
    border-radius: 12px !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.bg-accent.rounded-3xl.min-h-24:focus-within {
    border-color: hsl(var(--primary) / 0.6) !important;
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1) !important;
}
html.dark .bg-accent.rounded-3xl.min-h-24 {
    background-color: hsl(var(--primary) / 0.08) !important;
    border: 1.5px solid hsl(var(--primary) / 0.2) !important;
}
html.dark .bg-accent.rounded-3xl.min-h-24:focus-within {
    border-color: hsl(var(--primary) / 0.5) !important;
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.08) !important;
}

/* ===== FIX 6: Chat content max-width for readability ===== */
/* Constrain the message thread to a comfortable reading width */
[class*="messages-container"] > div,
.cl-message-list > div {
    max-width: 768px;
    margin-left: auto;
    margin-right: auto;
}

/* ===== Fix Sonner toast container intercepting clicks on action buttons ===== */
[data-sonner-toaster] {
    pointer-events: none !important;
}
[data-sonner-toast] {
    pointer-events: auto !important;
}

/* ===== Fix: Chainlit 2.10 action button click-target offset (GitHub #2204) ===== */
div.flex-shrink-0:last-child {
    height: 0px !important;
}

/* ===== Workflow progress card ===== */
[data-workflow-progress] {
    background: hsl(var(--card)) !important;
    border: 1px solid hsl(var(--border)) !important;
    border-radius: 8px !important;
    padding: 16px 20px !important;
    margin: 4px 0 !important;
}
[data-workflow-progress] p {
    line-height: 1.8 !important;
}

/* ===== Workflow completion card ===== */
[data-workflow-complete] {
    background: linear-gradient(135deg, hsl(var(--primary) / 0.15) 0%, hsl(var(--card)) 40%) !important;
    border: 1px solid hsl(var(--primary)) !important;
    border-radius: 8px !important;
    padding: 16px 20px !important;
    margin: 4px 0 !important;
}

/* ===== Input blocking during workflow execution ===== */
body.workflow-running [class*="composer"] {
    opacity: 0.35 !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease;
}

/* ===== Notification bell (Chainlit header) ===== */
.stratum-bell-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid hsl(var(--border));
    color: hsl(var(--muted-foreground));
    background: none;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
    margin-right: 8px;
}
.stratum-bell-btn:hover {
    color: hsl(var(--primary));
    background-color: hsl(var(--primary) / 0.08);
    border-color: hsl(var(--primary));
}
.stratum-bell-btn:focus-visible {
    outline: 2px solid hsl(var(--primary));
    outline-offset: 2px;
}
.stratum-bell-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ef4444;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    pointer-events: none;
    box-sizing: border-box;
}

/* ===== Notification dropdown panel ===== */
.stratum-notif-panel {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 6px;
    width: 320px;
    max-height: 384px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--border)) transparent;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 9999;
}
.stratum-notif-empty {
    padding: 32px 16px;
    text-align: center;
    color: hsl(var(--muted-foreground));
    font-size: 13px;
}
.stratum-notif-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
}
.stratum-notif-row:hover {
    background: hsl(var(--accent) / 0.05);
}
.stratum-notif-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 5px;
}
.stratum-notif-title {
    font-size: 13px;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.stratum-notif-time {
    font-size: 10px;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
}
.stratum-notif-cat {
    font-size: 10px;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
}
.stratum-notif-link {
    font-size: 10px;
    color: hsl(var(--primary));
    text-decoration: underline;
    text-underline-offset: 2px;
}
.stratum-notif-link:hover {
    color: hsl(var(--primary) / 0.7);
}
.stratum-notif-dismiss {
    font-size: 10px;
    color: hsl(var(--muted-foreground));
    background: none;
    border: none;
    cursor: pointer;
    margin-left: auto;
    padding: 2px 6px;
    border-radius: 3px;
    min-width: 40px;
    text-align: center;
}
.stratum-notif-dismiss:hover {
    color: #ef4444;
    background: hsl(0 84% 60% / 0.08);
}

/* ===== Bug Report FAB ===== */
.stratum-bug-fab {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 9998;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid hsl(var(--border, 220 13% 85%));
    background: hsl(var(--card, 0 0% 100%));
    color: hsl(var(--muted-foreground, 215 14% 46%));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.stratum-bug-fab:hover {
    background: hsl(var(--primary, 181 35% 48%));
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

/* ===== Bug Report Modal Overlay ===== */
.stratum-bug-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.stratum-bug-modal {
    background: hsl(var(--card, 0 0% 100%));
    border: 1px solid hsl(var(--border, 220 13% 85%));
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    max-height: 90vh;
    overflow-y: auto;
}

.stratum-bug-modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 16px;
    color: hsl(var(--foreground, 222 47% 11%));
}

.stratum-bug-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: hsl(var(--muted-foreground, 215 14% 46%));
    margin-bottom: 4px;
}

.stratum-bug-select,
.stratum-bug-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid hsl(var(--border, 220 13% 85%));
    border-radius: 8px;
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    font-size: 14px;
    background: hsl(var(--background, 0 0% 98%));
    color: hsl(var(--foreground, 222 47% 11%));
    margin-bottom: 12px;
    box-sizing: border-box;
}
.stratum-bug-select:focus,
.stratum-bug-textarea:focus {
    outline: none;
    border-color: hsl(var(--primary, 181 35% 48%));
    box-shadow: 0 0 0 2px hsl(var(--primary, 181 35% 48%) / 0.2);
}
.stratum-bug-textarea {
    resize: vertical;
    min-height: 80px;
}

.stratum-bug-screenshot-wrap {
    margin-bottom: 12px;
}
.stratum-bug-screenshot-img {
    width: 100%;
    max-height: 160px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid hsl(var(--border, 220 13% 85%));
    margin-bottom: 4px;
}
.stratum-bug-remove-ss {
    background: none;
    border: none;
    color: hsl(var(--destructive, 0 84% 60%));
    font-size: 12px;
    cursor: pointer;
    padding: 0;
}
.stratum-bug-remove-ss:hover {
    text-decoration: underline;
}

.stratum-bug-error {
    color: hsl(var(--destructive, 0 84% 60%));
    font-size: 13px;
    margin-bottom: 8px;
}

.stratum-bug-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.stratum-bug-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, opacity 0.15s;
}
.stratum-bug-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.stratum-bug-btn-cancel {
    background: transparent;
    border-color: hsl(var(--border, 220 13% 85%));
    color: hsl(var(--muted-foreground, 215 14% 46%));
}
.stratum-bug-btn-cancel:hover {
    background: hsl(var(--accent, 210 40% 96%));
}
.stratum-bug-btn-submit {
    background: hsl(var(--primary, 181 35% 48%));
    color: #fff;
}
.stratum-bug-btn-submit:hover {
    opacity: 0.9;
}

/* ===== Bug Report Toast ===== */
.stratum-bug-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: hsl(var(--foreground, 222 47% 11%));
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.stratum-bug-toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== Bug Report Mobile (bottom sheet) ===== */
@media (max-width: 639px) {
    .stratum-bug-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .stratum-bug-modal {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
        max-height: 85vh;
    }
    .stratum-bug-fab {
        bottom: 80px;
        right: 16px;
    }
}

/* ===== Stratum drawer — corpus section preview over any surface ===== */

#stratum-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    opacity: 0;
    transition: opacity 180ms ease;
    pointer-events: none;
    z-index: 9998;
}
#stratum-drawer-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

#stratum-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(480px, 100vw);
    background: hsl(var(--background, 220 20% 98%));
    color: hsl(var(--foreground, 220 30% 15%));
    border-left: 1px solid hsl(var(--border, 220 15% 88%));
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
    display: flex;
    flex-direction: column;
    z-index: 9999;
}
html.dark #stratum-drawer {
    background: hsl(220 25% 12%);
    border-left-color: hsl(220 15% 22%);
}
#stratum-drawer.is-open {
    transform: translateX(0);
}

.stratum-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid hsl(var(--border, 220 15% 88%));
}
html.dark .stratum-drawer-header {
    border-bottom-color: hsl(220 15% 22%);
}

.stratum-drawer-title-link {
    font-size: 13px;
    color: hsl(var(--muted-foreground, 220 15% 45%));
    text-decoration: none;
}
.stratum-drawer-title-link:hover {
    color: hsl(var(--primary, 181 40% 42%));
}

.stratum-drawer-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    color: hsl(var(--muted-foreground, 220 15% 45%));
    padding: 4px 8px;
    border-radius: 6px;
}
.stratum-drawer-close:hover {
    background: hsl(var(--muted, 220 15% 93%));
    color: hsl(var(--foreground, 220 30% 15%));
}
html.dark .stratum-drawer-close:hover {
    background: hsl(220 15% 22%);
}

#stratum-drawer > .stratum-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.stratum-drawer-loading,
.stratum-drawer-error {
    color: hsl(var(--muted-foreground, 220 15% 45%));
    font-size: 14px;
    padding: 24px 8px;
    text-align: center;
}
.stratum-drawer-error a {
    color: hsl(var(--primary, 181 40% 42%));
    text-decoration: underline;
    margin-left: 4px;
}

/* Fragment internals */
.stratum-drawer-body h2 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
}
.stratum-drawer-body p {
    margin: 0 0 12px;
}
.stratum-drawer-body p:last-child {
    margin-bottom: 0;
}

/* Full-screen drawer on narrow viewports */
@media (max-width: 640px) {
    #stratum-drawer {
        width: 100vw;
        border-left: none;
    }
}
