/* UNCS AI Assistant — Chat UI Styles */

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

:root {
    --navy: #1a365d;
    --navy-light: #2a4a7f;
    --navy-dark: #0f2440;
    --navy-hover: #1e3f6e;
    --blue: #2563eb;
    --blue-light: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --code-bg: #1e293b;
    --red-500: #ef4444;
    --red-50: #fef2f2;
    --red-100: #fee2e2;
    --red-700: #b91c1c;
    --green-500: #22c55e;
    --amber-50: #fffbeb;
    --amber-200: #fde68a;
    --amber-700: #b45309;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --sidebar-width: 260px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
        Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--white);
    /* WHY: Extend the navy background behind the iOS status bar so the
       notch area matches the header instead of showing white. */
    background-color: var(--navy);
}

/* WHY: The #app container gets the white background. The body stays navy
   so the safe-area behind the status bar blends with the header. */
#app {
    background: var(--white);
}

/* ── Login Overlay ──────────────────────────────────────────────────── */

.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f1b2d;
    overflow: hidden;
}

.login-bg-pattern {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(37,99,235,0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(26,54,93,0.3) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 100%, rgba(37,99,235,0.08) 0%, transparent 40%);
    pointer-events: none;
}

.login-card {
    position: relative;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 48px 44px 36px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    animation: loginCardIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.1),
        0 20px 50px rgba(0,0,0,0.4),
        0 0 100px rgba(37,99,235,0.08);
}

@keyframes loginCardIn {
    from { opacity: 0; transform: translateY(24px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo-mark {
    margin: 0 auto 20px;
    width: 56px;
    height: 56px;
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

.login-logo-mark svg {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(26,54,93,0.3);
}

.login-brand {
    font-size: 32px;
    font-weight: 800;
    color: #1a365d;
    letter-spacing: 0.08em;
    margin-bottom: 2px;
    line-height: 1;
}

.login-title {
    font-size: 17px;
    font-weight: 500;
    color: #64748b;
    margin-bottom: 6px;
}

.login-subtitle {
    font-size: 13px;
    color: #94a3b8;
    margin-bottom: 32px;
}

.login-overlay .sso-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 14px 20px;
    background: #1a365d;
    border: none;
    border-radius: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 14px rgba(26,54,93,0.35);
}

.login-overlay .sso-btn:hover {
    background: #2a4a7f;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(26,54,93,0.45);
}

.login-overlay .sso-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(26,54,93,0.3);
}

.login-overlay .sso-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.login-overlay .sso-btn svg {
    flex-shrink: 0;
    background: white;
    border-radius: 3px;
    padding: 1px;
}

.login-error {
    margin-top: 16px;
    font-size: 13px;
    color: #ef4444;
    min-height: 20px;
}

.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 28px;
    font-size: 11px;
    color: #94a3b8;
}

.login-footer-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #cbd5e1;
}

/* Keep hidden state for backward compat */
.login-overlay.hidden { display: none; }
.pin-form-hidden { display: none; }


/* ── App Hidden State ───────────────────────────────────────────────── */

.app-hidden {
    display: none !important;
}

/* ── Layout ─────────────────────────────────────────────────────────── */

#app {
    display: flex;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--navy-dark);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease;
    z-index: 20;
    overflow: hidden;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 12px;
    flex-shrink: 0;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: var(--white);
    background: var(--navy-light);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.new-chat-btn:hover {
    background: var(--navy-hover);
    border-color: rgba(255, 255, 255, 0.25);
}

/* ── Admin controls ───────────────────────────────────────────────── */

