/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    min-height: 100vh;
    direction: rtl;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.app-header {
    background: #111827;
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.header-content {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.header-brand   { justify-self: start; }
.main-nav       { justify-self: center; }
.header-user-info { justify-self: end; }

/* Brand */
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.header-logo {
    width: auto;
    height: 90px;
    object-fit: contain;
    border-radius: 10px;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.35));
}

.header-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.header-brand-name {
    font-size: 1.1rem;
    font-weight: 800;
    background: linear-gradient(90deg, #ffffff 0%, #d4af6a 60%, #f0c96e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-shadow: none;
    filter: drop-shadow(0 1px 4px rgba(200,148,26,0.4));
}

.header-brand-sub {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.55);
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

/* Nav */
.main-nav {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.22rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.42rem 0.95rem;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: rgba(255, 255, 255, 0.45);
    font-family: 'Cairo', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-btn i {
    font-size: 0.75rem;
    opacity: 0.7;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
}

.nav-btn.active {
    background: #ff6b35;
    color: #fff;
    box-shadow: 0 2px 10px rgba(255,107,53,0.45);
}

.nav-btn.active i {
    opacity: 1;
    color: #fff;
}

/* Admin dropdown */
.nav-dropdown {
    position: relative;
}

.nav-admin-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.42rem 0.95rem;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: rgba(255, 255, 255, 0.45);
    font-family: 'Cairo', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-admin-trigger:hover,
.nav-dropdown.open .nav-admin-trigger {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
}

/* Highlight trigger when a child section is active */
.nav-dropdown:has(.nav-btn.active) .nav-admin-trigger {
    background: rgba(255, 107, 53, 0.2);
    color: #ff8c5e;
}

.nav-dropdown-arrow {
    font-size: 0.6rem;
    transition: transform 0.2s ease;
    margin-right: 0.1rem;
}

.nav-dropdown.open .nav-dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #1e2a3a;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 9999;
}

.nav-dropdown.open .nav-dropdown-menu {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.nav-dropdown-item {
    width: 100%;
    justify-content: flex-end;
    text-align: right;
    border-radius: 7px;
    padding: 0.5rem 0.85rem;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.content-section {
    display: none;
    height: 100%;
}

.content-section.active {
    display: flex;
    flex-direction: column;
}

.section-body {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    min-height: 0;
}

.sticky-action-bar {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}
/* Hide WO sticky bar until sidebar fields are filled */
.sticky-action-bar.sab-hidden {
    height: 0;
    padding: 0;
    overflow: hidden;
    border-top: none;
    box-shadow: none;
    opacity: 0;
    transition: height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
}
.sticky-action-bar {
    transition: height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
}

/* Sticky bar buttons — white glass default, colour on hover */
.sab-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-size: 0.84rem;
    font-weight: 600;
    padding: 0.38rem 0.5rem;
    white-space: nowrap;
    border-radius: 10px;
    cursor: pointer;
    /* White glass default */
    background: rgba(255, 255, 255, 0.62) !important;
    color: #374151 !important;
    border: 1px solid rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.07), inset 0 1px 0 rgba(255,255,255,0.9);
    transition: background 0.22s ease, color 0.22s ease,
                border-color 0.22s ease, box-shadow 0.22s ease;
}
.sab-btn i { font-size: 0.82rem; }

/* حفظ وطباعة — amber/gold */
.sab-print:hover {
    background: rgba(217, 119, 6, 0.82) !important;
    color: #fff !important;
    border-color: rgba(251, 191, 36, 0.6) !important;
    box-shadow: 0 4px 16px rgba(217,119,6,0.35);
}

/* حفظ فقط — cyan */
.sab-save:hover {
    background: rgba(8, 145, 178, 0.82) !important;
    color: #fff !important;
    border-color: rgba(34, 211, 238, 0.6) !important;
    box-shadow: 0 4px 16px rgba(8,145,178,0.35);
}

/* جديد — blue */
.sab-new:hover {
    background: rgba(37, 99, 235, 0.82) !important;
    color: #fff !important;
    border-color: rgba(96, 165, 250, 0.6) !important;
    box-shadow: 0 4px 16px rgba(37,99,235,0.35);
}

/* تحويل — violet */
.sab-convert:hover {
    background: rgba(124, 58, 237, 0.82) !important;
    color: #fff !important;
    border-color: rgba(196, 181, 253, 0.6) !important;
    box-shadow: 0 4px 16px rgba(124,58,237,0.35);
}

/* حذف — red */
.sab-delete:hover {
    background: rgba(220, 38, 38, 0.82) !important;
    color: #fff !important;
    border-color: rgba(252, 165, 165, 0.6) !important;
    box-shadow: 0 4px 16px rgba(220,38,38,0.35);
}

/* ── View-mode action bar ─────────────────────────── */
.view-action-bar {
    display: none; /* shown via JS when locked */
    align-items: stretch;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.view-action-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    font-family: 'Cairo', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    padding: 0.55rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    border: none;
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.view-action-btn i {
    font-size: 1rem;
}
.view-action-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
}
.view-action-btn:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

/* Print button — indigo/blue gradient */
.view-action-print {
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45);
}
.view-action-print:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.55);
}

/* Convert button — amber/orange gradient */
.view-action-convert {
    background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(234, 88, 12, 0.4);
}
.view-action-convert:hover {
    box-shadow: 0 6px 20px rgba(234, 88, 12, 0.5);
}

/* Edit button — green gradient */
.view-action-edit {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}
.view-action-edit:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

/* Disabled state for convert (fully delivered) */
.view-action-convert.disabled,
.view-action-convert:disabled {
    background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
    box-shadow: none;
    cursor: not-allowed;
    transform: none !important;
    filter: none !important;
}

.section-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.section-content h2 {
    color: #2c3e50;
    margin-bottom: 2rem;
    font-size: 2rem;
    font-weight: 600;
}

/* Sidebar */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: #f8fafc;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease,
                opacity 0.2s ease, border-color 0.3s ease;
}

#woSidebar.collapsed,
#dnSidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    opacity: 0;
    overflow: hidden !important;
    border-color: transparent !important;
}

/* DN Search in sidebar */
.dn-search-wrap {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 0.5rem;
}
.dn-search-wrap input {
    flex: 1;
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}
.dn-search-wrap input:focus { border-color: #f97316; }
.dn-search-wrap button {
    flex-shrink: 0;
    padding: 0.4rem 0.7rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    font-size: 0.82rem;
    color: #64748b;
    transition: background 0.2s, color 0.2s;
}
.dn-search-wrap button:hover { background: #f97316; color: #fff; border-color: #f97316; }

#dnSearchResults { max-height: 220px; overflow-y: auto; }
#dnSearchResults .search-item { padding: 0.5rem 0.65rem; margin-bottom: 0.3rem; }
#dnSearchResults .search-item h4 { font-size: 0.82rem; margin-bottom: 0.1rem; }
#dnSearchResults .search-item p  { font-size: 0.75rem; }

/* Reduced sizes for WO sidebar to fit 14-inch screens */
#woSidebar .sidebar-section       { padding: 0.6rem 0.7rem; }
#woSidebar .sidebar-section h3    { font-size: 0.62rem; margin-bottom: 0.5rem; }
#woSidebar .form-group            { margin-bottom: 0.4rem; }
#woSidebar .form-group label      { font-size: 0.65rem; margin-bottom: 0.15rem; }
#woSidebar .form-group input,
#woSidebar .form-group select,
#woSidebar .form-group textarea   { padding: 0.35rem 0.55rem; font-size: 0.75rem; border-radius: 6px; }
#woSidebar .form-group textarea   { min-height: 46px; }
#woSidebar .action-buttons .btn   { font-size: 0.72rem; padding: 0.4rem 0.65rem; }
#woSidebar .status-indicator      { font-size: 0.65rem; padding: 3px 8px; }

/* Sidebar toggle tab (vertical strip between sidebar and preview) */
.sidebar-toggle-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    min-width: 22px;
    padding: 0;
    background: #c8d1db;
    border: none;
    cursor: pointer;
    color: #334155;
    font-size: 0.9rem;
    border-radius: 6px 0 0 6px;
    align-self: stretch;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
    z-index: 5;
    box-shadow: inset -2px 0 4px rgba(0,0,0,0.08);
}
.sidebar-toggle-tab:hover { background: #a8b8c8; color: #1e293b; }

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    padding: 5px 10px;
    border-radius: 20px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    width: fit-content;
    margin-bottom: 0.25rem;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.status-indicator.connected .status-dot {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34,197,94,0.2);
}

.status-indicator.disconnected .status-dot {
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(239,68,68,0.2);
}

.status-text {
    color: #64748b;
    font-weight: 500;
}

.sidebar-section {
    background: white;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 1rem;
    margin-bottom: 0;
}

.sidebar-section h3 {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.85rem;
    padding-bottom: 0;
    border-bottom: none;
}

/* Form Groups */
.form-group {
    margin-bottom: 0.65rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    color: #64748b;
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.01em;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #f8fafc;
    color: #1e293b;
}

/* Inline error highlight */
.input-error {
    border-color: #e74c3c !important;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.15) !important;
    background: #fff6f6 !important;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #ff6b35;
    background: white;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.08);
}

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

/* Priority Field Color Coding */
#priority {
    transition: all 0.3s ease;
}

.priority-normal {
    background-color: #d4edda !important;
    color: #155724 !important;
    border-color: #c3e6cb !important;
}

.priority-medium {
    background-color: #fff3cd !important;
    color: #856404 !important;
    border-color: #ffeaa7 !important;
}

.priority-urgent {
    background-color: #f8d7da !important;
    color: #721c24 !important;
    border-color: #f5c6cb !important;
}

/* Priority Preview Color Coding */
#previewPriority {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: bold;
    display: inline-block;
    min-width: 60px;
    text-align: center;
}

#previewPriority[data-priority="normal"] {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

#previewPriority[data-priority="medium"] {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

#previewPriority[data-priority="urgent"] {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* textarea base — overridden in focused rule above */

/* Logo Upload */
.logo-upload {
    position: relative;
}

.logo-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.logo-preview {
    width: 100%;
    height: 120px;
    border: 2px dashed #bdc3c7;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.logo-preview:hover {
    border-color: #3498db;
    background: #ecf0f1;
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.logo-preview span {
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* Tab Buttons */
.tab-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    background: #f8f9fa;
    color: #34495e;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Cairo', sans-serif;
    font-weight: 500;
}

.tab-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.tab-btn.active {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    border-color: #ff6b35;
    color: white;
}

/* Hidden Elements */
.hidden {
    display: none !important;
}

/* Items Container */
.item-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    align-items: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #e9ecef;
    position: relative;
}

.item-row .form-group {
    margin-bottom: 0;
}

.item-row input {
    padding: 0.5rem;
    font-size: 0.8rem;
}

/* Field with Checkbox */
.field-with-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    width: 100%;
}

.auto-calc-checkbox {
    position: relative;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #ff6b35;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
    margin: 0;
    padding: 0;
}

.auto-calc-checkbox:checked {
    background: #ff6b35;
    border-color: #ff6b35;
}

.auto-calc-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
}

.auto-calc-checkbox:hover {
    border-color: #e55a2b;
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}

.auto-calc-checkbox:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 0.25rem;
    pointer-events: none;
}

.field-with-checkbox input[type="number"] {
    flex: 1;
    margin: 0;
}

/* Readonly Fields (Auto-calculated) */
.item-row input[readonly] {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    border: 2px solid #dee2e6;
    font-weight: 500;
}

/* Manual Input Fields (When checkbox is unchecked) */
.field-with-checkbox input[type="checkbox"]:not(:checked)+input[readonly] {
    background: white !important;
    color: #2c3e50 !important;
    cursor: text !important;
    border: 2px solid #ff6b35 !important;
    font-weight: 600;
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.1);
}

/* Manual Input Fields - Active state */
.field-with-checkbox input[type="checkbox"]:not(:checked)+input[readonly]:focus {
    border-color: #ff6b35;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
    outline: none;
}

/* Visual indicator for manual input mode */
.field-with-checkbox input[type="checkbox"]:not(:checked)+input[readonly]::placeholder {
    color: #ff6b35;
    font-weight: 500;
}

/* Pricing Method Dropdown */
.item-pricing-method {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 0.9rem;
    color: #2c3e50;
    cursor: pointer;
}

.item-pricing-method:focus {
    outline: none;
    border-color: #ff6b35;
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}

/* Simple checkbox styling - clean version */
.auto-calc-checkbox {
    width: 20px !important;
    height: 20px !important;
    border: 2px solid #ff6b35 !important;
    border-radius: 4px !important;
    background: white !important;
    cursor: pointer !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    outline: none !important;
    position: relative !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

.auto-calc-checkbox:checked {
    background: #ff6b35 !important;
    border-color: #ff6b35 !important;
}

.auto-calc-checkbox:checked::after {
    content: '✓' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    color: white !important;
    font-size: 14px !important;
    font-weight: bold !important;
    line-height: 1 !important;
}


/* Buttons */
.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    font-size: 0.875rem;
    transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-align: center;
}

