/* ==========================================================================
   MAT-SA Quality Hub - Master Stylesheet
   ========================================================================== */

/* ==========================================================================
   MAT-SA Design Tokens
   Shared foundation intended to be copied into other MAT-SA apps as-is.
   Brand: "MAT-SA Cobalt" #2547B0 - chosen deliberately to avoid overlap
   with OpenAI/ChatGPT green and generic SaaS blue/indigo defaults.
   ========================================================================== */
:root {
    --brand-50:  #EAF0FB;
    --brand-100: #C9D9F3;
    --brand-300: #7C9BE0;
    --brand-500: #3A5FC4;
    --brand-600: #2547B0;  /* primary */
    --brand-700: #1B3585;
    --brand-900: #10204F;

    --gray-50:  #F7F8FA;
    --gray-100: #EEF0F3;
    --gray-200: #E2E5EA;
    --gray-400: #9AA3AF;
    --gray-600: #5B6472;
    --gray-800: #1F2530;
    --gray-900: #12161D;

    --success-500: #1C8A4B;
    --success-bg:  #E6F4EC;
    --warning-500: #C77A0C;
    --warning-bg:  #FBF0DF;
    --danger-500:  #C62828;
    --danger-bg:   #FBE9E9;

    /* Legacy variable names kept so the rest of this stylesheet (and other
       templates) don't need touching - they now resolve through tokens. */
    --bg-primary: #ffffff;
    --bg-secondary: var(--gray-50);
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-600);
    --accent-blue: var(--brand-600);
    --accent-blue-hover: var(--brand-700);
    --accent-blue-light: var(--brand-50);
    --border-color: var(--gray-200);
    --card-bg: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgba(16, 32, 79, 0.06);
    --shadow-md: 0 4px 10px -2px rgba(16, 32, 79, 0.12), 0 2px 4px -1px rgba(16, 32, 79, 0.06);
    --transition-speed: 0.2s;
    --border-radius: 10px;

    /* Type scale */
    --text-h1: 600 1.75rem/1.25 'Inter', sans-serif;
    --text-h2: 600 1.375rem/1.3 'Inter', sans-serif;
    --text-h3: 600 1.125rem/1.35 'Inter', sans-serif;
    --text-caption: 600 0.78rem/1.4 'Inter', sans-serif;

    /* Spacing scale */
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-6: 24px; --space-8: 32px;

    /* Dashboard shell variables */
    --sidebar-width: 236px;
    --sidebar-width-collapsed: 76px;
    --topbar-height: 60px;
    --right-panel-width: 280px;
    --bottom-nav-height: 60px;
}

/* Dark mode - the primary MAT-SA theme (default on load). Near-black
   surfaces + hairline borders instead of gray panels/shadows, cobalt held
   back to a single sparing accent, mono for numeric/data values. */
body.dark-mode {
    --bg-primary: #0A0A0A;
    --bg-secondary: #000000;
    --text-primary: #EDEDED;
    --text-secondary: #6B6B6B;
    --accent-blue: var(--brand-300);
    --accent-blue-hover: #9DB4E8;
    --accent-blue-light: #131A2E;
    --border-color: #262626;
    --card-bg: #0A0A0A;
    --shadow-sm: none;
    --shadow-md: none;
    --border-radius: 8px;
    --success-bg: #0F2118;
    --warning-bg: #241A0A;
    --danger-bg:  #24100F;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', ui-monospace, Menlo, Consolas, monospace;
}

/* Global Resets & Setup */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ==========================================================================
   Base type hierarchy (new - was previously ad hoc per component)
   ========================================================================== */
h1 { font: var(--text-h1); color: var(--text-primary); letter-spacing: -0.01em; }
h2 { font: var(--text-h2); color: var(--text-primary); }
h3 { font: var(--text-h3); color: var(--text-primary); }

/* ==========================================================================
   Page Loader (branded splash shown while the page boots, ChatGPT-style)
   ========================================================================== */
#page-loader {
    position: fixed;
    inset: 0;
    background-color: var(--bg-primary);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    transition: opacity 0.3s ease;
}

#page-loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loader-mark {
    width: 56px;
    height: 56px;
    color: var(--accent-blue);
    animation: loader-pulse 1.3s ease-in-out infinite;
}

.loader-mark img { width: 100%; height: 100%; display: block; }

.loader-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.02em;
}

@keyframes loader-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.85); opacity: 0.55; }
}