.admin-controls {
    padding: 4px 12px 4px;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

.admin-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    font-size: 12px;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.admin-toggle-btn:hover {
    background: rgba(34, 197, 94, 0.25);
    border-color: rgba(34, 197, 94, 0.5);
}

.admin-user-filter {
    flex: 1;
    min-width: 0;
    padding: 5px 6px;
    font-size: 12px;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    outline: none;
}

.admin-user-filter option {
    background: #1e293b;
    color: #fff;
}

/* WHY: Shows the conversation owner in admin mode so admins can tell
   whose conversation they're looking at without opening it */
.conv-item-owner {
    font-size: 11px;
    color: rgba(34, 197, 94, 0.7);
    font-weight: 500;
}

/* ── Sidebar search ────────────────────────────────────────────────── */

.sidebar-search {
    padding: 0 12px 8px;
    flex-shrink: 0;
}

.conv-search-input {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

.conv-search-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
}

.conv-search-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

/* WHY: Small archive button on each conversation item — works on mobile
   where right-click context menus aren't available. Visible on hover
   (desktop) or always visible (mobile). */
.conv-item-archive {
    position: absolute;
    right: 6px;
    top: 6px;
    width: 24px;
    height: 24px;
    font-size: 14px;
    line-height: 24px;
    text-align: center;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.3;
    color: rgba(255, 255, 255, 0.7);
    transition: opacity 0.15s;
    padding: 0;
}

.conv-item:hover .conv-item-archive {
    opacity: 0.8;
}

.conv-item-archive:hover {
    opacity: 1 !important;
    background: rgba(255, 255, 255, 0.15);
}

/* WHY: On mobile, always show the archive button since there's no hover */
@media (max-width: 768px) {
    .conv-item-archive {
        opacity: 0.6;
    }
}

.archive-toggle {
    padding: 4px 12px;
}

.archive-toggle-btn {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.archive-toggle-btn:hover {
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.25);
}

.archive-toggle-btn.active {
    color: var(--amber-200);
    border-color: var(--amber-200);
    background: rgba(253, 230, 138, 0.08);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conversation-list::-webkit-scrollbar {
    width: 4px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.conv-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 2px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.12s;
    position: relative;
    border-left: 3px solid transparent;
}

.conv-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.conv-item.active {
    background: rgba(255, 255, 255, 0.12);
    border-left-color: var(--blue-light);
}

.conv-item-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.conv-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 3px;
}

.conv-item-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
}

.conv-item-count {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
}

.conv-empty {
    padding: 24px 16px;
    text-align: center;
    color: rgba(255, 255, 255, 0.35);
    font-size: 13px;
    line-height: 1.6;
}

/* ── Sidebar backdrop (mobile overlay) ─────────────────────────────── */

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
}

.sidebar-backdrop.visible {
    display: block;
}

/* ── Context menu ──────────────────────────────────────────────────── */

.context-menu {
    display: none;
    position: fixed;
    z-index: 100;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 4px;
    min-width: 140px;
}

.context-menu.visible {
    display: block;
}

.context-menu-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--gray-700);
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
}

.context-menu-item:hover {
    background: var(--gray-100);
}

.context-menu-danger {
    color: var(--red-500);
}

.context-menu-danger:hover {
    background: var(--red-50);
}

/* ── Main content ──────────────────────────────────────────────────── */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    transition: margin-left 0.25s ease;
}

/* ── Header ─────────────────────────────────────────────────────────── */

/* WHY: padding-top pushes the header below the iPhone status bar icons
   (T-Mobile, time, battery) when running as a standalone PWA. We use
   env(safe-area-inset-top) with a 20px minimum fallback to ensure the
   header is always below the status bar even on devices where the env
   value is too small or unsupported. */
.header {
    background: var(--navy);
    color: var(--white);
    padding: 14px 24px;
    padding-top: calc(14px + max(env(safe-area-inset-top, 20px), 20px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}

/* WHY: Editable title uses contenteditable — these styles make the
   edit state visually distinct so the user knows they're editing. */
.header-title.editable {
    cursor: text;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.4);
    padding-bottom: 1px;
}

.header-title.editing {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 2px 6px;
    outline: none;
    border-bottom: none;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.role-badge {
    font-size: 11px;
    font-weight: 600;
    color: var(--white);
    padding: 3px 10px;
    border-radius: 12px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    /* WHY: Background color is set dynamically via JS based on role */
}

.signout-btn {
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.7);
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.signout-btn:hover {
    color: var(--white);
    border-color: rgba(255, 255, 255, 0.5);
}

/* ── Header Navigation Links ──────────────────────────────────────── */
/* WHY: Subtle nav links keep the header clean while giving users quick
   access to Chat and Reports without heavy tabs or a separate nav bar. */

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
}

.nav-link {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.1);
}

.nav-link-active {
    color: var(--white);
    background: rgba(255, 255, 255, 0.12);
}

/* WHY: Cash Flow nav link has a green accent to differentiate it from other nav items,
   signaling it's a specialized financial tool, not a general-purpose page. */
