/**
 * Sanamahi Graphix ERP — Unified Enterprise SaaS Component Library
 * Architecture: Reusable Primitives, States, Variants & Density
 */

/* ── 1. Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    height: var(--input-height-md);
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    user-select: none;
    white-space: nowrap;
    position: relative;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-canvas), 0 0 0 4px var(--border-focus);
}

.btn:disabled, .btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* Button Variants */
.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-primary-text);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: var(--shadow-xs);
}

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

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

.btn-secondary {
    background-color: var(--bg-surface-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--text-muted);
}

.btn-outline {
    background-color: transparent;
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-outline:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--text-muted);
}

.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--color-danger);
    color: #FFFFFF;
    border-color: rgba(255, 255, 255, 0.12);
}

.btn-danger:hover {
    background-color: #E11D48;
}

.btn-success {
    background-color: var(--color-success);
    color: #09090B;
    font-weight: 600;
}

.btn-success:hover {
    background-color: #15B85C;
}

/* Button Sizes */
.btn-xs { height: 24px; padding: 0 var(--space-2); font-size: 0.6875rem; border-radius: var(--radius-xs); }
.btn-sm { height: var(--input-height-sm); padding: 0 var(--space-3); font-size: 0.75rem; }
.btn-lg { height: var(--input-height-lg); padding: 0 var(--space-5); font-size: 0.9375rem; border-radius: var(--radius-md); }
.btn-icon { width: var(--input-height-md); height: var(--input-height-md); padding: 0; }
.btn-icon.btn-sm { width: var(--input-height-sm); height: var(--input-height-sm); }
.btn-icon.btn-xs { width: 24px; height: 24px; }

/* ── 2. Form Controls ────────────────────────────────────────── */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.form-label.required::after {
    content: " *";
    color: var(--color-danger);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0 var(--space-3);
    height: var(--input-height-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    line-height: 1.4;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.password-wrapper, .search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.password-wrapper .form-input {
    padding-right: 40px; /* Make room for the eye icon */
}

.password-toggle-btn {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

.password-toggle-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.form-textarea, textarea.form-input {
    height: auto;
    padding: var(--space-2) var(--space-3);
    min-height: 72px;
    resize: vertical;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px var(--color-primary-bg);
}

.form-input::placeholder, .form-textarea::placeholder {
    color: var(--text-disabled);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-input-wrapper .icon {
    position: absolute;
    left: var(--space-3);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input-wrapper .form-input {
    padding-left: var(--space-8);
}

/* ── 3. Cards & KPI Metrics ─────────────────────────────────── */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    position: relative;
}

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

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

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

.card-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    background-color: rgba(255, 255, 255, 0.01);
}

/* KPI Stat Cards & Metric Summary Grid (Canonical ERP Style) */
.stat-grid,
.kpi-bar,
.supplier-kpi-bar,
.expense-kpi-grid,
.inventory-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    width: 100%;
}

.stat-card,
.kpi-card,
.supplier-kpi-card,
.expense-kpi-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
    position: relative;
    box-shadow: var(--shadow-sm);
}

.stat-card:hover,
.kpi-card:hover,
.supplier-kpi-card:hover,
.expense-kpi-card:hover {
    border-color: var(--border-strong);
}

.stat-label,
.kpi-label,
.supplier-kpi-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.stat-value,
.kpi-value,
.supplier-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    font-family: var(--font-mono);
    line-height: 1.2;
}

.stat-subtext,
.kpi-subtext {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}


/* ── 4. Currency Ticker (Dashboard) ───────────────────────────── */
.currency-ticker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.currency-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.currency-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
    border-color: var(--border-strong);
}

.currency-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.currency-code {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-primary);
    background-color: var(--color-primary-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    letter-spacing: 0.05em;
}

.currency-base {
    font-size: 0.6875rem;
    color: var(--text-dim);
    font-weight: 500;
}

.currency-body {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: var(--space-2);
}