.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: #ff6b35;
    color: white;
}
.btn-primary:hover {
    opacity: 1;
    background: #e85a25;
    box-shadow: 0 4px 12px rgba(255,107,53,0.3);
}

.btn-save-only {
    background: #f1f5f9;
    color: #475569;
    border: 1.5px solid #e2e8f0;
}
.btn-save-only:hover {
    opacity: 1;
    background: #e2e8f0;
}

.btn-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1.5px solid #e2e8f0;
}
.btn-secondary:hover { opacity: 1; background: #e2e8f0; }

.btn-success {
    background: #16a34a;
    color: white;
}
.btn-success:hover { opacity: 1; background: #15803d; }

.btn-danger {
    background: #fff1f2;
    color: #e11d48;
    border: 1.5px solid #fecdd3;
}
.btn-danger:hover { opacity: 1; background: #ffe4e6; }

.btn-info {
    background: #eff6ff;
    color: #2563eb;
    border: 1.5px solid #bfdbfe;
}
.btn-info:hover { opacity: 1; background: #dbeafe; }

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.78rem;
    border-radius: 7px;
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.action-buttons .btn {
    margin-bottom: 0;
    padding: 0.6rem 0.75rem;
    font-size: 0.82rem;
    border-radius: 9px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

/* Full-width buttons inside action grid */
.action-buttons .btn-full {
    grid-column: 1 / -1;
}

/* Copy Last Order Button */
.btn-copy-last-order {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.4rem;
    padding: 0.38rem 0.75rem;
    font-size: 0.75rem;
    font-family: inherit;
    font-weight: 600;
    color: #2563eb;
    background: #eff6ff;
    border: 1.5px solid #bfdbfe;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    width: 100%;
    justify-content: center;
    direction: rtl;
}
.btn-copy-last-order:hover { background: #dbeafe; border-color: #93c5fd; }


/* Search */
.search-results {
    margin-top: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.search-item {
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

.search-item:hover {
    background: #e9ecef;
    border-color: #3498db;
}

.search-item h4 {
    color: #2c3e50;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.search-item p {
    color: #7f8c8d;
    font-size: 0.8rem;
    margin: 0;
}

/* Toast Notifications */
.toast-message {
    position: fixed;
    bottom: 30px;
    right: 30px;
    min-width: 300px;
    max-width: 500px;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast-message.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.toast-success {
    background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
    color: white;
    border-left: 4px solid #1e8449;
}

.toast-error {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    border-left: 4px solid #a93226;
}

.toast-info {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    border-left: 4px solid #21618c;
}

.toast-warning {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    color: white;
    border-left: 4px solid #d68910;
}

/* Preview Area */
.preview-area {
    flex: 1;
    background: #ecf0f1;
    padding: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Preview lock overlay */
.preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(236, 240, 241, 0.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: opacity 0.3s ease;
    pointer-events: all;
}
.preview-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.preview-overlay-content {
    text-align: center;
    color: #475569;
    user-select: none;
}
.preview-overlay-icon {
    font-size: 2.4rem;
    color: #b8941f;
    margin-bottom: 0.75rem;
    animation: overlay-bounce 1.1s ease-in-out infinite;
}
@keyframes overlay-bounce {
    0%, 100% { transform: translateX(0); }
    50%       { transform: translateX(10px); }
}
.preview-overlay-content p {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 0.4rem;
}
.preview-overlay-content small {
    font-size: 0.78rem;
    opacity: 0.7;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.preview-header h3 {
    color: #2c3e50;
    margin: 0;
}

.preview-controls {
    display: flex;
    gap: 0.5rem;
}

.preview-container {
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: auto;
    position: relative;
}

/* Document Preview */
.document-preview {
    display: none;
    padding: 2rem;
    min-height: 100%;
}

.document-preview.active {
    display: block;
}

.page-fit {
    background: white;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    position: relative;
    transform-origin: top center;
}

.page-fit[data-page="A4-landscape"] {
    width: 297mm;
    min-height: 210mm;
    padding: 10mm;
}

.page-fit[data-page="A4-portrait"] {
    width: 210mm;
    min-height: 297mm;
    padding: 16mm;
    /* more breathing room on screen */
}

/* Document Header */
.document-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e0e0e0;
}

/* ========================================
   WORK ORDER HEADER - Professional Layout
   ======================================== */
.wo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 3px solid #2c3e50;
    border-image: linear-gradient(to left, #2c3e50, #ff6b35, #2c3e50) 1;
    gap: 1rem;
}

.wo-header-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Right section (RTL) — WO Details */
.wo-details {
    align-items: flex-start;
    gap: 0.5rem;
}

.wo-detail-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.wo-detail-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
}

.wo-detail-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: #ff6b35;
    padding: 0.2rem 0.6rem;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    min-width: 80px;
    text-align: center;
}

/* Center section — Title */
.wo-title {
    align-items: center;
    text-align: center;
}

.wo-title h1 {
    font-size: 2rem;
    font-weight: 800;
    color: #2c3e50;
    margin: 0;
    letter-spacing: 1px;
    line-height: 1.2;
}

.wo-title-en {
    font-size: 0.8rem;
    color: #7f8c8d;
    font-weight: 500;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 0.15rem;
}

/* Left section (RTL) — Logo */
.wo-logo {
    align-items: flex-end;
    flex: 0 0 auto;
}

.wo-logo .company-logo {
    max-width: 85px;
    max-height: 85px;
    object-fit: contain;
}

/* Keep existing styles for receipt/delivery headers */
.order-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.order-number,
.issue-date {
    font-size: 0.9rem;
    color: #2c3e50;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.order-number span,
.issue-date span {
    font-weight: bold;
    color: #ff6b35;
}

.logo-section {
    flex: 0 0 80px;
}

.company-logo {
    max-width: 60px;
    max-height: 60px;
    object-fit: contain;
}

.title-section {
    flex: 1;
    text-align: center;
}

.title-section h1 {
    font-size: 1.8rem;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.company-info {
    color: #34495e;
    font-size: 0.9rem;
    line-height: 1.4;
}

.company-info div {
    margin-bottom: 0.1rem;
}

/* Document Meta */
.document-meta {
    margin-bottom: 1.5rem;
}

/* Delivery meta 2x3 grid */
.delivery-meta-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem 1rem;
}

.delivery-meta-grid .meta-item label {
    min-width: 80px;
}

@media print {
    .delivery-meta-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.4rem 0.8rem;
    }
}

.meta-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    flex-wrap: nowrap;
    gap: 0.5rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex: 1;
    min-width: 0;
}

.meta-item label {
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.85rem;
    min-width: 80px;
}

.meta-item span {
    color: #34495e;
    background: #f8f9fa;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    border: 1px solid #e9ecef;
    font-size: 0.8rem;
    flex: 1;
}

/* Items Table */
.items-table {
    margin-bottom: 2rem;
    overflow-x: auto;
}

.items-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.items-table th {
    background: #f9a825;
    color: white;
    padding: 0.75rem 0.5rem;
    text-align: center;
    font-weight: 600;
    border: 1px solid #d3d7db;
}

.items-table td {
    padding: 0.5rem;
    text-align: center;
    border: 1px solid #d3d7db;
    background: white;
}

.items-table tr:nth-child(even) td {
    background: #f8f9fa;
}

/* Work order totals row */
.wo-totals-row td {
    background: #f1f5f9 !important;
    border-top: 2px solid #94a3b8 !important;
    padding: 0.55rem 0.5rem;
}
.wo-totals-label {
    text-align: right;
    font-size: 0.78rem;
    font-weight: 700;
    color: #475569;
    padding-right: 0.75rem !important;
}
.wo-totals-cell {
    text-align: center;
    color: #1e293b;
    font-size: 0.82rem;
}
.wo-totals-unit {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 400;
}
.wo-del-th {
    width: 28px;
    padding: 0 !important;
}
.wo-row-del-cell {
    padding: 0 !important;
    text-align: center;
    width: 28px;
}
.wo-row-del-btn {
    background: none;
    border: none;
    color: #cbd5e1;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.wo-row-del-btn:hover {
    color: #e11d48;
    background: #fff1f2;
}


/* Document Footer */
.document-footer {
    border-top: 2px solid #e0e0e0;
    padding-top: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.notes-section {
    flex: 1;
}

.notes-section label {
    font-weight: 600;
    color: #2c3e50;
    display: block;
    margin-bottom: 0.5rem;
}

.notes-section div {
    color: #34495e;
    background: #f8f9fa;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    min-height: 40px;
}

.company-links {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    color: #7f8c8d;
    font-size: 0.8rem;
    text-align: left;
}

/* Print Styles */
@media print {

    /* Force print colors and backgrounds */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        margin: 0;
        background: white;
    }

    .page-fit {
        padding-top: 20mm !important;
    }

    .sidebar,
    .app-header,
    .preview-header {
        display: none !important;
    }

    .main-content {
        display: block;
    }

    .preview-area {
        padding: 0;
        background: white;
    }

    .preview-container {
        box-shadow: none;
        border-radius: 0;
    }

    .page-fit {
        box-shadow: none;
        margin: 0;
        transform: none !important;
    }

    .page-fit[data-page="A4-landscape"] {
        width: 297mm !important;
        height: 210mm !important;
        padding: 8mm !important;
        margin: 0 !important;
        max-width: 297mm !important;
    }

    .page-fit[data-page="A4-portrait"] {
        width: 210mm !important;
        height: 297mm !important;
        padding: 14mm !important;
        /* increase print padding */
        margin: 0 !important;
        max-width: 210mm !important;
    }

    /* Chrome-specific page size fixes */
    @supports (-webkit-appearance: none) {
        .page-fit[data-page="A4-landscape"] {
            width: 297mm !important;
            max-width: 297mm !important;
            min-width: 297mm !important;
        }

        .page-fit[data-page="A4-portrait"] {
            width: 210mm !important;
            max-width: 210mm !important;
            min-width: 210mm !important;
        }
    }

    /* Ensure order info prints */
    .order-number,
    .issue-date {
        color: #000 !important;
        font-weight: bold !important;
    }

    .order-number span,
    .issue-date span {
        color: #000 !important;
        font-weight: bold !important;
    }

    /* Optimize header for print */
    .document-header {
        margin-bottom: 1rem;
        padding-bottom: 0.3rem;
    }

    .title-section h1 {
        font-size: 1.6rem;
        margin-bottom: 0.3rem;
    }

    .company-info {
        font-size: 0.8rem;
    }

    .company-logo {
        max-width: 50px;
        max-height: 50px;
    }


    /* COPY PREVIEW LAYOUT TO PRINT - KEEP IT SIMPLE */
    @media print {
        .document-meta {
            margin-bottom: 1.5rem !important;
            margin-top: 1rem !important;
        }

        /* Keep the same flex layout that works in preview */
        .meta-row {
            display: flex !important;
            justify-content: space-between !important;
            margin-bottom: 0.5rem !important;
            flex-wrap: nowrap !important;
            gap: 0.5rem !important;
        }

        .meta-item {
            display: flex !important;
            align-items: center !important;
            gap: 0.3rem !important;
            flex: 1 !important;
            min-width: 0 !important;
        }

        .meta-item label {
            font-size: 0.75rem !important;
            font-weight: 600 !important;
            color: #2c3e50 !important;
            min-width: auto !important;
        }

        .meta-item span {
            font-size: 0.7rem !important;
            padding: 0.2rem 0.5rem !important;
            background: #f8f9fa !important;
            border: 1px solid #e9ecef !important;
            border-radius: 3px !important;
            flex: 1 !important;
        }
    }

    /* Table base */
    .items-table table {
        font-size: 0.7rem;
        width: 100% !important;
        table-layout: auto !important;
        border-collapse: collapse !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide delete column and pricing method in print — class-based, no nth-child fragility */
    .wo-del-th,
    .wo-row-del-cell,
    .pricing-col,
    .wo-pricing-cell,
    .wo-pricing-ph {
        display: none !important;
    }

    /* الصنف needs more room — use nowrap on all headers so columns size to their header text */
    .items-table th { white-space: nowrap; }
    /* give الصنف and ملاحظات a width hint so auto-layout allocates them more space */
    .items-table td:nth-child(2) { white-space: nowrap; }
    .items-table th:nth-child(8), .items-table td:nth-child(8) { width: 10%; }

    .items-table th {
        background: #f9a825 !important;
        color: white !important;
        padding: 0.5rem 0.3rem !important;
        text-align: center !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .items-table td {
        padding: 0.3rem !important;
        text-align: center !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .items-table th,
    .items-table td {
        border: 1px solid #c9ced3 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Responsive Design */
@media (max-width: 1200px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .main-nav {
        justify-content: center;
    }

    .sidebar {
        width: 350px;
    }

    .page-fit[data-page="A4-landscape"] {
        width: 250mm;
        min-height: 180mm;
    }

    .page-fit[data-page="A4-portrait"] {
        width: 180mm;
        min-height: 250mm;
    }

    .history-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        min-width: auto;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-title h1 {
        font-size: 1.4rem;
    }

    .header-title h2 {
        font-size: 0.9rem;
    }

    .main-nav {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .nav-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .content-section {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 50vh;
        order: 2;
    }

    .preview-area {
        max-height: 50vh;
        order: 1;
    }

    .page-fit[data-page="A4-landscape"],
    .page-fit[data-page="A4-portrait"] {
        width: 100%;
        min-height: auto;
        padding: 5mm;
    }

    .document-header {
        flex-direction: column;
        text-align: center;
    }

    .wo-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .wo-details {
        align-items: center;
    }

    .wo-logo {
        align-items: center;
    }

    .meta-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .section-content {
        padding: 1rem;
    }

    .history-filters {
        padding: 1rem;
    }

    .history-table {
        overflow-x: auto;
    }

    .history-table table {
        min-width: 600px;
    }
}

/* UI Components - Global */

/* View Mode Warning - Modern Premium Pill (Snickers-inspired shape) */
.view-mode-banner {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #3d2314 0%, #2c1a0f 100%);
    color: #f8f9fa;
    padding: 7px 7px 7px 18px;
    border-radius: 80px;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1.5px solid #5d4037;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: slideDownIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-weight: 600;
}

@keyframes slideDownIn {
    from {
        transform: translate(-50%, -120px) scale(0.8);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0) scale(1);
        opacity: 1;
    }
}

.view-mode-banner i {
    color: #f39c12;
    font-size: 1.1rem;
    filter: drop-shadow(0 0 4px rgba(243, 156, 18, 0.4));
}

.view-mode-banner span {
    font-size: 0.82rem;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.view-mode-banner .banner-actions {
    display: flex;
    gap: 8px;
}

.view-mode-banner .btn-edit-mode {
    background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
    color: white;
    border: none;
    padding: 6px 18px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 800;
    font-family: 'Cairo', sans-serif;
    transition: all 0.3s ease;
    box-shadow: 0 3px 8px rgba(230, 126, 34, 0.3);
    font-size: 0.76rem;
}

.view-mode-banner .btn-exit-mode {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 18px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    font-family: 'Cairo', sans-serif;
    transition: all 0.3s ease;
    font-size: 0.76rem;
}

.view-mode-banner .btn-edit-mode:hover {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    transform: scale(1.05);
    box-shadow: 0 5px 12px rgba(230, 126, 34, 0.5);
}

.view-mode-banner .btn-exit-mode:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

.view-mode-banner .btn-edit-mode:active,
.view-mode-banner .btn-exit-mode:active {
    transform: scale(0.95);
}

/* Locked State for Inputs */
.form-locked input,
.form-locked select,
.form-locked textarea {
    background-color: #f8f9fa !important;
    border-color: #dee2e6 !important;
    cursor: not-allowed !important;
    opacity: 0.8;
}

.form-locked .btn:not(.btn-sm):not(.btn-edit-mode) {
    display: none;
    /* Hide action buttons in view mode except small utility ones if needed */
}

.form-locked .preview-controls {
    display: flex;
    /* Keep zoom controls */
}

.form-locked .preview-controls .btn-primary {
    display: none;
    /* Hide "New Line" button in view mode */
}

/* Specific button styles */
.btn-save-only {
    background-color: #3498db;
    color: white;
}

.btn-save-only:hover {
    background-color: #2980b9;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Document Loading Overlay */
.doc-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(245, 247, 250, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    /* no transition here — show is instant; hide transition is applied via JS */
}
.doc-loading-overlay.visible {
    opacity: 1;
    pointer-events: all;
}
.doc-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    color: #334155;
}
.doc-loading-spinner {
    width: 46px;
    height: 46px;
    border: 4px solid #e2e8f0;
    border-top-color: #b8941f;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
.doc-loading-content p {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* Search Section */
.search-section {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    border: 1px solid #e9ecef;
}

.search-section h3 {
    margin: 0 0 1rem 0;
    color: #2c3e50;
    font-size: 1.1rem;
    border-bottom: 2px solid #ff6b35;
    padding-bottom: 0.5rem;
}

/* History Section */
.history-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 150px;
}

.filter-group label {
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.9rem;
}

.filter-group input,
.filter-group select {
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #ff6b35;
    background: white;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.history-table {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

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

.history-table th {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    color: white;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
}

/* DN mode — blue table header */
#history-section[data-hist-mode="delivery"] .history-table th {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
}

/* DN mode — blue accent on row hover */
#history-section[data-hist-mode="delivery"] .history-table tr:hover {
    background: #f0f9ff;
}

/* DN mode — a subtle top border on the table to further distinguish */
#history-section[data-hist-mode="delivery"] .history-table table {
    border-top: 3px solid #0ea5e9;
}

.history-table td {
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.9rem;
}

.history-table tr:hover {
    background: #f8f9fa;
}

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

/* Success/Error Messages */
.message {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: 500;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Delivery Note Header Styles */
.delivery-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* left - center - right */
    align-items: center;
    margin-bottom: 2rem;
    direction: rtl;
    column-gap: 1rem;
}

.delivery-logo-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 0 0 auto;
    justify-self: center;
    /* stick to the right in RTL layout */
}

.delivery-logo {
    width: 96px;
    height: 96px;
    object-fit: contain;
}

.delivery-company-name {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.delivery-company-name .delivery-company-arabic {
    font-size: 1rem;
    font-weight: bold;
    color: #2c3e50;
    text-align: right;
    line-height: 1.2;
    margin-bottom: 0.1rem;
}

.delivery-company-name .delivery-company-arabic:last-child {
    margin-bottom: 0;
}

.delivery-title-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-self: center;
    /* always centered */
    margin: 0 1rem;
}

.delivery-title-box {
    border: 2px solid #2c3e50;
    padding: 0.8rem 1.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
    background: white;
}

.delivery-title-arabic {
    font-size: 1.4rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 0.2rem;
}

.delivery-title-english {
    font-size: 1.2rem;
    font-weight: bold;
    color: #2c3e50;
}

.delivery-company-arabic {
    font-size: 1rem;
    color: #2c3e50;
    font-weight: normal;
    text-align: center;
}

.delivery-contact-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    flex: 0 0 auto;
    justify-self: end;
    /* stick to the left in RTL layout */
}

.delivery-contact-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.delivery-contact-label {
    font-weight: bold;
    color: #e67e22;
    font-size: 0.75rem;
    min-width: 50px;
}

.delivery-contact-value {
    color: #2c3e50;
    font-size: 0.75rem;
    direction: ltr;
    unicode-bidi: embed;
}

.input-with-unit {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.input-with-unit input {
    flex: 1;
    min-width: 0;
}

.input-with-unit select {
    width: auto;
    padding: 0.3rem 0.4rem;
    font-size: 0.85rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    color: #2c3e50;
    cursor: pointer;
}

/* Delivery Page Footer */
.delivery-page-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 0.4rem 1rem;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.dn-bottom-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    direction: rtl;
    margin-top: 0.25rem;
}

.dn-footer-thanks {
    font-size: 0.9rem;
    font-weight: 700;
    color: #2c3e50;
}

.dn-footer-brand {
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: #b8941f;
    text-align: center;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.dn-footer-qr {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.dn-qr-img {
    width: 42px;
    height: 42px;
    object-fit: contain;
}

.dn-qr-caption {
    font-size: 0.5rem;
    color: #888;
    text-transform: lowercase;
}

.delivery-company-footer {
    font-size: 0.9rem;
    color: #2c3e50;
    font-weight: 500;
}

/* Delivery Table Row Height */
#previewDeliveryItemsBody tr {
    height: 35px;
    min-height: 35px;
}

#previewDeliveryItemsBody td {
    vertical-align: middle;
    padding: 8px 4px;
}

/* Delivery Summary Section */
.delivery-summary-section {
    width: 100%;
}

.delivery-summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}

.delivery-summary-item {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.delivery-summary-item label {
    font-weight: bold;
    color: #2c3e50;
    font-size: 0.8rem;
    min-width: 80px;
}

.delivery-summary-value {
    flex: 1;
    border-bottom: 1px solid #2c3e50;
    padding: 0.3rem 0;
    font-size: 0.9rem;
    font-weight: bold;
    color: #2c3e50;
    min-height: 15px;
}

.delivery-signatures-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.delivery-signature-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.delivery-signature-item label {
    font-weight: bold;
    color: #2c3e50;
    font-size: 0.8rem;
}

.delivery-signature-line {
    border-bottom: 1px solid #2c3e50;
    height: 25px;
    width: 100%;
}

/* Print styles for delivery header */
@media print {
    .delivery-header {
        direction: rtl;
    }

    .delivery-logo-section {
        direction: rtl;
    }

    .delivery-contact-section {
        direction: rtl;
    }

    .delivery-page-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
}

/* ========================================
   PRODUCTIVITY & EFFICIENCY CSS
   ======================================== */

/* Sticky Table Headers */
.items-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #2c3e50;
}

#historyTable thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #2c3e50;
}

/* Visual Validation - Red border on empty required fields */
input:invalid {
    border-color: #dc3545 !important;
}

input:valid {
    border-color: #28a745 !important;
}

/* Edit Button Styling */
.btn-edit {
    background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
    color: white;
    border: none;
}

.btn-edit:hover {
    background: linear-gradient(135deg, #138496 0%, #117a8b 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(23, 162, 184, 0.3);
}

/* Focus states for better keyboard navigation */
input:focus,
select:focus,
textarea:focus,
button:focus {
    outline: 2px solid #ff6b35;
    outline-offset: 2px;
}

/* Smooth transitions for all interactive elements */
input,
select,
textarea,
button,
.btn {
    transition: all 0.2s ease;
}

/* Loading state for buttons */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Status Select in History */
.status-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 140px;
}

.status-select:focus {
    outline: none;
    border-color: #ff6b35;
}

/* Status Colors — matches dashboard ao-status-select palette */
.status-select[data-status="قيد الانتظار"] {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

.status-select[data-status="قيد التنفيذ"] {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.status-select[data-status="جاهز للتسليم"] {
    background: #f0fdf4;
    color: #166534;
    border-color: #bbf7d0;
}

.status-select[data-status="تم التسليم"] {
    background: #f8fafc;
    color: #64748b;
    border-color: #e2e8f0;
}

/* Dashboard Styles */
.dashboard-container {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
    height: 100%;
}

.quick-access-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.quick-access-bar .btn {
    flex: 1;
    min-width: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 1.1rem;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.dashboard-header {
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #ff6b35;
    display: inline-block;
}

.active-orders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    padding-bottom: 2rem;
}

.order-card {
    background: white;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    position: relative;
    overflow: hidden;
}

.order-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: transparent;
    transition: background 0.3s ease;
}

.order-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

.order-card:hover::before {
    background: #ff6b35;
}

.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.order-no {
    font-weight: 700;
    color: #2c3e50;
    font-size: 1.1rem;
}

.status-badge {
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-badge.status-pending {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
}

.status-badge.status-progress {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.status-badge.status-ready {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.status-badge.status-delivered {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.order-card-body .customer-name {
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 0.4rem;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-card-body .order-date {
    font-size: 0.85rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.order-card-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #f1f5f9;
}

.order-card-footer .btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.converted-tag {
    font-size: 0.8rem;
    color: #10b981;
    font-weight: 700;
    align-self: center;
}

.btn-outline {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #475569;
}

.btn-outline:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}

/* Mobile Responsiveness Improvements */
@media (max-width: 900px) {
    .app-header {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .main-nav {
        width: 100%;
        overflow-x: auto;
        padding: 0.5rem 0;
        justify-content: flex-start;
        scrollbar-width: none;
    }

    .main-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .dashboard-container {
        padding: 1rem;
    }

    .quick-access-bar .btn {
        min-width: 100%;
        padding: 1rem;
    }

    .active-orders-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Stacked table on mobile */
    .history-table table,
    .history-table thead,
    .history-table tbody,
    .history-table th,
    .history-table td,
    .history-table tr {
        display: block;
        width: 100%;
    }

    .history-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .history-table tr {
        margin-bottom: 1.5rem;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        background: white;
        padding: 1rem;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .history-table td {
        border: none;
        border-bottom: 1px solid #f1f5f9;
        position: relative;
        padding: 0.75rem 0.5rem 0.75rem 40% !important;
        text-align: left;
        min-height: 2.5rem;
    }

    .history-table td:last-child {
        border-bottom: none;
        padding-bottom: 0 !important;
    }

    .history-table td:before {
        position: absolute;
        right: 0.5rem;
        top: 0.75rem;
        width: 35%;
        padding-left: 10px;
        white-space: nowrap;
        font-weight: 700;
        content: attr(data-label);
        text-align: right;
        color: #64748b;
        font-size: 0.8rem;
    }

    .history-table .status-select {
        width: 100%;
    }
}

/* =============================================
   DASHBOARD — Apple-style redesign
   ============================================= */

/* Override old dashboard container */
.dashboard-container {
    padding: 2rem 2.5rem;
    max-width: 1240px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
    height: 100%;
}

/* Dashboard Toolbar — single thin bar, no duplicate heading */
.db-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.db-date {
    font-size: 0.82rem;
    color: #94a3b8;
    margin: 0;
    font-weight: 400;
}

.db-quick-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Dashboard Buttons */
.db-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
}

.db-btn-primary {
    background: #ff6b35;
    color: white;
}
.db-btn-primary:hover {
    background: #e85a25;
    box-shadow: 0 4px 14px rgba(255,107,53,0.35);
    transform: translateY(-1px);
}

.db-btn-outline {
    background: transparent;
    border: 1.5px solid #e2e8f0;
    color: #334155;
}
.db-btn-outline:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.db-btn-ghost {
    background: transparent;
    color: #64748b;
}
.db-btn-ghost:hover {
    color: #334155;
    background: #f1f5f9;
}

.db-btn-sm {
    padding: 0.38rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* DB Section card */
.db-section {
    background: white;
    border-radius: 16px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.03);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.db-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #f8fafc;
}

.db-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
    letter-spacing: -0.01em;
}

/* Active Orders List */
.active-orders-list { width: 100%; }

.ao-row {
    display: grid;
    grid-template-columns: 140px 1fr 175px 105px 120px;
    align-items: center;
    padding: 0.85rem 1.5rem;
    border-bottom: 1px solid #f8fafc;
    gap: 1rem;
    transition: background 0.12s;
}
.ao-row:last-child { border-bottom: none; }
.ao-row:hover { background: #fafafa; }

.ao-number {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.85rem;
    letter-spacing: 0.01em;
    cursor: pointer;
}
.ao-number:hover { color: #ff6b35; text-decoration: underline; }

.ao-customer {
    color: #475569;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ao-date {
    font-size: 0.8rem;
    color: #94a3b8;
    text-align: center;
}

.ao-actions {
    display: flex;
    gap: 0.35rem;
    justify-content: flex-end;
}

.ao-status-select {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    border: 1.5px solid transparent;
    font-family: 'Cairo', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: auto;
}
.ao-status-select:focus { outline: none; box-shadow: 0 0 0 3px rgba(255,107,53,0.12); }

.ao-status-select[data-status="قيد الانتظار"]  { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.ao-status-select[data-status="قيد التنفيذ"]   { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.ao-status-select[data-status="جاهز للتسليم"] { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.ao-status-select[data-status="تم التسليم"]    { background: #f8fafc; color: #64748b; border-color: #e2e8f0; }

.ao-action-btn {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid #e2e8f0;
    background: white;
    color: #64748b;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    transition: all 0.12s;
    flex-shrink: 0;
}
.ao-action-btn:hover {
    background: #f8fafc;
    color: #334155;
    border-color: #cbd5e1;
    transform: scale(1.08);
}

.ao-loading, .ao-empty {
    padding: 3rem 1.5rem;
    text-align: center;
    color: #94a3b8;
    font-size: 0.9rem;
}
.ao-empty i { font-size: 2rem; display: block; margin-bottom: 0.6rem; opacity: 0.3; }

/* =============================================
   STATS ROW — refined
   ============================================= */
.stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: 14px;
    padding: 1.25rem 1.25rem 1rem;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.025);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

/* Thin top accent stripe */
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 14px 14px 0 0;
}
.stat-accent-1::before { background: #ff6b35; }
.stat-accent-2::before { background: #f59e0b; }
.stat-accent-3::before { background: #3b82f6; }
.stat-accent-4::before { background: #10b981; }
.stat-accent-5::before { background: #8b5cf6; }

.stat-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.stat-label {
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.stat-icon-sm {
    color: #e2e8f0;
    font-size: 0.85rem;
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1;
    letter-spacing: -0.04em;
}

/* =============================================
   STATS STRIP — single unified card
   ============================================= */
.stats-strip {
    display: flex;
    align-items: stretch;
    background: white;
    border-radius: 16px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.025);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.stat-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 0.75rem;
    gap: 0.4rem;
    transition: background 0.12s, box-shadow 0.12s, transform 0.12s;
    cursor: default;
}

.stat-item-clickable {
    cursor: pointer;
}

.stat-item-clickable:hover {
    background: #f8fafc;
    box-shadow: inset 0 0 0 1px #e2e8f0;
}

.stat-item-clickable:hover .stat-num {
    transform: scale(1.06);
    display: block;
}

.stat-num {
    font-size: 2.6rem;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.04em;
    line-height: 1;
    transition: transform 0.12s;
}

.stat-lbl {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 600;
    white-space: nowrap;
}

.stat-divider {
    width: 1px;
    background: #f1f5f9;
    margin: 1rem 0;
    flex-shrink: 0;
}

.stat-amber  { color: #d97706; }
.stat-blue   { color: #2563eb; }
.stat-green  { color: #16a34a; }
.stat-orange { color: #ea580c; }
.stat-purple { color: #7c3aed; }

/* Zebra rows */
#historyTableBody tr:nth-child(even) td {
    background: #f8fafc;
}

/* Action button custom tooltips */
.action-btn {
    position: relative;
}
.action-btn::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    font-family: 'Cairo', sans-serif;
    font-size: 0.72rem;
    padding: 3px 9px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 200;
}
.action-btn:hover::after {
    opacity: 1;
}

/* =============================================
   HISTORY SECTION — tabs + refined layout
   ============================================= */
/* Tab type switcher — full width row */
.hist-type-switcher {
    display: flex;
    gap: 0.5rem;
    background: #f1f5f9;
    padding: 0.3rem;
    border-radius: 14px;
    width: 100%;
    margin-bottom: 1.5rem;
}

.hist-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    flex: 1;
    padding: 0.7rem 1rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
}

.hist-tab i {
    font-size: 1rem;
}

.hist-tab:not(.active) {
    background: #ffedd5;
    color: #c2410c;
}

.hist-tab:not(.active):hover {
    background: #fed7aa;
    color: #9a3412;
}

/* Active state — both tabs use bright orange */
.hist-tab.active {
    background: linear-gradient(135deg, #ff6b35 0%, #f97316 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(255,107,53,0.4);
}

/* Filter Bar */
.history-filter-bar {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    background: white;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.filter-search {
    position: relative;
    flex: 1;
    min-width: 180px;
}

.filter-search i {
    position: absolute;
    right: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    color: #cbd5e1;
    pointer-events: none;
    font-size: 0.8rem;
}

.filter-search input {
    width: 100%;
    height: 40px;
    padding: 0 2.2rem 0 0.8rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.875rem;
    background: #f8fafc;
    color: #1e293b;
    transition: border-color 0.15s, background 0.15s;
    box-sizing: border-box;
}

.filter-search input:focus {
    outline: none;
    border-color: #e2e8f0;
    background: white;
    box-shadow: none;
}

.history-filter-bar .filter-group { min-width: unset; }

.history-filter-bar .filter-group input,
.history-filter-bar .filter-group select {
    padding: 0.6rem 0.8rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.875rem;
    background: #f8fafc;
    color: #1e293b;
    cursor: pointer;
    transition: border-color 0.15s;
}

.history-filter-bar .filter-group input:focus,
.history-filter-bar .filter-group select:focus {
    outline: none;
    border-color: #ff6b35;
    background: white;
    box-shadow: 0 0 0 3px rgba(255,107,53,0.08);
}

/* Document Number Cell */
.doc-number-cell {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.88rem;
    letter-spacing: 0.01em;
}

/* Action Icon Buttons */
.actions-cell {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    transition: transform 0.12s, box-shadow 0.12s;
    flex-shrink: 0;
}

.action-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}

.action-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.action-btn-view    { background: #eff6ff; color: #2563eb; }
.action-btn-edit    { background: #f0fdfa; color: #0d9488; }
.action-btn-convert { background: #f0fdf4; color: #16a34a; }
.action-btn-print   { background: #f8fafc; color: #475569; border: 1px solid #e2e8f0; }
.action-btn-delete  { background: #fff1f2; color: #e11d48; }

/* Empty state inside table */
.history-empty-state {
    text-align: center;
    padding: 3.5rem 1rem;
    color: #94a3b8;
}

.history-empty-state i {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 0.6rem;
    opacity: 0.3;
}

/* =============================================
   MOBILE — comprehensive responsive
   ============================================= */
@media (max-width: 768px) {

    /* Header */
    .app-header { padding: 0 1rem; height: auto; min-height: 56px; }
    .header-content { flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0; }
    .header-brand-text { display: none; }
    .main-nav {
        width: 100%;
        gap: 0.15rem;
        overflow-x: auto;
        scrollbar-width: none;
        background: rgba(255,255,255,0.05);
        padding: 0.22rem;
        border-radius: 10px;
    }
    .main-nav::-webkit-scrollbar { display: none; }
    .nav-btn {
        padding: 0.42rem 0.75rem;
        font-size: 0.76rem;
        flex-shrink: 0;
    }

    /* Dashboard */
    .dashboard-container { padding: 1rem; }
    .db-toolbar { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .db-quick-actions { width: 100%; }
    .db-btn { flex: 1; justify-content: center; font-size: 0.8rem; padding: 0.5rem 0.6rem; }

    /* Stats row — 2 per row, last one full width */
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }
    .stat-card:last-child { grid-column: 1 / -1; }
    .stat-value { font-size: 1.8rem; }

    /* Active orders — vertical stack */
    .ao-row {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto;
        padding: 1rem;
        gap: 0.5rem;
    }
    .ao-number  { grid-column: 1; grid-row: 1; }
    .ao-date    { grid-column: 2; grid-row: 1; text-align: left; }
    .ao-customer { grid-column: 1 / -1; grid-row: 2; }
    .ao-status-select { grid-column: 1 / -1; grid-row: 3; }
    .ao-actions { grid-column: 2; grid-row: 1; justify-content: flex-end; display: none; }

    /* History */
    .section-content { padding: 1rem; }
    .hist-tab { font-size: 0.875rem; padding: 0.6rem 0.8rem; }
    .history-filter-bar {
        flex-direction: column;
        padding: 0.75rem;
        gap: 0.5rem;
    }
    .filter-search { min-width: 100%; }
    .history-filter-bar .filter-group input,
    .history-filter-bar .filter-group select { width: 100%; }
    .history-filter-bar .btn { width: 100%; }

    /* History table → stacked cards on mobile */
    .history-table table,
    .history-table thead,
    .history-table tbody,
    .history-table th,
    .history-table td,
    .history-table tr { display: block; width: 100%; }

    .history-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .history-table tr {
        margin-bottom: 0.75rem;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        background: white;
        padding: 0.75rem 1rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    }

    .history-table td {
        border: none;
        border-bottom: 1px solid #f8fafc;
        position: relative;
        padding: 0.4rem 0.6rem !important;
        text-align: right;
        min-height: 2rem;
        font-size: 0.85rem;
    }

    .history-table td:last-child { border-bottom: none; padding-bottom: 0 !important; }

    /* Label stacks ABOVE the value on mobile so wide controls (status, action buttons) don't overlap */
    .history-table td::before {
        position: static;
        top: auto;
        right: auto;
        width: auto;
        display: block;
        font-weight: 600;
        content: attr(data-label);
        text-align: right;
        color: #94a3b8;
        font-size: 0.7rem;
        margin-bottom: 4px;
        text-transform: none;
        white-space: normal;
    }
    /* The number cell (first td) gets a more prominent value */
    .history-table .doc-number-cell { font-weight: 700; font-size: 0.95rem; }

    .history-table .status-select { width: 100%; font-size: 0.85rem; padding: 8px 12px; }
    .actions-cell { justify-content: flex-start; flex-wrap: wrap; }

    /* Section / sidebar / preview on mobile – natural stacked scroll */
    .content-section.active {
        height: auto;
        min-height: 100%;
        overflow-y: visible;
    }
    .section-body {
        flex-direction: column;
        overflow: visible;
        min-height: 0;
        height: auto;
        flex: none;
    }
    .sidebar {
        width: 100%;
        min-width: 0;
        border-left: none;
        border-bottom: 1px solid #f1f5f9;
        overflow: visible;
        max-height: none;
        height: auto;
        order: 1; /* form first on mobile */
    }
    #orders-section .preview-area,
    #delivery-section .preview-area { order: 2; }
    .preview-area    { min-height: auto; height: auto; flex: none; }
    .preview-section { overflow: visible; height: auto; }
    /* Hide desktop sidebar collapse toggle on mobile */
    .sidebar-toggle-tab { display: none !important; }
    /* Belt-and-suspenders: never collapse the sidebar to zero on mobile */
    #woSidebar.collapsed,
    #dnSidebar.collapsed {
        width: 100% !important;
        min-width: 0 !important;
        padding: 1.25rem 1rem !important;
        opacity: 1 !important;
        overflow: visible !important;
    }
    /* Sticky action bar – fixed to bottom on mobile, wrap if needed */
    .sticky-action-bar  {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.55rem 0.75rem;
        min-height: 56px;
        overflow: visible;
        background: rgba(255, 255, 255, 0.95);
    }
    .sticky-action-bar .btn {
        flex: 1 1 calc(50% - 0.4rem);
        min-width: 0;
        font-size: 0.78rem;
        padding: 0.55rem 0.5rem;
        white-space: nowrap;
    }
    /* Add bottom padding to the active section so fixed bar doesn't cover content */
    #orders-section.active,
    #delivery-section.active { padding-bottom: 130px; }
    /* The desktop locks main-content to viewport with overflow:hidden — release on mobile */
    .main-content { overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .app-container { height: auto; min-height: 100vh; }
}

@media (max-width: 480px) {
    .stats-row { grid-template-columns: 1fr 1fr; }
    .db-title { font-size: 1.3rem; }
    .stat-value { font-size: 1.6rem; }
}
/* ═══════════════════════════════════════════════════════════════
   SALARY MODULE
   ═══════════════════════════════════════════════════════════════ */

.salary-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px 24px;
    gap: 20px;
    overflow-y: auto;
}

/* Sub-tab bar */
.salary-tab-bar {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0;
    flex-shrink: 0;
}

.salary-tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-family: 'Cairo', sans-serif;
    font-size: 0.92rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    border-radius: 6px 6px 0 0;
    transition: color 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.salary-tab-btn:hover { color: #1e293b; background: #f1f5f9; }

.salary-tab-btn.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    background: #eff6ff;
}

/* Tab views */
.stab-view { display: none; flex: 1; }
.stab-view.active { display: flex; flex-direction: column; gap: 16px; }

/* Two-column layout */
.salary-two-col {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
    align-items: start;
}

/* Panels */
.salary-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px 22px;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.salary-panel h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 16px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

/* Required star */
.req { color: #ef4444; font-size: 0.8rem; }

/* Breakdown panel */
.sal-breakdown-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #94a3b8;
    text-align: center;
    gap: 12px;
}

.sal-breakdown-placeholder i { font-size: 48px; }
.sal-breakdown-placeholder p { margin: 0; font-size: 0.95rem; }

.sal-cycle-badge {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sal-breakdown-rows { display: flex; flex-direction: column; gap: 6px; }

.sbr-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #374151;
}

.sbr-row:nth-child(odd) { background: #f8fafc; }

.sbr-row.sbr-add span:last-child { color: #16a34a; font-weight: 600; }
.sbr-row.sbr-deduct span:last-child { color: #dc2626; font-weight: 600; }

.sbr-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 6px 0;
}

.sbr-row.sbr-total {
    background: #f0fdf4;
    font-weight: 700;
    font-size: 1rem;
    color: #15803d;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 10px 12px;
}

.sbr-row.sbr-remaining {
    background: #fffbeb;
    font-weight: 700;
    font-size: 0.95rem;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 8px 12px;
}

/* Advance tab centered */
.sal-center-wrap {
    display: flex;
    justify-content: center;
}

.sal-center-wrap .salary-panel {
    width: 420px;
}

/* Records filter bar */
.sal-records-filter {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 16px;
}

.sal-records-filter select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.9rem;
    background: #f8fafc;
    color: #374151;
}

/* Status messages */
.sal-status-success,
.sal-status-error {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.sal-status-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.sal-status-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }

/* Empty state cell */
.sal-empty {
    text-align: center;
    padding: 28px !important;
    color: #94a3b8;
    font-style: italic;
}

/* Responsive */
@media (max-width: 900px) {
    .salary-two-col { grid-template-columns: 1fr; }
    .sal-center-wrap .salary-panel { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════
   SALARY MODULE — v2
   ═══════════════════════════════════════════════════════════════ */

/* Lock button */
.sal-lock-btn {
    margin-right: auto; /* pushes to far left in RTL */
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 7px 14px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.85rem;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, color 0.2s;
    align-self: center;
}
.sal-lock-btn:hover { background: #fef2f2; color: #dc2626; border-color: #fca5a5; }

/* Profit % badge in workers table */
.sal-pct {
    background: #eff6ff;
    color: #2563eb;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.78rem;
    font-weight: 700;
    margin-right: 4px;
}

/* Highlighted editing row */
.sal-row-editing { background: #fffbeb !important; outline: 2px solid #f59e0b; }

/* Settings toggle */
.sal-settings-toggle {
    background: none;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    padding: 8px 12px;
    width: 100%;
    font-family: 'Cairo', sans-serif;
    font-size: 0.88rem;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: background 0.2s;
}
.sal-settings-toggle:hover { background: #f1f5f9; color: #1e293b; }

/* Divider */
.sal-divider { height: 1px; background: #f1f5f9; }

/* Loading overlay on breakdown */
.sal-content-loading { opacity: 0.4; pointer-events: none; transition: opacity 0.2s; }

/* Negative salary warning */
.sal-warn-box {
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.88rem;
    color: #854d0e;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

/* Due date badge */
.sal-due-badge {
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
}
.sal-due-overdue  { background: #fef2f2; color: #dc2626; border: 1px solid #fca5a5; }
.sal-due-today    { background: #fff7ed; color: #c2410c; border: 1px solid #fdba74; }
.sal-due-soon     { background: #fffbeb; color: #d97706; border: 1px solid #fde68a; }
.sal-due-upcoming { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

/* Pagination */
.sal-pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 0 4px;
    flex-wrap: wrap;
}
.sal-page-btn {
    min-width: 36px;
    height: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    font-family: 'Cairo', sans-serif;
    font-size: 0.88rem;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s;
}
.sal-page-btn:hover:not(:disabled) { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.sal-page-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; font-weight: 700; }
.sal-page-btn:disabled { opacity: 0.35; cursor: default; }
.sal-page-info { margin-right: 8px; font-size: 0.85rem; color: #64748b; }

/* PIN overlay */
.sal-pin-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}
.sal-pin-box {
    background: #fff;
    border-radius: 20px;
    padding: 40px 36px;
    width: 340px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    position: relative;
}

.sal-pin-close {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: #f1f5f9;
    color: #64748b;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.sal-pin-close:hover {
    background: #fee2e2;
    color: #dc2626;
}
.sal-pin-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: #fff;
    margin-bottom: 4px;
}
.sal-pin-box h2 { margin: 0; font-size: 1.3rem; font-weight: 700; color: #1e293b; }
.sal-pin-box p  { margin: 0; font-size: 0.9rem; color: #64748b; }
.sal-pin-box input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1.3rem;
    text-align: center;
    letter-spacing: 6px;
    font-family: monospace;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.sal-pin-box input:focus { border-color: #2563eb; }
.sal-pin-error { color: #dc2626; font-size: 0.88rem; min-height: 18px; font-weight: 600; }
.sal-pin-submit {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: 'Cairo', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.sal-pin-submit:hover { opacity: 0.9; }

/* Toast */
.sal-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1e293b;
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.92rem;
    font-weight: 600;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    white-space: nowrap;
}
.sal-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.sal-toast.sal-toast-success { background: #15803d; }
.sal-toast.sal-toast-error   { background: #dc2626; }

/* Print styles */
@media print {
    .salary-tab-bar, .sal-lock-btn, .salary-form-panel,
    .sal-records-filter, .sal-pagination, header, nav { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   SALARY — Full Redesign
   ═══════════════════════════════════════════════════════════════ */
}

/* ── Page Shell ─────────────────────────────────────────────── */
#salary-section.active {
    display: block !important;
    padding: 0 !important;
    overflow: hidden;
    width: 100%;
}

.sal-page {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: #f0f4f8;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.sal-page-header {
    background: linear-gradient(135deg, #152035 0%, #1e3052 60%, #152035 100%);
    padding: 12px 24px 0;
    flex-shrink: 0;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
}

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

.sal-page-title {
    display: flex;
    align-items: center;
    gap: 14px;
    color: #fff;
}

.sal-title-icon {
    width: 36px;
    height: 36px;
    background: rgba(200,150,62,0.18);
    border: 1.5px solid rgba(200,150,62,0.45);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: #c8963e;
}

.sal-page-title h2 {
    font-size: 16px;
    font-weight: 800;
    margin: 0 0 2px;
    color: #fff;
}

.sal-page-title p {
    font-size: 11px;
    color: rgba(255,255,255,0.55);
    margin: 0;
}

.sal-lock-btn-n {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(220,38,38,0.13);
    border: 1.5px solid rgba(220,38,38,0.35);
    color: #f87171;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 700;
    transition: all 0.2s;
}
.sal-lock-btn-n:hover { background: rgba(220,38,38,0.25); border-color: rgba(220,38,38,0.6); }

/* ── Tab Navigation ─────────────────────────────────────────── */
.sal-tabs-nav {
    display: flex;
    gap: 2px;
}

.sal-tabs-nav .salary-tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px; font-size: 13px;
    background: rgba(255,255,255,0.07);
    border: none;
    border-radius: 10px 10px 0 0;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 700;
    transition: all 0.2s;
    position: relative;
    bottom: -1px;
    border-bottom: 3px solid transparent;
}
.sal-tabs-nav .salary-tab-btn:hover { color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.12); }
.sal-tabs-nav .salary-tab-btn.active {
    background: #ffffff;
    color: #1e293b;
    border-bottom-color: #ffffff;
    font-weight: 800;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.10);
}

/* ── Content Area ───────────────────────────────────────────── */
.sal-content-area {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px;
}

.stab-view { display: none; }
.stab-view.active { display: block; }

/* ── Two Column Layout ──────────────────────────────────────── */
.sal-two-col {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

/* ── Card ───────────────────────────────────────────────────── */
.sal-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.07);
    overflow: hidden;
}

.sal-card-hd {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 15px;
    font-weight: 800;
    color: #1e293b;
}
.sal-card-hd i { color: #c8963e; font-size: 15px; }

.sal-form-card { padding: 20px; }
.sal-form-card .sal-card-hd { margin: -20px -20px 18px; border-radius: 16px 16px 0 0; }

/* ── Form Fields ────────────────────────────────────────────── */
.sal-field { margin-bottom: 11px; }
.sal-field label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.sal-req { color: #dc2626; }

.sal-form-card input,
.sal-form-card select {
    width: 100%;
    height: 44px;
    padding: 0 13px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-family: 'Cairo', sans-serif;
    font-size: 14px;
    color: #1e293b;
    background: #f8fafc;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}
.sal-form-card input:focus,
.sal-form-card select:focus {
    outline: none;
    border-color: #c8963e;
    box-shadow: 0 0 0 3px rgba(200,150,62,0.1);
    background: #fff;
}

.sal-inp-wrap {
    display: flex;
    align-items: stretch;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    height: 44px;
    overflow: hidden;
    background: #f8fafc;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.sal-inp-wrap:focus-within {
    border-color: #c8963e;
    box-shadow: 0 0 0 3px rgba(200,150,62,0.1);
    background: #fff;
}
.sal-inp-wrap input {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    flex: 1;
    height: 100%;
    min-width: 0;
}
.sal-inp-wrap span {
    padding: 0 12px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    background: #f1f5f9;
    border-right: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Buttons ────────────────────────────────────────────────── */
.sal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 700;
    transition: all 0.18s;
    white-space: nowrap;
}
.sal-btn-primary { background: #c8963e; color: #fff; }
.sal-btn-primary:hover { background: #a87830; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(200,150,62,0.35); }
.sal-btn-success { background: #16a34a; color: #fff; }
.sal-btn-success:hover { background: #15803d; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(22,163,74,0.35); }
.sal-btn-outline { background: transparent; border: 1.5px solid #e2e8f0; color: #64748b; }
.sal-btn-outline:hover { border-color: #cbd5e1; background: #f8fafc; }
.sal-btn-icon-danger { background: #fee2e2; color: #dc2626; border: none; border-radius: 7px; padding: 6px 10px; cursor: pointer; transition: background 0.15s; }
.sal-btn-icon-danger:hover { background: #fecaca; }
.sal-btn-icon-edit { background: #dbeafe; color: #1d4ed8; border: none; border-radius: 7px; padding: 6px 10px; cursor: pointer; transition: background 0.15s; }
.sal-btn-icon-edit:hover { background: #bfdbfe; }
.sal-btn-sm { padding: 7px 14px; font-size: 12px; }

.sal-form-btns { display: flex; gap: 10px; margin-top: 16px; }
.sal-form-btns .sal-btn { flex: 1; }

/* ── Divider / PIN Toggle ───────────────────────────────────── */
.sal-hr { height: 1px; background: #f1f5f9; margin: 20px 0; }
.sal-toggle-pin {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 9px 13px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    text-align: right;
}
.sal-toggle-pin:hover { background: #f1f5f9; }

/* ── Workers Grid ───────────────────────────────────────────── */
.sal-workers-grid {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
    min-height: 120px;
}

.sal-loading-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: #94a3b8;
    font-size: 14px;
}

.sal-worker-card {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px 12px 12px;
    text-align: center;
    transition: all 0.2s;
}
.sal-worker-card:hover { border-color: #c8963e; box-shadow: 0 6px 20px rgba(200,150,62,0.13); transform: translateY(-2px); }
.sal-worker-card.editing { border-color: #c8963e; background: #fffbeb; }

.sal-w-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 900;
    color: #fff;
    margin: 0 auto 10px;
}
.sal-w-avatar.av-worker  { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.sal-w-avatar.av-manager { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.sal-w-avatar.av-owner   { background: linear-gradient(135deg, #c8963e, #92660a); }

.sal-w-name { font-size: 14px; font-weight: 800; color: #1e293b; margin-bottom: 5px; }

.sal-w-role {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 8px;
}
.sal-w-role.rv-worker  { background: #dbeafe; color: #1d4ed8; }
.sal-w-role.rv-manager { background: #ede9fe; color: #6d28d9; }
.sal-w-role.rv-owner   { background: #fef3c7; color: #92400e; }

.sal-w-salary { font-size: 16px; font-weight: 900; color: #16a34a; margin-bottom: 3px; }
.sal-w-join   { font-size: 11px; color: #94a3b8; margin-bottom: 12px; }

.sal-w-actions { display: flex; gap: 6px; justify-content: center; }
.sal-w-actions button { flex: 1; }

/* ── Tables ─────────────────────────────────────────────────── */
.sal-tbl-wrap { overflow-x: auto; }
.sal-tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.sal-tbl th {
    background: #f8fafc;
    padding: 11px 14px;
    text-align: right;
    font-weight: 700;
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}
.sal-tbl td {
    padding: 11px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
    font-size: 13px;
}
.sal-tbl tr:hover td { background: #fafbfc; }
.sal-tbl tr:last-child td { border-bottom: none; }
.sal-empty { text-align: center; color: #94a3b8; padding: 40px 20px !important; font-size: 14px; }

/* ── Advance total badge ────────────────────────────────────── */
.sal-total-badge {
    margin-right: auto;
    background: #fee2e2;
    color: #dc2626;
    font-size: 12px;
    font-weight: 800;
    padding: 3px 12px;
    border-radius: 20px;
}

/* ── Breakdown Panel ────────────────────────────────────────── */
.sal-breakdown-body { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.sal-bd-empty { text-align: center; padding: 60px 20px; color: #94a3b8; }
.sal-bd-empty i { font-size: 48px; color: #e2e8f0; margin-bottom: 12px; display: block; }

/* ★ Pay Hero — the most important element */
.sal-pay-hero {
    background: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
    border-radius: 16px;
    padding: 18px 16px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.sal-pay-hero-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: rgba(255,255,255,0.7);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.sal-pay-hero-amount {
    font-size: 2.2rem;
    font-weight: 900;
    color: #fff;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1;
}
.sal-pay-hero.hero-owe    { background: linear-gradient(135deg, #064e3b 0%, #065f46 100%); }
.sal-pay-hero.hero-done   { background: linear-gradient(135deg, #1e3a5f 0%, #1e3052 100%); }
.sal-pay-hero.hero-credit { background: linear-gradient(135deg, #7c2d12 0%, #9a3412 100%); }

/* Due badge inside hero */
.sal-pay-hero .sal-due-badge {
    margin-top: 4px;
    font-size: 0.78rem;
    padding: 3px 12px;
    border-radius: 20px;
}

/* Section label */
.sal-bd-section-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0 4px;
}

.sal-bd-rows { display: flex; flex-direction: column; gap: 3px; }

.sbr-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: 9px;
    font-size: 13.5px;
    color: #475569;
    background: #f8fafc;
}
.sbr-row span:first-child { color: #64748b; }
.sbr-row span:last-child { font-weight: 800; font-variant-numeric: tabular-nums; color: #1e293b; }

.sbr-neg { background: #fef2f2 !important; }
.sbr-neg span { color: #dc2626 !important; }
.sbr-pos { background: #f0fdf4 !important; }
.sbr-pos span { color: #16a34a !important; }
.sbr-neutral { background: #f8fafc; }
.sbr-neutral span { color: #64748b !important; }

.sbr-divider { height: 1px; background: #e2e8f0; margin: 2px 0; }

.sbr-total {
    background: #1e3052 !important;
    border-radius: 10px;
    padding: 11px 14px !important;
    font-size: 13px;
    margin-top: 2px;
}
.sbr-total span { color: #fff !important; font-weight: 900 !important; }
.sbr-total span:last-child { font-size: 16px !important; }

.sal-cycle-lbl {
    background: linear-gradient(90deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    color: #0369a1;
    padding: 7px 16px;
    border-radius: 9px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* ── Records Bar ────────────────────────────────────────────── */
.sal-records-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #f1f5f9;
    flex-wrap: wrap;
    gap: 12px;
}
.sal-rec-filters { display: flex; align-items: center; gap: 10px; }
.sal-rec-filters select {
    padding: 7px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    background: #f8fafc;
    cursor: pointer;
    color: #1e293b;
}

/* ── Pagination ─────────────────────────────────────────────── */
.sal-pg-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 14px;
    border-top: 1px solid #f1f5f9;
    flex-wrap: wrap;
}
.sal-pg-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    transition: all 0.18s;
}
.sal-pg-btn:hover:not(:disabled) { border-color: #c8963e; color: #c8963e; }
.sal-pg-btn.active { background: #c8963e; border-color: #c8963e; color: #fff; }
.sal-pg-btn:disabled { opacity: 0.35; cursor: default; }
.sal-pg-info { font-size: 12px; color: #94a3b8; padding: 0 8px; }

/* ── Warn Box ───────────────────────────────────────────────── */
.sal-warn-box {
    background: #fef3c7;
    border: 1.5px solid #fbbf24;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: #92400e;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

/* ── Status Messages ────────────────────────────────────────── */
.sal-status-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
    padding: 8px 12px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
}
.sal-status-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 8px 12px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 860px) {
    .sal-two-col { grid-template-columns: 1fr; }
    .sal-tabs-nav .salary-tab-btn { padding: 9px 14px; font-size: 12px; }
}
}

/* ═══════════════════════════════════════════════════════════════
   PHASE 4 — UX POLISH
═══════════════════════════════════════════════════════════════ */

/* ── Global Toast Notifications ─────────────────────────────── */
#toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: max-content;
    max-width: 90vw;
}

.app-toast {
    min-width: 280px;
    max-width: 480px;
    padding: 14px 20px;
    border-radius: 10px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: all;
    opacity: 0;
    transform: translateY(-14px);
    transition: opacity 0.28s ease, transform 0.28s ease;
    direction: rtl;
    cursor: pointer;
}
.app-toast.visible       { opacity: 1; transform: translateY(0); }
.app-toast.toast-success { background: linear-gradient(135deg,#16a34a,#15803d); }
.app-toast.toast-error   { background: linear-gradient(135deg,#dc2626,#b91c1c); }
.app-toast.toast-info    { background: linear-gradient(135deg,#2563eb,#1d4ed8); }
.app-toast.toast-warning { background: linear-gradient(135deg,#d97706,#b45309); }
.app-toast i { font-size: 1.1rem; flex-shrink: 0; }

/* ── Confirm Modal ───────────────────────────────────────────── */
#confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
#confirm-overlay.visible { opacity: 1; pointer-events: all; }

#confirm-box {
    background: #fff;
    border-radius: 16px;
    padding: 36px 32px 28px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    direction: rtl;
    font-family: 'Cairo', sans-serif;
    box-shadow: 0 24px 64px rgba(0,0,0,0.28);
    transform: scale(0.90);
    transition: transform 0.22s ease;
}
#confirm-overlay.visible #confirm-box { transform: scale(1); }

#confirm-icon { font-size: 2.8rem; margin-bottom: 12px; }
#confirm-msg {
    font-size: 1rem;
    color: #1e293b;
    line-height: 1.75;
    margin-bottom: 28px;
    white-space: pre-line;
}
.confirm-actions { display: flex; gap: 12px; justify-content: center; }
.confirm-actions button {
    padding: 11px 32px;
    border-radius: 9px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: background 0.15s, transform 0.1s;
}
.confirm-actions button:hover { transform: translateY(-1px); }
#confirm-ok           { background: #dc2626; color: #fff; }
#confirm-ok:hover     { background: #b91c1c; }
#confirm-cancel       { background: #f1f5f9; color: #334155; border: 1.5px solid #e2e8f0; }
#confirm-cancel:hover { background: #e2e8f0; }

/* ── Auto-save Indicator ────────────────────────────────────── */
#autosave-indicator {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(15,23,42,0.88);
    color: #94a3b8;
    padding: 7px 16px;
    border-radius: 20px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 7px;
    opacity: 0;
    transition: opacity 0.35s;
    z-index: 9000;
    pointer-events: none;
    backdrop-filter: blur(4px);
}
#autosave-indicator.visible { opacity: 1; }
#autosave-indicator i { color: #22c55e; }

/* ── History Status Filter ───────────────────────────────────── */
#historyStatusFilter {
    padding: 0 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.85rem;
    background: #f8fafc;
    color: #1e293b;
    cursor: pointer;
    height: 40px;
    line-height: 40px;
    direction: rtl;
    appearance: auto;
    -webkit-appearance: auto;
}

/* Date filter — inline badge + input in one row */
.filter-date-wrapper {
    display: flex;
    align-items: center;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    background: #f8fafc;
    overflow: hidden;
    height: 40px;
    transition: border-color 0.15s;
}
.filter-date-wrapper:focus-within {
    border-color: #ff6b35;
    background: white;
    box-shadow: 0 0 0 3px rgba(255,107,53,0.08);
}
.filter-date-badge {
    padding: 0 10px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    background: #94a3b8;
    height: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
    border-left: 1.5px solid #e2e8f0;
    flex-shrink: 0;
}
.filter-date-wrapper input[type="date"] {
    border: none;
    outline: none;
    background: transparent;
    padding: 0 10px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.85rem;
    color: #1e293b;
    height: 100%;
    min-width: 130px;
}

/* Reset/Clear filters button */
.btn-history-reset {
    background: #f1f5f9;
    color: #64748b;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    padding: 0 1rem;
    height: 40px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-history-reset:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fca5a5;
}

/* Ensure filter button also 40px */
.history-filter-bar .btn-primary {
    height: 40px;
    padding: 0 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Results counter bar */
.history-results-bar {
    display: flex;
    align-items: center;
    margin-bottom: 0.6rem;
    min-height: 22px;
}
.history-results-count {
    font-family: 'Cairo', sans-serif;
    font-size: 0.82rem;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 20px;
    padding: 2px 12px;
    font-weight: 600;
}
.history-results-count.has-filters {
    background: #fff7ed;
    color: #c2410c;
}

/* ── Mobile Responsive Fixes ────────────────────────────────── */
@media (max-width: 768px) {
    .history-filter-bar { flex-wrap: wrap; gap: 8px; }
    .history-filter-bar .filter-search   { width: 100%; }
    .history-filter-bar .filter-group    { flex: 1; min-width: 130px; }
    .history-filter-bar .filter-date-wrapper { flex: 1; min-width: 140px; }
    .history-filter-bar .filter-date-wrapper input[type="date"] { min-width: unset; width: 100%; }
    .history-filter-bar #historyStatusFilter { width: 100%; }
    .history-filter-bar .btn             { width: 100%; }
    .history-filter-bar .btn-history-reset { width: 100%; justify-content: center; }

    .action-buttons          { flex-wrap: wrap; }
    .action-buttons .btn     { flex: 1 1 45%; }

    .preview-controls        { flex-wrap: wrap; gap: 4px; }

    .history-table           { overflow-x: visible; }
    .history-table table     { min-width: 0; width: 100%; }

    #workers-cards-grid      { grid-template-columns: 1fr !important; }
    .sal-worker-card         { width: 100% !important; }

    .stats-strip             { flex-wrap: wrap; gap: 8px; }
    .stat-item               { flex: 1 1 45%; }
    .stat-divider            { display: none; }
}

/* ══════════════════════════════════════════════════════════════
   Partial Delivery Modal (PDM)
══════════════════════════════════════════════════════════════ */
.pdm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(3px);
}
.pdm-dialog {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 780px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    overflow: hidden;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
}
.pdm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg,#1e293b 0%,#334155 100%);
    color: #fff;
}
.pdm-header h3 { margin: 0; font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.pdm-header h3 i { color: #fb923c; }
.pdm-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 1.4rem;
    line-height: 1;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.pdm-close:hover { background: rgba(255,255,255,0.28); }
.pdm-meta {
    padding: 10px 22px;
    font-size: 0.88rem;
    color: #475569;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.pdm-meta span { display: flex; align-items: center; gap: 6px; }
.pdm-meta strong { color: #1e293b; }
.pdm-progress-section {
    padding: 14px 22px 10px;
    border-bottom: 1px solid #f1f5f9;
}
.pdm-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    color: #64748b;
    margin-bottom: 6px;
    font-weight: 600;
}
.pdm-progress-bg {
    height: 10px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}
.pdm-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #16a34a);
    border-radius: 999px;
    transition: width 0.4s ease;
}
.pdm-progress-nums {
    display: flex;
    gap: 18px;
    margin-top: 8px;
    font-size: 0.8rem;
    color: #64748b;
}
.pdm-progress-nums span { display: flex; align-items: center; gap: 5px; }
.pdm-progress-nums .pn-dot {
    width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.pn-ordered  { background: #94a3b8; }
.pn-delivered{ background: #22c55e; }
.pn-remaining{ background: #f97316; }
.pdm-table-wrap {
    overflow-y: auto;
    flex: 1;
    padding: 0 22px;
}
.pdm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.pdm-table thead th {
    padding: 10px 8px;
    text-align: center;
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
    font-size: 0.82rem;
    border-bottom: 2px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 1;
}
.pdm-table thead th:first-child { text-align: right; }
.pdm-table tbody tr { border-bottom: 1px solid #f1f5f9; }
.pdm-table tbody tr:hover { background: #fafafa; }
.pdm-table td {
    padding: 10px 8px;
    text-align: center;
    color: #1e293b;
    vertical-align: middle;
}
.pdm-table td:first-child { text-align: right; }
.pdm-num-col { width: 88px; }
.pdm-input-col { width: 110px; }
.pdm-cat { font-weight: 600; color: #1e293b; }
.pdm-finish { font-size: 0.78rem; color: #64748b; }
.pdm-dims { font-size: 0.78rem; color: #94a3b8; }
.pdm-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}
.pdm-badge-ok   { background: #dcfce7; color: #166534; }
.pdm-badge-part { background: #fff7ed; color: #c2410c; }
.pdm-badge-zero { background: #f1f5f9; color: #64748b; }
.pdm-qty-input {
    width: 80px;
    text-align: center;
    padding: 5px 6px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.9rem;
    color: #1e293b;
    outline: none;
    transition: border-color 0.2s;
}
.pdm-qty-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
.pdm-qty-input.over-limit { border-color: #ef4444; background: #fff1f2; }
.pdm-fully-delivered td { opacity: 0.5; }
.pdm-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px 22px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

/* ══════════════════════════════════════════════════════════════
   Delivery History Panel (DHP) – below WO preview
══════════════════════════════════════════════════════════════ */
.delivery-history-panel {
    margin: 14px 0 0;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
}
.dhp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    gap: 14px;
    flex-wrap: wrap;
}
.dhp-header h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
}
.dhp-header h4 i { color: #6366f1; }
.dhp-progress-wrap { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 180px; }
.dhp-progress-bar-bg { flex: 1; height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.dhp-progress-bar-fill { height: 100%; background: linear-gradient(90deg,#22c55e,#16a34a); border-radius: 999px; transition: width 0.4s; }
.dhp-progress-label { font-size: 0.82rem; font-weight: 700; color: #22c55e; min-width: 36px; }
.dhp-summary {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #e2e8f0;
}
.dhp-stat {
    flex: 1;
    text-align: center;
    padding: 10px 4px;
    border-left: 1px solid #e2e8f0;
    font-size: 0.82rem;
    color: #64748b;
}
.dhp-stat:last-child { border-left: none; }
.dhp-stat-num { display: block; font-size: 1.3rem; font-weight: 800; color: #1e293b; line-height: 1.2; }
.dhp-stat-num.green { color: #16a34a; }
.dhp-stat-num.orange { color: #ea580c; }
.dhp-item-table-wrap { padding: 0 16px 10px; }
.dhp-item-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    margin-top: 10px;
}
.dhp-item-table th {
    text-align: right;
    padding: 6px 8px;
    color: #64748b;
    font-weight: 700;
    border-bottom: 1.5px solid #e2e8f0;
    font-size: 0.78rem;
}
.dhp-item-table td {
    padding: 6px 8px;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.dhp-item-table td:not(:first-child) { text-align: center; }
.dhp-mini-bar-bg { height: 5px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-top: 3px; }
.dhp-mini-bar-fill { height: 100%; background: #22c55e; border-radius: 999px; }
#dhpDeliveries { padding: 10px 16px 14px; }
.dhp-dn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dhp-dn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.18s;
}
.dhp-dn-item:hover { background: #eff6ff; border-color: #bfdbfe; }
.dhp-dn-num { font-weight: 700; color: #1e293b; }
.dhp-dn-date { color: #64748b; font-size: 0.78rem; }
.dhp-dn-qty { font-weight: 700; color: #6366f1; }
.dhp-dn-arrow { margin-right: auto; color: #94a3b8; font-size: 0.8rem; }
.dhp-empty { padding: 14px 18px; color: #94a3b8; font-size: 0.85rem; text-align: center; }

/* status-select partial delivered colour */
.status-select[data-status="تسليم جزئي"] {
    background: #fff7ed;
    color: #c2410c;
    border-color: #fed7aa;
}
.ao-status-select[data-status="تسليم جزئي"] { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }

@media print {
    .delivery-history-panel { display: none !important; }
}
@media (max-width: 640px) {
    .pdm-dialog { border-radius: 10px; max-height: 95vh; }
    .pdm-header  { padding: 14px 14px 12px; }
    .pdm-header h3 { font-size: 0.95rem; }
    .pdm-meta { padding: 8px 14px; gap: 12px; font-size: 0.8rem; }
    .pdm-progress-section { padding: 10px 14px; }
    .pdm-progress-nums { gap: 12px; font-size: 0.75rem; }
    .pdm-table-wrap { padding: 0 10px; }
    .pdm-footer { padding: 12px 14px; }
    .pdm-footer .btn { flex: 1; }

    .pdm-table { font-size: 0.72rem; }
    .pdm-table th, .pdm-table td { padding: 8px 3px; }
    .pdm-num-col   { width: 46px !important; }
    .pdm-input-col { width: 68px !important; }
    .pdm-qty-input { width: 58px; padding: 4px 4px; font-size: 0.8rem; text-align: center; }
    .pdm-cat   { font-size: 0.78rem; line-height: 1.35; }
    .pdm-finish{ display: block; margin-top: 2px; }
    .pdm-dims  { font-size: 0.7rem; }
    .pdm-badge { display: inline-block; margin-top: 3px; font-size: 0.66rem; padding: 1px 5px; white-space: nowrap; }

    .dhp-summary { flex-wrap: wrap; }
    .dhp-stat { flex: 1 1 45%; border-bottom: 1px solid #e2e8f0; }
    .dhp-stat:nth-last-child(-n+2) { border-bottom: none; }
    .dhp-item-table { font-size: 0.75rem; }
    .dhp-item-table th, .dhp-item-table td { padding: 5px 4px; }
}

/* Extra-small viewports (< 360px – iPhone SE / older Androids) */
@media (max-width: 360px) {
    .pdm-header  { padding: 12px 10px 10px; }
    .pdm-meta    { padding: 8px 10px; gap: 8px; font-size: 0.74rem; }
    .pdm-progress-section { padding: 8px 10px; }
    .pdm-progress-nums    { gap: 8px; font-size: 0.7rem; }
    .pdm-table-wrap { padding: 0 6px; }
    .pdm-footer  { padding: 10px; }

    .pdm-table { font-size: 0.66rem; }
    .pdm-table th, .pdm-table td { padding: 7px 1px; }
    .pdm-num-col   { width: 32px !important; }
    .pdm-input-col { width: 56px !important; }
    .pdm-qty-input { width: 46px; padding: 3px 2px; font-size: 0.74rem; }
    .pdm-cat   { font-size: 0.72rem; }
    .pdm-finish, .pdm-dims { font-size: 0.62rem; }
    .pdm-badge { font-size: 0.58rem; padding: 1px 4px; }
}

/* ══════════════════════════════════════════════
   Delivery Status View Modal (DSM) — read-only
   ══════════════════════════════════════════════ */

/* Wider dialog to accommodate batch history */
.dsm-dialog {
    max-width: 640px;
    max-height: 88vh;
}

/* Single scrollable zone between header and footer */
.dsm-scroll-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Inside DSM the table wrap is not a flex scroller — it flows naturally */
.dsm-dialog .pdm-table-wrap {
    flex: none;
    overflow-y: visible;
}

/* Progress nums RTL layout */
.dsm-dialog .pdm-progress-nums {
    justify-content: flex-end;
    flex-direction: row-reverse;
}

/* Read-only cell states */
.dsm-remaining-cell { color: #dc2626; font-weight: 700; }
.dsm-done-cell      { color: #16a34a; font-weight: 700; }

/* Dimensions label */
.dsm-dims { font-size: 0.72rem; color: #94a3b8; font-weight: 400; white-space: nowrap; }

/* Inline unit label next to numeric values */
.dsm-unit-tag { font-size: 0.68rem; color: #6366f1; font-weight: 600; margin-right: 2px; }

/* Keep number + unit on a single line — no wrapping */
.dsm-qty-nowrap { white-space: nowrap; display: inline-block; }
.dsm-batch-qty  { white-space: nowrap; }

/* Completed item row — full green tint */
.dsm-row-done {
    background: linear-gradient(90deg, #f0fdf4 0%, #dcfce7 40%, #f0fdf4 100%);
}
.dsm-row-done td { border-color: #bbf7d0 !important; }

/* "مكتمل" badge inside completed rows */
.dsm-done-badge {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    background: #16a34a;
    color: #fff;
    vertical-align: middle;
}

/* Input + unit label wrapper */
.pdm-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
}
.pdm-input-unit {
    font-size: 0.7rem;
    font-weight: 700;
    color: #6366f1;
    white-space: nowrap;
}

/* Live m² preview below piece-count input */
.pdm-sqm-preview {
    font-size: 0.7rem;
    color: #6366f1;
    margin-top: 3px;
    white-space: nowrap;
    text-align: center;
}
.pdm-sqm-val { font-weight: 700; }

/* Unit badge shown on each item row in the partial delivery modal */
.pdm-unit-badge {
    display: inline-block;
    margin-top: 3px;
    font-size: 0.68rem;
    font-weight: 700;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    padding: 1px 5px;
}

/* Mini progress bar inside مسلّم cell */
.dsm-mini-bar {
    height: 4px;
    background: #e2e8f0;
    border-radius: 999px;
    margin-top: 4px;
    overflow: hidden;
}
.dsm-mini-fill {
    height: 100%;
    background: linear-gradient(90deg, #fb923c, #ea580c);
    border-radius: 999px;
    transition: width 0.4s;
}

/* Batches section */
.dsm-batches-section {
    padding: 0 1.1rem 0.5rem;
    border-top: 1px solid #f1f5f9;
    margin-top: 0.25rem;
}
.dsm-batches-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: #374151;
    margin: 0.85rem 0 0.6rem;
    display: flex;
    align-items: center;
    gap: 7px;
}
.dsm-batches-title i { color: #6366f1; }

/* Individual batch card */
.dsm-batch-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 0.6rem;
    overflow: hidden;
}
.dsm-batch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
}
.dsm-batch-num {
    font-size: 0.85rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 6px;
}
.dsm-batch-num i { color: #6366f1; }
.dsm-batch-date {
    font-size: 0.78rem;
    color: #64748b;
}

/* Batch items mini-table */
.dsm-batch-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.dsm-batch-table thead th {
    background: transparent;
    color: #64748b;
    font-weight: 600;
    padding: 5px 10px;
    text-align: right;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.78rem;
}
.dsm-batch-table thead th:last-child { text-align: center; width: 70px; }
.dsm-batch-table tbody tr:last-child td { border-bottom: none; }
.dsm-batch-item-name {
    padding: 6px 10px;
    color: #374151;
    border-bottom: 1px solid #f1f5f9;
}
.dsm-batch-qty {
    padding: 6px 10px;
    text-align: center;
    font-weight: 700;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
}

.dsm-no-batches {
    color: #94a3b8;
    font-size: 0.83rem;
    text-align: center;
    padding: 0.75rem 0;
    margin: 0;
}

/* Dashboard action button highlight */
.ao-delivery-status-btn { color: #6366f1 !important; }
.ao-delivery-status-btn:hover { background: #eef2ff !important; }
.ao-convert-btn { color: #16a34a !important; }
.ao-convert-btn:hover { background: #f0fdf4 !important; border-color: #bbf7d0 !important; }
.ao-manage-partial-btn { color: #ea580c !important; }
.ao-manage-partial-btn:hover { background: #fff7ed !important; border-color: #fed7aa !important; }

/* Missing badge variant */
.pdm-badge-partial { background: #fff7ed; color: #c2410c; }

@media (max-width: 640px) {
    .dsm-dialog { max-height: 92vh; }
    .dsm-batch-table { font-size: 0.75rem; }
    .dsm-batch-header { flex-direction: column; align-items: flex-start; gap: 2px; }
}

/* ═══════════════════════════════════════════════════════════════
   RBAC — Permission hiding
   ═══════════════════════════════════════════════════════════════ */
.perm-hidden {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   Header User Info & Logout
   ═══════════════════════════════════════════════════════════════ */
.header-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: auto;
    padding-right: 8px;
}

.header-user-name {
    font-size: 0.875rem;
    color: #d1d5db;
    font-weight: 500;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(239,68,68,0.15);
    color: #fca5a5;
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    transition: background 0.2s, color 0.2s;
}
.btn-logout:hover {
    background: rgba(239,68,68,0.3);
    color: #fff;
}

/* ═══════════════════════════════════════════════════════════════
   Login Overlay
   ═══════════════════════════════════════════════════════════════ */
.login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-card {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.5);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    margin-bottom: 10px;
}
.login-logo h2 {
    color: #f1f5f9;
    font-size: 1.3rem;
    margin: 0 0 4px;
    font-family: 'Cinzel', serif;
}
.login-logo p {
    color: #94a3b8;
    font-size: 0.85rem;
    margin: 0;
}

.login-card .form-group {
    margin-bottom: 16px;
}
.login-card .form-group label {
    display: block;
    font-size: 0.8rem;
    color: #94a3b8;
    margin-bottom: 6px;
    font-weight: 500;
}
.login-card .form-group input {
    width: 100%;
    padding: 10px 14px;
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #f1f5f9;
    font-size: 0.95rem;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.login-card .form-group input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.login-error {
    background: rgba(239,68,68,0.15);
    border: 1px solid rgba(239,68,68,0.3);
    color: #fca5a5;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85rem;
    margin-bottom: 14px;
    text-align: center;
}

.login-submit {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border-radius: 8px;
    margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   Users Management Page
   ═══════════════════════════════════════════════════════════════ */
.users-page {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    height: 100%;
    box-sizing: border-box;
}

.users-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.users-header h2 {
    font-size: 1.3rem;
    color: #1e293b;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Add/Edit form card */
.user-form-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.user-form-card h3 {
    margin: 0 0 18px;
    font-size: 1rem;
    color: #1e293b;
}
.user-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.perm-section-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.permissions-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}
.perm-checkbox {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
    padding: 7px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    transition: background 0.15s, border-color 0.15s;
}
.perm-checkbox:hover { background: #e0f2fe; border-color: #7dd3fc; }
.perm-checkbox input { cursor: pointer; accent-color: #6366f1; }

.form-hint {
    color: #94a3b8;
    font-size: 0.78rem;
    font-weight: 400;
}

.user-form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Users table */
.users-table-wrap {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.users-table th {
    background: #f8fafc;
    padding: 11px 14px;
    text-align: right;
    font-weight: 600;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.8rem;
}
.users-table td {
    padding: 11px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #374151;
    vertical-align: middle;
}
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: #f8fafc; }

.table-empty {
    text-align: center;
    color: #94a3b8;
    padding: 32px !important;
}

/* Role badges */
.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.role-super { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.role-admin  { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* Status chips */
.status-chip {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.chip-active   { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.chip-inactive { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Permission chips */
.perms-cell { max-width: 260px; }
.perm-chip {
    display: inline-block;
    padding: 2px 8px;
    background: #ede9fe;
    color: #5b21b6;
    border: 1px solid #c4b5fd;
    border-radius: 12px;
    font-size: 0.72rem;
    margin: 2px;
    white-space: nowrap;
}
.perm-none {
    background: #f1f5f9;
    color: #94a3b8;
    border-color: #e2e8f0;
}

/* Action buttons in table */
.actions-cell { white-space: nowrap; }
.btn-danger {
    background: #fee2e2 !important;
    color: #dc2626 !important;
    border-color: #fca5a5 !important;
}
.btn-danger:hover {
    background: #fca5a5 !important;
    color: #7f1d1d !important;
}

/* =====================================================
   Audit Log Panel
   ===================================================== */
.audit-panel {
    border-top: 1px solid #e5e7eb;
    background: #fff;
    direction: rtl;
}

/* When placed inside document-preview (scrolls with content) */
.audit-panel-inline {
    margin: 16px auto 0;
    width: 297mm;          /* match A4-landscape page width */
    max-width: 100%;
    border-top: none;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    box-shadow: 0 1px 6px rgba(0,0,0,0.07);
    background: #fff;
}

/* For delivery section the page is A4-portrait */
#deliveryPreview .audit-panel-inline {
    width: 210mm;
}

.audit-panel-inline .audit-panel-toggle {
    border-bottom: none;
    border-radius: 10px;
    background: #f8fafc;
}
.audit-panel-inline .audit-panel-toggle:hover {
    background: #f1f5f9;
}
.audit-panel-inline .audit-timeline-wrap {
    border-top: 1px solid #e2e8f0;
}

@media print {
    .audit-panel { display: none !important; }
}

.audit-panel-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #f8fafc;
    border: none;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    color: #374151;
    transition: background 0.2s;
    text-align: right;
}
.audit-panel-toggle:hover {
    background: #f1f5f9;
}

.audit-toggle-left {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6b7280;
}
.audit-toggle-left i {
    color: #6366f1;
    font-size: 0.9rem;
}
.audit-toggle-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.audit-badge {
    background: #6366f1;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    line-height: 1.6;
    display: none;
}
.audit-badge.visible {
    display: inline-block;
}

.audit-chevron {
    color: #9ca3af;
    font-size: 0.8rem;
    transition: transform 0.25s ease;
}
.audit-chevron.open {
    transform: rotate(180deg);
}

.audit-timeline-wrap {
    padding: 16px 20px;
    max-height: 360px;
    overflow-y: auto;
}

.audit-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
}
.audit-timeline::before {
    content: '';
    position: absolute;
    right: 15px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e5e7eb;
}

.audit-entry {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 10px 0;
    position: relative;
}

.audit-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px currentColor;
    flex-shrink: 0;
    margin-top: 3px;
    position: relative;
    z-index: 1;
}
.audit-dot.dot-created  { color: #16a34a; background: #16a34a; }
.audit-dot.dot-updated  { color: #2563eb; background: #2563eb; }
.audit-dot.dot-deleted  { color: #dc2626; background: #dc2626; }
.audit-dot.dot-printed  { color: #9ca3af; background: #9ca3af; }
.audit-dot.dot-default  { color: #6366f1; background: #6366f1; }

.audit-body {
    flex: 1;
    min-width: 0;
}
.audit-action-line {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    width: 100%;
}
.audit-action-label {
    font-size: 0.83rem;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 999px;
}
.label-created { background: #dcfce7; color: #15803d; }
.label-updated  { background: #dbeafe; color: #1d4ed8; }
.label-deleted  { background: #fee2e2; color: #b91c1c; }
.label-printed  { background: #f3f4f6; color: #6b7280; }
.label-default  { background: #ede9fe; color: #4f46e5; }

.audit-user {
    font-size: 0.8rem;
    color: #374151;
    font-weight: 600;
}
.audit-details {
    font-size: 0.78rem;
    color: #6b7280;
    margin-top: 2px;
    word-break: break-word;
}
.audit-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-right: auto;
    white-space: nowrap;
    direction: ltr;
}

.audit-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 0.85rem;
    padding: 20px 0;
}

.audit-loading {
    text-align: center;
    color: #9ca3af;
    font-size: 0.85rem;
    padding: 16px 0;
}
.audit-loading i {
    animation: spin 1s linear infinite;
    margin-left: 6px;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ── Advance Cycle Label ────────────────────────────────────── */
.adv-cycle-lbl {
    font-size: 12px;
    color: #0369a1;
    background: #e0f2fe;
    border-radius: 0;
    padding: 6px 16px;
    border-bottom: 1px solid #bae6fd;
    font-weight: 600;
}

/* ── Notes Cell ─────────────────────────────────────────────── */
.sal-notes-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #64748b;
    font-size: 12px;
}

/* ── Salary Ledger (Records Tab) ────────────────────────────── */
.sal-ledger-header {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 14px 14px 0 0;
    border-bottom: 2px solid #f1f5f9;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    margin-bottom: 0;
    overflow: hidden;
}
.sal-ledger-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    gap: 14px;
    flex-wrap: wrap;
}
.sal-ledger-filters-row {
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    padding: 10px 20px;
}
.sal-ledger-dates {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.sal-date-lbl {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
}
.sal-date-inp {
    height: 34px;
    padding: 0 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    color: #1e293b;
    background: #fff;
    cursor: pointer;
    transition: border-color .18s;
}
.sal-date-inp:focus { outline: none; border-color: #c8963e; }
.sal-ledger-exports {
    display: flex;
    align-items: center;
    gap: 8px;
}
.sal-ledger-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
}
.sal-ledger-title i {
    color: #c8963e;
    font-size: 18px;
}
.sal-ledger-worker-sel {
    padding: 9px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-family: 'Cairo', sans-serif;
    font-size: 14px;
    font-weight: 600;
    background: #f8fafc;
    color: #1e293b;
    cursor: pointer;
    min-width: 200px;
    transition: border-color .18s;
}
.sal-ledger-worker-sel:focus {
    outline: none;
    border-color: #c8963e;
    background: #fff;
}
.sal-ledger-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #94a3b8;
    text-align: center;
    background: #fff;
    border-radius: 0 0 14px 14px;
    min-height: 220px;
}
.sal-ledger-empty i {
    font-size: 48px;
    margin-bottom: 14px;
    opacity: .35;
}
.sal-ledger-empty p {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 6px;
}
.sal-ledger-empty small {
    font-size: 12px;
    opacity: .7;
}
#sal-ledger-body .sal-card {
    border-radius: 0 0 14px 14px;
}

/* ── Transaction Type Badges ────────────────────────────────── */
.sal-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.sal-type-salary {
    background: #dcfce7;
    color: #166534;
}
.sal-type-advance {
    background: #ffedd5;
    color: #9a3412;
}

/* ── Ledger Amount Cells ────────────────────────────────────── */
.sal-ledger-amount {
    font-weight: 800;
    font-size: 13px;
}
.sal-ledger-credit { color: #16a34a; }
.sal-ledger-debit  { color: #dc2626; }

/* ══════════════════════════════════════════════════════════════
   SUPPLIERS MODULE
   ══════════════════════════════════════════════════════════════ */

/* ── Receipt layout: sidebar + items card ── */
.sup-receipt-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.sup-receipt-sidebar {
    min-width: 260px;
    max-width: 280px;
    flex-shrink: 0;
}
.sup-receipt-items-card {
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

/* ── Items table ── */
.sup-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 860px;
}
.sup-items-table th {
    background: #1e3052;
    color: #fff;
    padding: 9px 8px;
    text-align: center;
    font-weight: 700;
    white-space: nowrap;
    font-size: 12px;
}
.sup-items-table td {
    padding: 5px 4px;
    border-bottom: 1px solid #f1f5f9;
    text-align: center;
    vertical-align: middle;
}
.sup-items-table tbody tr:hover { background: #f8fafc; }
.sup-item-input {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 7px;
    font-family: 'Cairo', sans-serif;
    font-size: 12px;
    text-align: center;
    background: #fff;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.sup-item-input:focus { outline: none; border-color: #c8963e; box-shadow: 0 0 0 2px rgba(200,150,62,0.15); }
.sup-item-input[readonly] { background: #f0f4f8; color: #64748b; }
.sup-item-select {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 4px;
    font-family: 'Cairo', sans-serif;
    font-size: 11px;
    background: #fff;
    cursor: pointer;
}

/* ── Grand total row ── */
.sup-receipt-total-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-top: 2px solid #f1f5f9;
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    background: #fafbfc;
}
.sup-receipt-total-row strong {
    color: #c8963e;
    font-size: 18px;
}

/* ── Summary cards ── */
.sup-summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.sup-summary-card {
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}
.sup-sc-icon { font-size: 22px; opacity: 0.75; }
.sup-sc-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.75; }
.sup-sc-value { font-size: 22px; font-weight: 800; }

.sup-card-debt    { background: #fff7ed; color: #9a3412; }
.sup-card-paid    { background: #f0fdf4; color: #166534; }
.sup-card-balance { background: #eff6ff; color: #1d4ed8; }

@media (max-width: 700px) {
    .sup-receipt-layout { flex-direction: column; }
    .sup-receipt-sidebar { max-width: 100%; min-width: unset; }
    .sup-summary-cards { grid-template-columns: 1fr; }
    .sal-two-col { grid-template-columns: 1fr; }
}
