/* ============================================================
   Mobile Helpdesk — Material Design 3 (React Native Paper style)
   ============================================================ */

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

/* --- M3 Color Tokens --- */
:root {
    --md-primary: #6366F1;
    --md-on-primary: #FFFFFF;
    --md-primary-container: #E8DEF8;
    --md-on-primary-container: #21005D;
    --md-secondary: #625B71;
    --md-on-secondary: #FFFFFF;
    --md-secondary-container: #E8DEF8;
    --md-on-secondary-container: #1D192B;
    --md-tertiary: #7D5260;
    --md-tertiary-container: #FFD8E4;
    --md-on-tertiary-container: #31111D;
    --md-surface: #FFFBFE;
    --md-surface-variant: #E7E0EC;
    --md-surface-container: #F3EDF7;
    --md-surface-container-low: #F7F2FA;
    --md-surface-container-high: #ECE6F0;
    --md-surface-container-highest: #E6E0E9;
    --md-on-surface: #1C1B1F;
    --md-on-surface-variant: #49454F;
    --md-outline: #79747E;
    --md-outline-variant: #CAC4D0;
    --md-background: #FFFBFE;
    --md-error: #B3261E;
    --md-on-error: #FFFFFF;
    --md-error-container: #F9DEDC;
    --md-on-error-container: #410E0B;
    --md-success: #2E7D32;
    --md-success-container: #C8E6C9;
    --md-warning: #F9A825;
    --md-warning-container: #FFF9C4;
    --md-inverse-surface: #313033;
    --md-inverse-on-surface: #F4EFF4;
    /* Elevation overlays */
    --md-elevation-1: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
    --md-elevation-2: 0 1px 2px rgba(0,0,0,0.3), 0 2px 6px 2px rgba(0,0,0,0.15);
    --md-elevation-3: 0 4px 8px 3px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.3);
    /* Shape */
    --md-shape-xs: 4px;
    --md-shape-sm: 8px;
    --md-shape-md: 12px;
    --md-shape-lg: 16px;
    --md-shape-xl: 28px;
    --md-shape-full: 9999px;
    /* Font */
    --md-font: 'Roboto', 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --md-primary: #D0BCFF;
        --md-on-primary: #381E72;
        --md-primary-container: #4F378B;
        --md-on-primary-container: #EADDFF;
        --md-secondary: #CCC2DC;
        --md-on-secondary: #332D41;
        --md-secondary-container: #4A4458;
        --md-on-secondary-container: #E8DEF8;
        --md-tertiary: #EFB8C8;
        --md-tertiary-container: #633B48;
        --md-on-tertiary-container: #FFD8E4;
        --md-surface: #1C1B1F;
        --md-surface-variant: #49454F;
        --md-surface-container: #211F26;
        --md-surface-container-low: #1D1B20;
        --md-surface-container-high: #2B2930;
        --md-surface-container-highest: #36343B;
        --md-on-surface: #E6E1E5;
        --md-on-surface-variant: #CAC4D0;
        --md-outline: #938F99;
        --md-outline-variant: #49454F;
        --md-background: #1C1B1F;
        --md-error: #F2B8B5;
        --md-on-error: #601410;
        --md-error-container: #8C1D18;
        --md-on-error-container: #F9DEDC;
        --md-success: #81C784;
        --md-success-container: #1B5E20;
        --md-warning: #FFD54F;
        --md-warning-container: #F57F17;
        --md-inverse-surface: #E6E1E5;
        --md-inverse-on-surface: #313033;
    }
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--md-font);
    background: var(--md-background);
    color: var(--md-on-surface);
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    line-height: 1.43;
}

a { color: inherit; text-decoration: none; }

/* --- Phone Frame (iPhone 15/16: 393×852 logical points) --- */
@media (min-width: 500px) {
    body { background: #121212; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
    .phone-frame {
        width: 393px;
        height: 852px;
        margin: 24px auto;
        box-shadow: 0 0 60px rgba(0,0,0,0.5);
        border-radius: 47px;
        overflow: hidden;
    }
}

.phone-frame {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--md-background);
    overflow: hidden;
}