.nav-link-cashflow {
    font-weight: 700;
    border: 1px solid rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.12);
    color: rgba(255, 255, 255, 0.9);
}
.nav-link-cashflow:hover {
    border-color: rgba(34, 197, 94, 0.6);
    background: rgba(34, 197, 94, 0.2);
}

/* ── Chat area ──────────────────────────────────────────────────────── */

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

/* ── Messages ───────────────────────────────────────────────────────── */

.messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    flex-direction: column;
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-items: flex-end;
}

.message.assistant {
    align-items: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--blue);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--gray-100);
    color: var(--gray-800);
    border-bottom-left-radius: 4px;
}

.message.error .message-bubble {
    background: var(--red-50);
    color: var(--red-500);
    border: 1px solid var(--red-500);
}

/* WHY: Messages loaded from history don't need the slide-in animation
   since they appear all at once when loading a conversation. */
.message.no-animate {
    animation: none;
}

/* ── Access Denied Messages ─────────────────────────────────────────── */
/* WHY: Visually distinct from normal messages so users immediately understand
   this is an access restriction, not an error or a normal answer. */

.message.access-denied .message-bubble {
    background: var(--amber-50);
    color: var(--amber-700);
    border: 1px solid var(--amber-200);
    border-left: 4px solid var(--amber-700);
    border-bottom-left-radius: 4px;
}

.lock-icon {
    font-size: 1.1em;
    margin-right: 4px;
}

/* ── Markdown content inside assistant messages ─────────────────────── */

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
    margin-top: 12px;
    margin-bottom: 6px;
    font-weight: 600;
    line-height: 1.3;
}

.message-bubble h1 { font-size: 1.3em; }
.message-bubble h2 { font-size: 1.15em; }
.message-bubble h3 { font-size: 1.05em; }

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child {
    margin-top: 0;
}

.message-bubble p {
    margin-bottom: 8px;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

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

.message-bubble code {
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.88em;
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
}

.message.user .message-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.message-bubble pre {
    margin: 8px 0;
    border-radius: 8px;
    overflow-x: auto;
    background: var(--code-bg);
    padding: 12px 16px;
}

.message-bubble pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
    font-size: 0.85em;
    line-height: 1.5;
}

/* SQL keywords highlighted in code blocks */
.message-bubble pre code .sql-keyword {
    color: #93c5fd;
    font-weight: 600;
}

.message-bubble ul,
.message-bubble ol {
    margin: 6px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin-bottom: 4px;
}

/* Tables in messages */
.message-bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.9em;
    width: 100%;
    overflow-x: auto;
    display: block;
}

.message-bubble table th,
.message-bubble table td {
    border: 1px solid var(--gray-300);
    padding: 6px 10px;
    text-align: left;
    white-space: nowrap;
}

.message-bubble table th {
    background: var(--gray-200);
    font-weight: 600;
}

.message-bubble table tr:nth-child(even) {
    background: var(--gray-50);
}

/* ── SQL viewer collapsible ─────────────────────────────────────────── */

.sql-viewer {
    max-width: 85%;
    margin-top: 4px;
}

.sql-toggle {
    font-size: 12px;
    color: var(--gray-500);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: inherit;
}

.sql-toggle:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.sql-content {
    display: none;
    margin-top: 4px;
}

/* ── CSV export button ─────────────────────────────────────────────── */

.csv-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    color: var(--navy);
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.csv-export-btn:hover {
    background: var(--gray-100);
    border-color: var(--navy-light);
}

/* ── Document generation toolbar ──────────────────────────────────── */
/* WHY: Appears on every assistant message so users can export any
   response to PowerPoint, Excel, or Word with one click. */

.doc-gen-toolbar {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    margin-left: 6px;
}

.doc-gen-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    color: var(--white);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.02em;
}

.doc-gen-btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.doc-gen-btn:active {
    transform: translateY(0);
}

.doc-gen-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* WHY: Colors match the official Microsoft Office branding so users
   instantly recognize which file type each button generates. */
