/* ==========================================================================
   BOM CHATBOT - COMPACT MOBILE-FIRST APP DESIGN
   Optimized for Phones & Desktops, Segmented Tabs, 100dvh, Touch Friendly
   ========================================================================== */

:root {
    /* Dark Palette (Default) */
    --bg-app: #080c14;
    --bg-card: #111827;
    --bg-card-subtle: #1f2937;
    --bg-nav: rgba(17, 24, 39, 0.92);
    --border: rgba(255, 255, 255, 0.09);
    --border-active: rgba(59, 130, 246, 0.4);

    --text-main: #f9fafb;
    --text-sub: #9ca3af;
    --text-muted: #6b7280;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.15);

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.25);

    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
    --bg-app: #f1f5f9;
    --bg-card: #ffffff;
    --bg-card-subtle: #f8fafc;
    --bg-nav: rgba(255, 255, 255, 0.96);
    --border: rgba(0, 0, 0, 0.09);
    --border-active: rgba(37, 99, 235, 0.4);

    --text-main: #0f172a;
    --text-sub: #334155;
    --text-muted: #64748b;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(37, 99, 235, 0.08);

    --success: #059669;
    --success-bg: rgba(5, 150, 105, 0.1);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.1);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.1);

    --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .bubble,
[data-theme="light"] .message-bubble,
[data-theme="light"] .bom-single-card,
[data-theme="light"] .compact-fixed-table,
[data-theme="light"] .table-scroll-container,
[data-theme="light"] .catalog-item-compact,
[data-theme="light"] .compact-card {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .badge-layer {
    background-color: rgba(109, 40, 217, 0.1);
    color: #6d28d9;
}

[data-theme="light"] .badge-info {
    background-color: rgba(2, 132, 199, 0.1);
    color: #0284c7;
}

[data-theme="light"] .ratio-pill {
    background: rgba(37, 99, 235, 0.1);
    color: #1d4ed8;
}

[data-theme="light"] .thickness-chip {
    background: rgba(5, 150, 105, 0.1);
    color: #059669;
    border-color: rgba(5, 150, 105, 0.25);
}

[data-theme="light"] .meta-tag {
    background: #f1f5f9;
    color: #475569;
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .filter-pill {
    background: #ffffff;
    color: #475569;
    border-color: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .filter-pill.active {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

[data-theme="light"] .data-table th,
[data-theme="light"] .compact-fixed-table th {
    background: #f8fafc;
    color: #475569;
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .data-table tr:hover td {
    background: rgba(0, 0, 0, 0.02);
}

/* Global Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.45;
}

/* App Container - Centered on Desktop, Fullscreen on Mobile */
.mobile-app-container {
    max-width: 860px;
    height: 100%;
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-app);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    position: relative;
    box-shadow: var(--shadow-soft);
}

/* TOP APP BAR */
.top-nav {
    height: 54px;
    padding: 0 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-nav);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 20;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.portal-return-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 9px;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.76rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    flex-shrink: 0;
}

.portal-return-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateX(-2px);
}

.portal-return-btn svg {
    transition: transform 0.2s ease;
}

.portal-return-btn:hover svg {
    transform: translateX(-2px);
}

.nav-brand-icon {
    font-size: 1.35rem;
}

.nav-brand-logo {
    height: 28px;
    width: auto;
    max-width: 105px;
    object-fit: contain;
    display: inline-block;
    flex-shrink: 0;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

[data-theme="light"] .nav-brand-logo {
    filter: brightness(0);
}

.nav-titles {
    display: flex;
    flex-direction: column;
}

.nav-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--text-sub);
    cursor: pointer;
    white-space: nowrap;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background-color: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-dot.warning {
    background-color: var(--warning);
    box-shadow: 0 0 6px var(--warning);
}

.status-dot.offline {
    background-color: var(--danger);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.icon-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.icon-action-btn:hover {
    background-color: var(--bg-card-subtle);
    border-color: var(--border-active);
}

/* ==========================================================================
   BỐ CỤC 3 NÚT TAG TỪ TRÁI QUA PHẢI TRÊN CÙNG 1 HÀNG NGANG
   Áp dụng cho cả .bottom-tab-bar và .tab-bar để đảm bảo 100% không bị xếp dọc
   ========================================================================== */
.bottom-tab-bar,
.tab-bar,
#bottomTabBar {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    padding: 6px 10px !important;
    padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
    background: var(--bg-card) !important;
    border-top: 1px solid var(--border) !important;
    width: 100% !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
    z-index: 40 !important;
    box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.05) !important;
}

[data-theme="dark"] .bottom-tab-bar,
[data-theme="dark"] .tab-bar,
[data-theme="dark"] #bottomTabBar {
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35) !important;
}