.currency-rate {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.currency-trend {
    font-size: 0.6875rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
}

.currency-trend.trend-up {
    color: var(--color-success);
    background-color: rgba(23, 201, 100, 0.1);
}

.currency-trend.trend-down {
    color: var(--color-danger);
    background-color: rgba(243, 18, 96, 0.1);
}

.trend-icon {
    font-size: 0.5rem;
}

/* ── 5. High-Density Data Tables ────────────────────────────── */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
}

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

.table th {
    padding: var(--space-2) var(--space-3);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    background-color: var(--bg-surface-elevated);
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

.table td {
    padding: var(--space-2) var(--space-3);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

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

.table tbody tr {
    transition: background-color var(--transition-fast);
}

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

/* ── Table-Form Controls (Compact inputs inside tables & modals) ── */
.table td .form-input,
.table td .form-select,
.table-form .form-input,
.table-form .form-select {
    height: 32px;
    padding: 0 var(--space-2);
    font-size: 0.8125rem;
    line-height: 30px;
    border-radius: var(--radius-xs);
    width: 100%;
    min-width: 0;
}

.table td .form-select,
.table-form .form-select {
    padding-right: 22px;
    background-size: 10px 10px;
    background-position: right 6px center;
}

.table td .btn-xs,
.table-form .btn-xs {
    height: 28px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.table-form td {
    padding: 4px 6px;
}

.table-form th {
    padding: 6px 8px;
}

/* Add-on Builder Dynamic Line Card */
.addon-line-item-row {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    transition: border-color var(--transition-fast);
}

.addon-line-item-row:hover {
    border-color: var(--border-strong);
}



/* ── 5. Status Badges & Chips ────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1.2;
    border: 1px solid transparent;
    text-transform: uppercase;
}

.badge-primary, .badge-info {
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
    border-color: var(--color-info-border);
}

.badge-success {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    border-color: var(--color-success-border);
}

.badge-warning {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
    border-color: var(--color-warning-border);
}

.badge-danger {
    background-color: var(--color-danger-bg);
    color: var(--color-danger-text);
    border-color: var(--color-danger-border);
}

.badge-purple {
    background-color: var(--color-purple-bg);
    color: var(--color-purple-text);
    border-color: var(--color-purple-border);
}

.badge-neutral, .badge-draft {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border-color: var(--border-subtle);
}

/* Status-specific Aliases */
.badge-paid, .badge-completed, .badge-approved, .badge-preflight_passed, .badge-ready_to_print {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    border-color: var(--color-success-border);
}

.badge-unpaid, .badge-overdue, .badge-rejected, .badge-preflight_failed, .badge-print_issue {
    background-color: var(--color-danger-bg);
    color: var(--color-danger-text);
    border-color: var(--color-danger-border);
}

.badge-partial, .badge-printing_paused, .badge-approval_pending {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
    border-color: var(--color-warning-border);
}

.badge-in_production, .badge-printing_now, .badge-sent_to_finishing {
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
    border-color: var(--color-info-border);
}

/* ── 6. Tabs & Segmented Controls ───────────────────────────── */
.tab-nav {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-4);
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

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

/* Segmented Control Pills */
.segmented-control {
    display: inline-flex;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.segmented-btn {
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    padding: var(--space-1) var(--space-3);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.segmented-btn.active {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: var(--shadow-xs);
}

/* ── 7. Modals, Overlays & Contextual Drawers ───────────────── */
/*
 * CANONICAL MODAL SYSTEM — Single source of truth for the entire ERP.
 * All page-specific CSS files must NOT redefine these classes.
 *
 * Structure:
 *   .modal-overlay (or .modal, .modal-backdrop)
 *     └── .modal-dialog [.modal-sm | .modal-md | .modal-lg | .modal-xl | .modal-full]
 *           └── .modal-content
 *                 ├── .modal-header
 *                 │     ├── .modal-title
 *                 │     └── .modal-close
 *                 ├── .modal-body
 *                 └── .modal-footer
 */

/* ── Backdrop / Overlay ──────────────────────────────────────── */
.modal-overlay,
.modal-backdrop,
.modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.70);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    box-sizing: border-box;
    overscroll-behavior: contain;
}

/* Hidden state — used for page-local modals toggled by JS */
.modal-overlay.hidden,
.modal-backdrop.hidden,
.modal.hidden {
    display: none !important;
}

/* Active/shown states — for .modal class toggled by adding active/show */
.modal.active,
.modal.show,
.modal[style*="display: flex"],
.modal[style*="display: block"] {
    display: flex !important;
}

/* ── Dialog Container (sized) ────────────────────────────────── */
.modal-dialog {
    width: 100%;
    max-width: 600px;       /* Default = modal-md */
    max-height: 92vh;
    margin: auto;
    position: relative;
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

/* Size Modifiers */
.modal-sm   { max-width: 440px; }
.modal-md   { max-width: 600px; }
.modal-lg   { max-width: 820px; }
.modal-xl   { max-width: 1020px; }
.modal-full { max-width: calc(100vw - 48px); }

/* ── Content Shell ───────────────────────────────────────────── */
.modal-content {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 48px -8px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
    display: flex;
    flex-direction: column;
    max-height: 92vh;
    overflow: hidden;
    animation: modalScaleIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    width: 100%;
}

/* When modal-content is the direct child of .modal-overlay (no .modal-dialog wrapper) */
.modal-overlay > .modal-content,
.modal-backdrop > .modal-content,
.modal > .modal-content {
    max-width: 560px;
    width: 100%;
}

/* modal.js renders .modal-backdrop > .modal-dialog > [header/body/footer] (no .modal-content wrapper).
 * Give .modal-dialog the visual shell when used this way inside .modal-backdrop. */
.modal-backdrop > .modal-dialog {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 48px -8px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
    overflow: hidden;
    animation: modalScaleIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

/* ── Header ──────────────────────────────────────────────────── */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-surface-elevated);
    flex-shrink: 0;
    gap: var(--space-3);
}

.modal-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
}

/* ── Close Button ────────────────────────────────────────────── */
.modal-close {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    line-height: 1;
    flex-shrink: 0;
    transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
    padding: 0;
}

.modal-close:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-hover);
    border-color: var(--border-strong);
}

