/* ═══════════════════════════════════════════════
   Shared Layout — Header, Sidebar, Dropdowns
   Stripe-inspired enterprise styling
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --ref: 2216;
    --header-h: 56px;
    --sidebar-w: 56px;
}

* {
    box-sizing: border-box;
}

html {
    scrollbar-gutter: stable;
}

/* ── Header Background (not on login page) ── */
body:not(.page-login)::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg-card);
    z-index: 100;
    pointer-events: none;
}

/* ── Header Bar ── */
.logo-box {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-w);
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 101;
    background: var(--accent);
    border-bottom: none;
    border-right: none;
}

.logo-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

/* ── Search Bar ── */
.search-bar {
    position: fixed;
    left: calc(var(--sidebar-w) + 24px);
    top: 12px;
    width: 380px;
    height: 32px;
    background: var(--gray-25);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    padding-left: 10px;
    gap: 8px;
    z-index: 101;
    transition: all var(--transition-fast);
    cursor: text;
}

.search-bar:hover,
.search-bar:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
    background: var(--bg-card);
}

.search-icon {
    width: 14px;
    height: 14px;
    opacity: 0.4;
}

.search-text {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-placeholder);
    letter-spacing: 0;
}

/* ── Header Line ── */
.header-line {
    position: fixed;
    left: var(--sidebar-w);
    top: var(--header-h);
    width: 100%;
    height: 1px;
    background: var(--border-default);
    z-index: 100;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    width: var(--sidebar-w);
    bottom: 0;
    background: var(--accent);
    border-right: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 12px;
    gap: 4px;
    z-index: 99;
    border-radius: 0;
    border: none;
    box-shadow: none;
}

.sidebar-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    position: relative;
}

.sidebar-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: scale(1.05);
}

.sidebar-icon.active {
    background: var(--active-gold);
    box-shadow: none;
}

.sidebar-icon.active img {
    filter: brightness(0);
}

.sidebar-icon a {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.sidebar-icon img {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    filter: brightness(0) invert(1);
    transition: opacity 0.2s ease;
}

.sidebar-icon:hover img {
    opacity: 1;
    filter: brightness(0) invert(1);
}

.sidebar-icon.active img {
    opacity: 1;
    filter: brightness(0);
}

/* Enhanced tooltip with slide-in animation */
.sidebar-icon[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    padding: 6px 12px;
    background: var(--gray-950);
    color: var(--text-inverse);
    font-size: 12px;
    line-height: 1.4;
    font-weight: 500;
    font-family: var(--font-sans);
    border-radius: var(--radius-md);
    white-space: nowrap;
    z-index: 10000;
    animation: tooltipSlide 0.15s ease both;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    letter-spacing: 0;
}

/* Tooltip arrow */
.sidebar-icon[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--gray-950);
    z-index: 10000;
    animation: tooltipSlide 0.15s ease both;
}

@keyframes tooltipSlide {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* ── Top Right Icons ── */
.top-icons {
    position: fixed;
    right: 108px;
    top: 0;
    height: var(--header-h);
    display: flex;
    gap: 4px;
    align-items: center;
    z-index: 101;
}

.top-icon {
    width: 32px;
    height: 32px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.top-icon:hover {
    background: var(--gray-50);
}

.top-icon img {
    width: 16px;
    height: 16px;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

.top-icon:hover img {
    opacity: 0.75;
}

/* ── Divider Line ── */
.divider-line {
    position: fixed;
    right: 96px;
    top: 16px;
    width: 1px;
    height: 24px;
    background: var(--border-default);
    z-index: 101;
}

/* ── Plus Button ── */
.plus-button {
    position: fixed;
    right: 56px;
    top: 0;
    height: var(--header-h);
    width: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 101;
}

.plus-button img {
    width: 18px;
    height: 18px;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

.plus-button:hover img {
    opacity: 0.8;
}

/* ── Profile Icon ── */
.profile-icon {
    position: fixed;
    right: 16px;
    top: 0;
    height: var(--header-h);
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 101;
}

.profile-icon img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    opacity: 0.6;
    transition: opacity 0.15s ease;
}

.profile-icon:hover img {
    opacity: 1;
}

/* ═══════════════════════════════════════════════
   Dropdown Menus
   ═══════════════════════════════════════════════ */

.header-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: -8px;
    min-width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    overflow: hidden;
    animation: dropdown-in 0.15s ease;
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.header-dropdown * {
    font-family: var(--font-sans) !important;
    font-size: 13px !important;
}

.header-dropdown.open {
    display: block;
}

.dropdown-header {
    padding: 12px 16px;
    font-size: 11px !important;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-light);
}

.dropdown-item {
    padding: 8px 16px;
    font-size: 13px !important;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--gray-25);
    color: var(--text-primary);
}

.dropdown-item a {
    color: inherit;
    text-decoration: none;
    display: block;
}

.dropdown-item.logout a {
    color: var(--danger);
}

/* ── Profile Dropdown ── */
.profile-dropdown {
    min-width: 220px;
}

.profile-dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
}