/* ==========================================================================
   Dashboard Shell: Sidebar + Topbar + Main + Right Panel
   ========================================================================== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width var(--transition-speed) ease;
    z-index: 200;
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.sidebar.collapsed .label,
.sidebar.collapsed .logo-text {
    display: none;
}

.sidebar.collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border-color);
    min-height: var(--topbar-height);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    overflow: hidden;
}

.logo-mark {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    white-space: nowrap;
}

.logo-mark img {
    width: 100%;
    height: 100%;
    display: block;
}

.logo-text {
    font: var(--text-h3);
    color: var(--text-primary);
    white-space: nowrap;
}

.logo-accent {
    color: var(--accent-blue);
}

.sidebar-collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, transform 0.2s ease;
}

.sidebar-collapse-btn:hover {
    background-color: var(--bg-secondary);
}

.sidebar-nav {
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
}

.nav-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    opacity: 0.7;
    padding: 14px 10px 6px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-link i,
.sidebar-link .nav-sigma {
    width: 18px;
    flex-shrink: 0;
    text-align: center;
    font-size: 0.95rem;
}

.sidebar-link .nav-sigma {
    font-family: "Times New Roman", Times, serif;
    font-size: 1.1rem;
}

.sidebar-link:hover {
    background-color: var(--bg-secondary);
    color: var(--accent-blue);
}

.sidebar-link.active {
    background-color: var(--accent-blue-light);
    color: var(--accent-blue);
    font-weight: 600;
}

/* --- Main column (topbar + content) --- */
.main-column {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Topbar neutralized to match the body background (no colored strip) -
   plain header like ChatGPT's, distinguished only by a thin border. */
.topbar {
    height: var(--topbar-height);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 150;
}

.topbar-search {
    flex-grow: 1;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 14px;
}

.topbar-search i {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.topbar-search input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.88rem;
    width: 100%;
    font-family: inherit;
}

.topbar-search input::placeholder {
    color: var(--text-secondary);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: var(--accent-blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    color: var(--text-primary);
}

.auth-chip-link {
    color: #fff;
    background-color: var(--accent-blue);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 6px;
}

/* --- Content body: main content + right panel --- */
.content-body {
    display: flex;
    align-items: flex-start;
    flex-grow: 1;
}

.main-content {
    flex-grow: 1;
    min-width: 0;
    padding: 28px 28px 60px;
}

.right-panel {
    width: var(--right-panel-width);
    flex-shrink: 0;
    padding: 28px 20px 60px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: var(--topbar-height);
    max-height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
}

.right-panel:empty {
    display: none;
    padding: 0;
    width: 0;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
}

.page-title {
    font: var(--text-h1);
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.section-title {
    font: var(--text-h3);
    color: var(--text-primary);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* Flash message stack */
.flash-stack {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flash-msg {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid;
}

.flash-success,
.flash-danger,
.flash-warning,
.flash-info {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.flash-success { border-left: 4px solid var(--text-primary); }
.flash-danger { border-left: 4px solid var(--text-primary); }
.flash-warning { border-left: 4px solid var(--text-secondary); }
.flash-info { border-left: 4px solid var(--text-secondary); }

/* ==========================================================================
   Tool Tile Grid (Dashboard cards)
   ========================================================================== */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

.tool-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease, border-color var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
}

.tool-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--tile-color, var(--accent-blue));
}

.tool-tile {
    height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--text-primary);
    color: var(--bg-primary);
    font-size: 1.9rem;
}

.tool-sigma {
    font-family: "Times New Roman", Times, serif;
    font-size: 2.1rem;
}

.tool-info {
    padding: 14px 16px 16px;
}

.tool-title {
    font-size: 0.98rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.tool-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.coming-soon-grid .tool-card-disabled {
    cursor: default;
    opacity: 0.7;
}

.tool-tile-disabled {
    background-color: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
    border-bottom: 1px solid var(--border-color);
}

.coming-soon-tag {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 3px 8px;
    border-radius: 20px;
}

/* ==========================================================================
   Right Panel Sections (Recent Activity / Trial / Challenge / Coach)
   ========================================================================== */
.panel-section {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
}

.panel-section-header {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.activity-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.activity-item .activity-module {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-blue);
    text-transform: uppercase;
}

.activity-item .activity-prompt {
    font-size: 0.82rem;
    color: var(--text-primary);
}

.activity-item .activity-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.panel-empty-text {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-style: italic;
}

.trial-widget .trial-count-text {
    font-size: 0.85rem;
    margin-bottom: 10px;
}

/* ==========================================================================
   Shared Dashboard Components (Settings, Admin, etc.)
   ========================================================================== */
.dash-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 24px;
}

.page-header-block {
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 18px;
}

.page-header-block h1 {
    font-size: 1.8rem;
    font-weight: 800;
}

.page-header-block p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.72rem;
    border: 1px solid var(--border-color);
}

.badge-success { background-color: var(--success-bg); color: var(--success-500); border-color: var(--success-500); }
.badge-danger { background-color: var(--danger-bg); color: var(--danger-500); border-color: var(--danger-500); }
.badge-info { background-color: var(--brand-50); color: var(--brand-700); border-color: var(--brand-300); }
.badge-neutral { background-color: transparent; color: var(--text-secondary); }

/* FMEA RPN risk tiers - now color-coded so severity is readable at a
   glance, not just from the label text */
.badge-risk-high { background-color: var(--danger-bg); color: var(--danger-500); border-color: var(--danger-500); font-weight: 700; }
.badge-risk-medium { background-color: var(--warning-bg); color: var(--warning-500); border-color: var(--warning-500); font-weight: 700; }
.badge-risk-low { background-color: var(--success-bg); color: var(--success-500); border-color: var(--success-500); }

.data-table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
}