.modal-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-canvas), 0 0 0 4px var(--border-focus);
}

/* ── Body (scrollable) ───────────────────────────────────────── */
.modal-body {
    padding: var(--space-5);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.modal-body::-webkit-scrollbar {
    width: 5px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

/* ── Footer ──────────────────────────────────────────────────── */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
    flex-shrink: 0;
}

/* Contextual Slide-Out Drawer */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
}

.drawer-content {
    background-color: var(--bg-surface-elevated);
    border-left: 1px solid var(--border-strong);
    width: 100%;
    max-width: 480px;
    height: 100vh;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    animation: drawerSlideIn 0.2s ease-out;
}

@keyframes drawerSlideIn {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}


/* ── 8. Empty States & Skeletons ────────────────────────────── */
.empty-state {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

.empty-state-icon {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.empty-state-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.empty-state-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    max-width: 320px;
}

/* Skeleton Loading Shimmer */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface-elevated) 25%, var(--bg-surface-hover) 50%, var(--bg-surface-elevated) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-xs);
}

.skeleton-text {
    height: 14px;
    border-radius: 4px;
}

.skeleton-title {
    height: 20px;
    border-radius: 4px;
}

.skeleton-block {
    height: 80px;
    border-radius: var(--radius-md);
}

.skeleton-table-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: none;
}

.skeleton-table-row {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    align-items: center;
}

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

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── 9. Toasts & Alerts ─────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: var(--space-4);
    right: var(--space-4);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3) var(--space-4);
    min-width: 280px;
    max-width: 380px;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 0.8125rem;
    border-left: 3px solid var(--color-primary);
    animation: toastSlide 0.18s ease-out;
}

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

.toast-success { border-left-color: var(--color-success); }
.toast-error   { border-left-color: var(--color-danger); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-info    { border-left-color: var(--color-info); }

/* ── 10. Unified KPI & Metric Summary System ─────────────────── */
.kpi-bar,
.supplier-kpi-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    width: 100%;
}