.profile-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.profile-info {
    display: flex;
    flex-direction: column;
}

.profile-name {
    font-size: 13px !important;
    font-weight: 600;
    color: var(--text-primary);
}

.profile-role {
    font-size: 11px !important;
    color: var(--text-muted);
}

/* ── Flag Dropdown Tabs ── */
.dropdown-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-light);
}

.dropdown-tab {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 12px !important;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

.dropdown-tab:hover {
    color: var(--text-primary);
}

.dropdown-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.dropdown-tab-content {
    max-height: 200px;
    overflow-y: auto;
}

/* ═══════════════════════════════════════════════
   Page Structure Classes
   Enterprise-grade reusable layout components
   ═══════════════════════════════════════════════ */

/* ── Page Wrapper ── */
.page-wrapper {
    position: absolute;
    left: var(--sidebar-w);
    top: var(--header-h);
    right: 0;
    bottom: 0;
    background: var(--bg-page);
    overflow-y: auto;
}

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

.page-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-7) var(--space-7) var(--space-10);
    animation: fadeInContent 0.2s ease-out;
}

.page-inner-wide {
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--space-7) var(--space-7) var(--space-10);
    animation: fadeInContent 0.2s ease-out;
}

.page-inner-full {
    padding: var(--space-6) var(--space-7) var(--space-10);
    animation: fadeInContent 0.2s ease-out;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
}

.page-header h1 {
    font-size: var(--text-3xl);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-header-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

/* ── Back Link ── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-md);
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: var(--space-4);
    transition: color var(--transition-fast);
}

.back-link:hover {
    color: var(--accent);
}

/* ── Section Card ── */
.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-6);
    overflow: hidden;
}

.section-card-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-card-header h2 {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
}

.section-card-body {
    padding: var(--space-6);
}

.section-card-body-flush {
    padding: 0;
}

/* ── KPI Grid ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.kpi-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.kpi-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.kpi-grid-5 {
    grid-template-columns: repeat(5, 1fr);
}

/* ── Data Table Container ── */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: var(--space-6);
}

.table-card-header {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-card-header h2,
.table-card-header h3 {
    font-size: var(--text-lg);
    font-weight: 600;
}

/* ── Filter Bar ── */
.filter-bar {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
    width: auto;
    min-width: 160px;
}

/* ── Form Layout ── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-5);
}

.form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-group {
    margin-bottom: var(--space-5);
}

.form-group label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
    letter-spacing: 0.01em;
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    padding-top: var(--space-5);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-6);
}

/* ── Detail Page Layout ── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--space-6);
}

.detail-main {
    min-width: 0;
}

.detail-sidebar {
    min-width: 0;
}

/* ── Stat Row (inline stats) ── */
.stat-row {
    display: flex;
    gap: var(--space-6);
    margin-bottom: var(--space-5);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.stat-label {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
}

/* ── List items ── */
.list-item {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background var(--transition-fast);
}

.list-item:hover {
    background: var(--gray-25);
}

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

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-6);
    color: var(--text-muted);
}

.empty-state p {
    font-size: var(--text-md);
    color: var(--text-muted);
    margin-top: var(--space-2);
}

/* ── Subpage Tabs (horizontal nav within page) ── */
.page-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-default);
    margin-bottom: var(--space-6);
}

.page-tab {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all var(--transition-fast);
}

.page-tab:hover {
    color: var(--text-primary);
}

.page-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ── Action Buttons Group ── */
.action-group {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

/* ── Two Column Layout ── */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
}

.three-col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--space-6);
}

/* ═══════════════════════════════════════════════
   Advanced UI Enhancements
   ═══════════════════════════════════════════════ */

/* Duplicate sidebar tooltip rules removed — handled by .sidebar-icon[data-tooltip] rules above */

/* ── Entrance Animations ── */
@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeSlideUp 0.35s ease forwards;
}

.animate-in:nth-child(1) {
    animation-delay: 0s;
}

.animate-in:nth-child(2) {
    animation-delay: 0.04s;
}

.animate-in:nth-child(3) {
    animation-delay: 0.08s;
}

