:root {
    --primary: #142045;
    --secondary: #ffffff;
    --accent: #1E88E5;
    --surface: #f4f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #657089;
    --line: #d9deea;
    --danger: #b42318;
}

[data-theme="dark"] {
    --surface: #0c1220;
    --panel: #121a2b;
    --ink: #eef3ff;
    --muted: #aab6cf;
    --line: #26344f;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    background: var(--surface);
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

.app-navbar,
.hero {
    background: var(--primary);
}

.app-navbar {
    box-shadow: 0 8px 24px rgba(20, 32, 69, 0.16);
}

.navbar-brand {
    color: #fff;
    font-weight: 800;
}

.navbar-brand:hover {
    color: #fff;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border-color: rgba(255, 255, 255, .45);
    color: #fff;
}

.app-shell {
    max-width: 1680px;
}

.hero {
    border-radius: 8px;
    color: var(--secondary);
    padding: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.hero p {
    color: #d8e2fb;
    margin: 8px 0 0;
}

.eyebrow {
    display: block;
    color: #c8d2ee;
    font-size: .86rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.hero h1 {
    font-size: clamp(1.55rem, 2.2vw, 2.35rem);
    margin: 0;
    font-weight: 800;
}

.hero-actions,
.button-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.button-grid .btn {
    flex: 1 1 130px;
}

.metric-card,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(20, 32, 69, 0.06);
}

.metric-card {
    min-height: 116px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
}

.metric-card span {
    color: var(--muted);
}

.metric-card strong {
    color: var(--accent);
    font-size: 2.25rem;
    line-height: 1;
}

.panel {
    padding: 20px;
}

.panel h2 {
    color: var(--ink);
    font-size: 1.16rem;
    font-weight: 800;
    margin: 0 0 14px;
}

.form-control,
.form-control:focus {
    background: var(--panel);
    color: var(--ink);
    border-color: var(--line);
}

.ltr-input,
code,
.barcode-number {
    direction: ltr;
    text-align: left;
    font-family: Consolas, "Courier New", monospace;
}

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: #203262;
    --bs-btn-hover-border-color: #203262;
}

.btn-outline-primary {
    --bs-btn-color: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent);
    --bs-btn-hover-border-color: var(--accent);
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.details-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    min-width: 0;
}

.details-grid .wide {
    grid-column: 1 / -1;
}

.details-grid span {
    color: var(--muted);
    display: block;
    font-size: .78rem;
}

.details-grid strong {
    color: var(--ink);
    direction: ltr;
    display: block;
    overflow-wrap: anywhere;
}

.barcode-card {
    min-height: 195px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 10px;
}

.barcode-card svg,
.table-barcode svg {
    max-width: 100%;
    direction: ltr;
}

.label-svg {
    width: 100%;
    height: auto;
    aspect-ratio: 280 / 195;
    display: block;
    direction: ltr;
}

.drop-zone {
    border: 2px dashed #9aa7c5;
    border-radius: 8px;
    min-height: 188px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s ease, background .2s ease, transform .2s ease;
}

.drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(30, 136, 229, .08);
    transform: translateY(-1px);
}

.file-badge {
    width: 66px;
    height: 66px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.selected-file {
    min-height: 24px;
    margin-top: 14px;
    color: var(--muted);
    word-break: break-word;
}

.progress {
    height: 12px;
}

.progress-bar {
    background: var(--accent);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ink);
    --bs-table-border-color: var(--line);
}

.empty-row td {
    color: var(--muted);
    text-align: center;
    padding: 30px;
}

.error-text {
    color: var(--danger);
}

.app-toast {
    background: var(--primary);
    color: #fff;
}

.print-area {
    display: none;
}

/* تصفية وترتيب الجدول */
th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px !important;
}

th.sortable .sort-icon::after {
    content: " ↕";
    font-size: 0.8rem;
    color: var(--muted);
}

th.sortable.asc .sort-icon::after {
    content: " ↑";
    color: var(--accent);
}

th.sortable.desc .sort-icon::after {
    content: " ↓";
    color: var(--accent);
}

/* لوحة السجل */
.history-list .history-item {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    padding: 10px 5px;
    color: var(--ink);
    transition: background-color 0.2s ease;
}

.history-list .history-item:hover {
    background: rgba(30, 136, 229, 0.08);
}

/* مؤشر التقدم التراكبي */
.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.progress-overlay-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    color: var(--ink);
}

/* أزرار الإجراءات */
.row-actions-btn-group {
    display: flex;
    gap: 4px;
}

.row-actions-btn-group .btn-sm {
    padding: 2px 6px;
    font-size: 0.75rem;
}

/* طباعة جماعية وتخطيط شبكي */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }

    body > *:not(.print-area) {
        display: none !important;
    }

    .print-area {
        display: block !important;
        background: #ffffff !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* تخطيط شبكة للطباعة الجماعية */
    .print-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
        padding: 10px !important;
    }

    .print-grid .print-item-wrapper {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border: 1px solid #000000;
        padding: 8px;
        background: #ffffff;
        border-radius: 4px;
    }

    .print-grid .print-item-wrapper svg {
        width: 100% !important;
        height: auto !important;
        max-height: 140px !important;
    }

    /* عند طباعة باركود فردي */
    .print-single-container {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        width: 100%;
        background: #ffffff;
    }
}

@media (max-width: 767.98px) {
    .hero {
        align-items: stretch;
        flex-direction: column;
        padding: 20px;
    }

    .hero-actions .btn {
        flex: 1 1 100%;
    }

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