@media (min-width: 500px) {
    .phone-frame { height: 852px; }
}

/* --- Page --- */
.md-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* --- M3 Top App Bar (small) --- */
.md-appbar {
    display: flex;
    align-items: center;
    min-height: 64px;
    padding: 0 8px;
    padding-top: 54px; /* iOS status bar / Dynamic Island safe area */
    background: var(--md-surface);
    flex-shrink: 0;
    z-index: 10;
}

.md-appbar--elevated {
    box-shadow: var(--md-elevation-2);
}

.md-appbar-nav,
.md-appbar-action {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--md-shape-full);
    cursor: pointer;
    color: var(--md-on-surface);
    flex-shrink: 0;
}

.md-appbar-nav:active,
.md-appbar-action:active {
    background: var(--md-surface-container-highest);
}

.md-appbar-nav svg,
.md-appbar-action svg { width: 24px; height: 24px; }

.md-appbar-title {
    flex: 1;
    padding: 0 4px;
    min-width: 0;
}

.md-appbar-title-text {
    font-size: 22px;
    font-weight: 400;
    line-height: 28px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-appbar-title-sub {
    font-size: 12px;
    line-height: 16px;
    color: var(--md-on-surface-variant);
}

/* --- M3 Segmented Button --- */
.md-segmented-btn {
    display: flex;
    border: 1px solid var(--md-outline);
    border-radius: var(--md-shape-full);
    overflow: hidden;
    margin: 0 8px 8px;
}

.md-segmented-btn-item {
    flex: 1;
    text-align: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--md-font);
    color: var(--md-on-surface);
    cursor: pointer;
    border-right: 1px solid var(--md-outline);
}

.md-segmented-btn-item:last-child { border-right: none; }

.md-segmented-btn-item--active {
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
}

/* --- M3 Search Bar --- */
.md-search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 16px 8px;
    padding: 12px 16px;
    background: var(--md-surface-container-high);
    border-radius: var(--md-shape-full);
    flex-shrink: 0;
    cursor: text;
}

.md-search-bar svg {
    color: var(--md-on-surface-variant);
    flex-shrink: 0;
}

.md-search-bar-text {
    font-size: 16px;
    line-height: 24px;
    color: var(--md-on-surface-variant);
    flex: 1;
}

.md-search-bar-menu-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--md-shape-full);
    cursor: pointer;
    color: var(--md-on-surface-variant);
    margin: -4px -4px -4px -8px;
}

.md-search-bar-menu-btn:active { background: var(--md-surface-container-highest); }
.md-search-bar-menu-btn svg { width: 22px; height: 22px; }

/* --- Navigation Drawer (Gmail-style) --- */
.md-drawer {
    width: 280px;
    background: var(--md-surface-container-low);
    border-radius: 0 var(--md-shape-lg) var(--md-shape-lg) 0;
    box-shadow: var(--md-elevation-3);
    overflow: hidden;
}

.md-drawer-header {
    padding: 24px 16px 16px;
}

.md-drawer-header-name {
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    color: var(--md-on-surface);
}

.md-drawer-header-email {
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
}

.md-drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    border-radius: 0 var(--md-shape-full) var(--md-shape-full) 0;
    margin-right: 12px;
}

.md-drawer-item:active { background: var(--md-surface-container-highest); }

.md-drawer-item svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.md-drawer-item--active {
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
}

.md-drawer-item-badge {
    margin-left: auto;
    font-size: 12px;
    font-weight: 500;
}

.md-drawer-divider {
    height: 1px;
    background: var(--md-outline-variant);
    margin: 8px 0;
}

/* --- View Title (below search bar) --- */
.md-view-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px 8px;
    flex-shrink: 0;
}

.md-view-title-text {
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    color: var(--md-on-surface);
}

.md-view-title-count {
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
    color: var(--md-on-surface-variant);
}

/* --- Editor Card (V2 ticket detail) --- */
.md-editor-card {
    background: var(--md-surface);
    border-bottom: 1px solid var(--md-outline-variant);
    padding: 0 0 12px;
    flex-shrink: 0;
}

