/* ============================================
   Chat Styles — Nusoos 2026
   Uses CSS custom properties from design-system.css
   ============================================ */

body {
    font-family: 'IBM Plex Sans Arabic', sans-serif;
}

#message-input {
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    background: var(--surface);
    color: var(--text-primary);
    border-color: var(--border);
}

/* --- Message Bubbles --- */
.msg-user {
    display: flex;
    justify-content: flex-start;
}

.msg-user .msg-bubble {
    background: var(--brand-50);
    border: 1px solid var(--brand-100);
    border-radius: 1rem 1rem 0.25rem 1rem;
    max-width: 80%;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
}

[data-theme="dark"] .msg-user .msg-bubble {
    background: rgba(34,197,94,0.1);
    border-color: rgba(34,197,94,0.2);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .msg-user .msg-bubble {
        background: rgba(34,197,94,0.1);
        border-color: rgba(34,197,94,0.2);
    }
}

.msg-assistant {
    display: flex;
    justify-content: flex-end;
}

.msg-assistant .msg-bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem 1rem 1rem 0.25rem;
    max-width: 85%;
    padding: 1rem 1.25rem;
    color: var(--text-primary);
}

/* --- Message Content --- */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    font-weight: 700;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.msg-bubble h2 { font-size: 1.1rem; }
.msg-bubble h3 { font-size: 1rem; }

.msg-bubble p {
    margin-bottom: 0.5rem;
    line-height: 1.8;
    overflow-wrap: break-word;
    word-break: break-word;
}

.msg-bubble ul, .msg-bubble ol {
    padding-right: 1.25rem;
    margin-bottom: 0.5rem;
}

.msg-bubble li {
    margin-bottom: 0.25rem;
    line-height: 1.7;
}

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

.msg-bubble a {
    color: var(--brand-600);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

.msg-bubble a:hover {
    color: var(--brand-700);
    text-decoration-style: solid;
}

.msg-bubble pre, .msg-bubble code {
    direction: ltr;
    text-align: left;
    unicode-bidi: embed;
}

/* --- Citations --- */
.citation-tag {
    display: inline-block;
    background: var(--brand-50);
    color: var(--brand-700);
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    border: 1px solid var(--brand-200);
    cursor: pointer;
    transition: all 150ms ease;
}

.citation-tag:hover {
    background: var(--brand-100);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .citation-tag {
    background: rgba(34,197,94,0.1);
    border-color: rgba(34,197,94,0.2);
    color: var(--brand-400);
}

/* --- References --- */
.references-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.references-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

.reference-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.375rem 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.reference-item::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--brand-500);
    border-radius: 50%;
    margin-top: 0.5rem;
    flex-shrink: 0;
}

.reference-link {
    color: var(--brand-700);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px dashed var(--brand-300);
    transition: all 150ms ease;
}

.reference-link:hover {
    color: var(--brand-800);
    border-bottom-color: var(--brand-800);
}

[data-theme="dark"] .reference-link {
    color: var(--brand-400);
    border-bottom-color: var(--brand-600);
}

.reference-law {
    font-weight: 500;
    color: var(--text-primary);
}

/* --- Status Badges --- */
.status-badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 9999px;
    font-weight: 500;
}

.status-amended {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.status-repealed {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

[data-theme="dark"] .status-amended {
    background: rgba(245,158,11,0.15);
    color: #fbbf24;
    border-color: rgba(245,158,11,0.3);
}

[data-theme="dark"] .status-repealed {
    background: rgba(220,38,38,0.15);
    color: #f87171;
    border-color: rgba(220,38,38,0.3);
}

/* --- Disclaimer --- */
.disclaimer-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.75rem;
}

/* --- Cost Badge --- */
.cost-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 0.5rem;
}

/* --- Agent Plan Progress Stepper --- */
.agent-plan {
    position: relative;
    padding: 0.75rem 1rem;
}

.agent-plan-steps {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Vertical connecting line */
.agent-plan-steps::before {
    content: '';
    position: absolute;
    right: 11px;
    top: 14px;
    bottom: 14px;
    width: 2px;
    background: var(--border);
    border-radius: 1px;
    z-index: 0;
}

/* Filled portion of connecting line */
.agent-plan-line-fill {
    position: absolute;
    right: 11px;
    top: 14px;
    width: 2px;
    background: var(--brand-500);
    border-radius: 1px;
    z-index: 1;
    transition: height 0.5s cubic-bezier(0.2, 0.65, 0.3, 0.9);
}

/* Step row */
.agent-step {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.375rem 0;
    position: relative;
    z-index: 2;
    transition: opacity 0.3s ease;
}

.agent-step.pending {
    opacity: 0.45;
}

.agent-step.done,
.agent-step.active {
    opacity: 1;
}

/* Step icon container */
.agent-step-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    position: relative;
    transition: all 0.3s cubic-bezier(0.2, 0.65, 0.3, 0.9);
}

.agent-step.done .agent-step-icon {
    background: var(--brand-100);
    color: var(--brand-600);
}

.agent-step.active .agent-step-icon {
    background: var(--brand-100);
    color: var(--brand-600);
    animation: agent-pulse 2s ease-in-out infinite;
}

.agent-step.pending .agent-step-icon {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

@keyframes agent-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
}

/* Spinner for active step */
.agent-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--brand-300);
    border-top-color: var(--brand-600);
    border-radius: 50%;
    animation: agent-spin 0.8s linear infinite;
}

@keyframes agent-spin {
    to { transform: rotate(360deg); }
}