@media (max-width: 768px) {
    .kpi-bar,
    .supplier-kpi-bar {
        grid-template-columns: 1fr;
    }
}

.kpi-card,
.supplier-kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.kpi-card::before,
.supplier-kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    transition: background var(--transition-fast);
}

.kpi-card:hover,
.supplier-kpi-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-card.primary::before,
.supplier-kpi-card.primary::before { background: var(--color-primary); }
.kpi-card.success::before,
.supplier-kpi-card.success::before { background: var(--color-success); }
.kpi-card.warning::before,
.supplier-kpi-card.warning::before { background: var(--color-warning); }
.kpi-card.danger::before,
.supplier-kpi-card.danger::before  { background: var(--color-danger); }
.kpi-card.info::before,
.supplier-kpi-card.info::before    { background: var(--color-info); }

.kpi-label,
.supplier-kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.kpi-value,
.supplier-kpi-value {
    font-size: 1.5rem;
    font-weight: 800;
    font-family: var(--font-mono, monospace);
    color: var(--text-primary);
    line-height: 1.2;
}

.kpi-subtext {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

/* ── 11. Table Container & Filter Toolbar Primitives ─────────── */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.filter-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    width: 100%;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 240px;
}

.search-box .form-input {
    padding-left: 2.25rem;
    width: 100%;
}

.search-box .icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.skeleton-row-placeholder {
    height: 38px;
    width: 100%;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--bg-surface-elevated) 25%, var(--bg-surface-hover) 50%, var(--bg-surface-elevated) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    margin: var(--space-2) 0;
}

/* ── 12. SaaS Utility Variants, Badges & Spinners ────────────── */
.btn-warning {
    background-color: var(--color-warning);
    color: #000000;
    border-color: rgba(255, 255, 255, 0.12);
    font-weight: 600;
}

.btn-warning:hover {
    background-color: #E5A000;
    color: #000000;
}

.badge-secondary {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.badge-lg {
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    border-radius: var(--radius-md);
}

.badge-product {
    background: rgba(0, 111, 238, 0.12);
    color: var(--color-primary);
    border: 1px solid rgba(0, 111, 238, 0.25);
}

.spinner,
.spinner-border {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    vertical-align: text-bottom;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

.spinner-sm,
.spinner-border-sm {
    width: 0.875rem;
    height: 0.875rem;
    border-width: 1.5px;
}

@keyframes spinner-border {
    to { transform: rotate(360deg); }
}

.form-select-sm,
.form-input-sm {
    height: var(--input-height-sm);
    padding: 0 var(--space-2);
    font-size: 0.75rem;
}

.form-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.field-error {
    font-size: 0.75rem;
    color: var(--color-danger);
    margin-top: var(--space-1);
}

.invoice-meta-box {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
}

/* Common Typography & Density Helpers */
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }
.text-xs       { font-size: 0.75rem; }
.p-3           { padding: var(--space-3); }
.p-4           { padding: var(--space-4); }
.mt-1          { margin-top: var(--space-1); }

/* Key-Value Pair Rows */
.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 0.8125rem;
}

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

.kv-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.kv-val {
    color: var(--text-primary);
    font-weight: 600;
}

/* Pagination & Table Footer */
.table-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.pagination {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.pagination button,
.pagination .page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.pagination button:hover:not(:disabled),
.pagination .page-btn:hover:not(.disabled) {
    background: var(--bg-surface-hover);
    border-color: var(--border-strong);
}

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

.pagination button:disabled,
.pagination .page-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Tab Navigation Primitives */
.tabs-nav {
    display: flex;
    gap: var(--space-2);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-4);
    overflow-x: auto;
}

.tab-content {
    display: block;
    width: 100%;
}

.tab-pane {
    display: none;
}

.tab-pane.active,
.tab-pane:not(.hidden) {
    display: block;
}

.tab-pane.hidden {
    display: none !important;
}

.page-container {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.badge-green {
    background: rgba(23, 201, 100, 0.15);
    color: var(--color-success);
    border: 1px solid rgba(23, 201, 100, 0.3);
}