/* Mỗi nút tag chia đều 1/3 hàng ngang, icon bên trái, chữ bên phải */
.bottom-tab-bar .tab-btn,
.tab-bar .tab-btn,
#bottomTabBar .tab-btn {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    height: 42px !important;
    padding: 0 8px !important;
    display: flex !important;
    flex-direction: row !important; /* Bố cục ngang: Icon trái - Chữ phải */
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid transparent !important;
    background: rgba(0, 0, 0, 0.02) !important;
    color: var(--text-sub) !important;
    font-family: var(--font-sans) !important;
    cursor: pointer !important;
    text-decoration: none !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

[data-theme="dark"] .bottom-tab-bar .tab-btn,
[data-theme="dark"] .tab-bar .tab-btn,
[data-theme="dark"] #bottomTabBar .tab-btn {
    background: rgba(255, 255, 255, 0.03) !important;
}

.bottom-tab-bar .tab-btn .tab-icon-wrap,
.tab-bar .tab-btn .tab-icon-wrap,
#bottomTabBar .tab-btn .tab-icon-wrap {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 26px !important;
    height: 26px !important;
    border-radius: 7px !important;
    background: rgba(0, 0, 0, 0.05) !important;
    color: var(--text-sub) !important;
    flex-shrink: 0 !important;
    transition: all 0.18s ease !important;
}

[data-theme="dark"] .bottom-tab-bar .tab-btn .tab-icon-wrap,
[data-theme="dark"] .tab-bar .tab-btn .tab-icon-wrap,
[data-theme="dark"] #bottomTabBar .tab-btn .tab-icon-wrap {
    background: rgba(255, 255, 255, 0.07) !important;
}

.bottom-tab-bar .tab-btn .tab-icon-wrap svg,
.tab-bar .tab-btn .tab-icon-wrap svg,
#bottomTabBar .tab-btn .tab-icon-wrap svg {
    width: 16px !important;
    height: 16px !important;
}

.bottom-tab-bar .tab-btn .tab-label,
.tab-bar .tab-btn .tab-label,
#bottomTabBar .tab-btn .tab-label {
    font-size: 0.74rem !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    color: var(--text-sub) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    transition: color 0.15s ease !important;
}

/* Hiệu ứng rê chuột */
.bottom-tab-bar .tab-btn:hover,
.tab-bar .tab-btn:hover,
#bottomTabBar .tab-btn:hover {
    color: var(--primary) !important;
    background: var(--primary-light) !important;
    border-color: rgba(37, 99, 235, 0.2) !important;
}

.bottom-tab-bar .tab-btn:hover .tab-icon-wrap,
.tab-bar .tab-btn:hover .tab-icon-wrap,
#bottomTabBar .tab-btn:hover .tab-icon-wrap {
    color: var(--primary) !important;
    background: rgba(37, 99, 235, 0.15) !important;
}

.bottom-tab-bar .tab-btn:active,
.tab-bar .tab-btn:active,
#bottomTabBar .tab-btn:active {
    transform: scale(0.96) !important;
}

/* Trạng thái Nút Đang Chọn (Active) - Nổi bật, sang trọng */
.bottom-tab-bar .tab-btn.active,
.tab-bar .tab-btn.active,
#bottomTabBar .tab-btn.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.14) 0%, rgba(37, 99, 235, 0.06) 100%) !important;
    border-color: rgba(37, 99, 235, 0.35) !important;
    color: var(--primary) !important;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12) !important;
}

.bottom-tab-bar .tab-btn.active .tab-icon-wrap,
.tab-bar .tab-btn.active .tab-icon-wrap,
#bottomTabBar .tab-btn.active .tab-icon-wrap {
    background: var(--primary) !important;
    color: #ffffff !important;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35) !important;
}

.bottom-tab-bar .tab-btn.active .tab-label,
.tab-bar .tab-btn.active .tab-label,
#bottomTabBar .tab-btn.active .tab-label {
    color: var(--primary) !important;
    font-weight: 800 !important;
}

