/* ============================================================
   ChemFlow — Light Industrial Theme
   Clean, professional, chemical-industry aesthetic
   ============================================================ */

:root {
    /* Core palette — warm neutrals with teal accent */
    --bg-primary: #F7F8FA;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #EEF0F4;
    --bg-hover: #E8EBF0;

    --text-primary: #1A1D23;
    --text-secondary: #5A6070;
    --text-muted: #8B90A0;
    --text-inverse: #FFFFFF;

    --accent: #0F7B6C;
    --accent-hover: #0A5F53;
    --accent-light: #E6F5F2;
    --accent-muted: #B2DDD5;

    --border: #DDE0E6;
    --border-light: #EAECF0;
    --border-focus: #0F7B6C;

    --danger: #D93025;
    --danger-light: #FDE8E6;
    --warning: #E37400;
    --warning-light: #FFF3E0;
    --success: #188038;
    --success-light: #E6F4EA;
    --info: #1967D2;
    --info-light: #E8F0FE;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.10);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --sidebar-width: 290px;
    --sidebar-collapsed: 64px;
    --topbar-height: 60px;

    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ============================================================
   RESET & BASE
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

code {
    font-family: var(--font-mono);
    font-size: 0.87em;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-page {
    background: linear-gradient(135deg, #F0F4F8 0%, #E2E8F0 50%, #D5DDE6 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px;
    border: 1px solid var(--border-light);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo-img {
    max-width: 380px;
    width: 100%;
    height: auto;
    margin-bottom: 12px;
}

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

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--bg-primary);
}

.login-form input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease, width 0.3s ease;
}

/* Collapsed sidebar on desktop */
.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar.collapsed + .main-content {
    margin-left: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-light);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-img {
    height: 130px;
    width: auto;
    object-fit: contain;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
}

.sidebar-toggle svg { width: 20px; height: 20px; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.92rem;
    font-weight: 450;
    transition: all 0.15s;
    margin-bottom: 2px;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    line-height: 1.4;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    min-width: 20px;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar, .user-avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-muted);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.user-avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
    display: inline-flex;
    vertical-align: middle;
    margin-right: 6px;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name { font-weight: 600; font-size: 0.88rem; }
.user-role { font-size: 0.78rem; color: var(--text-muted); }

.logout-btn {
    padding: 6px;
    color: var(--text-muted);
    transition: color 0.15s;
}

.logout-btn:hover { color: var(--danger); }
.logout-btn svg { width: 18px; height: 18px; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.top-bar {
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
}

.mobile-menu-btn svg { width: 22px; height: 22px; }

.page-title {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.top-bar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.content-area {
    flex: 1;
    padding: 24px 28px;
}

/* Sidebar collapse toggle button (top bar) */
.sidebar-collapse-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 5px 7px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    transition: all 0.15s;
}
.sidebar-collapse-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.sidebar-collapse-btn svg { width: 18px; height: 18px; }

/* Right panel collapse toggle button */
.panel-collapse-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 5px 7px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-body);
    transition: all 0.15s;
}
.panel-collapse-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.panel-collapse-btn svg { width: 16px; height: 16px; }

/* Detail layout when right panel is hidden */
.detail-layout.sidebar-hidden {
    grid-template-columns: 1fr;
}
.detail-layout.sidebar-hidden .detail-sidebar {
    display: none;
}

/* ============================================================
   FLASH MESSAGES
   ============================================================ */

.flash-container {
    padding: 16px 28px 0;
}

.flash-msg {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
    cursor: pointer;
    animation: flashIn 0.3s ease;
}

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

