/* ============================================================
   نظام إدارة المستودع — نظام التصميم
   كحلي عميق + ذهبي · Cairo · موجه للهاتف أولاً · RTL
   ============================================================ */

:root {
    --ink:      #0a1424;
    --ink-2:    #0e1b31;
    --panel:    #14253f;
    --panel-2:  #1b3050;
    --line:     rgba(255, 255, 255, 0.09);
    --text:     #eef3fb;
    --muted:    #9db0cc;
    --gold:     #e6b451;
    --gold-2:   #f3cf82;
    --gold-dim: rgba(230, 180, 81, 0.14);
    --green:    #35c98a;
    --red:      #ff6f6f;
    --radius:   16px;
    --nav-h:    62px;
    --shadow:   0 10px 30px rgba(0, 0, 0, 0.35);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: linear-gradient(180deg, var(--ink) 0%, var(--ink-2) 55%, #12233c 100%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    font-size: 16px;
    line-height: 1.6;
}

body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }

/* ---------- الرأس ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(10, 20, 36, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.app-header-inner {
    max-width: 720px;
    margin: 0 auto;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-logo { font-size: 26px; }

.app-header-text { display: flex; flex-direction: column; line-height: 1.25; }
.app-header-text strong { font-size: 15px; font-weight: 800; color: var(--gold-2); }
.app-header-text span   { font-size: 12.5px; color: var(--muted); }

/* ---------- الحاوية ---------- */
.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 14px 14px 28px;
}

/* ---------- البطاقات ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 14px;
}

.card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--gold-2);
    margin-bottom: 10px;
}

.card-title .hint { font-size: 12px; font-weight: 600; color: var(--muted); }

/* ---------- الحقول ---------- */
label.field-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    font-family: inherit;
    font-size: 16px; /* يمنع تكبير iOS التلقائي */
    color: var(--text);
    background: var(--ink-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

input:focus, select:focus { border-color: var(--gold); }

input[type="date"] { color-scheme: dark; }

select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239db0cc' stroke-width='2' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 14px center;
    padding-left: 36px;
}

/* ---------- الأزرار ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 15.5px;
    font-weight: 800;
    border: none;
    border-radius: 13px;
    padding: 13px 18px;
    cursor: pointer;
    min-height: 48px;
    transition: transform 0.08s, opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-gold  { background: linear-gradient(135deg, var(--gold), #d09c31); color: #201503; }
.btn-ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn-red   { background: rgba(255, 111, 111, 0.14); color: var(--red); border: 1px solid rgba(255, 111, 111, 0.3); }
.btn-block { width: 100%; }
.btn-sm    { min-height: 38px; padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }

/* ---------- شرائح الزبائن ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 15px;
    min-height: 42px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.12s, background 0.12s;
}

.chip.selected {
    background: var(--gold-dim);
    border-color: var(--gold);
    color: var(--gold-2);
}

.selected-customer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--gold-dim);
    border: 1px solid var(--gold);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 10px;
}

.selected-customer strong { color: var(--gold-2); font-size: 16px; }

.selected-customer button {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

/* نتائج البحث */
.search-results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 240px; overflow-y: auto; }

