:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --border: #262c37;
  --text: #e7eaf0;
  --muted: #8b94a7;
  --primary: #4f7cff;
  --primary-dark: #3a5fd9;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --blue: #38bdf8;
  --purple: #a855f7;
  --radius: 10px;
  font-family: 'Segoe UI', Tahoma, 'Noto Sans Arabic', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

a { color: inherit; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}
.brand { font-weight: 700; font-size: 18px; margin-bottom: 20px; padding: 0 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
}
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link.active { background: var(--primary); color: white; }
.sidebar-footer { margin-top: auto; padding: 0 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  padding: 12px 22px; border-bottom: 1px solid var(--border);
}
.app-view { padding: 22px; flex: 1; overflow-x: auto; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-card__label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-card__value { font-size: 24px; font-weight: 700; }
.stat-card__change { font-size: 12.5px; margin-top: 6px; }
.stat-card__change.up { color: var(--green); }
.stat-card__change.down { color: var(--red); }

.alert-pills { display: flex; flex-direction: column; gap: 8px; }
.alert-pill {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 8px 12px; border-radius: 8px; background: var(--panel-2); font-size: 14px;
}
.alert-pill b { margin-inline-start: auto; }
.alert-pill--red { border-inline-start: 3px solid var(--red); }
.alert-pill--orange { border-inline-start: 3px solid var(--orange); }
.alert-pill--blue { border-inline-start: 3px solid var(--blue); }
.alert-pill--purple { border-inline-start: 3px solid var(--purple); }
.alert-pill--green { border-inline-start: 3px solid var(--green); }

.insight-list { margin: 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 8px; }
.link { display: inline-block; margin-top: 10px; color: var(--primary); text-decoration: none; font-size: 13.5px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.table thead th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; }
.cell-title { font-weight: 600; }
.row-actions { display: flex; gap: 6px; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-orange { color: var(--orange); }

.shift-grid th, .shift-grid td { text-align: center; vertical-align: top; }
.shift-cell { min-width: 110px; }
.shift-pill { background: var(--panel-2); border-radius: 6px; padding: 4px 6px; font-size: 12px; margin-bottom: 4px; cursor: pointer; }
.shift-pill:hover { outline: 1px solid var(--primary); }
.shift-add-btn { width: 100%; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge--green { background: rgba(34,197,94,.15); color: var(--green); }
.badge--orange { background: rgba(245,158,11,.15); color: var(--orange); }
.badge--red { background: rgba(239,68,68,.15); color: var(--red); }
.badge--blue { background: rgba(56,189,248,.15); color: var(--blue); }
.badge--purple { background: rgba(168,85,247,.15); color: var(--purple); }
.badge--muted { background: var(--panel-2); color: var(--muted); }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.4); color: #ff8a8a; }
.btn-outline { background: transparent; }

.toolbar { margin-bottom: 14px; }
.input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; width: 100%;
}
.input-lg { padding: 14px; font-size: 16px; }
.input-sm { padding: 5px 8px; width: 70px; }
select.input { cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab-btn { background: transparent; border: none; color: var(--muted); padding: 10px 14px; cursor: pointer; font-weight: 600; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--text); border-color: var(--primary); }

.loading, .empty-state { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- POS ---------- */
.pos-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pos-layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .pos-layout { grid-template-columns: 1fr; } }
.pos-results { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; }
.pos-result { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; cursor: pointer; }
.pos-result:hover { outline: 1px solid var(--primary); }
/* Out-of-stock search result (see pos.js resultRowHTML) — still shown and clickable (clicking
   re-explains why via the same toast addToCart already shows), just visually dimmed so it reads
   as "found, but not sellable right now" instead of a normal in-stock row. */
.pos-result--disabled { opacity: .6; }
.product-thumb { object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.product-thumb--placeholder { display: flex; align-items: center; justify-content: center; background: var(--panel-2); border-radius: 8px; font-size: 18px; }
.product-image-upload { display: flex; align-items: center; gap: 12px; }
.product-image-upload .product-thumb, .product-image-upload .product-thumb--placeholder { width: 72px; height: 72px; font-size: 28px; }
.pos-cart { margin-bottom: 14px; }
.qty-stepper { display: flex; align-items: center; gap: 8px; }
.qty-stepper button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; }
.pos-summary { display: flex; flex-direction: column; gap: 12px; }
.pos-summary label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.pos-totals { background: var(--panel-2); border-radius: 8px; padding: 12px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.total-line { font-size: 18px; font-weight: 700; margin-top: 4px; }
.pos-payment { display: flex; gap: 8px; flex-wrap: wrap; }
.payment-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.pos-mode-toggle { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.mode-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.qty-input { width: 56px; text-align: center; }
.total-editable { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.input-total { width: 110px; font-size: 17px; font-weight: 700; padding: 6px 10px; }
.margin-warning { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 12px; }
.margin-warning--warn { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.4); color: #ffb84d; }
.margin-warning--danger { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.4); color: #ff8a8a; }

/* ---------- Reports ---------- */
.period-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.period-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.pos-final-actions { display: flex; gap: 10px; }
.pos-final-actions .btn-primary { flex: 1; }

/* ---------- Invoice ---------- */
.invoice-modal { max-width: 480px; }
.invoice h2 { text-align: center; }
.invoice-meta { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; margin-bottom: 12px; }
.invoice-totals { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.invoice-credit-block { background: var(--panel-2); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 13.5px; display: flex; flex-direction: column; gap: 3px; }

/* ---------- Credit sale (آجل) panel + signature pad — POS ---------- */
.signature-pad { display: block; width: 100%; max-width: 360px; height: 130px; border: 1px dashed var(--border); border-radius: 8px; background: #fff; cursor: crosshair; touch-action: none; }

/* ---------- Debt Center (مركز الديون) ---------- */
.debt-summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.debt-summary-card { text-align: center; }
.debt-summary-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.debt-customer-card { margin-bottom: 16px; }
.debt-customer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.debt-customer-totals { text-align: end; font-size: 14px; }

/* ---------- Assistant ---------- */
.assistant-questions { display: flex; flex-wrap: wrap; gap: 8px; }
.assistant-answer { margin-top: 16px; }
.assistant-text { white-space: pre-wrap; background: var(--panel-2); padding: 14px; border-radius: 8px; font-family: inherit; line-height: 1.8; }

/* ---------- Toasts ---------- */
#toast-host { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 8px; opacity: 0; transform: translateY(-8px);
  transition: all .25s ease; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--success { border-color: rgba(34,197,94,.5); }
.toast--error { border-color: rgba(239,68,68,.5); }
.toast--info { border-color: rgba(56,189,248,.5); }

/* ---------- Login (Phase 5C) ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 380px; text-align: center; }
.login-users { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-user-btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 14px; border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.login-user-btn:hover { border-color: var(--primary); }
.login-pin-display { font-size: 26px; letter-spacing: 8px; margin: 16px 0; }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pin-key { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 16px; border-radius: 10px; font-size: 18px; cursor: pointer; }
.pin-key:hover { border-color: var(--primary); }
.current-user-box { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }

/* ---------- Print ---------- */
@media print {
  body * { visibility: hidden; }
  #invoice-print-area, #invoice-print-area * { visibility: visible; }
  #invoice-print-area { position: absolute; top: 0; right: 0; width: 100%; }
  #labels-print-area.printing-now, #labels-print-area.printing-now * { visibility: visible; }
  #labels-print-area.printing-now { position: absolute; top: 0; left: 0; width: 100%; display: block !important; }
  .labels-print-page { page-break-inside: avoid; }
  .no-print { display: none !important; }
}
