@layer components {
  /* ================= APP SHELL & TOPBAR ================= */
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--bg-app);
  }

  /* Sticky Top Header */
  .top-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
  }

  .brand-logo {
    font-size: 1.5rem;
  }

  .brand-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .badge {
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    background-color: var(--accent-subtle);
    color: var(--accent-primary);
  }

  /* Global Filters Bar */
  .filter-bar {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
  }

  .filter-select, .filter-date, .input-control {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.45rem 0.75rem;
    font-family: inherit;
    font-size: 0.8125rem;
    outline: none;
    transition: border-color 0.15s ease;
  }

  .filter-select:focus, .filter-date:focus, .input-control:focus {
    border-color: var(--accent-primary);
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 0.625rem;
  }

  .icon-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    padding: 0.45rem 0.65rem;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .icon-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
  }

  .avatar-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--accent-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--accent-primary);
  }

  .account-dropdown-wrapper {
    position: relative;
  }

  .account-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    width: 220px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .account-dropdown[hidden] {
    display: none;
  }

  .account-user-info {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 0.25rem;
  }

  .account-user-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-main);
  }

  .account-user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
  }

  .dropdown-item-btn {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.15s ease;
  }

  .dropdown-item-btn:hover {
    background-color: var(--bg-hover);
    color: var(--accent-primary);
  }

  .dropdown-item-btn.danger-item:hover {
    color: var(--accent-danger);
    background-color: rgba(225, 29, 72, 0.1);
  }

  /* Category Navigation Bar */
  .category-nav-bar {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.25rem 1.5rem;
    overflow-x: auto;
  }

  .category-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.625rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
  }

  .category-tab:hover {
    color: var(--text-main);
  }

  .category-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    font-weight: 600;
  }

  /* Main Content Area */
  .main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
  }

  .tab-section[hidden] {
    content-visibility: hidden;
    display: none;
  }

  /* ================= LOGIN VIEW ================= */
  #login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background-color: var(--bg-app);
  }

  .login-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: 2.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .login-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
  }

  .login-header p {
    font-size: 0.875rem;
    color: var(--text-muted);
  }

  .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
  }

  .form-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-main);
  }

  .form-group input, .form-group select {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.625rem 0.875rem;
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s ease;
  }

  .form-group input:focus, .form-group select:focus {
    border-color: var(--accent-primary);
  }

  .btn-primary {
    background-color: var(--accent-primary);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.625rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
  }

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

  .btn-secondary {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.625rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease;
  }

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

  .btn-danger {
    background-color: var(--accent-danger);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.625rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
  }

  .btn-danger:hover {
    opacity: 0.9;
  }

  .forgot-toggle {
    background: transparent;
    border: none;
    color: var(--accent-primary);
    font-size: 0.8125rem;
    cursor: pointer;
    text-align: right;
    padding: 0;
  }

  .forgot-panel {
    border-top: 1px solid var(--border-subtle);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .forgot-panel[hidden] {
    display: none;
  }

  .error-message {
    color: var(--accent-danger);
    font-size: 0.8125rem;
    background-color: rgba(225, 29, 72, 0.1);
    border: 1px solid rgba(225, 29, 72, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
  }

  .success-message {
    color: var(--accent-success);
    font-size: 0.8125rem;
    background-color: rgba(5, 150, 105, 0.1);
    border: 1px solid rgba(5, 150, 105, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
  }

  /* ================= USERS MANAGEMENT VIEW ================= */
  .users-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
  }

  @media (max-width: 900px) {
    .users-layout {
      grid-template-columns: 1fr;
    }
  }

  .users-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .users-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }

  .users-search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
  }

  .users-table-wrapper {
    overflow-x: auto;
  }

  .users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
  }

  .users-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    background-color: var(--bg-app);
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-subtle);
  }

  .users-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-main);
  }

  .users-table tr:hover {
    background-color: var(--bg-hover);
  }

  .role-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
  }

  .role-admin {
    background-color: rgba(225, 29, 72, 0.15);
    color: var(--accent-danger);
  }

  .role-editor {
    background-color: rgba(217, 119, 6, 0.15);
    color: var(--accent-warning);
  }

  .role-viewer {
    background-color: rgba(13, 148, 136, 0.15);
    color: var(--accent-primary);
  }

  .pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
  }

  .pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.35rem;
  }

  .page-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.65rem;
    font-size: 0.8125rem;
    color: var(--text-main);
    cursor: pointer;
  }

  .page-btn:hover {
    background-color: var(--bg-hover);
  }

  .page-btn.active {
    background-color: var(--accent-primary);
    color: #ffffff;
    border-color: var(--accent-primary);
  }

  /* ================= BENTO GRID & DASHBOARD CARDS ================= */
  .bento-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
  }

  .col-12 { grid-column: span 12; }
  .col-8 { grid-column: span 8; }
  .col-7 { grid-column: span 7; }
  .col-6 { grid-column: span 6; }
  .col-5 { grid-column: span 5; }
  .col-4 { grid-column: span 4; }
  .col-3 { grid-column: span 3; }

  @media (max-width: 1024px) {
    .col-8, .col-7, .col-6, .col-5, .col-4, .col-3 {
      grid-column: span 12;
    }
  }

  /* KPI Card */
  .kpi-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
  }

  .kpi-card-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .kpi-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
  }

  .kpi-card-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
  }

  .kpi-trend-up {
    color: var(--accent-success);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
  }

  .kpi-trend-down {
    color: var(--accent-danger);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
  }

  .kpi-comparison-banner {
    font-size: 0.75rem;
    color: var(--text-muted);
    background-color: var(--bg-app);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    margin-top: 0.25rem;
  }

  /* Chart Card */
  .chart-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .chart-title-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
  }

  .ai-chart-btn {
    background-color: var(--accent-subtle);
    color: var(--accent-primary);
    border: 1px solid rgba(13, 148, 136, 0.25);
    border-radius: var(--radius-md);
    padding: 0.35rem 0.65rem;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .ai-chart-btn:hover {
    background-color: var(--accent-primary);
    color: #ffffff;
  }

  .chart-canvas-container {
    width: 100%;
    min-height: 280px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .chart-canvas {
    width: 100% !important;
    height: 100% !important;
  }

  /* Risk Badges & Data Integrity */
  .risk-badge-low {
    background-color: rgba(5, 150, 105, 0.15);
    color: var(--accent-success);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8125rem;
  }

  .risk-badge-medium {
    background-color: rgba(217, 119, 6, 0.15);
    color: var(--accent-warning);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8125rem;
  }

  .risk-badge-high {
    background-color: rgba(225, 29, 72, 0.15);
    color: var(--accent-danger);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8125rem;
  }

  .integrity-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.875rem;
  }

  .integrity-row:last-child {
    border-bottom: none;
  }

  /* ================= AI INSIGHTS SPLIT VIEW & CHAT ================= */
  .ai-insights-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1.5rem;
  }

  @media (max-width: 1024px) {
    .ai-insights-grid {
      grid-template-columns: 1fr;
    }
  }

  .report-section-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.25rem;
  }

  .report-section-card h3 {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .report-item {
    background-color: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  .report-item-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-main);
  }

  .report-item-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.5;
  }

  .chat-panel {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    height: 720px;
    position: sticky;
    top: 5rem;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
  }

  .chat-bubble-user {
    align-self: flex-end;
    background-color: var(--accent-primary);
    color: #ffffff;
    border-radius: var(--radius-lg) var(--radius-lg) 0 var(--radius-lg);
    padding: 0.75rem 1rem;
    max-width: 82%;
    font-size: 0.875rem;
    line-height: 1.4;
  }

  .chat-bubble-ai {
    align-self: flex-start;
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 0;
    padding: 0.75rem 1rem;
    max-width: 85%;
    font-size: 0.875rem;
    line-height: 1.5;
  }

  /* Safe Markdown Content Styling */
  .chat-bubble-ai strong, .msg-bubble strong, #narrative-text strong {
    font-weight: 600;
    color: var(--text-main);
  }

  .chat-bubble-ai em, .msg-bubble em, #narrative-text em {
    font-style: italic;
  }

  .chat-bubble-ai ul, .msg-bubble ul, #narrative-text ul {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
    list-style-type: disc;
  }

  .chat-bubble-ai ol, .msg-bubble ol, #narrative-text ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
    list-style-type: decimal;
  }

  .chat-bubble-ai li, .msg-bubble li, #narrative-text li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
  }

  .chat-bubble-ai p, .msg-bubble p, #narrative-text p {
    margin: 0.4rem 0;
    line-height: 1.5;
  }

  .chat-bubble-ai p:first-child, .msg-bubble p:first-child, #narrative-text p:first-child {
    margin-top: 0;
  }

  .chat-bubble-ai p:last-child, .msg-bubble p:last-child, #narrative-text p:last-child {
    margin-bottom: 0;
  }

  /* Loading Indicators & Typing Pulsing Dots */
  .loading-bubble {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.75rem 1rem;
  }

  .typing-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-primary, #0d9488);
    border-radius: 50%;
    animation: typingPulse 1.4s infinite ease-in-out;
  }

  .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
  }

  .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
  }

  .loading-label {
    margin-left: 0.35rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-style: italic;
  }

  @keyframes typingPulse {
    0%, 80%, 100% {
      transform: scale(0.6);
      opacity: 0.4;
    }
    40% {
      transform: scale(1.1);
      opacity: 1;
    }
  }

  /* Comparative Processing Events Stream */
  #comparative-processing-events {
    padding: 0.5rem 1.25rem;
    background-color: var(--bg-app);
    border-top: 1px solid var(--border-subtle);
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 28px;
  }

  #comparative-processing-events:empty {
    display: none;
  }

  .event-step-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    background-color: var(--accent-subtle);
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 0.6875rem;
  }

  .chat-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
  }

  /* ================= NATURAL LANGUAGE SQL RESEARCH STUDIO ================= */
  .research-studio-bar {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .search-bar-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  #research-input {
    flex: 1;
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 0.9375rem;
    outline: none;
  }

  #research-input:focus {
    border-color: var(--accent-primary);
  }

  .starter-pills-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }

  .starter-pill {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    padding: 0.4rem 0.85rem;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
  }

  .starter-pill:hover {
    border-color: var(--accent-primary);
    background-color: rgba(13, 148, 136, 0.08);
    color: var(--accent-primary);
  }

  .decision-note-banner {
    background-color: rgba(13, 148, 136, 0.08);
    border-left: 3px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.85rem;
    margin-bottom: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-main);
    line-height: 1.45;
  }

  .decision-note-banner[hidden] {
    display: none;
  }

  .page-size-select {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.5rem;
    font-size: 0.8125rem;
    font-family: inherit;
  }

  .pagination-info,
  .page-indicator {
    font-size: 0.8125rem;
    color: var(--text-muted);
  }

  .page-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }

  #widget-canvas .chart-card {
    width: 100%;
    min-width: 0;
  }

  .sse-status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    background-color: var(--bg-app);
    color: var(--text-muted);
    border: 1px solid var(--border-subtle);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
  }

  .narrative-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
  }

  .narrative-card[hidden] {
    display: none;
  }

  .narrative-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
  }

  .narrative-body {
    font-size: 0.9375rem;
    color: var(--text-main);
    line-height: 1.6;
  }

  /* ================= MODALS & DIALOGS ================= */
  dialog {
    background: transparent;
    border: none;
    padding: 0;
    margin: auto;
    max-width: 580px;
    width: 90%;
  }

  dialog::backdrop {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
  }

  .modal-box {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
  }

  .modal-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-main);
  }

  .modal-close-btn {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
  }

  .modal-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 60vh;
    overflow-y: auto;
  }

  .modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.625rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-app);
  }

  /* ================= INLINE SVG ICONS ================= */
  .svg-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    vertical-align: middle;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
  }

  .svg-icon-sm {
    width: 1rem;
    height: 1rem;
  }

  .svg-icon-lg {
    width: 1.5rem;
    height: 1.5rem;
  }

  canvas {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    display: block;
  }

  /* ================= COMPARATIVE ANALYTICS 5-COLUMN STUDIO ================= */
  .comparative-studio {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1.25rem;
    min-height: 620px;
    align-items: start;
  }

  @media (max-width: 1024px) {
    .comparative-studio {
      grid-template-columns: 1fr;
    }
  }

  .comparative-visual-pane {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .comparative-welcome-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
  }

  .comparative-welcome-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
  }

  .comparative-welcome-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 1rem;
  }

  .comparative-chat-pane {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: 620px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    position: sticky;
    top: 5rem;
  }

  .comparative-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-card);
  }

  .comparative-chat-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .comparative-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
  }

  .msg-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-width: 90%;
  }

  .msg-user {
    align-self: flex-end;
  }

  .msg-user .msg-bubble {
    background-color: var(--accent-primary);
    color: #ffffff;
    border-radius: var(--radius-md) var(--radius-md) 0 var(--radius-md);
  }

  .msg-ai {
    align-self: flex-start;
  }

  .msg-ai .msg-bubble {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 0;
  }

  .msg-bubble {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
  }

  .msg-meta {
    font-size: 0.6875rem;
    color: var(--text-muted);
    padding: 0 0.25rem;
  }

  .comparative-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-app);
  }

  .suggestion-chip {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
  }

  .suggestion-chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background-color: var(--accent-subtle);
  }

  .comparative-input-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-card);
  }

  .comparative-input {
    flex: 1;
    background-color: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.55rem 0.85rem;
    font-size: 0.875rem;
    color: var(--text-main);
    outline: none;
    font-family: inherit;
  }

  .comparative-input:focus {
    border-color: var(--accent-primary);
  }

  .comparative-send-btn {
    background-color: var(--accent-primary);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.55rem 0.95rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: background-color 0.15s ease;
  }

  .comparative-send-btn:hover {
    background-color: var(--accent-hover);
  }

  .progress-events-box {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background-color: var(--accent-subtle);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
  }
}
