/* Modern CSS Reset */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    /* Shopify Polaris-inspired Color Palette: dark-gray primary, green kept for success */
    --color-primary: #1a1a1a;
    --color-primary-hover: #303030;
    --color-primary-light: #f0f0f0;

    --color-secondary: #5c6ac4;
    --color-secondary-hover: #4a5ab8;

    --color-success: #008060;
    --color-warning: #ffc453;
    --color-danger: #d72c0d;
    --color-info: #2c6ecb;

    /* Neutral Colors */
    --color-bg: #f6f6f7;
    --color-bg-surface: #ffffff;
    --color-bg-surface-secondary: #f9fafb;
    --color-bg-surface-hover: #f3f4f6;

    --color-text: #202223;
    --color-text-secondary: #6d7175;
    --color-text-disabled: #8c9196;
    --color-text-inverse: #ffffff;

    --color-border: #e1e3e5;
    --color-border-strong: #c9cccf;
    --color-border-focus: #005bd3;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Layout */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 60px;
    --header-height: 56px;

    /* Transition */
    --transition-speed: 0.2s;
}

/* Dark Mode */
[data-theme="dark"] {
    --color-primary: #fafafa;
    --color-primary-hover: #e5e5e5;
    --color-primary-light: #2a2a2a;

    --color-bg: #111318;
    --color-bg-surface: #1a1d24;
    --color-bg-surface-secondary: #22262e;
    --color-bg-surface-hover: #2a2e38;

    --color-text: #e1e3e6;
    --color-text-secondary: #8b8f96;
    --color-text-disabled: #5c5f66;
    --color-text-inverse: #111318;

    --color-border: #2e3138;
    --color-border-strong: #3e424a;
    --color-border-focus: #3b82f6;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-lg: 0 4px 6px -1px rgb(0 0 0 / 0.4);
}

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

/* Base Styles */
html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
    margin: 0;
    padding: 0;
}

/* Links */
a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--color-primary-hover);
}

/* ===================== */
/* Layout Components     */
/* ===================== */

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.header-logo {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
}

.header-logo img {
    height: 32px;
    width: auto;
}

.header-logo svg {
    width: 28px;
    height: 28px;
    color: var(--color-primary);
}

.erp-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-3);
    border-radius: var(--radius-full, 999px);
    color: #fff;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.erp-badge:hover {
    opacity: 0.85;
    color: #fff;
}

/* ERP without its own color falls back to --color-primary, which is near-white in the dark theme */
[data-theme="dark"] .erp-badge.erp-badge-default,
[data-theme="dark"] .erp-badge.erp-badge-default:hover {
    color: #1a1a1a;
}

.header-search {
    position: relative;
    width: 400px;
    max-width: 100%;
}

.header-search input {
    width: 100%;
    padding: var(--space-2) var(--space-3) var(--space-2) 40px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    background: var(--color-bg-surface-secondary);
    transition: all 0.15s ease;
}

.header-search input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    background: var(--color-bg-surface);
    box-shadow: 0 0 0 2px rgba(0, 91, 211, 0.1);
}

.header-search svg {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--color-text-secondary);
}

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

.header-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.header-user:hover {
    background: var(--color-bg-surface-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-inverse);
    font-weight: 600;
    font-size: var(--font-size-sm);
}

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

.user-name {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
}

.user-account {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

/* Main Content Area */
.main-wrapper {
    display: flex;
    flex: 1;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--color-bg-surface);
    border-right: 1px solid var(--color-border);
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    overflow: hidden;
    transition: width 0.2s ease, min-width 0.2s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
}

.nav-section {
    margin-bottom: var(--space-4);
}

.nav-section-title {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
}

.sidebar.collapsed .nav-section-title {
    display: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    text-decoration: none;
}

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

.nav-item.active {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar.collapsed .nav-item-text {
    display: none;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: var(--space-2);
}

.nav-item-badges {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.nav-item-badge {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
}

.nav-item-badge.badge-warning {
    background: #f59e0b;
}

.nav-item-badge.badge-error {
    background: var(--color-danger);
}

.sidebar.collapsed .nav-item-badge,
.sidebar.collapsed .nav-item-badges {
    display: none;
}

/* Content Area */
.content {
    flex: 1;
    padding: var(--space-6);
    overflow-x: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
}

.content-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.content-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-top: var(--space-1);
}

/* ===================== */
/* Card Component        */
/* ===================== */

.card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

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

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

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

.card-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-surface-secondary);
}