[data-theme="dark"] .bottom-tab-bar .tab-btn.active,
[data-theme="dark"] .tab-bar .tab-btn.active,
[data-theme="dark"] #bottomTabBar .tab-btn.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.22) 0%, rgba(37, 99, 235, 0.12) 100%) !important;
    border-color: rgba(59, 130, 246, 0.45) !important;
    color: #60a5fa !important;
}

[data-theme="dark"] .bottom-tab-bar .tab-btn.active .tab-icon-wrap,
[data-theme="dark"] .tab-bar .tab-btn.active .tab-icon-wrap,
[data-theme="dark"] #bottomTabBar .tab-btn.active .tab-icon-wrap {
    background: #2563eb !important;
    color: #ffffff !important;
}

[data-theme="dark"] .bottom-tab-bar .tab-btn.active .tab-label,
[data-theme="dark"] .tab-bar .tab-btn.active .tab-label,
[data-theme="dark"] #bottomTabBar .tab-btn.active .tab-label {
    color: #ffffff !important;
}

/* Màn hình điện thoại nhỏ */
@media (max-width: 480px) {
    .bottom-tab-bar,
    .tab-bar,
    #bottomTabBar {
        padding: 5px 6px !important;
        padding-bottom: max(5px, env(safe-area-inset-bottom)) !important;
        gap: 4px !important;
    }
    .bottom-tab-bar .tab-btn,
    .tab-bar .tab-btn,
    #bottomTabBar .tab-btn {
        height: 38px !important;
        padding: 0 4px !important;
        gap: 4px !important;
    }
    .bottom-tab-bar .tab-btn .tab-icon-wrap,
    .tab-bar .tab-btn .tab-icon-wrap,
    #bottomTabBar .tab-btn .tab-icon-wrap {
        width: 22px !important;
        height: 22px !important;
        border-radius: 6px !important;
    }
    .bottom-tab-bar .tab-btn .tab-icon-wrap svg,
    .tab-bar .tab-btn .tab-icon-wrap svg,
    #bottomTabBar .tab-btn .tab-icon-wrap svg {
        width: 13px !important;
        height: 13px !important;
    }
    .bottom-tab-bar .tab-btn .tab-label,
    .tab-bar .tab-btn .tab-label,
    #bottomTabBar .tab-btn .tab-label {
        font-size: 0.67rem !important;
    }
}

/* MAIN CONTENT VIEWS */
.content-views {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.tab-pane {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 0.85rem;
}

.tab-pane.active {
    display: flex;
    flex-direction: column;
}

/* TAB 1: CHAT VIEW */
#tab-chat {
    padding: 0;
    display: none;
    flex-direction: column;
}

#tab-chat.active {
    display: flex;
}

/* Horizontal Quick Suggestion Chips */
.quick-scroll-wrap {
    padding: 0.5rem 0.85rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
}

.quick-scroll-wrap::-webkit-scrollbar {
    display: none;
}

.quick-scroll-inner {
    display: flex;
    gap: 0.45rem;
    white-space: nowrap;
}

.chip-btn, .btn-chip {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--border-active);
    border-radius: 999px;
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s ease;
}

.chip-btn:hover, .btn-chip:hover {
    background: var(--primary);
    color: #ffffff;
}

/* Chat Thread */
.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    scroll-behavior: smooth;
}

.message-wrapper {
    display: flex;
    gap: 0.6rem;
    max-width: 96%;
}

.message-wrapper.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-wrapper.assistant {
    align-self: flex-start;
    width: 100%;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.bubble, .message-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.85rem;
    font-size: 0.82rem;
    line-height: 1.45;
    box-shadow: var(--shadow-soft);
    width: 100%;
    max-width: 100%;
    word-break: break-word;
    overflow-x: hidden;
    box-sizing: border-box;
}

.message-wrapper.user .bubble, .message-wrapper.user .message-bubble {
    background: var(--primary);
    color: #ffffff;
    border: none;
    width: auto;
    max-width: 85%;
    border-bottom-right-radius: 2px;
}

.welcome-bubble h3 {
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
    color: var(--text-main);
}

.welcome-bubble p {
    color: var(--text-sub);
    font-size: 0.82rem;
}