.search-results button {
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    text-align: right;
    color: var(--text);
    background: var(--ink-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 14px;
    cursor: pointer;
}

.search-results .add-new { color: var(--green); border-style: dashed; }

/* ---------- شبكة المنتجات السريعة (العنصر المميز) ---------- */
.product-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.product-box {
    position: relative;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 700;
    color: var(--text);
    background: linear-gradient(160deg, var(--panel-2), var(--panel));
    border: 1.5px solid var(--line);
    border-radius: 14px;
    min-height: 78px;
    padding: 10px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.35;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
    word-break: break-word;
}

.product-box:active { transform: scale(0.97); }

.product-box.in-cart {
    border-color: var(--gold);
    background: linear-gradient(160deg, rgba(230, 180, 81, 0.2), rgba(230, 180, 81, 0.07));
    box-shadow: 0 0 0 1px rgba(230, 180, 81, 0.25), 0 6px 18px rgba(230, 180, 81, 0.12);
}

.product-box .qty-badge {
    position: absolute;
    top: -8px;
    left: -6px;
    background: var(--gold);
    color: #201503;
    font-size: 13px;
    font-weight: 800;
    border-radius: 999px;
    min-width: 26px;
    height: 26px;
    padding: 0 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

/* ---------- قائمة الفاتورة الحالية ---------- */
.cart-list { display: flex; flex-direction: column; gap: 8px; }

.cart-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ink-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
}

.cart-item .ci-name { flex: 1; font-weight: 700; font-size: 15px; }
.cart-item .ci-qty  { color: var(--gold-2); font-weight: 800; font-size: 16px; white-space: nowrap; }

.cart-item button {
    background: none;
    border: none;
    color: var(--red);
    font-size: 19px;
    cursor: pointer;
    padding: 4px 6px;
}

/* ---------- شريط الحفظ الثابت ---------- */
.save-bar {
    position: fixed;
    right: 0;
    left: 0;
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    z-index: 45;
    background: rgba(10, 20, 36, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 10px 14px;
}

.save-bar-inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.save-bar .summary { flex: 1; font-size: 13.5px; color: var(--muted); line-height: 1.4; }
.save-bar .summary strong { color: var(--gold-2); font-size: 15px; display: block; }

body.has-savebar { padding-bottom: calc(var(--nav-h) + 82px + env(safe-area-inset-bottom, 0px)); }

/* ---------- اللوحة السفلية (إدخال الكمية) ---------- */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(4, 9, 18, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.sheet {
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: 61;
    background: var(--panel);
    border-top: 1px solid var(--line);
    border-radius: 22px 22px 0 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateY(105%);
    transition: transform 0.22s ease-out;
    box-shadow: var(--shadow);
    max-width: 720px;
    margin: 0 auto;
}

body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
body.sheet-open .sheet { transform: translateY(0); }

.sheet-handle {
    width: 42px;
    height: 4px;
    border-radius: 4px;
    background: var(--line);
    margin: 0 auto 14px;
}

.sheet-product-name {
    text-align: center;
    font-size: 18px;
    font-weight: 800;
    color: var(--gold-2);
    margin-bottom: 4px;
}

.sheet-customer-name {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 16px;
}

.qty-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.qty-step {
    font-family: inherit;
    font-size: 28px;
    font-weight: 800;
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.qty-step:active { transform: scale(0.94); background: var(--gold-dim); }

#qtyInput {
    flex: 1;
    text-align: center;
    font-size: 26px;
    font-weight: 800;
    padding: 12px 8px;
    height: 60px;
    color: var(--gold-2);
}

.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }

/* ---------- التبويبات ---------- */
.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

.tabs a {
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 16px;
    text-decoration: none;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
}

.tabs a.active { color: var(--gold-2); background: var(--gold-dim); border-color: var(--gold); }

/* ---------- صفوف الإدارة ---------- */
.row-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--ink-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.row-item .ri-name { flex: 1; min-width: 120px; font-weight: 700; font-size: 15px; }
.row-item .ri-meta { font-size: 12px; color: var(--muted); width: 100%; }

.icon-btn {
    font-family: inherit;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    min-width: 42px;
    min-height: 42px;
    font-size: 17px;
    cursor: pointer;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn.star-on { color: var(--gold); border-color: var(--gold); background: var(--gold-dim); }
.icon-btn.danger  { color: var(--red); }

.order-input { width: 64px !important; text-align: center; padding: 8px 6px !important; }

/* ---------- الجداول (معاينة التصدير) ---------- */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 12px;
}

table.report {
    border-collapse: collapse;
    width: 100%;
    min-width: 560px;
    font-size: 13.5px;
}

table.report th, table.report td {
    padding: 9px 12px;
    text-align: center;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

table.report th {
    background: var(--panel-2);
    color: var(--gold-2);
    font-weight: 800;
    position: sticky;
    top: 0;
}

table.report td:first-child, table.report th:first-child {
    text-align: right;
    position: sticky;
    right: 0;
    background: var(--panel);
}

table.report tr.total-row td {
    background: var(--gold-dim);
    color: var(--gold-2);
    font-weight: 800;
    border-top: 2px solid var(--gold);
}

/* ---------- شريط التنقل السفلي ---------- */
.bottom-nav {
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(10, 20, 36, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    display: flex;
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--muted);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav a.active { color: var(--gold-2); }
.bottom-nav .nav-ic { font-size: 21px; }

/* ---------- التنبيهات ---------- */
.toast-wrap {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top, 0px));
    right: 14px;
    left: 14px;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    margin: 0 auto;
    max-width: 480px;
    width: fit-content;
    font-size: 14.5px;
    font-weight: 700;
    padding: 11px 20px;
    border-radius: 999px;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(-12px);
    transition: opacity 0.25s, transform 0.25s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok  { background: #103826; color: #7ff0bf; border: 1px solid rgba(53, 201, 138, 0.4); }
.toast-err { background: #3a1620; color: #ffb3b3; border: 1px solid rgba(255, 111, 111, 0.4); }

/* ---------- صفحة الدخول ---------- */
.login-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 28px 22px;
    box-shadow: var(--shadow);
}

.login-logo { text-align: center; font-size: 52px; margin-bottom: 6px; }

.login-title {
    text-align: center;
    font-size: 20px;
    font-weight: 800;
    color: var(--gold-2);
    margin-bottom: 4px;
}

.login-sub { text-align: center; font-size: 13.5px; color: var(--muted); margin-bottom: 20px; }

.form-group { margin-bottom: 14px; }

.alert-err {
    background: rgba(255, 111, 111, 0.12);
    border: 1px solid rgba(255, 111, 111, 0.35);
    color: #ffb3b3;
    font-size: 14px;
    font-weight: 700;
    border-radius: 12px;
    padding: 11px 14px;
    margin-bottom: 14px;
    text-align: center;
}

/* ---------- حالات فارغة ---------- */
.empty-state {
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    padding: 22px 12px;
    line-height: 1.8;
}

.empty-state a { color: var(--gold-2); font-weight: 700; }

/* ---------- متفرقات ---------- */
.muted { color: var(--muted); font-size: 13px; }
.mb-0 { margin-bottom: 0 !important; }
.mt-10 { margin-top: 10px; }
.flex-row { display: flex; gap: 10px; align-items: center; }
.flex-row > * { flex: 1; }

.stat-line {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 6px 2px;
    border-bottom: 1px dashed var(--line);
}

.stat-line:last-child { border-bottom: none; }
.stat-line strong { color: var(--gold-2); }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media (min-width: 480px) {
    .product-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- صورة الفاتورة الحالية والطابور ---------- */
.scan-photo {
    width: 100%;
    max-height: 260px;
    object-fit: cover;
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: zoom-in;
    background: var(--ink-2);
}

/* ---------- عارض الصور الداخلي ---------- */
.img-overlay {
    position: fixed;
    inset: 0;
    z-index: 95;
    background: rgba(4, 9, 18, 0.94);
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 10px calc(24px + env(safe-area-inset-bottom, 0px));
}

.img-overlay.open { display: flex; }

.img-overlay img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    cursor: zoom-out;
}

/* ---------- شبكة أرشيف الصور ---------- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.photo-card {
    background: var(--ink-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.photo-card img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
    background: var(--panel-2);
}

.photo-card .pc-meta {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
}

.photo-card .pc-meta .pc-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 800;
    border-radius: 999px;
    padding: 2px 9px;
    white-space: nowrap;
}

.badge-queued  { background: rgba(230, 180, 81, 0.16); color: var(--gold-2); }
.badge-done    { background: rgba(53, 201, 138, 0.16); color: #7ff0bf; }
.badge-skipped { background: rgba(157, 176, 204, 0.16); color: var(--muted); }