/* Step content */
.agent-step-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.agent-step-title {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.5;
    transition: color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.agent-step.done .agent-step-title {
    color: var(--text-secondary);
}

.agent-step.active .agent-step-title {
    color: var(--text-primary);
    font-weight: 600;
}

.agent-step.pending .agent-step-title {
    color: var(--text-tertiary);
}

/* Status badge */
.agent-step-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.0625rem 0.375rem;
    border-radius: var(--radius-full);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.agent-step-badge.done {
    background: var(--brand-100);
    color: var(--brand-700);
}

.agent-step-badge.active {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.agent-step-badge.pending {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

/* Sub-details */
.agent-step-details {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    line-height: 1.4;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s cubic-bezier(0.2, 0.65, 0.3, 0.9), opacity 0.25s ease;
}

.agent-step-details.visible {
    max-height: 40px;
    opacity: 1;
}

/* Overall progress bar */
.agent-plan-progress {
    width: 100%;
    height: 3px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    margin-top: 0.625rem;
    overflow: hidden;
}

.agent-plan-progress-fill {
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--brand-500), var(--brand-400));
    transition: width 0.7s cubic-bezier(0.2, 0.65, 0.3, 0.9);
    position: relative;
}

.agent-plan-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: agent-shimmer 1.5s infinite;
}

@keyframes agent-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* SVG icons inside steps */
.agent-step-icon svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

/* Prevent SVGs from overflowing message bubbles */
.msg-bubble svg {
    max-width: 24px;
    max-height: 24px;
    display: inline-block;
    vertical-align: middle;
}

.prose-content svg {
    max-width: 24px;
    max-height: 24px;
}

/* Prevent checkboxes from rendering oversized */
.msg-bubble input[type="checkbox"] {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

/* Constrain code blocks and preformatted text inside messages */
.msg-bubble pre {
    max-height: 500px;
    overflow: auto;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    line-height: 1.6;
    margin: 0.5rem 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-bubble code {
    font-size: 0.85em;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    background: var(--bg-secondary);
}

.msg-bubble pre code {
    padding: 0;
    background: none;
    font-size: inherit;
}

/* Block any oversized elements inside prose */
.prose-content img,
.prose-content video,
.prose-content iframe,
.prose-content canvas,
.prose-content object,
.prose-content embed {
    max-width: 100%;
    height: auto;
}

/* Dark mode adjustments */
[data-theme="dark"] .agent-step.done .agent-step-icon {
    background: rgba(22, 163, 74, 0.15);
}
[data-theme="dark"] .agent-step.active .agent-step-icon {
    background: rgba(22, 163, 74, 0.15);
}
[data-theme="dark"] .agent-step-badge.done {
    background: rgba(22, 163, 74, 0.15);
    color: var(--brand-400);
}
[data-theme="dark"] .agent-step-badge.active {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .agent-step.done .agent-step-icon {
        background: rgba(22, 163, 74, 0.15);
    }
    :root:not([data-theme="light"]) .agent-step.active .agent-step-icon {
        background: rgba(22, 163, 74, 0.15);
    }
    :root:not([data-theme="light"]) .agent-step-badge.done {
        background: rgba(22, 163, 74, 0.15);
        color: var(--brand-400);
    }
    :root:not([data-theme="light"]) .agent-step-badge.active {
        background: rgba(59, 130, 246, 0.15);
        color: #60a5fa;
    }
}

/* --- Conversation List --- */
.conv-item {
    transition: all 150ms ease;
}

.conv-item.active {
    background: var(--brand-50);
    color: var(--brand-700);
    font-weight: 600;
}

[data-theme="dark"] .conv-item.active {
    background: rgba(34,197,94,0.1);
    color: var(--brand-400);
}

/* --- Typing Indicator --- */
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.typing-indicator span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-tertiary);
    border-radius: 50%;
    margin: 0 2px;
    animation: pulse-dot 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* --- Paywall Card --- */
.paywall-card {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    border: 2px solid var(--warning);
    border-radius: 1.25rem;
    padding: 1.5rem;
    max-width: 85%;
    text-align: center;
}

.paywall-icon {
    width: 3.5rem;
    height: 3.5rem;
    background: var(--bg-tertiary);
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
}

.paywall-discount {
    display: inline-block;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0.5rem 1.25rem;
    border-radius: 9999px;
    margin-bottom: 1rem;
}

.paywall-btn {
    display: inline-block;
    background: var(--brand-600);
    color: white;
    font-weight: 600;
    padding: 0.75rem 2rem;
    border-radius: 0.75rem;
    text-decoration: none;
    transition: all 150ms ease;
}

.paywall-btn:hover {
    background: var(--brand-700);
    box-shadow: 0 0 20px rgba(34,197,94,0.15);
}

/* --- Clarification Card --- */
.clarification-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
    max-width: 85%;
}

.clarification-question {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.875rem;
    line-height: 1.6;
}

.clarification-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.875rem;
}

.clarification-option {
    display: flex;
    flex-direction: column;
    text-align: right;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    background: var(--surface);
    cursor: pointer;
    transition: all 150ms ease;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    width: 100%;
    color: var(--text-primary);
}

.clarification-option:hover:not(:disabled) {
    border-color: var(--brand-600);
    background: var(--brand-50);
}

[data-theme="dark"] .clarification-option:hover:not(:disabled) {
    background: rgba(34,197,94,0.1);
}

.clarification-option:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.option-desc {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.125rem;
    font-weight: 400;
}

.clarification-custom {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.custom-clarification-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    outline: none;
    direction: rtl;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.custom-clarification-input:focus {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.15);
}

.custom-clarification-input:disabled {
    opacity: 0.5;
    background: var(--bg-tertiary);
}

.custom-send-btn {
    padding: 0.5rem 1rem;
    background: var(--brand-600);
    color: white;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    cursor: pointer;
    border: none;
    transition: all 150ms ease;
    white-space: nowrap;
}

.custom-send-btn:hover:not(:disabled) {
    background: var(--brand-700);
}

.custom-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