/* Single Compact Card for 5, 7, 9 Layer BOMs - Fits Phone Screen */
.bom-single-card {
    background: var(--bg-card-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    margin-top: 0.4rem;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.bom-card-top {
    margin-bottom: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.bom-meta-line {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
    font-size: 0.72rem;
    color: var(--text-sub);
}

.meta-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--bg-card);
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.bom-desc-compact {
    font-size: 0.75rem;
    color: var(--text-main);
    font-weight: 500;
    line-height: 1.35;
}

.selector-row-compact {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.version-selector-compact,
.thickness-selector-compact {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.selector-label {
    font-weight: 600;
    color: var(--text-sub);
    font-size: 0.72rem;
    margin-right: 2px;
}

.thickness-chip {
    font-size: 0.68rem;
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 4px;
    padding: 1px 6px;
    font-weight: 600;
}

.chip-current {
    background: var(--primary) !important;
    color: #ffffff !important;
    border-color: var(--primary) !important;
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.4);
}

/* Mini Visual Layer Gauge */
.layer-bar-container {
    display: flex;
    height: 14px;
    border-radius: 4px;
    overflow: hidden;
    margin: 0.4rem 0 0.5rem 0;
    width: 100%;
    border: 1px solid var(--border);
    box-sizing: border-box;
}

.layer-bar-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Horizontal Layer Pill Switcher (Interactive Layer Tab on Mobile & Desktop) */
.layer-pill-bar {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 2px 2px 6px 2px;
    margin-bottom: 0.45rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.45) rgba(255, 255, 255, 0.05);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.layer-pill-bar:active,
.layer-pill-bar.is-dragging {
    cursor: grabbing;
}

.layer-pill-bar.is-dragging .layer-pill-btn {
    pointer-events: none;
}

/* Custom Visible Scrollbar for Layer Pill Bar */
.layer-pill-bar::-webkit-scrollbar {
    height: 5px;
    display: block;
}

.layer-pill-bar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
}

.layer-pill-bar::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.45);
    border-radius: 4px;
}

.layer-pill-bar::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

[data-theme="light"] .layer-pill-bar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.06);
}

.layer-pill-btn {
    flex-shrink: 0;
    padding: 4px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.layer-pill-btn:hover {
    color: var(--text-main);
    border-color: var(--primary);
}

.layer-pill-btn.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.35);
}

/* Layer Panes Wrapper */
.layer-panes-wrapper {
    width: 100%;
    overflow: hidden;
}

.bom-layer-pane {
    display: none;
    width: 100%;
}

.bom-layer-pane.active {
    display: block;
    animation: paneFadeIn 0.15s ease-in-out;
}

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

.pane-layer-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    font-size: 0.72rem;
    color: var(--text-sub);
}

.pane-stage-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ultra-Compact Fixed Width Table - Fits Phone Screen with Zero Overflow */
.compact-fixed-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-card);
    box-sizing: border-box;
}