.animate-in:nth-child(4) {
    animation-delay: 0.12s;
}

.animate-in:nth-child(5) {
    animation-delay: 0.16s;
}

.animate-in:nth-child(6) {
    animation-delay: 0.2s;
}

.animate-in:nth-child(7) {
    animation-delay: 0.24s;
}

.animate-in:nth-child(8) {
    animation-delay: 0.28s;
}

/* ── Skeleton Loading ── */
@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--gray-50) 25%,
        var(--gray-100) 50%,
        var(--gray-50) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 14px;
    width: 60%;
    border-radius: 0;
    background: linear-gradient(
        90deg,
        var(--gray-50) 25%,
        var(--gray-100) 50%,
        var(--gray-50) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(
        90deg,
        var(--gray-50) 25%,
        var(--gray-100) 50%,
        var(--gray-50) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
    background: linear-gradient(
        90deg,
        var(--gray-50) 25%,
        var(--gray-100) 50%,
        var(--gray-50) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* ── Focus-Visible States ── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-md);
}

/* ── Better Hover Depth on Cards ── */
.card:hover,
.section-card:hover,
.kpi-card:hover,
.table-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ── Notification Badge ── */
.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-card);
}

/* ── Floating "Ask anything" bar ── */
.ai-ask-bar {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(calc(-50% + var(--sidebar-w) / 2));
    z-index: 97;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.ai-ask-bar.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(calc(-50% + var(--sidebar-w) / 2)) translateY(8px);
}

.ai-ask-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 28px;
    padding: 10px 20px;
    box-shadow: 0 4px 24px rgba(17, 24, 22, 0.10), 0 1px 4px rgba(17, 24, 22, 0.06);
    min-width: 340px;
    max-width: 480px;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.ai-ask-bar-inner:focus-within {
    border-color: var(--accent);
    box-shadow: 0 4px 24px rgba(17, 24, 22, 0.10), 0 0 0 3px rgba(var(--accent-rgb, 59, 130, 246), 0.12);
}

.ai-ask-bar-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.6;
}

.ai-ask-bar-input {
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
    font-family: inherit;
    line-height: 1.5;
}

.ai-ask-bar-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

/* ═══════════════════════════════════════════════
   AI Chat Sidebar
   ═══════════════════════════════════════════════ */

.ai-chat-panel {
    position: fixed;
    right: 0;
    top: var(--header-h);
    bottom: 0;
    width: 420px;
    background: var(--bg-card);
    border-left: 1px solid var(--border-light);
    box-shadow: -8px 0 32px rgba(17, 24, 22, 0.06), -2px 0 8px rgba(17, 24, 22, 0.03);
    z-index: 98;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

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

/* Chat Header */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
}

.ai-chat-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.ai-chat-header-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}

.ai-chat-header-btn:hover {
    background: var(--gray-50);
    color: var(--text-primary);
}

/* Chat Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message Bubble */
.ai-chat-message {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 85%;
    animation: messageSlideIn 0.25s ease-out;
}

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

.ai-chat-message.user {
    align-self: flex-end;
}

.ai-chat-message.assistant {
    align-self: flex-start;
}

.ai-chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.6;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    word-wrap: break-word;
}

.ai-chat-message.user .ai-chat-bubble {
    background: var(--accent);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 77, 64, 0.12);
}