/* ===================== */
/* Button Component      */
/* ===================== */

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.5rem 0.95rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 600;
    letter-spacing: 0.005em;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
    user-select: none;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease,
                box-shadow 0.18s ease, transform 0.08s ease;
    will-change: transform;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 91, 211, 0.35);
}

.btn:active {
    transform: translateY(0.5px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Primary — Shopify Polaris-style dark, with subtle inner highlight + soft depth */
.btn-primary {
    background: linear-gradient(180deg, #2c2c2c 0%, var(--color-primary) 100%);
    color: var(--color-text-inverse);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        inset 0 0 0 1px rgba(0, 0, 0, 0.20),
        0 1px 0 rgba(0, 0, 0, 0.05);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #3a3a3a 0%, var(--color-primary-hover) 100%);
    color: var(--color-text-inverse);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 0 0 1px rgba(0, 0, 0, 0.22),
        0 2px 4px rgba(0, 0, 0, 0.10);
}

.btn-primary:active {
    background: var(--color-primary-hover);
    box-shadow:
        inset 0 2px 3px rgba(0, 0, 0, 0.30),
        inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .btn-primary {
    background: linear-gradient(180deg, #ffffff 0%, var(--color-primary) 100%);
    color: var(--color-text-inverse);
    box-shadow:
        inset 0 -1px 0 rgba(0, 0, 0, 0.08),
        inset 0 0 0 1px rgba(0, 0, 0, 0.06),
        0 1px 2px rgba(0, 0, 0, 0.30);
}

[data-theme="dark"] .btn-primary:hover {
    background: linear-gradient(180deg, #ffffff 0%, var(--color-primary-hover) 100%);
}

/* Secondary — soft elevated surface */
.btn-secondary {
    background: var(--color-bg-surface);
    color: var(--color-text);
    border-color: var(--color-border);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.btn-secondary:hover {
    background: var(--color-bg-surface-hover);
    border-color: var(--color-border-strong);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn-secondary:active {
    background: var(--color-bg-surface-hover);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Danger — red, same depth treatment as primary */
.btn-danger {
    background: linear-gradient(180deg, #e6411f 0%, var(--color-danger) 100%);
    color: var(--color-text-inverse);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 0 0 1px rgba(0, 0, 0, 0.10),
        0 1px 0 rgba(0, 0, 0, 0.05);
}

.btn-danger:hover {
    background: linear-gradient(180deg, #d72c0d 0%, #bf2609 100%);
    color: var(--color-text-inverse);
}

.btn-danger:active {
    background: #bf2609;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.25);
}

/* Ghost — minimal, no chrome */
.btn-ghost {
    background: transparent;
    color: var(--color-text);
    border-color: transparent;
}

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

.btn-ghost:active {
    background: var(--color-bg-surface-hover);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--font-size-md);
}

.btn-icon {
    padding: var(--space-2);
    min-width: 36px;
    min-height: 36px;
}

.btn-icon.btn-sm {
    min-width: 28px;
    min-height: 28px;
    padding: var(--space-1);
}

/* ===================== */
/* Form Components       */
/* ===================== */

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

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--space-1);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-family: inherit;
    background: var(--color-bg-surface);
    color: var(--color-text);
    transition: all 0.15s ease;
}

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

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

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

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

/* inline validation (initFormValidation in app.js) */
.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-danger) 15%, transparent);
}

.field-error {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    font-size: var(--font-size-xs);
    color: var(--color-danger);
    animation: fieldErrorIn 0.18s ease-out;
}

.field-error::before {
    content: '';
    flex: 0 0 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

@keyframes fieldErrorIn {
    from { opacity: 0; transform: translateY(-3px); }
    to { opacity: 1; transform: none; }
}

form.shake {
    animation: formShake 0.3s ease-in-out;
}

@keyframes formShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-danger);
    margin-top: var(--space-1);
}

/* ===================== */
/* Table Component       */
/* ===================== */

.table-container {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    gap: var(--space-3);
    flex-wrap: wrap;
}

.table-toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.table-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.table-search {
    position: relative;
}

.table-search input {
    padding-left: 36px;
    width: 250px;
}

.table-search svg {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: var(--color-bg-surface-secondary);
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--color-border);
    position: relative;
    user-select: none;
}

.data-table th.sortable {
    cursor: pointer;
}

.data-table th.sortable:hover {
    background: var(--color-bg-surface-hover);
}

.data-table th .sort-icon {
    display: inline-flex;
    flex-direction: column;
    margin-left: var(--space-1);
    opacity: 0.3;
}

.data-table th.sorted .sort-icon {
    opacity: 1;
}

.data-table th .resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
}

.data-table th .resize-handle:hover {
    background: var(--color-primary);
}

.data-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    vertical-align: middle;
}

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

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

/* Queue ID cell with direction arrow */
.queue-id-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-bg-surface-secondary);
    color: var(--color-text);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: var(--font-size-xs);
}