.compact-fixed-table th {
    background: var(--bg-card-subtle);
    color: var(--text-muted);
    padding: 5px 6px;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.compact-fixed-table td {
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    word-break: break-word;
}

.compact-fixed-table tr:last-child td {
    border-bottom: none;
}

.rm-name-cell {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.rm-name-text {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.74rem;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rm-code-text {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ratio-pill {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary);
    font-weight: 700;
    font-size: 0.72rem;
    white-space: nowrap;
}

.unit-text {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: normal;
}

.section-title-compact {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0.45rem 0 0.3rem 0;
}

.diff-ver-row {
    font-size: 0.74rem;
    color: var(--text-main);
    line-height: 1.35;
}

/* Tables in Chat (General fallback) */
.table-responsive {
    overflow-x: auto;
    margin: 0.5rem 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    max-width: 100%;
}

.bom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
    text-align: left;
    box-sizing: border-box;
}

.bom-table th {
    background-color: var(--bg-card-subtle);
    color: var(--text-muted);
    font-weight: 700;
    padding: 0.4rem 0.55rem;
    text-transform: uppercase;
    font-size: 0.66rem;
    border-bottom: 1px solid var(--border);
}

.bom-table td {
    padding: 0.4rem 0.55rem;
    border-bottom: 1px solid var(--border);
}

.bom-subtable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.73rem;
    margin-top: 0.25rem;
}

.bom-subtable th, .bom-subtable td {
    padding: 0.3rem 0.45rem;
    border-bottom: 1px solid var(--border);
}

/* Layer Cards in Chat */
.layer-card {
    background: var(--bg-card-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.55rem;
    margin-bottom: 0.55rem;
}

.layer-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.45rem;
}

.badge-layer-large {
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.75rem;
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
}

.layer-ratio-text {
    font-size: 0.78rem;
    color: var(--text-sub);
}

.layer-stage-text {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-version {
    background-color: var(--primary-light);
    color: var(--primary);
}

.badge-layer {
    background-color: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

.badge-info {
    background-color: rgba(14, 165, 233, 0.15);
    color: #38bdf8;
}

.status-added { background-color: var(--success-bg); color: var(--success); }
.status-removed { background-color: var(--danger-bg); color: var(--danger); }
.status-modified { background-color: var(--warning-bg); color: var(--warning); }
.status-unchanged { background-color: rgba(255, 255, 255, 0.05); color: var(--text-muted); }

.diff-added { background-color: rgba(16, 185, 129, 0.05); }
.diff-removed { background-color: rgba(239, 68, 68, 0.05); }
.diff-modified { background-color: rgba(245, 158, 11, 0.05); }

/* Metric Summaries */
.calc-summary-card, .bom-overview-card, .diff-header-card {
    background: var(--bg-card-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.summary-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.5rem;
}

.metric-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    display: flex;
    flex-direction: column;
}

.metric-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
}

.metric-value {
    font-size: 1.15rem;
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--text-main);
    margin-top: 0.15rem;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin: 0.85rem 0 0.45rem;
    color: var(--text-main);
}

.layer-details {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    margin-bottom: 0.45rem;
}

.layer-details summary {
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.typing-indicator.active {
    display: flex;
}

.dots { display: flex; gap: 3px; }
.dots span {
    width: 5px; height: 5px;
    border-radius: 50%;
    background-color: var(--primary);
    animation: bounce 1.2s infinite ease-in-out both;
}
.dots span:nth-child(1) { animation-delay: -0.32s; }
.dots span:nth-child(2) { animation-delay: -0.16s; }

/* CHAT INPUT BAR (Sits cleanly right above the bottom-tab-bar) */
.chat-input-bar {
    padding: 0.45rem 0.75rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chat-input-field {
    flex: 1;
    height: 40px;
    padding: 0 0.85rem;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-field:focus {
    border-color: var(--primary);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s;
}

.chat-send-btn:active {
    transform: scale(0.92);
}

.chat-clear-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bg-card-subtle);
    color: var(--text-sub);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.chat-clear-btn:hover {
    background-color: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.35);
}

.chat-clear-btn:active {
    transform: scale(0.92);
}

/* TAB 2 & 3: FORMS & CARDS */
.compact-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
    box-shadow: var(--shadow-soft);
}

.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.2rem;
}

.card-subtitle {
    font-size: 0.78rem;
    color: var(--text-sub);
    margin-bottom: 0.85rem;
}

.form-row-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

@media (max-width: 500px) {
    .form-row-grid { grid-template-columns: 1fr; }
}

.form-field {
    margin-bottom: 0.6rem;
}

.form-field label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-sub);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.compact-select, .compact-input, .compact-search {
    width: 100%;
    height: 38px;
    padding: 0 0.65rem;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    outline: none;
}

.compact-select:focus, .compact-input:focus, .compact-search:focus {
    border-color: var(--primary);
}

.form-row-flex {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.flex-1 { flex: 1; }

.arrow-divider {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-top: 1rem;
}

.form-check-row {
    margin: 0.4rem 0 0.65rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    color: var(--text-sub);
    cursor: pointer;
}

/* TAB 4: COMPACT CATALOG */
.catalog-top-filter {
    margin-bottom: 0.65rem;
}

.compact-catalog-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.catalog-item-compact {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.catalog-item-compact:hover, .catalog-item-compact:active {
    background: var(--bg-card-subtle);
    border-color: var(--border-active);
}

.item-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.2rem;
}

.item-fg {
    font-family: var(--font-mono);
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--primary);
}

.item-desc {
    font-size: 0.78rem;
    color: var(--text-sub);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.35rem;
}

.item-badge-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.layer-chip {
    font-size: 0.7rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.1rem 0.45rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}

/* BUTTONS & UTILITIES */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-secondary { background-color: var(--bg-card-subtle); color: var(--text-main); border-color: var(--border); }
.btn-secondary:active { background-color: rgba(255, 255, 255, 0.1); }

.full-width { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-highlight { color: var(--primary); font-family: var(--font-mono); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.error-text { color: var(--danger); font-size: 0.82rem; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   TAB 3: TRA CỨU TÀI LIỆU NGUYÊN LIỆU (3 LỰA CHỌN)
   ========================================================================== */
#tab-material-docs {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 0.65rem;
}

#tab-material-docs.active {
    display: flex;
}

/* SUB NAVIGATION SWITCHER - COMPACT HORIZONTAL MODERN TABS */
.sub-tab-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.25rem;
    margin-bottom: 0.45rem;
    flex-shrink: 0;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}