.ai-chat-message.assistant .ai-chat-bubble {
    background: var(--gray-50, #f5f2ef);
    color: var(--text-primary);
    border: none;
    border-bottom-left-radius: 4px;
}

.ai-chat-timestamp {
    font-size: 10px;
    color: var(--text-placeholder);
    padding: 0 4px;
}

.ai-chat-message.user .ai-chat-timestamp {
    text-align: right;
}

/* Code blocks in chat */
.ai-chat-code-block {
    margin: 8px 0 4px;
    padding: 10px 12px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
}

.ai-chat-code-block code {
    font-family: inherit;
}

/* HTML preview iframe in chat */
.ai-chat-html-preview {
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    margin: 8px 0 4px;
    height: 80px;
    background: #fff;
}

/* Tool Result Display */
.ai-chat-tool-result {
    margin-top: 6px;
    padding: 10px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 12px;
}

.ai-chat-tool-name {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.ai-chat-tool-data {
    color: var(--text-secondary);
    font-family: monospace;
    white-space: pre-wrap;
}

/* Typing Indicator */
.ai-chat-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 16px;
    background: var(--gray-50, #f5f2ef);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    margin: 0 20px;
}

.ai-chat-typing.active {
    display: flex;
    gap: 5px;
    align-items: center;
    animation: messageSlideIn 0.25s ease-out;
}

.ai-chat-typing-dot {
    width: 5px;
    height: 5px;
    background: var(--text-placeholder);
    border-radius: 50%;
    animation: typingPulse 1.4s infinite ease-in-out;
}

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

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

@keyframes typingPulse {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Chat Input Area */
.ai-chat-input-area {
    padding: 12px 16px 14px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-card);
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 0;
    align-items: flex-end;
    background: var(--bg-page);
    border: 1.5px solid var(--border-default);
    border-radius: 22px;
    padding: 4px 4px 4px 0;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 77, 64, 0.07);
}

.ai-chat-input {
    flex: 1;
    min-height: 34px;
    max-height: 120px;
    padding: 7px 0 7px 16px;
    border: none;
    border-radius: 0;
    font-size: 13.5px;
    font-family: var(--font-sans);
    background: transparent;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
    color: var(--text-primary);
}

.ai-chat-input::placeholder {
    color: var(--text-placeholder);
    opacity: 0.7;
}

.ai-chat-input:focus {
    outline: none;
    box-shadow: none;
}

.ai-chat-send {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border: none;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
    flex-shrink: 0;
}

.ai-chat-send svg {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    color: var(--text-inverse);
    display: block;
}

.ai-chat-send:hover {
    background: var(--accent-hover);
    transform: scale(1.06);
}

.ai-chat-send:active {
    transform: scale(0.95);
}

.ai-chat-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

/* Session History (collapsible) */
.ai-chat-history {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-page);
}

.ai-chat-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 4px 0;
}

.ai-chat-history-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.ai-chat-history-toggle {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.ai-chat-history-toggle.expanded {
    transform: rotate(180deg);
}

.ai-chat-history-list {
    display: none;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.ai-chat-history-list.expanded {
    display: flex;
}

.ai-chat-history-item {
    padding: 6px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-history-item:hover {
    background: var(--gray-50);
    border-color: var(--border-default);
}

/* Empty State */
.ai-chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    color: var(--text-muted);
}

.ai-chat-empty-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.ai-chat-empty-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.ai-chat-empty-text {
    font-size: 12px;
    line-height: 1.5;
    max-width: 280px;
}

/* ═══════════════════════════════════════════════
   Mobile Hamburger Button
   ═══════════════════════════════════════════════ */

.mobile-hamburger {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-w);
    height: var(--header-h);
    align-items: center;
    justify-content: center;
    z-index: 102;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    transition: all 0.3s ease;
    position: relative;
}

.mobile-hamburger span::before,
.mobile-hamburger span::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    transition: all 0.3s ease;
    left: 0;
}

.mobile-hamburger span::before { top: -6px; }
.mobile-hamburger span::after { top: 6px; }

.mobile-hamburger.open span { background: transparent; }
.mobile-hamburger.open span::before { top: 0; transform: rotate(45deg); }
.mobile-hamburger.open span::after { top: 0; transform: rotate(-45deg); }

/* Mobile search button (hidden on desktop) */
.mobile-search-btn {
    display: none;
    position: fixed;
    left: var(--sidebar-w);
    top: 0;
    width: 44px;
    height: var(--header-h);
    align-items: center;
    justify-content: center;
    z-index: 102;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-search-btn img {
    width: 18px;
    height: 18px;
    opacity: 0.5;
}

/* Sidebar backdrop overlay */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 98;
}

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