.md-editor-tabs {
    display: flex;
    border-bottom: 1px solid var(--md-outline-variant);
}

.md-editor-tabs button {
    flex: 1;
    height: 48px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--md-font);
    color: var(--md-on-surface-variant);
    cursor: pointer;
    position: relative;
}

.md-editor-tabs button.active {
    color: var(--md-primary);
}

.md-editor-tabs button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 3px;
    background: var(--md-primary);
    border-radius: 3px 3px 0 0;
}

.md-editor-tabs button.active-internal {
    color: var(--md-tertiary);
}

.md-editor-tabs button.active-internal::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 3px;
    background: var(--md-tertiary);
    border-radius: 3px 3px 0 0;
}

.md-editor-area {
    margin: 12px 16px 0;
    min-height: 80px;
    padding: 12px;
    border-radius: var(--md-shape-sm);
    border: 1px solid var(--md-outline-variant);
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
}

.md-editor-toolbar {
    display: flex;
    align-items: center;
    padding: 8px 12px 0;
    gap: 4px;
}

.md-editor-toolbar-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--md-shape-full);
    cursor: pointer;
    color: var(--md-on-surface-variant);
}

.md-editor-toolbar-btn svg { width: 20px; height: 20px; }

.md-editor-send {
    margin-left: auto;
    height: 40px;
    padding: 0 24px;
    border-radius: var(--md-shape-full);
    background: var(--md-primary);
    color: var(--md-on-primary);
    border: none;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--md-font);
    cursor: pointer;
}

.md-editor-send:active { opacity: 0.85; }

/* --- History Items (V2 email-style message cards) --- */
.md-history {
    padding: 0;
}

.md-history-item {
    border-bottom: 1px solid var(--md-outline-variant);
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface);
}

/* Envelope header (From row) */
.md-history-envelope {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
}

.md-history-envelope-right {
    flex: 1;
    min-width: 0;
}

.md-history-from {
    font-size: 13px;
    font-weight: 600;
    color: var(--md-on-surface);
    display: flex;
    align-items: center;
}

.md-history-meta {
    font-size: 11px;
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.md-history-time {
    font-size: 11px;
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Message body */
.md-history-body {
    padding: 0 16px 14px;
    font-size: 14px;
    line-height: 22px;
}

.md-history-body p {
    margin: 0 0 8px;
}

.md-history-body p:last-child {
    margin-bottom: 0;
}

/* Customer messages */
.md-history-item--in {
    background: var(--md-surface);
}

/* Agent messages */
.md-history-item--out {
    background: var(--md-surface-container-low);
}

/* Internal notes */
.md-history-item--internal {
    background: #FFF8E1;
}

/* --- Online Dot (visitor status) --- */
.md-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--md-shape-full);
    background: #22C55E;
    flex-shrink: 0;
}

