/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0f1117;
    --bg2:      #161b27;
    --bg3:      #1e2536;
    --border:   #2a3245;
    --text:     #e2e8f0;
    --text2:    #8892a4;
    --blue:     #3b82f6;
    --blue2:    #2563eb;
    --green:    #10b981;
    --orange:   #f59e0b;
    --red:      #ef4444;
    --purple:   #8b5cf6;
    --sidebar-w: 240px;
    --radius:   10px;
    --shadow:   0 4px 20px rgba(0,0,0,.4);
}

body { font-family: 'Cairo', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; direction: rtl; }
a { color: var(--blue); text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ── Layout ─────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.main   { flex: 1; display: flex; flex-direction: column; margin-right: var(--sidebar-w); min-height: 100vh; transition: margin .3s; }
.content { padding: 24px; flex: 1; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w); background: var(--bg2); border-left: 1px solid var(--border);
    position: fixed; top: 0; right: 0; height: 100vh; display: flex; flex-direction: column;
    z-index: 100; transition: transform .3s;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px; padding: 18px 16px;
    border-bottom: 1px solid var(--border);
}
.brand-icon { width: 36px; height: 36px; background: var(--blue); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; flex-shrink: 0; }
.brand-name  { font-weight: 700; font-size: 15px; display: block; }
.brand-sub   { font-size: 10px; color: var(--text2); display: block; }
.sidebar-close { display: none; margin-right: auto; background: none; border: none; color: var(--text2); cursor: pointer; font-size: 16px; }