.sub-tab-btn {
    min-width: 0;
    padding: 0.35rem 0.35rem;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-sm);
    color: var(--text-sub);
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    height: 34px;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.sub-tab-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-sub);
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.sub-tab-icon-wrap svg {
    width: 14px;
    height: 14px;
}

.sub-tab-label {
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sub-tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-1px);
}

.sub-tab-btn:hover .sub-tab-icon-wrap {
    color: var(--primary);
    background: var(--primary-light);
}

.sub-tab-btn:active {
    transform: scale(0.97);
}

.sub-tab-btn.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.18) 0%, rgba(30, 64, 175, 0.28) 100%);
    border-color: rgba(59, 130, 246, 0.55);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.sub-tab-btn.active .sub-tab-icon-wrap {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    box-shadow: 0 1px 5px rgba(37, 99, 235, 0.4);
}

.sub-tab-btn.active .sub-tab-label {
    color: #ffffff;
    font-weight: 800;
}

@media (max-width: 480px) {
    .sub-tab-bar {
        padding: 0.2rem;
        gap: 0.2rem;
    }
    .sub-tab-btn {
        padding: 0.25rem 0.15rem;
        gap: 0.2rem;
        height: 32px;
    }
    .sub-tab-icon-wrap {
        width: 19px;
        height: 19px;
    }
    .sub-tab-icon-wrap svg {
        width: 12px;
        height: 12px;
    }
    .sub-tab-label {
        font-size: 0.66rem;
    }
}

/* SUB VIEWS CONTAINER */
.sub-views-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.sub-view-pane {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.sub-view-pane.active {
    display: flex;
    animation: paneFadeIn 0.15s ease-in-out;
}

/* TOP CONTROLS */
.pane-top-controls {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 0.55rem;
    flex-shrink: 0;
}

.filter-pills-row {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.filter-pills-row::-webkit-scrollbar {
    display: none;
}

.filter-pill {
    padding: 0.25rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-sub);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.filter-pill:hover {
    color: var(--text-main);
    border-color: var(--primary);
}

.filter-pill.active {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border-color: var(--primary);
    font-weight: 700;
}

.info-pill-bar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* TABLE SCROLL CONTAINER & DATA TABLES */
.table-scroll-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    scrollbar-width: thin;
    min-height: 0;
}

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

.data-table th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--bg-card-subtle);
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* CHIPS FOR SUBSTITUTES & USAGES */
.substitute-chips-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.sub-chip {
    font-size: 0.7rem;
    font-weight: 600;
    font-family: var(--font-mono);
    background: rgba(59, 130, 246, 0.12);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 4px;
    padding: 2px 7px;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
}

.sub-chip:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    transform: translateY(-1px);
}

.usage-fg-chip {
    font-size: 0.68rem;
    font-weight: 700;
    font-family: var(--font-mono);
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 4px;
    padding: 1px 6px;
    cursor: pointer;
    margin-right: 3px;
    margin-bottom: 3px;
    display: inline-block;
    transition: all 0.15s;
}

.usage-fg-chip:hover {
    background: var(--success);
    color: #ffffff;
}

/* SUBTAB 3: IFRAME STYLES */
.iframe-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.45rem;
    flex-shrink: 0;
}

.folder-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.iframe-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.72rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
}

.iframe-hint-banner {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.65rem;
    font-size: 0.72rem;
    color: #fbbf24;
    margin-bottom: 0.55rem;
    flex-shrink: 0;
    line-height: 1.4;
}

.iframe-wrapper {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-card);
    min-height: 380px;
    position: relative;
    display: flex;
    flex-direction: column;
}

#tdsMsdsIframe {
    width: 100%;
    height: 100%;
    flex: 1;
    border: none;
    display: block;
    background: #ffffff;
}

/* ==========================================================================
   SUBTAB 3: ONEDRIVE ACTION & DOCUMENT DIRECTORY (TDS / MSDS / REGULATORY)
   ========================================================================== */
.onedrive-action-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 0.65rem;
}

.btn-onedrive-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1.1rem;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff !important;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn-onedrive-primary:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.45);
}

.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 4px;
}

.pane-meta-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0.45rem 0 0.65rem 0;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.meta-count {
    font-weight: 600;
    color: var(--text-sub);
}