.doc-gen-btn--pptx { background: #D24726; }  /* PowerPoint orange-red */
.doc-gen-btn--xlsx { background: #217346; }  /* Excel green */
.doc-gen-btn--docx { background: #2B579A; }  /* Word blue */

.doc-gen-btn .doc-gen-spinner {
    display: none;
    width: 10px;
    height: 10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: doc-gen-spin 0.6s linear infinite;
}

.doc-gen-btn.loading .doc-gen-spinner {
    display: inline-block;
}

.doc-gen-btn.loading .doc-gen-label {
    display: none;
}

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

/* ── Export actions row (CSV + doc gen buttons together) ───────────── */
.export-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    margin-top: 6px;
}

.sql-content.open {
    display: block;
}

.sql-content pre {
    background: var(--code-bg);
    color: #e2e8f0;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.82em;
    overflow-x: auto;
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    line-height: 1.5;
}

/* ── Thinking indicator ─────────────────────────────────────────────── */

.thinking {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    animation: messageIn 0.3s ease-out;
}

.thinking-dot {
    width: 8px;
    height: 8px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.16s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* ── Input area ─────────────────────────────────────────────────────── */

.input-area {
    flex-shrink: 0;
    padding: 16px;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}

/* ── Mode Toggle (Auto / Fast / Deep) ────────────────────────────── */
/* WHY: Users need control over speed vs depth. Auto is the default
   (existing complexity-based routing). Fast = Sonnet for quick reports.
   Deep = Opus for thorough validation. */
.mode-toggle-bar {
    max-width: 800px;
    margin: 0 auto 8px;
    display: flex;
    justify-content: center;
}

.mode-toggle {
    display: inline-flex;
    background: var(--gray-100);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.mode-btn {
    padding: 4px 14px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--gray-500);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 0.02em;
}

.mode-btn:hover {
    color: var(--gray-700);
}

.mode-btn.active {
    background: var(--white);
    color: var(--gray-800);
    box-shadow: var(--shadow-sm);
}

.mode-btn.active[data-mode="fast"] {
    color: #059669;
}

.mode-btn.active[data-mode="deep"] {
    color: #7c3aed;
}

/* ── Mic Button ──────────────────────────────────────────────────── */
/* WHY: Speech-to-text via Web Speech API. Same styling as upload-btn
   for visual consistency. Red pulse when actively recording. */
.mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--gray-500);
    transition: all 0.15s;
    flex-shrink: 0;
}

.mic-btn:hover {
    color: var(--blue);
    background: #eef2ff;
}

.mic-btn.recording {
    color: #ef4444;
    background: #fef2f2;
    animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* WHY: Hide mic button if browser doesn't support SpeechRecognition.
   JS adds this class to <body> on load. */
.no-speech-api .mic-btn {
    display: none;
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-wrapper input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid var(--gray-300);
    border-radius: 24px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    background: var(--gray-50);
}

.input-wrapper input:focus {
    border-color: var(--blue);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-wrapper input::placeholder {
    color: var(--gray-400);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--blue);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.send-btn:hover {
    background: var(--blue-light);
}

.send-btn:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

/* ── Welcome message ────────────────────────────────────────────────── */

.welcome {
    text-align: center;
    color: var(--gray-500);
    padding: 40px 20px;
    max-width: 500px;
    margin: 0 auto;
}

.welcome h2 {
    color: var(--navy);
    font-size: 20px;
    margin-bottom: 12px;
    font-weight: 600;
}

.welcome p {
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 8px;
}

.welcome .try-it {
    margin-top: 16px;
    padding: 10px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    font-size: 13px;
    color: var(--gray-700);
    cursor: pointer;
    transition: background 0.15s;
}

.welcome .try-it:hover {
    background: var(--gray-100);
}

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    /* WHY: On mobile, the sidebar overlays the content instead of pushing it.
       This avoids squeezing the chat area to an unusable width. */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 25;
        transition: transform 0.25s ease;
        transform: translateX(0);
    }

    .sidebar.collapsed {
        margin-left: 0;
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }

    .header {
        padding: 12px 16px;
    }

    .header-title {
        font-size: 16px;
    }

    .chat-area {
        padding: 16px 12px;
    }

    .message-bubble {
        max-width: 92%;
    }

    .sql-viewer {
        max-width: 92%;
    }

    .input-area {
        padding: 12px;
    }

    .mode-toggle-bar {
        margin-bottom: 6px;
    }

    .mode-btn {
        padding: 3px 10px;
        font-size: 11px;
    }

    .input-wrapper input {
        padding: 10px 14px;
        font-size: 16px; /* WHY: Prevents iOS zoom on input focus */
    }

    .login-card {
        margin: 16px;
        padding: 36px 28px;
    }

    .pin-input {
        font-size: 20px;
    }

    .csv-export-btn {
        max-width: 92%;
    }

    .export-actions {
        max-width: 92%;
    }
}

/* ── Inline Charts ─────────────────────────────────────────────────── */
/* WHY: Charts appear above tables so visual learners see the shape of
   the data before diving into exact numbers in the table below. */

.chart-container {
    position: relative;
    width: 100%;
    max-height: 320px;
    margin: 12px 0;
    padding: 16px;
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

.chart-container canvas {
    max-height: 280px; /* WHY: Prevents chart from overflowing its container */
}

/* ── Email Integration ─────────────────────────────────────────────── */

.email-connect-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.8);
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.email-connect-btn:hover {
    color: var(--white);
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.08);
}