.md-online-dot--away { background: #F59E0B; }
.md-online-dot--offline { background: #9CA3AF; }

/* --- Agent Status Dot (on account chip) --- */
.md-status-dot {
    width: 10px;
    height: 10px;
    border-radius: var(--md-shape-full);
    border: 2px solid var(--md-surface);
    position: absolute;
    bottom: -1px;
    right: -1px;
}

.md-status-dot--online { background: #22C55E; }
.md-status-dot--away { background: #F59E0B; }
.md-status-dot--offline { background: #9CA3AF; }

/* --- Chat Tabs (Active / History) --- */
.md-chat-tabs {
    display: flex;
    border-bottom: 1px solid var(--md-outline-variant);
    flex-shrink: 0;
}

.md-chat-tabs a,
.md-chat-tabs button {
    flex: 1;
    height: 48px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--md-font);
    color: var(--md-on-surface-variant);
    cursor: pointer;
    position: relative;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.md-chat-tabs a.active,
.md-chat-tabs button.active {
    color: var(--md-primary);
}

.md-chat-tabs a.active::after,
.md-chat-tabs button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 3px;
    background: var(--md-primary);
    border-radius: 3px 3px 0 0;
}

/* --- Chat List Item Enhancements --- */
.md-chat-preview {
    font-size: 13px;
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Info Section Headers (bottom sheet) --- */
.md-info-section {
    padding: 16px 16px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--md-on-surface-variant);
}

/* --- Order Row --- */
.md-order-row {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 14px;
    gap: 8px;
}

.md-order-row-code {
    font-weight: 500;
    color: var(--md-on-surface);
}

.md-order-row-amount {
    color: var(--md-on-surface);
}

.md-order-row-date {
    margin-left: auto;
    font-size: 12px;
    color: var(--md-on-surface-variant);
}

/* --- Custom Field Row --- */
.md-field-row {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 14px;
}

.md-field-row-label {
    color: var(--md-on-surface-variant);
    min-width: 100px;
}

.md-field-row-value {
    color: var(--md-on-surface);
    font-weight: 500;
    margin-left: auto;
}

/* --- Status Option (agent status selector) --- */
.md-status-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    font-size: 16px;
    cursor: pointer;
}

.md-status-option-dot {
    width: 12px;
    height: 12px;
    border-radius: var(--md-shape-full);
    flex-shrink: 0;
}

.md-status-option-text {
    flex: 1;
}

.md-status-option-desc {
    font-size: 13px;
    color: var(--md-on-surface-variant);
}

.md-status-option--active {
    background: var(--md-surface-container-high);
}

/* --- Closed Conversation Banner --- */
.md-closed-banner {
    padding: 14px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--md-on-surface-variant);
    background: var(--md-surface-container-high);
    border-top: 1px solid var(--md-outline-variant);
    flex-shrink: 0;
}

/* --- Section Header (chat list groups) --- */
.md-section-header {
    padding: 20px 16px 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--md-on-surface-variant);
}

/* --- Muted List Item (idle chats) --- */
.md-list-item--muted {
    opacity: 0.7;
}

/* --- Visitor Browsing Info --- */
.md-visitor-page {
    font-size: 13px;
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Roboto Mono', monospace;
}

/* --- Agent Chip (in chat list items) --- */
.md-agent-chip {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 6px;
    border-radius: var(--md-shape-full);
    font-size: 11px;
    font-weight: 500;
    line-height: 18px;
    background: var(--md-surface-container-high);
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    flex-shrink: 0;
}

.md-agent-chip--you {
    background: rgba(99, 102, 241, 0.12);
    color: var(--md-primary);
}

/* --- Section Header Variants --- */
.md-section-header--warning {
    color: #B45309;
}

/* --- Assignee Badge --- */
.md-assignee {
    color: var(--md-on-surface-variant);
}
.md-assignee--none {
    color: var(--md-outline);
    font-style: italic;
}

/* --- Scrollable Content --- */
.md-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- M3 List Item --- */
.md-list-item {
    display: flex;
    align-items: center;
    min-height: 72px;
    padding: 8px 16px 8px 16px;
    gap: 16px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}

.md-list-item:active {
    background: rgba(28, 27, 31, 0.08);
}

@media (prefers-color-scheme: dark) {
    .md-list-item:active {
        background: rgba(230, 225, 229, 0.08);
    }
}

.md-list-item-leading {
    flex-shrink: 0;
}

.md-list-item-content {
    flex: 1;
    min-width: 0;
}

.md-list-item-headline {
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: var(--md-on-surface);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-list-item-headline--bold {
    font-weight: 500;
}

.md-list-item-supporting {
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.md-list-item-trailing {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.md-list-item-trailing-text {
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    letter-spacing: 0.5px;
    color: var(--md-on-surface-variant);
}

/* --- Divider --- */
.md-divider {
    height: 1px;
    background: var(--md-outline-variant);
    margin: 0 16px;
}

.md-divider--full { margin: 0; }

/* --- Avatar --- */
.md-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: var(--md-shape-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 500;
    color: #FFFFFF;
}

/* --- Chip (Assist/Filter style) --- */
.md-chip {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 10px;
    border-radius: var(--md-shape-sm);
    font-size: 12px;
    font-weight: 500;
    line-height: 16px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    gap: 4px;
}

/* --- Badge dot --- */
.md-badge-dot {
    width: 8px;
    height: 8px;
    min-width: 8px;
    border-radius: var(--md-shape-full);
    background: var(--md-primary);
}

/* --- Priority dot --- */
.md-priority-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    border-radius: var(--md-shape-full);
}

/* --- Badges row --- */
.md-list-item-badges {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- M3 Navigation Bar --- */
.md-nav-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 80px;
    background: var(--md-surface-container);
    box-shadow: var(--md-elevation-2);
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.md-nav-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 0 16px;
    flex: 1;
    position: relative;
    color: var(--md-on-surface-variant);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.5px;
    line-height: 16px;
}

.md-nav-bar-item svg { width: 24px; height: 24px; position: relative; z-index: 1; }

/* Pill-shaped active indicator */
.md-nav-bar-item--active {
    color: var(--md-on-surface);
}

.md-nav-bar-item--active .md-nav-bar-indicator {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 64px;
    height: 32px;
    background: var(--md-secondary-container);
    border-radius: var(--md-shape-lg);
    z-index: 0;
}

.md-nav-bar-item--active svg {
    color: var(--md-on-secondary-container);
}

.md-nav-bar-label { position: relative; z-index: 1; }

/* --- Account Chip (in app bar) --- */
.md-account-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px 4px 4px;
    background: var(--md-surface-container-high);
    border: none;
    border-radius: var(--md-shape-full);
    cursor: pointer;
    color: var(--md-on-surface-variant);
    flex-shrink: 0;
    font-family: var(--md-font);
}

.md-account-chip:active {
    background: var(--md-surface-container-highest);
}

.md-account-chip-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: var(--md-shape-full);
    background: var(--md-primary);
    color: var(--md-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 500;
}

/* --- M3 Card (filled) --- */
.md-card {
    background: var(--md-surface-container-low);
    border-radius: var(--md-shape-md);
    overflow: hidden;
}

.md-card--outlined {
    background: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
}

.md-card--elevated {
    background: var(--md-surface-container-low);
    box-shadow: var(--md-elevation-1);
}

/* --- Message Bubbles --- */
.md-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

.md-msg-row {
    display: flex;
    margin-bottom: 12px;
}

.md-msg-row--in { justify-content: flex-start; }
.md-msg-row--out { justify-content: flex-end; }

.md-msg-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 20px 20px 20px 4px;
    background: var(--md-surface-container-high);
    color: var(--md-on-surface);
    font-size: 16px;
    line-height: 24px;
}

.md-msg-bubble--out {
    background: var(--md-primary);
    color: var(--md-on-primary);
    border-radius: 20px 20px 4px 20px;
}

.md-msg-bubble--internal {
    background: var(--md-tertiary-container);
    color: var(--md-on-tertiary-container);
    border-radius: 20px 20px 4px 20px;
}

.md-msg-meta {
    margin-top: 6px;
    font-size: 11px;
    line-height: 16px;
    opacity: 0.7;
}

.md-msg-row--out .md-msg-meta { text-align: right; }

.md-msg-attachment {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.15);
}