.data-table thead tr {
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.data-table th {
    padding: 10px;
}

.data-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.data-table .snippet-cell {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table .actions-cell {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.data-table .empty-row td {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

.icon-btn-link {
    padding: 4px 10px;
    font-size: 0.75rem;
    text-decoration: none;
}

.icon-btn-link.danger {
    border-color: #ef4444;
    color: #ef4444;
}

.settings-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.tier-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-primary);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* ==========================================================================
   Theme Toggle Button
   ========================================================================== */
.theme-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--accent-blue);
}

/* ==========================================================================
   Interactive Widgets (Fun Features)
   ========================================================================== */
.widget-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.widget-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 8px;
}

.widget-intro {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.score-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.score-input-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    resize: none;
    outline: none;
}

.score-input-group textarea:focus {
    border-color: var(--accent-blue);
}

.widget-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.widget-btn:hover {
    background-color: var(--accent-blue-hover);
}

.widget-btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    align-self: flex-start;
}

.widget-btn-secondary:hover {
    background-color: var(--bg-primary);
}

.score-display {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.score-bar-bg {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    background-color: var(--accent-blue);
    width: 0%;
    transition: width 0.5s ease-out;
}

#score-value {
    font-size: 0.9rem;
    font-weight: 700;
    align-self: flex-end;
}

.score-feedback {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-height: 24px;
}

.coach-advice-box {
    background-color: var(--bg-primary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    text-align: center;
    font-style: italic;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-weight: 500;
}

.challenge-question {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 12px;
}

.challenge-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.challenge-opt-btn {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 0.8rem;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.challenge-opt-btn:hover {
    border-color: var(--accent-blue);
    background-color: var(--accent-blue-light);
}

.challenge-feedback {
    font-size: 0.8rem;
    font-weight: 600;
    min-height: 20px;
}

/* ==========================================================================
   Chat Interface Styles
   ========================================================================== */
.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 40px);
    max-width: 900px;
    margin: 0 auto;
}

.chat-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.chat-title-group h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.chat-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chat-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chat-message {
    display: flex;
    gap: 16px;
    padding: 16px;
    border-radius: var(--border-radius);
    max-width: 85%;
    line-height: 1.6;
}

.chat-message.user {
    background-color: var(--bg-secondary);
    align-self: flex-end;
}

.chat-message.assistant {
    background-color: transparent;
    border: 1px solid var(--border-color);
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--accent-blue-light);
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.chat-message.user .message-avatar {
    background-color: var(--border-color);
    color: var(--text-secondary);
}

.message-text {
    font-size: 0.95rem;
    word-break: break-word;
}

.message-text pre, .message-text code {
    background-color: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
}

.message-text p {
    margin-bottom: 10px;
}
.message-text p:last-child {
    margin-bottom: 0;
}

.chat-input-container {
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-primary);
}

.input-box-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 6px 14px;
}

.input-box-wrapper:focus-within {
    border-color: var(--accent-blue);
}

.chat-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    outline: none;
    padding: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background-color: var(--border-color);
    color: var(--accent-blue);
}

.icon-btn.active-recording {
    background-color: #ef4444;
    color: #ffffff !important;
    animation: pulse 1.5s infinite;
}

/* Auth Pages Style */
.auth-wrapper {
    max-width: 400px;
    margin: 60px auto;
    padding: 30px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
}

.form-control:focus {
    border-color: var(--accent-blue);
}

.auth-btn {
    width: 100%;
    background-color: var(--accent-blue);
    color: #ffffff;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.auth-btn:hover {
    background-color: var(--accent-blue-hover);
}