.flash-success { background: var(--success-light); color: var(--success); border: 1px solid #C4E6CE; }
.flash-error { background: var(--danger-light); color: var(--danger); border: 1px solid #F5C6C2; }
.flash-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #FFDBA6; }
.flash-info { background: var(--info-light); color: var(--info); border: 1px solid #B3CFF5; }

.flash-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-weight: 550;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.3;
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.btn-danger { color: var(--danger); }
.btn-success { color: var(--success); }

.btn-sm { padding: 5px 12px; font-size: 0.82rem; }
.btn-full { width: 100%; justify-content: center; padding: 11px; }

/* ============================================================
   FORMS
   ============================================================ */

.form-layout {
    max-width: 900px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.form-full { grid-column: 1 / -1; }

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.92rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.multi-select { min-height: 120px; }

.form-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-help {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

.form-actions {
    display: flex;
    gap: 10px;
    padding-top: 8px;
}

.form-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.92rem;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.form-group-inline {
    display: flex;
    gap: 10px;
    align-items: center;
}

.form-group-inline input {
    flex: 1;
    padding: 8px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.92rem;
    background: var(--bg-primary);
}

.form-group-inline input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Role chips */
.role-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.chip-label { cursor: pointer; }
.chip-label input { display: none; }

.chip {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    transition: all 0.15s;
}

.chip-label input:checked + .chip {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.chip:hover {
    border-color: var(--accent-muted);
}

/* ============================================================
   PANELS / CARDS
   ============================================================ */

.panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.panel-title {
    font-size: 0.98rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.panel-body {
    padding: 18px 20px;
}

/* ============================================================
   DASHBOARD
   ============================================================ */

.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }

.stat-icon-blue { background: var(--info-light); color: var(--info); }
.stat-icon-amber { background: var(--warning-light); color: var(--warning); }
.stat-icon-green { background: var(--success-light); color: var(--success); }

.stat-content { display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.82rem; color: var(--text-muted); font-weight: 450; }

.dashboard-panels {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
}

.dashboard-quad {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.dashboard-quad .panel {
    margin-bottom: 0;
}

.panel-body-scroll {
    max-height: 360px;
    overflow-y: auto;
}

.on-order-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

/* Alert list */
.alert-list { display: flex; flex-direction: column; gap: 8px; }

.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    border-left: 3px solid transparent;
}

.alert-alert { border-left-color: var(--warning); }
.alert-on_order { border-left-color: var(--info); }

.alert-info { display: flex; flex-direction: column; gap: 2px; }
.alert-item-name { font-weight: 600; font-size: 0.92rem; }
.alert-meta { font-size: 0.8rem; color: var(--text-muted); }

/* Badge variants */
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-muted { background: var(--bg-tertiary); color: var(--text-muted); }
.badge-admin { background: var(--accent-light); color: var(--accent); font-size: 0.72rem; margin-left: 6px; }

/* Message thread list */
.panel-messages { min-height: 400px; }
.panel-body-messages { padding: 0; }

.message-thread-list { display: flex; flex-direction: column; }

.message-thread-item {
    border-bottom: 1px solid var(--border-light);
    transition: opacity 0.2s, transform 0.2s;
}

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

.message-thread-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    cursor: pointer;
    transition: background 0.15s;
}

.message-thread-row:hover { background: var(--bg-primary); }

.message-thread-item.message-unread {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
}

.message-thread-info { flex: 1; min-width: 0; }

.message-thread-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.message-sender { font-weight: 600; font-size: 0.9rem; }
.message-subject { font-size: 0.88rem; margin-top: 3px; font-weight: 500; }
.message-preview { font-size: 0.82rem; color: var(--text-muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message-time { font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; }

.reply-badge { font-size: 0.72rem; flex-shrink: 0; }

/* Dismiss button */
.dismiss-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border-medium);
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: all 0.15s;
}

.dismiss-btn:hover {
    border-color: var(--success);
    color: var(--success);
    background: var(--success-light);
}

.dismissed-icon {
    border-color: var(--success);
    color: var(--success);
    cursor: default;
}

/* Expanded thread */
.thread-expanded {
    padding: 0 18px 14px 62px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-primary);
}

.thread-body {
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 12px 0;
    color: var(--text-primary);
    white-space: pre-wrap;
}

.thread-replies { display: flex; flex-direction: column; gap: 8px; }

.reply-item {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border-left: 2px solid var(--accent-muted);
}

.reply-sender { font-weight: 600; font-size: 0.84rem; }
.reply-time { font-size: 0.74rem; color: var(--text-muted); margin-left: 8px; }
.reply-body { font-size: 0.86rem; margin-top: 4px; line-height: 1.4; }
.no-replies { font-size: 0.82rem; color: var(--text-muted); padding: 8px 0; }

.thread-reply-form {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
}

.reply-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    background: var(--bg-secondary);
}

.reply-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

/* Inline compose form */
.compose-inline {
    border-bottom: 1px solid var(--border-light);
    padding: 16px 18px;
    background: var(--bg-primary);
}

.compose-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.compose-subject {
    padding: 8px 12px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.compose-body {
    padding: 8px 12px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    resize: vertical;
    min-height: 60px;
}

.compose-subject:focus, .compose-body:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.recipient-section { margin-bottom: 10px; }

.recipient-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: block;
}

.recipient-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.recipient-check {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.84rem;
    cursor: pointer;
    padding: 3px 0;
}

.recipient-check input[type="checkbox"] { margin: 0; }

.recipient-name { color: var(--text-primary); }

.compose-actions {
    display: flex;
    gap: 8px;
}

/* Cleared messages */
.cleared-toggle {
    text-align: center;
    padding: 10px 18px;
    border-top: 1px solid var(--border-light);
}

.cleared-section { }

.message-cleared {
    opacity: 0.5;
}

.message-cleared .message-thread-row {
    cursor: default;
}

.message-cleared .message-thread-row:hover {
    background: transparent;
}

/* Sent messages */
.sent-to {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Order modal overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay .modal-content {
    padding: 24px;
    width: 90%;
    max-width: 420px;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.modal-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* Outline button */
.btn-outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
}

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

/* Danger ghost button (delete) */
.btn-danger-ghost {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.15s;
}

.btn-danger-ghost:hover {
    color: var(--danger);
}

/* Message Archive */
.archive-search-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.archive-search-input {
    padding: 6px 12px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    width: 240px;
}

.archive-search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.archive-row {
    cursor: pointer;
    transition: background 0.15s;
}

.archive-row:hover { background: var(--bg-primary); }
.archive-row-active { background: var(--accent-light) !important; }

.archive-date {
    white-space: nowrap;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.archive-detail {
    padding: 12px 16px;
    background: var(--bg-primary);
    border-left: 3px solid var(--accent);
}

.archive-msg-body {
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.archive-replies-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.archive-detail .reply-item {
    margin-bottom: 6px;
}

.archive-detail-row td {
    padding: 0 !important;
}

/* Rework panel */
.rework-panel {
    border: 2px solid var(--warning);
}

.rework-instructions-box {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
}

.rework-instructions-text {
    font-size: 0.92rem;
    line-height: 1.5;
    white-space: pre-wrap;
    margin-top: 4px;
    font-weight: 500;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
}

.empty-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 10px;
    opacity: 0.4;
}

/* ============================================================
   TABLES
   ============================================================ */

.table-container {
    overflow-x: auto;
    max-height: calc(100vh - 240px);
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
}

/* Right-aligned headers match right-aligned data */
.data-table th.text-right { text-align: right; }

/* Inline adjust popover */
.inline-adjust {
    position: relative;
    display: inline-block;
}
.inline-adjust-pop {
    display: none;
    position: fixed;
    z-index: 1000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 12px;
    min-width: 260px;
}
.inline-adjust-pop.open { display: block; }
.inline-adjust-pop .form-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}
.inline-adjust-pop select,
.inline-adjust-pop input {
    font-size: 0.85rem;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.inline-adjust-pop input[type="number"] { width: 90px; }
.inline-adjust-pop input[type="text"] { width: 100%; }
.inline-adjust-pop .pop-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* Accordion panels (settings, edit forms) */
.settings-accordion .panel,
.form-accordion .panel { margin-bottom: 2px; }
.settings-accordion .acc-header,
.settings-accordion .panel-header[onclick],
.form-accordion .acc-header {
    cursor: pointer; user-select: none; transition: background 0.15s;
}
.settings-accordion .acc-header:hover,
.settings-accordion .panel-header[onclick]:hover,
.form-accordion .acc-header:hover { background: var(--bg-secondary); }
.acc-toggle,
.panel-toggle {
    display: inline-block; width: 20px; text-align: center;
    font-size: 0.8rem; color: var(--text-secondary);
    transition: transform 0.2s; margin-right: 4px;
}
.acc-toggle.open,
.panel-toggle.open { transform: rotate(90deg); }
.acc-body { display: none; border-top: 1px solid var(--border); }
.acc-body.open { display: block; }
.settings-accordion .panel-body { display: none; border-top: 1px solid var(--border); }
.settings-accordion .panel-body.open { display: block; }
.acc-hint,
.setting-status {
    font-size: 0.78rem; padding: 2px 8px; border-radius: 10px; margin-left: 8px;
    background: var(--bg-tertiary); color: var(--text-secondary);
}
.setting-status.status-on {
    background: var(--success-light, #e6f4ea); color: var(--success);
}
.setting-status.status-off {
    background: var(--bg-tertiary); color: var(--text-secondary);
}

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

.data-table tbody tr:hover {
    background: var(--bg-primary);
}

.row-inactive { opacity: 0.5; }

.td-name {
    font-weight: 500;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.td-actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.td-check { text-align: center; }
.td-module { font-weight: 500; }

.perm-table td, .perm-table th { padding: 8px 12px; }
.perm-table input[type="checkbox"] { accent-color: var(--accent); }

/* ============================================================
   TABS
   ============================================================ */

.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

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

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

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================================
   MESSAGES PAGE
   ============================================================ */

.message-list-full { display: flex; flex-direction: column; gap: 8px; }

.message-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    cursor: pointer;
    transition: all 0.15s;
}

.message-card:hover { box-shadow: var(--shadow-md); }

.message-card.message-unread {
    border-left: 3px solid var(--accent);
    background: var(--accent-light);
}

.message-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.message-body-full {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

.message-resolved {
    margin-top: 8px;
    padding: 6px 10px;
    background: var(--success-light);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--success);
}

/* Color grid in settings */
.color-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.color-chip-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.color-name { font-weight: 500; font-size: 0.9rem; }

.inline-form { margin-top: 8px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
    .dashboard-panels { grid-template-columns: 1fr; }
    .dashboard-quad { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;  /* Override collapsed on mobile */
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .main-content {
        margin-left: 0 !important;  /* Override collapsed on mobile */
    }

    .mobile-menu-btn {
        display: block;
    }

    .sidebar-collapse-btn {
        display: none;  /* Hide desktop toggle on mobile */
    }

    .sidebar-toggle {
        display: block;
    }

    .content-area {
        padding: 16px;
    }

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

    .stats-row {
        grid-template-columns: 1fr;
    }

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

/* ============================================================
   FILTER BAR
   ============================================================ */

.filter-bar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.filter-group { flex-shrink: 0; }

.filter-input {
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.88rem;
    background: var(--bg-primary);
    min-width: 220px;
    transition: border-color 0.2s;
}

.filter-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.filter-select {
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.88rem;
    background: var(--bg-primary);
    cursor: pointer;
}

.filter-check { font-size: 0.88rem; }

.results-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-left: 4px;
}

/* ============================================================
   TABLE ENHANCEMENTS
   ============================================================ */

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-success { color: var(--success); }
.text-pending { color: var(--warning); }
.text-muted { color: var(--text-muted); }

.num-cell { font-family: var(--font-mono); font-size: 0.85rem; }

.td-reorder {
    text-align: center;
    white-space: nowrap;
}
.btn-arrow {
    background: none;
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    padding: 1px 6px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1;
}
.btn-arrow:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.input-disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
}

td.td-name-scaled {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chem-name-link {
    font-weight: 600;
    color: var(--text-primary);
}
.chem-name-link:hover { color: var(--accent); }

.chem-code {
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.78em;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    margin-right: 4px;
}

.cell-trade-names {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 2px;
}
.trade-name-tag {
    display: inline-block;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 1px 6px;
    border-radius: 3px;
    line-height: 1.4;
}

.cell-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.cas-num { font-size: 0.82rem; }

.row-low-stock {
    background: var(--warning-light) !important;
}

.empty-table {
    text-align: center;
    padding: 30px !important;
    color: var(--text-muted);
}

.hazard-cell {
    white-space: nowrap;
}

.hazard-tag {
    font-size: 0.9rem;
    cursor: help;
}

.sds-link {
    display: inline-flex;
    align-items: center;
    color: var(--accent);
}
.sds-link:hover { color: var(--accent-hover); }

/* ============================================================
   DETAIL PAGE
   ============================================================ */

.detail-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}

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

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.detail-full { grid-column: 1 / -1; }

.detail-field { display: flex; flex-direction: column; gap: 3px; }
.detail-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.detail-value { font-size: 0.95rem; }

.hazard-display {
    margin-bottom: 16px;
}

.hazard-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.hazard-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 14px;
    font-size: 0.82rem;
    font-weight: 500;
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #F5C6C2;
}

.hazard-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.hazard-checkbox-label {
    cursor: pointer;
}

.hazard-checkbox-label input { display: none; }

.hazard-check-chip {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    transition: all 0.15s;
}

.hazard-checkbox-label input:checked + .hazard-check-chip {
    background: var(--danger-light);
    border-color: var(--danger);
    color: var(--danger);
}

.detail-notes {
    margin-top: 8px;
}
.detail-notes p {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-top: 4px;
}

/* ============================================================
   INVENTORY STATS
   ============================================================ */

.inventory-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
}

.inv-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inv-stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1.2;
}

.inv-stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================================
   ADJUST FORM
   ============================================================ */

.adjust-form-container {
    border-top: 1px solid var(--border-light);
    padding-top: 16px;
}

.section-title {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.adjust-form .form-group-inline {
    margin-bottom: 10px;
}

.adjust-qty-input {
    width: 140px;
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.92rem;
}

.unit-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================================
   SUPPLIER CARDS
   ============================================================ */

.supplier-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.supplier-card {
    padding: 14px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.supplier-primary {
    border-left: 3px solid var(--accent);
}

.supplier-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.supplier-detail {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

/* Supplier form rows */
.supplier-row {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 10px;
}

.supplier-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

/* ============================================================
   HISTORY LIST
   ============================================================ */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

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

.history-action {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.history-qty {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 600;
}

.history-notes {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.history-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.history-detail {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin-bottom: 2px;
}

/* ============================================================
   COMPONENT CATEGORY BADGES
   ============================================================ */

.category-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.cat-tote { background: #E8F0FE; color: #1967D2; }
.cat-drum { background: #FDE8E6; color: #D93025; }
.cat-pail { background: #FFF3E0; color: #E37400; }
.cat-gallon { background: #E6F4EA; color: #188038; }
.cat-quart { background: #F3E8FD; color: #8430CE; }
.cat-cap { background: #E6F5F2; color: #0F7B6C; }
.cat-label { background: #FEF3E2; color: #B06000; }
.cat-box { background: #EEF0F4; color: #5A6070; }
.cat-liner { background: #E8F0FE; color: #4285F4; }
.cat-seal { background: #FCE8E6; color: #C5221F; }
.cat-bung { background: #F1F3F4; color: #5F6368; }
.cat-other { background: var(--bg-tertiary); color: var(--text-muted); }

/* ============================================================
   CATEGORY BADGES (Components)
   ============================================================ */

.category-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 550;
    text-transform: capitalize;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.cat-tote { background: #E8F0FE; color: #1967D2; }
.cat-drum { background: #FCE8E6; color: #C5221F; }
.cat-pail { background: #FEF7E0; color: #E37400; }
.cat-gallon { background: #E6F4EA; color: #188038; }
.cat-quart { background: #F3E8FD; color: #8430CE; }
.cat-cap { background: #E0F2F1; color: #00796B; }
.cat-label { background: #FFF3E0; color: #E65100; }
.cat-box { background: #EFEBE9; color: #5D4037; }
.cat-liner { background: #E8EAF6; color: #3949AB; }
.cat-bung { background: #F3E5F5; color: #7B1FA2; }
.cat-seal { background: #E0F7FA; color: #00838F; }
.cat-other { background: var(--bg-tertiary); color: var(--text-muted); }

/* ============================================================
   LAB MODULE
   ============================================================ */

.form-layout-wide { max-width: 1100px; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 14px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.status-pending { background: var(--warning-light); color: var(--warning); }
.status-approved { background: var(--success-light); color: var(--success); }
.status-failed { background: var(--danger-light); color: var(--danger); }
.status-na { background: var(--bg-tertiary); color: var(--text-muted); }

/* Lab card grid */
.lab-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 14px;
}

.lab-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s;
}
.lab-card:hover { box-shadow: var(--shadow-md); }

.lab-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.lab-card-name {
    font-weight: 600;
    font-size: 1.02rem;
    color: var(--text-primary);
}
.lab-card-name:hover { color: var(--accent); }

.lab-card-code {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.lab-card-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    gap: 6px;
}

.lab-card-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.spec-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.lab-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.lab-card-date { font-size: 0.78rem; color: var(--text-muted); }
.lab-card-actions { display: flex; gap: 6px; }

/* Tab count */
.tab-count {
    font-size: 0.78rem;
    background: var(--bg-tertiary);
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
}

/* AI tag */
.ai-tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    background: #E8F0FE;
    color: #1967D2;
    vertical-align: middle;
}

.ai-input-group { display: flex; align-items: center; gap: 8px; }
.ai-input-group input { flex: 1; }

/* Range inputs */
.range-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}
.range-inputs input { flex: 1; min-width: 0; }
.range-sep {
    color: var(--text-muted);
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Chemical search */
.chem-search-bar {
    position: relative;
    margin-bottom: 16px;
}
.chem-search-bar input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.92rem;
    background: var(--bg-primary);
}
.chem-search-bar input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.chem-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    z-index: 200;
}

.chem-result-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s;
}
.chem-result-item:hover { background: var(--accent-light); }
.chem-result-item:last-child { border-bottom: none; }

.chem-result-name { font-weight: 600; font-size: 0.92rem; display: block; }
.chem-result-meta { font-size: 0.8rem; color: var(--text-muted); display: block; margin-top: 2px; }
.chem-result-empty { padding: 14px; color: var(--text-muted); text-align: center; }

/* Chemical table in form */
.pct-input {
    width: 80px;
    padding: 5px 8px;
    border: 1.5px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: right;
}
.pct-input:focus {
    outline: none;
    border-color: var(--border-focus);
}

.mini-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 0.82rem;
}
.mini-input:focus {
    outline: none;
    border-color: var(--border-focus);
}

.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.totals-row {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.chem-row-name { font-weight: 500; }

/* Price display */
.price-toggle {
    display: flex;
    gap: 30px;
    padding: 14px 0 0;
    border-top: 1px solid var(--border-light);
    margin-top: 14px;
}

.price-display { display: flex; align-items: baseline; gap: 8px; }
.price-label { font-size: 0.88rem; color: var(--text-secondary); font-weight: 500; }
.price-value { font-family: var(--font-mono); font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.price-hint { font-size: 0.78rem; color: var(--text-muted); }

/* Spec grid on detail page */
.spec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.spec-card {
    padding: 12px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}
.spec-card-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.spec-card-value {
    font-size: 1rem;
    font-weight: 600;
}

/* Instructions text */
.instructions-text {
    white-space: pre-wrap;
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* Revision banner */
.revision-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--info-light);
    border: 1px solid #B3CFF5;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 0.92rem;
}
.revision-banner-icon { font-size: 1.3rem; }

.rev-link { font-weight: 600; color: var(--accent); }
.rev-link:hover { text-decoration: underline; }

/* Panel header actions */
.panel-header-actions {
    display: flex;
    gap: 8px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.ai-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ai-results { display: flex; flex-direction: column; gap: 12px; }
.ai-result-row { display: flex; justify-content: space-between; align-items: center; }
.ai-result-label { font-weight: 500; }
.ai-result-value { font-family: var(--font-mono); font-weight: 600; font-size: 1.05rem; }
.ai-result-notes { font-size: 0.88rem; color: var(--text-secondary); padding: 10px; background: var(--bg-primary); border-radius: var(--radius-sm); }
.ai-result-error { color: var(--danger); font-size: 0.88rem; }
.ai-disclaimer { font-size: 0.82rem; color: var(--text-muted); font-style: italic; margin-top: 8px; }

@media (max-width: 768px) {
    .form-grid-3 { grid-template-columns: 1fr; }
    .lab-card-grid { grid-template-columns: 1fr; }
    .spec-grid { grid-template-columns: 1fr 1fr; }
    .price-toggle { flex-direction: column; gap: 10px; }
}

/* ============================================================
   FORMULA MODULE
   ============================================================ */

/* Product type grid */
.pt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.pt-card {
    padding: 14px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
}

.pt-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.pt-name { font-weight: 600; font-size: 0.95rem; }

.pt-size {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-muted);
}

.pt-components {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.pt-comp-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
    background: var(--accent-light);
    color: var(--accent);
}

/* Send to batch */
.estimate-row {
    display: flex;
    align-items: center;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--info-light);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--info);
}

.shortage-banner {
    background: var(--warning-light);
    border: 1px solid #FFDBA6;
    border-radius: var(--radius-md);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.shortage-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    margin-bottom: 10px;
}

.shortage-icon { font-size: 1.3rem; }

.shortage-list {
    margin: 10px 0 10px 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.shortage-list li { margin-bottom: 4px; }

.shortage-note {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

/* ============================================================
   BATCHING MODULE
   ============================================================ */

.status-batching { background: #E8F0FE; color: #1967D2; }
.status-holding { background: var(--warning-light); color: var(--warning); }
.status-rework { background: #F3E8FD; color: #8430CE; }
.status-qc { background: #E0F7FA; color: #00838F; }
.status-in_qc { background: #E0F7FA; color: #00838F; }
.status-qc_flagged { background: var(--danger-light); color: var(--danger); }
.status-qc_passed { background: var(--success-light); color: var(--success); }
.status-production { background: #E6F4EA; color: #188038; }
.status-in_production { background: #E6F4EA; color: #188038; }
.status-in_final_check { background: #FEF7E0; color: #E37400; }
.status-completed { background: var(--success-light); color: var(--success); }
.status-rescinded { background: var(--bg-tertiary); color: var(--text-muted); text-decoration: line-through; }
.status-archived { background: var(--bg-tertiary); color: var(--text-muted); }

.record-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ============================================================
   QC MODULE
   ============================================================ */

.qc-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.qc-result-card {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 2px solid;
}

.qc-pass {
    border-color: #C4E6CE;
    background: var(--success-light);
}

.qc-fail {
    border-color: #F5C6C2;
    background: var(--danger-light);
}

.qc-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.qc-result-label {
    font-weight: 600;
    font-size: 0.88rem;
}

.qc-result-indicator {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.qc-pass .qc-result-indicator { color: var(--success); }
.qc-fail .qc-result-indicator { color: var(--danger); }

.qc-result-values {
    display: flex;
    gap: 20px;
}

.qc-result-value {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.05rem;
    display: block;
    margin-top: 2px;
}

.qc-result-spec {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    color: var(--text-secondary);
    display: block;
    margin-top: 2px;
}

.qc-input-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.qc-input-row input, .qc-input-row select {
    width: 100%;
}

.qc-spec-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ============================================================
   ARCHIVE & REORDER
   ============================================================ */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.pagination-info {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* Reorder cards */
.reorder-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.reorder-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid transparent;
}

.reorder-alert { border-left-color: var(--warning); }
.reorder-on_order { border-left-color: var(--info); }
.reorder-resolved { border-left-color: var(--success); opacity: 0.7; }

.reorder-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.reorder-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reorder-item-name {
    font-weight: 600;
    font-size: 1rem;
}

.reorder-card-body {}

.reorder-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 12px;
}

.reorder-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reorder-stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.reorder-stat-value {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 600;
}

.reorder-order-info {
    padding: 8px 12px;
    background: var(--info-light);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

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

.reorder-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.reorder-action-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Batch alert banners — flat, prominent, no box */
.batch-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-radius: 8px;
    border-left: 5px solid;
    margin-bottom: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
}
.batch-alert-icon { font-size: 1.4rem; flex-shrink: 0; margin-top: 1px; }
.batch-alert-content { flex: 1; }
.batch-alert-list { margin: 6px 0 0 18px; padding: 0; }
.batch-alert-list li { margin-bottom: 2px; }

.batch-alert-success {
    background: #E8F5E9;
    border-color: #43A047;
    color: #2E7D32;
}
.batch-alert-warning {
    background: #FFF3E0;
    border-color: #FB8C00;
    color: #E65100;
}
.batch-alert-danger {
    background: #FBE9E7;
    border-color: #E53935;
    color: #C62828;
}

/* Permission module cards grid */
.perm-modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.perm-module-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.perm-module-header {
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.perm-module-title {
    font-weight: 600;
    font-size: 0.9rem;
}
.perm-module-body {
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.perm-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}
.perm-checkbox-label input[type="checkbox"] {
    margin: 0;
}

/* Real-time poll update banner */
.poll-update-banner {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: #E3F2FD;
    border: 1px solid #90CAF9;
    border-left: 4px solid #1976D2;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: #1565C0;
    animation: pollSlideIn 0.3s ease;
}
@keyframes pollSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tab bar for sub-views (Chemical Inventory tabs) */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
}
.tab-link {
    padding: 8px 18px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.tab-link:hover {
    color: var(--text-primary);
}
.tab-link.tab-active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