.queue-id-cell i {
    font-style: normal;
    color: var(--color-text-secondary);
}

.queue-id-cell svg {
    flex-shrink: 0;
    color: var(--color-text-secondary);
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-surface-secondary);
}

.pagination-info {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

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

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-surface);
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-text-inverse);
}

/* ===================== */
/* Status Badges         */
/* ===================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 500;
    line-height: 1;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-neutral {
    background: var(--color-bg-surface-secondary);
    color: var(--color-text-secondary);
}

/* ===================== */
/* Toast Notifications   */
/* ===================== */

.toast-container {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 450px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.hiding {
    animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

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

.toast-content {
    flex: 1;
}

.toast-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-1);
}

.toast-message {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.toast-close {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
    font-size: 18px;
    line-height: 1;
}

.toast-close:hover {
    color: var(--color-text);
}

/* ===================== */
/* Modal Component       */
/* ===================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--color-bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn 0.2s ease;
}

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

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

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

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

.modal-body {
    padding: var(--space-4);
    overflow-y: auto;
    max-height: calc(90vh - 140px);
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-4);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-surface-secondary);
}

/* ===================== */
/* Dropdown Menu         */
/* ===================== */

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--space-1);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    padding: var(--space-1);
    z-index: 100;
    display: none;
}

.dropdown-menu.active {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.dropdown-item:hover {
    background: var(--color-bg-surface-hover);
    color: var(--color-text);
}

.dropdown-item svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
}

.dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-1) 0;
}

/* ===================== */
/* Loading States        */
/* ===================== */

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.skeleton {
    background: linear-gradient(90deg, var(--color-bg-surface-secondary) 25%, var(--color-bg-surface-hover) 50%, var(--color-bg-surface-secondary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

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

/* ===================== */
/* Empty State           */
/* ===================== */

.empty-state {
    text-align: center;
    padding: var(--space-12);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-4);
    color: var(--color-text-disabled);
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
}

/* ===================== */
/* Utilities             */
/* ===================== */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.text-primary { color: var(--color-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }

.d-flex { display: flex; }
.d-inline-flex { display: inline-flex; }
.d-none { display: none; }

.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.align-center { align-items: center; }
.align-start { align-items: flex-start; }
.align-end { align-items: flex-end; }

.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.m-0 { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }

.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }

.w-100 { width: 100%; }

.rounded { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===================== */
/* Responsive            */
/* ===================== */

@media (max-width: 1024px) {
    .header-search {
        width: 200px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

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

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

@media (max-width: 768px) {
    .header-search {
        display: none;
    }

    .user-info {
        display: none;
    }

    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .table-toolbar-left,
    .table-toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .table-search input {
        width: 100%;
    }

    .content {
        padding: var(--space-3);
    }
}

/* ===================== */
/* Page Header           */
/* ===================== */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    gap: var(--space-4);
}

.page-header-left {
    flex: 1;
}

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

.page-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.page-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: var(--space-1) 0 0 0;
}

/* ===================== */
/* Filters Panel         */
/* ===================== */

.filters-panel {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.filters-row {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 150px;
}

.filter-group label {
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* ===================== */
/* Detail View Component */
/* ===================== */

.detail-view {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-surface-secondary);
}

.detail-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
}

.detail-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.detail-title-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.detail-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.detail-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-top: var(--space-1);
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-6);
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-surface);
}

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