.auth-footer {
    margin-top: 15px;
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--accent-blue);
    text-decoration: none;
}

/* ==========================================================================
   LinkedIn-style Bottom Navigation (Mobile)
   ========================================================================== */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottom-nav-height);
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    z-index: 500;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
}

.bottom-nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 100%;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    height: 100%;
    background: none;
    border: none;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.bottom-nav-item i {
    font-size: 1.2rem;
}

.bottom-nav-item.active {
    color: var(--accent-blue);
}

/* ==========================================================================
   Bottom Sheets (Tools / Activity / Account menus on mobile)
   ========================================================================== */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--card-bg);
    border-radius: 16px 16px 0 0;
    max-height: 75vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 601;
    padding: 14px 18px calc(var(--bottom-nav-height) + 24px);
}

.bottom-sheet.open {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.sheet-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px;
}

.sheet-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 14px;
}

.sheet-search-box i {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.sheet-search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    width: 100%;
    font-family: inherit;
    font-size: 0.9rem;
}

.sheet-tool-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sheet-tool-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 6px;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
}

.sheet-tool-item:active {
    background-color: var(--bg-secondary);
}

.sheet-tool-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--text-primary);
    color: var(--bg-primary);
    font-size: 1rem;
    flex-shrink: 0;
}

.sheet-tool-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.sheet-account-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 6px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.sheet-account-link i {
    width: 20px;
    text-align: center;
    color: var(--text-secondary);
}

.sheet-account-link:active {
    background-color: var(--bg-secondary);
}

.sheet-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 10px 0;
}

/* ==========================================================================
   Global Live Chat (right panel on desktop, collapsible top dock on mobile)
   ========================================================================== */
.chat-widget {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
}

.chat-warning-text {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.4;
}

.chat-online-count {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-secondary);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    border-radius: 20px;
}

.chat-online-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.chat-online-pill {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 3px 9px;
    border-radius: 20px;
}

.chat-online-pill::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--text-primary);
    margin-right: 5px;
    vertical-align: middle;
}

.chat-message-list {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
    padding-right: 2px;
}

.chat-message-item {
    font-size: 0.8rem;
    line-height: 1.4;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.chat-message-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.chat-message-item .chat-msg-author {
    font-weight: 700;
    color: var(--text-primary);
}

.chat-message-item .chat-msg-time {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-left: 6px;
}

.chat-message-item .chat-msg-text {
    color: var(--text-primary);
    display: block;
}

.chat-input-row {
    display: flex;
    gap: 8px;
}

.chat-message-input {
    flex-grow: 1;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
}

.chat-message-input:focus {
    border-color: var(--accent-blue);
}

.chat-send-btn {
    background-color: var(--accent-blue);
    color: var(--bg-primary);
    border: none;
    border-radius: 8px;
    width: 36px;
    flex-shrink: 0;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Mobile top dock - hidden on desktop, collapsible bar on mobile */
.mobile-chat-dock {
    display: none;
}

.mobile-chat-dock-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-primary);
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
}

.mobile-chat-dock-toggle i.fa-chevron-down {
    transition: transform 0.2s ease;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.mobile-chat-dock.open .mobile-chat-dock-toggle i.fa-chevron-down {
    transform: rotate(180deg);
}

.mobile-chat-dock-body {
    display: none;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.mobile-chat-dock.open .mobile-chat-dock-body {
    display: block;
}

.mobile-chat-dock .chat-widget {
    border: none;
    padding: 0;
}

/* ==========================================================================
   Future Expansion Tags (legacy support)
   ========================================================================== */
.tag {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* ==========================================================================
   Animations & Media Queries
   ========================================================================== */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@media (max-width: 900px) {
    .right-panel {
        display: none;
    }

    .mobile-chat-dock {
        display: block;
    }
}

@media (max-width: 768px) {
    /* Sidebar is fully replaced by the bottom nav + sheets on mobile */
    .sidebar {
        display: none;
    }

    .topbar-search,
    .topbar-actions {
        display: none;
    }

    .topbar {
        justify-content: center;
    }

    .main-content {
        padding: 18px 16px calc(60px + var(--bottom-nav-height));
    }

    .bottom-nav {
        display: block;
    }

    .tool-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 14px;
    }

    .page-title {
        font-size: 1.3rem;
    }

    .chat-wrapper {
        height: calc(100vh - var(--topbar-height) - var(--bottom-nav-height) - 20px);
    }
}

@media (min-width: 769px) {
    .bottom-nav,
    .sheet-backdrop,
    .bottom-sheet {
        display: none;
    }
}