/* WHY: Green state signals "connected" without needing extra UI chrome */
.email-connect-btn.connected {
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.4);
}

.email-connect-btn.connected:hover {
    background: rgba(74, 222, 128, 0.1);
    border-color: rgba(74, 222, 128, 0.6);
}

/* ── Email Search Panel ──────────────────────────────────────────────── */
/* WHY: Side panel slides in from the right to avoid covering the chat.
   Users can search email and chat simultaneously. */

.email-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    background: var(--white);
    border-left: 1px solid var(--gray-200);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    z-index: 30;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

.email-panel.open {
    transform: translateX(0);
}

.email-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.email-panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
}

.email-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.email-panel-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.email-search-bar {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--gray-100);
    flex-shrink: 0;
}

.email-search-input {
    flex: 1;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    outline: none;
    background: var(--gray-50);
    transition: border-color 0.15s;
}

.email-search-input:focus {
    border-color: var(--blue);
    background: var(--white);
}

.email-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--navy);
    color: var(--white);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.email-search-btn:hover {
    background: var(--navy-light);
}

.email-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.email-results::-webkit-scrollbar {
    width: 4px;
}

.email-results::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 2px;
}

.email-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--gray-400);
    font-size: 13px;
    line-height: 1.6;
}

/* ── Individual email result card ────────────────────────────────────── */

.email-item {
    padding: 12px 14px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: default;
    transition: border-color 0.15s;
}

.email-item:hover {
    border-color: var(--gray-300);
}

.email-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.email-item-from {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.email-item-date {
    font-size: 11px;
    color: var(--gray-400);
    white-space: nowrap;
    flex-shrink: 0;
}

.email-item-subject {
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* WHY: Unread emails get a left border accent for quick scanning */
.email-item.unread {
    border-left: 3px solid var(--blue);
}

.email-item.unread .email-item-subject {
    font-weight: 600;
    color: var(--gray-900);
}

.email-item-preview {
    font-size: 12px;
    color: var(--gray-500);
    line-height: 1.4;
    /* WHY: 3-line clamp gives enough preview without overwhelming the list */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.email-item-badges {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.email-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.email-badge--attachment {
    background: var(--gray-100);
    color: var(--gray-600);
}

.email-badge--high {
    background: var(--red-50);
    color: var(--red-700);
}

/* WHY: Loading spinner reuses the doc-gen pattern for consistency */
.email-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}

.email-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--navy);
    border-radius: 50%;
    animation: doc-gen-spin 0.6s linear infinite;
}

/* ── Email panel responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .email-panel {
        width: 100vw;
    }
}

/* ── Print ──────────────────────────────────────────────────────────── */

@media print {
    .header,
    .input-area,
    .sql-viewer,
    .csv-export-btn,
    .doc-gen-toolbar,
    .export-actions,
    .chart-container,
    .thinking,
    .login-overlay,
    .sidebar,
    .sidebar-backdrop,
    .email-panel {
        display: none !important;
    }

    .chat-area {
        overflow: visible;
    }

    .message-bubble {
        max-width: 100%;
        break-inside: avoid;
    }
}

/* ── Inline Email Results (AI-triggered) ─────────────────────────── */
/* WHY: These appear inside assistant message bubbles when the AI triggers
   an email-search. Styled distinctly from the main answer so users can
   immediately tell this data comes from their inbox, not the database. */

.email-results {
    margin-top: 12px;
    padding: 12px 16px;
    background: #f0f4ff;
    border-left: 3px solid #2b6cb0;
    border-radius: 4px;
}

.email-results--loading {
    /* WHY: Slightly muted background while loading so it doesn't compete
       visually with the main answer content. */
    background: #f7f9ff;
    border-left-color: var(--gray-300);
}

.email-result-item {
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.email-result-item:last-child {
    border-bottom: none;
}

.email-result-subject {
    font-weight: 600;
}

.email-result-meta {
    font-size: 0.85em;
    color: #718096;
}

.email-result-preview {
    font-size: 0.9em;
    color: #4a5568;
    margin-top: 4px;
}

/* Upload button */
.upload-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    background: transparent; cursor: pointer;
    color: #6b7280; transition: all 0.15s;
    flex-shrink: 0;
}
.upload-btn:hover { color: #2563eb; background: #eef2ff; }

/* ── Image Paste Preview ─────────────────────────────────────────────── */
/* WHY: Users paste screenshots/product photos into chat. Show thumbnails
   above the input so they can see what's attached before sending. */

#chat-input {
    resize: none;
    overflow: hidden;
    min-height: 20px;
    max-height: 120px;
    line-height: 1.4;
    font-family: inherit;
    font-size: inherit;
    border: none;
    outline: none;
    background: transparent;
    width: 100%;
    padding: 0;
}

.image-preview-bar {
    display: flex;
    gap: 8px;
    padding: 8px 0 4px 0;
    flex-wrap: wrap;
    align-items: center;
}

.image-preview-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e2e8f0;
    flex-shrink: 0;
}