.sidebar-user { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--blue2); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.user-name  { font-weight: 600; font-size: 13px; display: block; }
.user-role  { font-size: 11px; color: var(--text2); display: block; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.nav-section { font-size: 10px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 1px; padding: 10px 8px 4px; }
.nav-link {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
    color: var(--text2); font-size: 13px; font-weight: 500; transition: all .2s; margin-bottom: 2px;
}
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: var(--blue); color: #fff; }
.nav-link i { width: 16px; text-align: center; }

.sidebar-logout {
    margin: 10px; padding: 10px 14px; border-radius: 8px; display: flex; align-items: center;
    gap: 10px; color: var(--red); font-size: 13px; font-weight: 600;
    border: 1px solid rgba(239,68,68,.3); transition: background .2s;
}
.sidebar-logout:hover { background: rgba(239,68,68,.1); color: var(--red); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
    background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 20px;
    height: 60px; display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.menu-btn { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 6px; border-radius: 6px; display: none; }
.menu-btn:hover { background: var(--bg3); color: var(--text); }
.page-title h1 { font-size: 16px; font-weight: 700; }
.page-title span { font-size: 11px; color: var(--text2); display: block; }
.clock { font-size: 13px; color: var(--text2); font-family: monospace; }

/* ── Page Head ─────────────────────────────────────────────────── */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.page-head h2 { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.page-head h2 i { color: var(--blue); }
.btn-group { display: flex; gap: 8px; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px; }
.card-body.p0 { padding: 0; }
.card-search { padding: 14px 16px; border-bottom: 1px solid var(--border); }

/* ── Stats ─────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stats-row.mini { grid-template-columns: repeat(2, 1fr); }
.stat-card {
    background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; display: flex; align-items: center; gap: 14px;
}
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.stat-card.blue .stat-icon  { background: rgba(59,130,246,.15); color: var(--blue); }
.stat-card.green .stat-icon { background: rgba(16,185,129,.15); color: var(--green); }
.stat-card.orange .stat-icon{ background: rgba(245,158,11,.15);  color: var(--orange); }
.stat-card.purple .stat-icon{ background: rgba(139,92,246,.15);  color: var(--purple); }
.stat-val { font-size: 20px; font-weight: 700; }
.stat-lbl { font-size: 11px; color: var(--text2); margin-top: 2px; }

/* ── Grid ─────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── Table ─────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: right; padding: 11px 14px; font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); background: var(--bg3); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,.02); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-warn td { background: rgba(245,158,11,.05) !important; }
.empty { text-align: center; color: var(--text2); padding: 30px !important; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 13px;
    transition: all .2s; white-space: nowrap;
}
.btn-primary  { background: var(--blue);   color: #fff; }
.btn-primary:hover  { background: var(--blue2); }
.btn-secondary{ background: var(--bg3);    color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover{ background: var(--border); }
.btn-warning  { background: rgba(245,158,11,.15); color: var(--orange); border: 1px solid rgba(245,158,11,.3); }
.btn-warning:hover  { background: rgba(245,158,11,.25); }
.btn-danger   { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover   { background: rgba(239,68,68,.25); }
.btn-ghost    { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--bg3); color: var(--text); }
.btn-sm  { padding: 5px 10px; font-size: 12px; }
.btn-lg  { padding: 13px 20px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-success { background: rgba(16,185,129,.15); color: var(--green); }
.badge-danger  { background: rgba(239,68,68,.15);  color: var(--red); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--orange); }
.badge-blue    { background: rgba(59,130,246,.15); color: var(--blue); }
.badge-purple  { background: rgba(139,92,246,.15); color: var(--purple); }

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-success { background: rgba(16,185,129,.15); color: var(--green); border: 1px solid rgba(16,185,129,.3); }
.alert-error   { background: rgba(239,68,68,.15);  color: var(--red);   border: 1px solid rgba(239,68,68,.3); }
.alert-close   { margin-right: auto; background: none; border: none; cursor: pointer; color: inherit; font-size: 14px; padding: 2px; }

/* ── Forms ─────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.field input, .field select, .field textarea {
    width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
    padding: 9px 12px; color: var(--text); transition: border .2s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--blue); }
.field-icon { position: relative; }
.field-icon i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text2); pointer-events: none; }
.field-icon input { padding-right: 36px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-check label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text); text-transform: none; letter-spacing: 0; }
.field-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--blue); }

/* ── Search bar ─────────────────────────────────────────────────── */
.search-box { display: flex; align-items: center; gap: 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.search-box i { color: var(--text2); }
.search-box input { flex: 1; background: none; border: none; color: var(--text); outline: none; }

/* ── Filter bar ─────────────────────────────────────────────────── */
.filter-bar { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; }
.filter-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.filter-row .field { margin-bottom: 0; min-width: 160px; }
.filter-bar select, .filter-bar input[type=date], .filter-bar input[type=text] {
    background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 10px; color: var(--text); width: 100%;
}

/* ── Login ─────────────────────────────────────────────────────── */
.page-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-wrap { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 36px; box-shadow: var(--shadow); }
.login-header { text-align: center; margin-bottom: 28px; }
.login-icon { width: 56px; height: 56px; background: var(--blue); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: #fff; margin: 0 auto 12px; }
.login-header h1 { font-size: 22px; font-weight: 800; }
.login-header p { color: var(--text2); font-size: 13px; margin-top: 4px; }
.login-hint { text-align: center; margin-top: 16px; font-size: 11px; color: var(--text2); background: var(--bg3); padding: 6px; border-radius: 6px; }
.login-card .field input { padding: 11px 12px; padding-right: 38px; }

/* ── POS ─────────────────────────────────────────────────────── */
.pos-wrap { display: grid; grid-template-columns: 1fr 380px; gap: 20px; height: calc(100vh - 120px); }
.pos-search-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.pos-search-panel h3 { font-size: 15px; font-weight: 700; }
.pos-branch { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pos-branch select { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; color: var(--text); }
.pos-input-wrap { position: relative; }
.pos-input-wrap input { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 38px 10px 12px; color: var(--text); font-size: 14px; }
.pos-input-wrap input:focus { outline: none; border-color: var(--blue); }
.pos-input-wrap i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text2); }
.pos-results { flex: 1; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.result-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s; }
.result-item:last-child { border-bottom: none; }
.result-item:hover { background: var(--bg3); }
.ri-name  { font-weight: 600; font-size: 13px; }
.ri-meta  { display: flex; gap: 12px; margin-top: 4px; }
.ri-price { color: var(--green); font-weight: 700; font-size: 13px; }
.ri-stock { color: var(--text2); font-size: 12px; }
.ri-stock.out { color: var(--red); }
.no-res   { padding: 20px; text-align: center; color: var(--text2); }

.pos-cart-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.cart-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cart-top h3 { font-size: 14px; font-weight: 700; }
.cart-list { flex: 1; overflow-y: auto; padding: 8px; }
.cart-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text2); gap: 8px; }
.cart-empty i { font-size: 32px; opacity: .3; }
.cart-item { background: var(--bg3); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.ci-name { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.ci-controls { display: flex; align-items: center; gap: 8px; }
.qty-btn { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; }
.qty-btn:hover { background: var(--blue); border-color: var(--blue); color: #fff; }
.ci-price { margin-right: auto; font-weight: 700; color: var(--green); font-size: 13px; }
.del-btn  { background: none; border: none; color: var(--red); cursor: pointer; font-size: 13px; padding: 4px; opacity: .6; }
.del-btn:hover { opacity: 1; }

.cart-summary { padding: 12px 16px; border-top: 1px solid var(--border); }
.summary-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.summary-row.total { font-size: 16px; font-weight: 800; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; }
.summary-row.change { color: var(--green); font-weight: 700; }
.summary-row input { width: 110px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; color: var(--text); text-align: left; }
#checkoutBtn { margin: 12px 16px 16px; width: calc(100% - 32px); }

/* ── Invoice detail ─────────────────────────────────────────────── */
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px; border-bottom: 1px solid var(--border); }
.inv-logo { font-size: 20px; font-weight: 800; }
.inv-meta p { font-size: 13px; margin-bottom: 4px; }
.inv-totals { padding: 16px 20px; border-top: 1px solid var(--border); max-width: 300px; margin-right: auto; }
.inv-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.inv-row.bold { font-weight: 800; font-size: 16px; border-top: 1px solid var(--border); padding-top: 8px; }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 999; display: flex; align-items: center; justify-content: center; }
.modal-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); max-width: 480px; width: 95%; max-height: 90vh; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; justify-content: center; padding: 16px; border-top: 1px solid var(--border); }

/* ── Rank badges ─────────────────────────────────────────────────── */
.rank { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; font-size: 12px; font-weight: 800; }
.rank-1 { background: #f59e0b; color: #000; }
.rank-2 { background: #94a3b8; color: #000; }
.rank-3 { background: #b45309; color: #fff; }

/* ── Utilities ─────────────────────────────────────────────────── */
.text-danger  { color: var(--red) !important; }
.text-warning { color: var(--orange) !important; }
.text-success { color: var(--green) !important; }
.mt-4 { margin-top: 16px; }

/* ── Print ─────────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .page-head .btn-group, .modal-actions { display: none !important; }
    .main { margin-right: 0; }
    body { background: #fff; color: #000; }
    .card { border: 1px solid #ccc; box-shadow: none; }
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .grid-2    { grid-template-columns: 1fr; }
    .pos-wrap  { grid-template-columns: 1fr; grid-template-rows: auto 500px; height: auto; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .sidebar-overlay.show { display: block; }
    .main { margin-right: 0; }
    .menu-btn { display: flex; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .field-row { grid-template-columns: 1fr; }
    .filter-row { flex-direction: column; }
    .content { padding: 14px; }
}