.detail-meta-label {
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-meta-value {
    font-size: var(--font-size-sm);
    color: var(--color-text);
    font-weight: 500;
}

.detail-meta-value code {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: var(--font-size-xs);
    background: var(--color-bg-surface);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

/* Detail Sections */
.detail-section {
    padding: var(--space-6);
    border-bottom: 1px solid var(--color-border);
}

.detail-section:last-child {
    border-bottom: none;
}

.detail-section-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 var(--space-4) 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.detail-section-title .section-toggle {
    margin-left: auto;
}

.detail-section-title .section-toggle svg {
    transition: transform 0.2s ease;
}

.detail-section.collapsed .section-toggle svg {
    transform: rotate(-90deg);
}

.detail-section.collapsed .detail-section-content {
    display: none;
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--space-4);
}

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

.info-item-full {
    grid-column: 1 / -1;
}

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

.info-value {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.info-value code {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: var(--font-size-xs);
    background: var(--color-bg-surface-secondary);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

/* ===================== */
/* JSON Viewer Component */
/* ===================== */

.json-viewer {
    font-size: var(--font-size-sm);
}

.json-object {
    background: var(--color-bg-surface-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.json-property {
    display: flex;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

.json-property:last-child {
    border-bottom: none;
}

.json-property:nth-child(even) {
    background: var(--color-bg-surface);
}

.json-key {
    flex-shrink: 0;
    width: 180px;
    font-weight: 500;
    color: var(--color-text);
    padding-right: var(--space-3);
}

.json-value {
    flex: 1;
    color: var(--color-text-secondary);
    word-break: break-word;
}

.json-value-string {
    color: #059669;
}

.json-value-number {
    color: #2563eb;
    font-family: 'Monaco', 'Consolas', monospace;
}

.json-value-boolean {
    color: #7c3aed;
    font-weight: 500;
}

.json-value-null {
    color: var(--color-text-disabled);
    font-style: italic;
}

/* Nested JSON Objects */
.json-nested {
    margin-top: var(--space-2);
}

.json-nested .json-object {
    margin-left: 0;
}

/* JSON Array */
.json-array {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.json-array-item {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
}

.json-array-item-header {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}

/* Simple Array (strings/numbers) */
.json-simple-array {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.json-simple-array-item {
    background: var(--color-bg-surface-secondary);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

/* JSON Items List (for multiple data items) */
.json-items-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.json-item-wrapper {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.json-item-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-surface-secondary);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease;
}

.json-item-header:hover {
    background: var(--color-bg-surface-hover);
}

.json-item-index {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
    min-width: 24px;
}

.json-item-name {
    flex: 1;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
}

.json-item-toggle {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
    transition: transform 0.2s ease;
}

.json-item-header.collapsed .json-item-toggle {
    transform: rotate(-90deg);
}

.json-item-content {
    padding: var(--space-4);
    border-top: 1px solid var(--color-border);
    display: none;
}

.json-item-content.expanded {
    display: block;
}

/* Price Group Styling */
.json-price-group {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
}

.json-price-group:last-child {
    margin-bottom: 0;
}

.json-price-group-header {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}

/* Alert Boxes */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-4);
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* ===================== */
/* Direction Badges      */
/* ===================== */

.direction-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 500;
}

.direction-inbound {
    background: #dbeafe;
    color: #1e40af;
}

.direction-outbound {
    background: #dcfce7;
    color: #166534;
}

.direction-bidirectional {
    background: #f3e8ff;
    color: #6b21a8;
}

.direction-badge svg {
    width: 12px;
    height: 12px;
}

/* ===================== */
/* Large Modal           */
/* ===================== */

.modal-lg {
    max-width: 1120px;
}

.modal-lg .modal-body {
    max-height: calc(92vh - 160px);
    padding: var(--space-5) var(--space-6);
    background: var(--color-bg);
}

/* ===================== */
/* Detail tables (used inside modal cards: order/customer/product detail) */
/* ===================== */

.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
    font-size: var(--font-size-sm);
}

.detail-table tr:last-child td {
    border-bottom: 0;
}

.detail-table .detail-label {
    color: var(--color-text-secondary);
    width: 180px;
    white-space: nowrap;
    font-weight: 500;
}

.detail-table code {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    background: var(--color-bg-surface-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    color: var(--color-text);
}

/* ===================== */
/* Cards inside the dataitem detail modal — more prominent headers */
/* ===================== */

#dataitemDetailModal .card {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

#dataitemDetailModal .card-header {
    position: relative;
    padding: var(--space-3) var(--space-4) var(--space-3) var(--space-5);
    background: var(--color-bg-surface-secondary);
    border-bottom: 1px solid var(--color-border);
}

#dataitemDetailModal .card-header::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--color-primary);
    border-top-left-radius: var(--radius-lg);
    border-bottom-left-radius: var(--radius-lg);
}

#dataitemDetailModal .card-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--color-text);
}

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

#dataitemDetailModal h4 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    margin: var(--space-4) 0 var(--space-2);
}

#dataitemDetailModal .data-table {
    font-size: var(--font-size-sm);
}

#dataitemDetailModal .data-table thead th {
    background: var(--color-bg-surface-secondary);
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

#dataitemDetailModal .data-table tbody td {
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

/* ===================== */
/* Modern Order/Customer/Product Detail Layout (in modal) */
/* ===================== */

.order-detail {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    color: var(--color-text);
}

/* Hero */
.order-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-6);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--color-border);
}
.order-hero-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    color: var(--color-text-tertiary, var(--color-text-secondary));
    margin-bottom: 4px;
}
.order-hero-number {
    font-size: 1.65rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
    color: var(--color-text);
}
.order-hero-meta {
    margin-top: var(--space-2);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    align-items: center;
}
.order-hero-meta .dot {
    color: var(--color-text-tertiary, var(--color-text-secondary));
    opacity: 0.5;
}
.order-hero-right {
    text-align: right;
    flex-shrink: 0;
}
.order-hero-total {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}
.order-hero-badges {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
    justify-content: flex-end;
}