.image-preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-thumb .remove-image {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: #e53e3e;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    padding: 0;
}

.image-preview-thumb .remove-image:hover {
    background: #c53030;
}

.image-attached-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #ebf8ff;
    color: #2b6cb0;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 4px;
}

/* User message with image */
.message.user .message-image {
    max-width: 200px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid rgba(255,255,255,0.2);
}

.message.assistant .message-image {
    max-width: 300px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid #e2e8f0;
}

/* Drag-over visual feedback */
.input-wrapper.drag-over {
    border-color: #4299e1 !important;
    background: #ebf8ff !important;
}

/* ── Stop Button (abort in-flight request) ────────────────────────── */
/* WHY: Visual swap from send arrow to stop square while AI is thinking.
   Red pulse draws attention so users know they can cancel. */
.send-btn.stop-btn-active {
    background: #e53e3e !important;
    animation: stop-pulse 1.5s ease-in-out infinite;
}
.send-btn.stop-btn-active:hover {
    background: #c53030 !important;
}
.send-btn.stop-btn-active svg {
    fill: white;
}
@keyframes stop-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}


/* -- Quality Monitoring: Feedback Buttons ------------------------------ */
/* WHY: Subtle inline feedback controls that appear on hover so they don't
   clutter the conversation but are always one click away. Phase 4. */
.feedback-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.message:hover .feedback-actions { opacity: 1; }
.feedback-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    transition: all 0.15s;
}
.feedback-btn:hover { background: rgba(0,0,0,0.05); border-color: #ddd; }
.feedback-btn.active { background: #e8f0fe; border-color: #2a4494; }
.feedback-btn.active.feedback-down { background: #fde8e8; border-color: #c53030; }
.feedback-btn.active.feedback-flag { background: #fefce8; border-color: #ca8a04; }

/* ── Inline Feedback Panel ─────────────────────────────────────────── */
/* WHY: Replaces browser prompt() dialogs with a polished inline form.
   Category buttons let users classify with one click; optional note
   captures context without requiring it. Panel expands below the message. */
.feedback-panel {
    margin-top: 8px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    animation: feedbackSlideIn 0.2s ease;
}
@keyframes feedbackSlideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.feedback-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}
.feedback-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.feedback-cat-btn {
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: #4b5563;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
}
.feedback-cat-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}
.feedback-cat-btn.selected {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #1d4ed8;
    font-weight: 600;
}
.feedback-note-input {
    display: block;
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    outline: none;
    margin-bottom: 8px;
    font-family: inherit;
}
.feedback-note-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.feedback-submit-row {
    display: flex;
    gap: 8px;
}
.feedback-submit-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 600;
    color: white;
    background: #2a4494;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.feedback-submit-btn:hover { background: #1e3a8a; }
.feedback-cancel-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.feedback-cancel-btn:hover { background: #f3f4f6; }
.feedback-confirmation {
    font-size: 13px;
    color: #16a34a;
    font-weight: 500;
    padding: 4px 0;
}