.md-msg-attachment svg { width: 14px; height: 14px; flex-shrink: 0; }

/* --- Footer Input --- */
.md-footer {
    border-top: 1px solid var(--md-outline-variant);
    background: var(--md-surface);
    padding: 6px 8px 10px;
    flex-shrink: 0;
}

.md-footer--internal {
    background: var(--md-tertiary-container);
}

.md-footer-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.md-footer-field {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 6px 6px 16px;
    border-radius: var(--md-shape-full);
    background: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    min-height: 44px;
    font-size: 16px;
    font-family: var(--md-font);
    color: var(--md-on-surface-variant);
}

.md-footer-field-text {
    flex: 1;
    min-width: 0;
}

.md-footer-field-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--md-shape-full);
    cursor: pointer;
    color: var(--md-on-surface-variant);
}

.md-footer-field-btn svg { width: 20px; height: 20px; }

/* Send button (inside field) */
.md-send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: var(--md-shape-full);
    background: var(--md-primary);
    color: var(--md-on-primary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.md-send-btn:active { opacity: 0.85; }
.md-send-btn svg { width: 18px; height: 18px; }

/* + button */
.md-footer-icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--md-shape-full);
    cursor: pointer;
    color: var(--md-on-surface-variant);
}

.md-footer-icon-btn svg { width: 22px; height: 22px; }