/* Pills (status badges) */
.pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.4;
    border: 1px solid transparent;
}
.pill-neutral  { background: var(--color-bg-surface-secondary); color: var(--color-text-secondary); border-color: var(--color-border); }
.pill-success  { background: rgba(0, 128, 96, 0.10); color: var(--color-success, #008060); border-color: rgba(0, 128, 96, 0.25); }
.pill-warning  { background: rgba(255, 196, 83, 0.18); color: #8a5a00; border-color: rgba(255, 196, 83, 0.45); }

/* Section heading */
.section-h {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-3);
    padding: 0;
    border: 0;
}
.section-h-with-count {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.count-pill {
    background: var(--color-bg-surface-secondary);
    color: var(--color-text-secondary);
    border-radius: var(--radius-full);
    padding: 1px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    border: 1px solid var(--color-border);
}

/* Meta grid: label/value pairs */
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4) var(--space-6);
    margin: 0;
    padding: 0;
}
.meta-grid > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.meta-grid dt {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary, var(--color-text-secondary));
    font-weight: 500;
}
.meta-grid dd {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.meta-grid dd code {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    background: var(--color-bg-surface-secondary);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
}

/* Note block */
.note-block {
    background: var(--color-bg-surface-secondary);
    border-left: 3px solid var(--color-border-strong);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}
.note-block p { margin: 0; }
.note-block p + p { margin-top: var(--space-2); }

/* Addresses */
.addr-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
}
.addr-block p {
    margin: 0;
    line-height: 1.6;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}
.addr-block .addr-name {
    font-weight: 600;
    margin-bottom: 4px;
}
.addr-block .addr-tax {
    margin-top: var(--space-2);
    font-size: 0.78rem;
    color: var(--color-text-secondary);
}
.addr-block .addr-extra {
    margin-top: var(--space-2);
    font-size: 0.78rem;
    color: var(--color-text-secondary);
}
.addr-block .muted { color: var(--color-text-tertiary, var(--color-text-secondary)); font-style: italic; }

/* Items table */
.items-table-wrap {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--color-bg-surface);
}
.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}
.items-table thead th {
    background: var(--color-bg-surface-secondary);
    text-align: left;
    padding: var(--space-2) var(--space-4);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
}
.items-table thead th.num { text-align: right; }
.items-table tbody td {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    color: var(--color-text);
}
.items-table tbody tr:first-child td { border-top: 0; }
.items-table tbody tr:hover td { background: var(--color-bg-surface-secondary); }
.items-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.items-table .strong { font-weight: 600; }
.items-table code {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--color-text-secondary);
}
.items-table .muted { color: var(--color-text-tertiary, var(--color-text-secondary)); font-size: 0.85em; }