/* ═══════════════════════════════════════════════
   Mobile Responsive (<= 768px)
   ═══════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Prevent horizontal overflow — use clip (not hidden) so no scroll
       container is created and content width is truly clamped. !important
       guards against analytics/tracking scripts overriding body styles. */
    html {
        overflow-x: clip !important;
    }

    body {
        overflow-x: clip !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Override figma page containers that use width: 100vw (causes viewport expansion on mobile) */
    .figma-page,
    .dashboard-figma,
    .figma-dispatch-page,
    .figma-calendar-page,
    .figma-scheduling-page,
    .figma-confirmations-page,
    .report-page {
        width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Show hamburger */
    .mobile-hamburger {
        display: flex;
    }

    /* Hide logo box (hamburger takes its place) */
    .logo-box {
        display: none;
    }

    /* Hide search bar, show mobile search icon */
    .search-bar {
        display: none;
    }

    .mobile-search-btn {
        display: flex;
    }

    /* Sidebar: hidden by default, slides in as overlay */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Top icons: shift left since search bar is gone */
    .top-icons {
        right: 48px;
    }

    /* Hide divider and plus button for space */
    .divider-line,
    .plus-button {
        display: none;
    }

    /* Profile icon: tighten */
    .profile-icon {
        right: 8px;
        width: 32px;
    }

    /* ── Content Area: remove sidebar offset ── */
    .page-wrapper {
        left: 0;
    }

    /* Override all custom page wrappers that hardcode left: 56px.
       left has no effect on non-positioned elements, so this is safe. */
    [class*="-wrapper"],
    [class*="-outer"] {
        left: 0 !important;
    }

    /* Sales module margin override */
    .sales-page {
        margin-left: 0 !important;
    }

    /* ── Layout Grids: single column ── */
    .kpi-grid, .kpi-grid-3, .kpi-grid-4, .kpi-grid-5 {
        grid-template-columns: 1fr !important;
    }

    .form-grid, .form-grid-3 {
        grid-template-columns: 1fr;
    }

    .two-col, .three-col {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    /* ── Page Header: stack on mobile ── */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    /* ── Tabs: horizontal scroll ── */
    .page-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .page-tabs::-webkit-scrollbar {
        display: none;
    }

    .page-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* ── Tables: horizontal scroll ── */
    .table-card,
    .cust-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        max-width: 100%;
    }

    /* ── Reduce padding on mobile ── */
    .page-inner, .page-inner-wide, .page-inner-full {
        padding: 16px 12px 24px;
    }

    /* ── AI chat + sales script panels full width ── */
    .ai-chat-panel {
        width: 100%;
        max-width: none;
    }

    /* ── Floating ask bar: center without sidebar offset ── */
    .ai-ask-bar {
        transform: translateX(-50%);
        bottom: 20px;
    }
    .ai-ask-bar.hidden {
        transform: translateX(-50%) translateY(8px);
    }
    .ai-ask-bar-inner {
        min-width: 280px;
    }

    .sales-script-panel {
        width: 100%;
    }

    /* ── Stat row wrap ── */
    .stat-row {
        flex-wrap: wrap;
        gap: var(--space-4);
    }

    /* ── Action groups wrap ── */
    .action-group {
        flex-wrap: wrap;
    }

    /* ── Filter bar ── */
    .filter-bar select,
    .filter-bar input {
        min-width: 0;
        flex: 1;
    }

    /* ── Account pages: tighten card padding ── */
    .page-login .login-card {
        padding: 32px 20px;
        margin: 16px;
        max-width: none;
    }

    .page-login .login-title {
        font-size: 20px;
    }

    /* ── Header dropdowns: constrain width ── */
    .header-dropdown {
        max-width: calc(100vw - 24px);
    }

    /* ── Job Detail: stack sidebar below main ── */
    .jd-wrapper {
        bottom: auto !important;
        overflow: visible !important;
    }

    .jd-content {
        flex-direction: column !important;
        overflow: visible !important;
    }

    .jd-main {
        overflow-y: visible !important;
    }

    .jd-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        border-left: none !important;
        border-top: 1px solid var(--border-light);
    }

    .jd-tabs {
        flex-wrap: wrap !important;
        gap: 0 var(--space-4) !important;
    }

    .jd-tab {
        white-space: nowrap !important;
    }

    .jd-customer-bar {
        flex-wrap: wrap !important;
        padding: 8px 12px !important;
        gap: 4px 12px !important;
    }

    .jd-cust-followup {
        display: none !important;
    }

    .comm-subtabs {
        overflow: visible !important;
    }

    .comm-subtab {
        flex: 1 1 0 !important;
        padding: 8px 4px !important;
        font-size: 11px !important;
    }

    .comm-subtab svg {
        display: none !important;
    }

    .comm-form-row {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .comm-form-row select,
    .comm-form-row input {
        min-width: 120px !important;
    }

    /* ── Job Calendar: scroll instead of squish ── */
    .jc-calendar-card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .jc-grid {
        min-width: 580px !important;
    }
}

/* ═══════════════════════════════════════════════
   Small Phone (<= 480px)
   ═══════════════════════════════════════════════ */

@media (max-width: 480px) {
    .top-icons {
        gap: 0;
        right: 40px;
    }

    .top-icon {
        width: 28px;
        height: 28px;
    }

    .profile-icon {
        right: 4px;
        width: 28px;
    }

    .profile-icon img {
        width: 24px;
        height: 24px;
    }

    .page-inner, .page-inner-wide, .page-inner-full {
        padding: 12px 8px 20px;
    }

    .page-login .login-card {
        padding: 24px 16px;
        margin: 8px;
    }
}