.meta-hint {
    font-style: italic;
    color: var(--text-muted);
}

/* Document Type Badges in Table */
.doc-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    letter-spacing: 0.2px;
    text-transform: uppercase;
}

.doc-type-tds {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.doc-type-msds {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.doc-type-reg {
    background: rgba(168, 85, 247, 0.15);
    color: #c084fc;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.doc-type-other {
    background: rgba(107, 114, 128, 0.15);
    color: #9ca3af;
    border: 1px solid rgba(107, 114, 128, 0.3);
}

/* Document Action Buttons */
.doc-action-btns {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.btn-copy-doc {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.btn-copy-doc:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
    transform: translateY(-1px);
}

.btn-copy-doc.copied {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: #ffffff !important;
}

/* Document Name Cell in Table */
.doc-name-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-main);
    word-break: break-word;
}

.doc-name-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

/* Interactive Document Tag Pills (in Approved Resins & BOM Cards) */
.doc-tag-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.doc-pill {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    line-height: 1.4;
    background: transparent;
}

.doc-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.doc-pill-tds,
.doc-pill-msds {
    display: none !important;
}

.doc-pill-reg {
    background: rgba(168, 85, 247, 0.14);
    color: #c084fc;
    border-color: rgba(168, 85, 247, 0.35);
}

.doc-pill-reg:hover {
    background: #a855f7;
    color: #ffffff;
}

.doc-pill-none {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-style: italic;
}

@media (max-width: 768px) {
    .onedrive-action-header {
        justify-content: stretch;
    }
    .onedrive-action-header .btn-onedrive-primary {
        width: 100%;
        text-align: center;
    }
}

/* ==========================================================================
   APPROVED RESIN (SHEET RM) TABLE STYLING
   ========================================================================== */
.resin-item-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.resin-title {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.78rem;
    line-height: 1.35;
}

.resin-sub-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.resin-code-tag {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    padding: 1px 6px;
    background: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.resin-code-tag:hover {
    background: #3b82f6;
    color: #ffffff;
}

.resin-mfr-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-sub);
}

.rm-type-badge {
    display: inline-block;
    padding: 2px 7px;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 4px;
    letter-spacing: 0.3px;
    background: rgba(148, 163, 184, 0.15);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.rm-type-badge.type-c4,
.rm-type-badge.type-c6,
.rm-type-badge.type-c8,
.rm-type-badge.type-b-ll {
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.35);
}

.rm-type-badge.type-evoh,
.rm-type-badge.type-tie {
    background: rgba(236, 72, 153, 0.14);
    color: #f472b6;
    border-color: rgba(236, 72, 153, 0.35);
}

.rm-type-badge.type-hd,
.rm-type-badge.type-ld,
.rm-type-badge.type-md,
.rm-type-badge.type-b-md {
    background: rgba(168, 85, 247, 0.12);
    color: #c084fc;
    border-color: rgba(168, 85, 247, 0.3);
}

.rm-type-badge.type-wmb,
.rm-type-badge.type-mb {
    background: rgba(248, 250, 252, 0.15);
    color: #f1f5f9;
    border-color: rgba(248, 250, 252, 0.35);
}

.rm-type-badge.type-ab,
.rm-type-badge.type-sab,
.rm-type-badge.type-ppa,
.rm-type-badge.type-sp,
.rm-type-badge.type-rivive {
    background: rgba(245, 158, 11, 0.14);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.35);
}

.rm-prop-box {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rm-prop-row {
    display: flex;
    align-items: baseline;
    gap: 5px;
    font-size: 0.72rem;
}

.prop-lbl {
    color: var(--text-muted);
    font-size: 0.68rem;
    min-width: 48px;
}

.prop-num {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-main);
}

.prop-unit {
    color: var(--text-muted);
    font-size: 0.65rem;
}

.compliance-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.compliance-chips-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.comp-pill {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px 5px;
    font-size: 0.63rem;
    font-weight: 600;
    border-radius: 3px;
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.28);
}

.comp-pill-gray {
    background: rgba(100, 116, 139, 0.12);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.2);
}

/* ==========================================================================
   TỐI ƯU HÓA HIỂN THỊ TRÊN ĐIỆN THOẠI (MOBILE SCREEN & TOUCH ERGONOMICS)
   - Thiết kế gọn gàng, hiển thị vừa vặn trong 1 màn hình điện thoại
   - Các nút bấm to vừa phải, dễ chạm ngón tay cái
   - Bảng biểu và thanh trượt hiển thị trực quan, không bị tràn khó coi
   ========================================================================== */