.md-footer-toggle-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 4px 8px 0;
    gap: 12px;
}

.md-footer-toggle-label {
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
}

/* --- M3 Switch --- */
.md-switch {
    width: 52px;
    height: 32px;
    background: var(--md-surface-container-highest);
    border: 2px solid var(--md-outline);
    border-radius: var(--md-shape-full);
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}

.md-switch::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: var(--md-shape-full);
    background: var(--md-outline);
    top: 6px;
    left: 6px;
    transition: all 0.2s;
}

.md-switch--on {
    background: var(--md-primary);
    border-color: var(--md-primary);
}

.md-switch--on::after {
    background: var(--md-on-primary);
    width: 24px;
    height: 24px;
    top: 2px;
    left: 22px;
}

/* --- Customer Info Bar --- */
.md-info-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--md-surface-container-low);
    cursor: pointer;
    flex-shrink: 0;
}

.md-info-bar svg { width: 20px; height: 20px; color: var(--md-on-surface-variant); flex-shrink: 0; }

.md-info-bar-text {
    flex: 1;
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-info-bar-chevron {
    width: 20px;
    height: 20px;
    color: var(--md-on-surface-variant);
    flex-shrink: 0;
}

/* --- Detail Header --- */
.md-detail-header {
    background: var(--md-surface);
    flex-shrink: 0;
    z-index: 10;
    padding-top: 54px; /* iOS status bar / Dynamic Island safe area */
}

.md-detail-header-row {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 6px 4px;
}

.md-detail-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: var(--md-shape-full);
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    position: relative;
    cursor: pointer;
}

.md-detail-header-center {
    flex: 1;
    min-width: 0;
}

.md-detail-header-title {
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.md-detail-header-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-detail-header-sub {
    font-size: 12px;
    line-height: 16px;
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    gap: 2px;
    overflow: hidden;
}

.md-detail-header-sub span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-detail-header-sub svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--md-on-surface-variant);
}

/* --- Login Styles --- */
.md-login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 54px 24px 32px; /* top accounts for status bar */
    flex: 1;
}

.md-login-logo {
    width: 80px;
    height: 80px;
    border-radius: var(--md-shape-xl);
    background: var(--md-primary-container);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.md-login-logo svg {
    width: 40px;
    height: 40px;
    color: var(--md-on-primary-container);
}

.md-login-title {
    font-size: 32px;
    font-weight: 400;
    line-height: 40px;
    margin-bottom: 8px;
}

.md-login-subtitle {
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
    margin-bottom: 36px;
}

.md-login-form {
    width: 100%;
    max-width: 340px;
}

/* --- M3 Outlined Text Field --- */
.md-text-field {
    position: relative;
    margin-bottom: 16px;
}

.md-text-field input {
    display: block;
    width: 100%;
    height: 56px;
    padding: 16px;
    border: 1px solid var(--md-outline);
    border-radius: var(--md-shape-xs);
    background: transparent;
    font-size: 16px;
    font-family: var(--md-font);
    color: var(--md-on-surface);
    outline: none;
    transition: border-color 0.15s;
}

.md-text-field input:focus {
    border-color: var(--md-primary);
    border-width: 2px;
    padding: 15px;
}

.md-text-field label {
    position: absolute;
    top: -8px;
    left: 12px;
    padding: 0 4px;
    background: var(--md-background);
    font-size: 12px;
    font-weight: 400;
    line-height: 16px;
    color: var(--md-primary);
}

/* --- M3 Filled Button --- */
.md-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 40px;
    border: none;
    border-radius: var(--md-shape-full);
    background: var(--md-primary);
    color: var(--md-on-primary);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--md-font);
    letter-spacing: 0.1px;
    cursor: pointer;
    margin-top: 8px;
}