/* Totals / VAT recap */
.totals-block { display: flex; flex-direction: column; gap: var(--space-3); }
.recap-table {
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    margin-left: auto;
    min-width: 360px;
}
.recap-table th, .recap-table td {
    padding: 6px 12px;
    text-align: left;
}
.recap-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.recap-table thead th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
}
.recap-table tbody td { color: var(--color-text-secondary); }
.recap-table tfoot td {
    border-top: 1px solid var(--color-border);
    padding-top: 8px;
    color: var(--color-text);
    font-weight: 600;
}
.recap-table tfoot .strong { font-weight: 700; font-size: 1.05em; }

/* Sync strip — compact at bottom */
.sync-strip {
    background: var(--color-bg-surface-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--color-border);
}
.sync-strip .section-h { margin-bottom: var(--space-3); }
.sync-strip .meta-grid dd { font-weight: 500; font-size: 0.85rem; }

/* Responsive collapse for narrow modal width */
@media (max-width: 720px) {
    .order-hero { flex-direction: column; }
    .order-hero-right { text-align: left; }
    .order-hero-badges { justify-content: flex-start; }
    .addr-grid { grid-template-columns: 1fr; }
}

/* Modal Loading State */
.modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    gap: var(--space-3);
    color: var(--color-text-secondary);
}

/* Modal Detail Styles */
.modal-detail-header {
    margin-bottom: var(--space-4);
}

.modal-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-surface-secondary);
    border-radius: var(--radius-md);
}

.modal-detail-section {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}

.modal-detail-section:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.modal-detail-section-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 var(--space-3) 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.modal-detail-section-title.collapsible {
    cursor: pointer;
    user-select: none;
    padding: var(--space-2);
    margin: calc(-1 * var(--space-2));
    margin-bottom: var(--space-3);
    border-radius: var(--radius-md);
    transition: background-color 0.15s ease;
}

.modal-detail-section-title.collapsible:hover {
    background: var(--color-bg-surface-hover);
}

.modal-detail-section-title .section-toggle-icon {
    margin-left: auto;
    transition: transform 0.2s ease;
    color: var(--color-text-secondary);
}

.modal-detail-section.collapsed .section-toggle-icon {
    transform: rotate(-90deg);
}

.modal-detail-section.collapsed .modal-detail-section-content {
    display: none;
}

/* ===================== */
/* Draggable Modal       */
/* ===================== */

.modal-header-draggable {
    cursor: move;
}

.modal-header-draggable .modal-close {
    cursor: pointer;
}

.modal.dragging {
    user-select: none;
    opacity: 0.95;
}

.modal.resizing {
    user-select: none;
}

/* ===================== */
/* Resizable Modal       */
/* ===================== */

.modal-resizable {
    position: relative;
    display: flex;
    flex-direction: column;
}

.modal-resizable .modal-body {
    flex: 1;
    overflow-y: auto;
}

.modal-resize-handle {
    position: absolute;
    z-index: 10;
}

/* Corner handles */
.modal-resize-se {
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: se-resize;
}

.modal-resize-sw {
    left: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: sw-resize;
}

.modal-resize-ne {
    right: 0;
    top: 0;
    width: 16px;
    height: 16px;
    cursor: ne-resize;
}

.modal-resize-nw {
    left: 0;
    top: 0;
    width: 16px;
    height: 16px;
    cursor: nw-resize;
}

/* Edge handles */
.modal-resize-n {
    top: 0;
    left: 16px;
    right: 16px;
    height: 6px;
    cursor: n-resize;
}

.modal-resize-s {
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 6px;
    cursor: s-resize;
}

.modal-resize-e {
    right: 0;
    top: 16px;
    bottom: 16px;
    width: 6px;
    cursor: e-resize;
}

.modal-resize-w {
    left: 0;
    top: 16px;
    bottom: 16px;
    width: 6px;
    cursor: w-resize;
}

/* Resize indicator in corner */
.modal-resize-se::after {
    content: '';
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--color-border-strong);
    border-bottom: 2px solid var(--color-border-strong);
    opacity: 0.5;
}

.modal-resizable:hover .modal-resize-se::after {
    opacity: 1;
}