@media (max-width: 600px) {
    /* Header thu gọn tiết kiệm diện tích */
    .top-nav {
        height: 46px;
        padding: 0 0.6rem;
    }
    .portal-return-btn {
        padding: 4px 7px;
        font-size: 0.7rem;
    }
    .nav-brand-logo {
        height: 22px;
        max-width: 80px;
    }
    .nav-title {
        font-size: 0.85rem;
    }
    .status-pill {
        font-size: 0.65rem;
    }
    .icon-action-btn {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }

    /* Khung hội thoại & Bong bóng tin nhắn */
    .chat-thread {
        padding: 0.5rem 0.55rem;
        gap: 0.6rem;
    }
    .message-wrapper {
        max-width: 100%;
        gap: 0.45rem;
    }
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }
    .bubble, .message-bubble {
        padding: 0.5rem 0.65rem;
        font-size: 0.78rem;
    }

    /* Thẻ BOM Công thức màng thổi - Vừa vặn 1 màn hình điện thoại */
    .bom-single-card {
        padding: 0.45rem 0.55rem;
        border-radius: 8px;
        margin-top: 0.3rem;
    }
    .bom-card-top {
        margin-bottom: 0.3rem;
    }
    .bom-meta-line {
        gap: 0.25rem 0.35rem;
        font-size: 0.68rem;
    }
    .meta-tag {
        padding: 0.12rem 0.35rem;
    }
    .bom-desc-compact {
        font-size: 0.73rem;
    }
    .layer-bar-container {
        height: 12px;
        margin: 0.35rem 0 0.45rem 0;
    }

    /* Thanh trượt chọn lớp: Vuốt chạm mượt mà, nút dễ bấm */
    .layer-pill-bar {
        padding: 2px 2px 5px 2px;
        gap: 5px;
        margin-bottom: 0.35rem;
    }
    .layer-pill-btn {
        padding: 5px 9px;
        font-size: 0.72rem;
        min-height: 32px;
        border-radius: 6px;
    }

    /* Bảng thành phần nguyên liệu cố định theo tỷ lệ - Tuyệt đối không bị vỡ */
    .compact-fixed-table {
        font-size: 0.72rem;
    }
    .compact-fixed-table th {
        padding: 4px 5px;
        font-size: 0.63rem;
    }
    .compact-fixed-table td {
        padding: 3.5px 5px;
    }
    .rm-name-text {
        font-size: 0.72rem;
    }
    .rm-code-text {
        font-size: 0.63rem;
    }
    .ratio-pill {
        font-size: 0.68rem;
        padding: 1px 4px;
    }

    /* Thanh nhập liệu chat phía trên thanh điều hướng đáy */
    .chat-input-bar {
        padding: 0.35rem 0.55rem;
    }
    .chat-input-field {
        height: 38px;
        font-size: 0.82rem;
        padding: 0 0.75rem;
    }
    .chat-send-btn, .chat-clear-btn {
        width: 38px;
        height: 38px;
    }

    /* Tab 2: Danh mục mã thành phẩm */
    .catalog-top-filter {
        padding: 0.4rem 0.55rem;
    }
    .compact-search {
        height: 36px;
        font-size: 0.8rem;
    }
    .compact-catalog-list {
        padding: 0.4rem 0.55rem;
        gap: 0.45rem;
    }
    .catalog-item-compact {
        padding: 0.45rem 0.55rem;
    }

    /* Tab 3: Bảng tra cứu tài liệu & Nhựa */
    #tab-material-docs {
        padding: 0.45rem 0.5rem;
    }
    .sub-tab-bar {
        padding: 0.2rem;
        gap: 0.25rem;
        margin-bottom: 0.35rem;
    }
    .sub-tab-btn {
        height: 32px;
        padding: 0.2rem;
    }
    .sub-tab-icon-wrap {
        width: 18px;
        height: 18px;
    }
    .sub-tab-icon-wrap svg {
        width: 13px;
        height: 13px;
    }
    .sub-tab-label {
        font-size: 0.66rem;
    }
    .pane-top-controls {
        gap: 0.35rem;
        margin-bottom: 0.4rem;
    }
    .data-table th {
        padding: 5px 6px;
        font-size: 0.65rem;
    }
    .data-table td {
        padding: 5px 6px;
        font-size: 0.71rem;
    }
}