.md-button:active { opacity: 0.88; }

.md-button--text {
    background: none;
    color: var(--md-primary);
    margin-top: 4px;
}

.md-button--large {
    height: 48px;
    font-size: 16px;
}

/* --- 2FA text --- */
.md-2fa-text {
    text-align: center;
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface-variant);
    margin-bottom: 24px;
}

/* --- Action Sheet / Bottom Sheet (static previews) --- */
.md-preview-section {
    margin: 32px 16px;
    padding-top: 24px;
    border-top: 2px dashed var(--md-outline-variant);
}

.md-preview-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--md-on-surface-variant);
    margin-bottom: 12px;
}

/* M3 Menu / Action Sheet */
.md-menu {
    background: var(--md-surface-container);
    border-radius: var(--md-shape-xs);
    box-shadow: var(--md-elevation-2);
    overflow: hidden;
    margin-bottom: 8px;
}

.md-menu-item {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 20px;
    color: var(--md-on-surface);
    cursor: pointer;
}

.md-menu-item:active { background: var(--md-surface-container-highest); }
.md-menu-item--danger { color: var(--md-error); }

/* M3 Bottom Sheet */
.md-bottom-sheet {
    background: var(--md-surface-container-low);
    border-radius: var(--md-shape-xl) var(--md-shape-xl) 0 0;
    box-shadow: var(--md-elevation-3);
    overflow: hidden;
    margin-top: 16px;
}

.md-bottom-sheet-handle {
    width: 32px;
    height: 4px;
    background: var(--md-on-surface-variant);
    border-radius: 2px;
    margin: 12px auto 0;
    opacity: 0.4;
}

.md-bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px 12px;
}

.md-bottom-sheet-title {
    font-size: 22px;
    font-weight: 400;
    line-height: 28px;
}

.md-bottom-sheet-btn {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-primary);
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--md-font);
}

.md-bottom-sheet-body { padding: 0 24px 24px; }

.md-bottom-sheet-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 20px;
}

.md-bottom-sheet-row svg {
    width: 20px;
    height: 20px;
    color: var(--md-on-surface-variant);
    flex-shrink: 0;
}

.md-bottom-sheet-row-big { font-size: 22px; font-weight: 400; line-height: 28px; }

.md-bottom-sheet-divider {
    height: 1px;
    background: var(--md-outline-variant);
    margin: 16px 0;
}

.md-bottom-sheet-section {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
}

.md-bottom-sheet-section svg { width: 20px; height: 20px; color: var(--md-on-surface-variant); }

.md-bottom-sheet-ticket {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 8px 32px;
    font-size: 14px;
}

/* --- Empty State --- */
.md-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--md-on-surface-variant);
    font-size: 14px;
}

/* --- Search Page --- */
.md-search-input {
    flex: 1;
    border: none;
    background: none;
    font-size: 16px;
    line-height: 24px;
    color: var(--md-on-surface);
    outline: none;
    min-width: 0;
}
.md-search-input::placeholder {
    color: var(--md-on-surface-variant);
}

.md-filter-chips {
    display: flex;
    gap: 8px;
    padding: 4px 16px 8px;
    overflow-x: auto;
    flex-shrink: 0;
}
.md-filter-chips::-webkit-scrollbar { display: none; }

.md-filter-chip {
    height: 32px;
    padding: 0 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--md-outline-variant);
    background: var(--md-surface);
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}
.md-filter-chip--active {
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
    border-color: transparent;
}

.md-search-result-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.md-search-result-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--md-primary);
}

mark {
    background: rgba(99, 102, 241, 0.15);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.md-search-show-all {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-primary);
    cursor: pointer;
    text-decoration: none;
}
.md-search-show-all svg {
    color: var(--md-primary);
}

.md-search-load-more {
    margin: 16px;
    padding: 12px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-primary);
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-shape-md);
    cursor: pointer;
}
.md-search-load-more:active {
    background: var(--md-surface-container-high);
}

/* --- Utility --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}
