/* ===== تصميم تطبيق معمل الماهر ===== */

:root {
  --bg: #f6f3f1;
  --surface: #ffffff;
  --surface-2: #faf8f7;
  --ink: #221a18;
  --muted: #776a66;
  --line: #e8e1de;
  --line-strong: #d6ccc8;

  /* ألوان الهوية: أحمر شعار الماهر + فحمي */
  --brand: #A80F26;
  --brand-hover: #8A0C1F;
  --brand-soft: #FBEAEC;
  --brand-ink: #ffffff;
  --charcoal: #17110F;
  --logo-red: #C8102E;

  --ok: #3d7a37;
  --ok-soft: #e5f1e1;
  --warn: #9a6400;
  --warn-soft: #fbf0d6;
  --bad: #b3261e;
  --bad-soft: #fbe4e1;
  --info: #2b5c88;
  --info-soft: #e2edf7;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(23, 17, 15, .06), 0 2px 8px rgba(23, 17, 15, .05);
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", "DejaVu Sans", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .4rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h2 small, h1 small { font-weight: 400; color: var(--muted); font-size: .85rem; margin-inline-start: .35rem; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.txt-bad { color: var(--bad); font-weight: 600; }
.txt-ok { color: var(--ok); font-weight: 600; }
.txt-warn { color: var(--warn); font-weight: 600; }
.num, .t-num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ===== الشريط العلوي ===== */
.topbar {
  background: var(--charcoal);
  border-bottom: 3px solid var(--logo-red);
  color: var(--brand-ink);
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: .45rem 16px;
}
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { height: 44px; width: auto; display: block; }
.brand span { letter-spacing: .2px; }
.nav { display: flex; align-items: center; gap: .15rem; flex: 1; flex-wrap: wrap; }
.nav > a {
  color: rgba(255,255,255,.88); padding: .45rem .7rem; border-radius: 8px; font-size: .95rem; position: relative;
}
.nav > a:hover { background: rgba(255,255,255,.1); text-decoration: none; color: #fff; }
.nav > a.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.nav .dot { position: absolute; top: 6px; inset-inline-start: 4px; width: 8px; height: 8px; border-radius: 50%; background: #ffcf5c; }
.nav-user { margin-inline-start: auto; display: flex; align-items: center; gap: .2rem; }
.nav-user .who { color: #fff; font-size: .9rem; padding-inline-end: .4rem; }
.nav-user .who small { opacity: .75; }
.nav-user a { color: rgba(255,255,255,.8); padding: .4rem .55rem; border-radius: 8px; font-size: .88rem; }
.nav-user a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.menu-btn { display: none; margin-inline-start: auto; background: none; border: 0; padding: 8px; cursor: pointer; }
.menu-btn span { display: block; width: 22px; height: 2px; background: #fff; margin: 5px 0; border-radius: 2px; }

@media (max-width: 900px) {
  .menu-btn { display: block; }
  .nav {
    display: none; position: absolute; top: 100%; inset-inline: 0;
    background: var(--charcoal); flex-direction: column; align-items: stretch;
    padding: .5rem 16px 1rem; gap: .1rem; box-shadow: 0 8px 16px rgba(0,0,0,.15);
  }
  .nav.open { display: flex; }
  .nav > a { padding: .7rem .8rem; font-size: 1rem; }
  .nav-user { margin: .5rem 0 0; border-top: 1px solid rgba(255,255,255,.2); padding-top: .5rem; flex-wrap: wrap; }
  .nav-user .who { width: 100%; padding: .3rem .8rem; }
}

/* ===== الحاوية والبطاقات ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 18px 16px 48px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card.narrow { max-width: 520px; }
.card.empty { text-align: center; padding: 40px 18px; }
.card-accent { border-color: #e6c48c; background: #fffaf0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.sub { color: var(--muted); margin: .15rem 0 0; font-size: .92rem; }
.hint { color: var(--muted); font-size: .9rem; margin-top: .8rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 14px; align-items: center; }
form.inline { display: inline; margin: 0; }

.hero { text-align: center; padding: 28px 18px; }
.hero h2 { font-size: 1.3rem; display: flex; justify-content: center; align-items: center; gap: .5rem; flex-wrap: wrap; }
.hero .btn-lg { margin-top: .4rem; min-width: 220px; }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .55rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; line-height: 1.3; white-space: nowrap;
  min-height: 42px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--brand); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #326630; }
.btn-danger { color: var(--bad); border-color: #e7b9b4; }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); border-color: transparent; }
.btn-sm { padding: .3rem .65rem; min-height: 34px; font-size: .88rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.08rem; min-height: 50px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ===== الحقول ===== */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field small { color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); font: inherit; font-size: 16px; min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(168, 15, 38, .22); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: .5rem; margin-bottom: 10px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 150px; }
.filters .btn { margin-bottom: 0; }

.date-nav { display: flex; align-items: center; gap: .3rem; }
.date-nav input[type=date] { width: auto; min-width: 150px; }
.date-nav .btn { min-width: 42px; font-size: 1.15rem; padding: .3rem .6rem; }
.date-label { font-weight: 700; color: var(--brand); padding-inline-start: .3rem; }

/* ===== الرسائل ===== */
.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); color: #23531f; border-color: #c4dfbd; }
.alert-error { background: var(--bad-soft); color: #8a1d16; border-color: #f0c2bc; }
.alert-warn { background: var(--warn-soft); color: #6d4700; border-color: #ecd49b; }
.alert-info { background: var(--info-soft); color: #1f4466; border-color: #c3d7ea; }

/* ===== الشارات ===== */
.badge {
  display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap; vertical-align: middle;
}
.st-new { background: var(--info-soft); color: var(--info); }
.st-confirmed { background: var(--warn-soft); color: var(--warn); }
.st-shipped, .st-issued { background: #efe5f7; color: #6a3b8f; }
.st-received { background: var(--ok-soft); color: var(--ok); }
.st-cancelled { background: #eee; color: #777; text-decoration: line-through; }
.st-missing { background: var(--bad-soft); color: var(--bad); }
.st-return { background: var(--info-soft); color: var(--info); }
.st-damaged { background: var(--bad-soft); color: var(--bad); }

/* ===== الإحصائيات ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: .88rem; }
.stat strong { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat small { color: var(--muted); }

/* ===== لوحة الفروع ===== */
.branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.branch-tile {
  display: flex; flex-direction: column; gap: .35rem; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
}
.branch-tile:hover { border-color: var(--brand); text-decoration: none; }
.branch-tile.missing { border-style: dashed; border-color: #e3b5af; background: #fffafa; }
.branch-tile small { color: var(--muted); }

/* ===== القوائم ===== */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 10px 2px; border-bottom: 1px solid var(--line); color: var(--ink);
}
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); text-decoration: none; }
.list-row small { display: block; color: var(--muted); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.quick-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--ink); box-shadow: var(--shadow); }
.quick-item:hover { border-color: var(--brand); text-decoration: none; }
.quick-item small { display: block; color: var(--muted); }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
.table th { font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: #fdfbf7; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line-strong); background: var(--surface-2); }
.table .t-end { text-align: end; white-space: nowrap; }
.table .t-num { text-align: end; white-space: nowrap; }
.table .group td { background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .88rem; }
.table input[type=text] { min-height: 38px; padding: .35rem .5rem; }
.table tr.diff td { background: #fff8e8; }
input.missing { border-color: var(--bad) !important; background: #fff6f5; }
.table tr.off td { opacity: .55; }
.table.compact th, .table.compact td { padding: .35rem .45rem; }

/* ===== نموذج الطلب ===== */
.order-tools { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.order-tools input[type=search] { flex: 1; min-width: 180px; }
.qty-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.qty-row .name strong { display: block; }
.qty-row .name small { color: var(--muted); }
.qty-row.has { background: #fffaf2; }
.qty-row.unavailable { opacity: .5; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 40px; height: 42px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: #fff; font-size: 1.25rem; cursor: pointer; color: var(--brand); font-weight: 700; line-height: 1;
}
.stepper button:active { background: var(--brand-soft); }
.stepper input { width: 78px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper .unit { min-width: 42px; color: var(--muted); font-size: .85rem; text-align: center; }
.cat-title { margin: 16px 0 2px; color: var(--brand); font-size: .95rem; font-weight: 700; }
.sticky-bar {
  position: sticky; bottom: 0; z-index: 20; background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
  margin: 16px -18px -18px; padding: 12px 18px; border-radius: 0 0 var(--radius) var(--radius);
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  box-shadow: 0 -4px 12px rgba(60,35,10,.06);
}
.sticky-bar .summary { font-weight: 600; }
.sticky-bar .summary small { display: block; color: var(--muted); font-weight: 400; }

/* ===== الرسم البياني البسيط ===== */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 140px; gap: 10px; align-items: center; font-size: .9rem; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 18px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { background: var(--brand); height: 100%; border-radius: 6px; min-width: 2px; }
.bar-fill.alt { background: #5b4b47; }
.bar-row .v { text-align: end; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .bar-row { grid-template-columns: 90px 1fr 100px; font-size: .82rem; } }

/* ===== التبويبات ===== */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ===== الإشعارات ===== */
.toast {
  position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--ink); color: #fff; padding: .75rem 1.2rem; border-radius: 10px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 600; max-width: calc(100% - 32px); cursor: pointer;
}

/* ===== صفحة الدخول ===== */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-page .container { width: 100%; }
.login-box { max-width: 400px; margin: 0 auto; }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand .logo-tile { display: inline-flex; align-items: center; justify-content: center; width: 112px; height: 132px; border-radius: 22px; background: var(--charcoal); box-shadow: 0 6px 20px rgba(23,17,15,.25); border-bottom: 4px solid var(--logo-red); }
.login-brand .logo-tile img { height: 96px; width: auto; }
.login-brand h1 { margin-top: .6rem; }
.login-brand p { color: var(--muted); }

/* ===== الفاتورة وأوراق الطباعة ===== */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; max-width: 860px; margin: 0 auto 16px; box-shadow: var(--shadow); }
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 14px; }
.doc-head h1 { font-size: 1.4rem; margin: 0; }
.doc-head .co small { display: block; color: var(--muted); }
.doc-head { align-items: center; }
.doc-brand { display: flex; align-items: center; gap: 14px; }
.doc-brand img { height: 78px; width: auto; }
.doc-head h1 { color: var(--charcoal); }
.doc-manager { margin-top: 4px; font-size: .92rem; }
.doc-manager b { color: var(--brand); }
.thermal .doc-brand { flex-direction: column; gap: 4px; }
.thermal .doc-brand img { height: 54px; }
@media print { .doc-brand img { print-color-adjust: exact; -webkit-print-color-adjust: exact; } }
.doc-title { text-align: center; font-size: 1.15rem; font-weight: 700; margin: 0 0 12px; letter-spacing: .3px; }
.doc-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 24px; margin-bottom: 14px; font-size: .95rem; }
.doc-meta div { display: flex; gap: .4rem; }
.doc-meta b { min-width: 90px; color: var(--muted); font-weight: 600; }
.doc .table th { background: #f3eee6; color: var(--ink); }
.doc-total { display: flex; justify-content: flex-end; margin-top: 10px; }
.doc-total table td { padding: .3rem .8rem; }
.doc-total .grand td { font-size: 1.15rem; font-weight: 800; border-top: 2px solid var(--ink); }
.doc-words { margin-top: 6px; color: var(--muted); font-size: .9rem; }
.doc-foot { margin-top: 26px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; text-align: center; }
.doc-foot .sig { border-top: 1px dashed var(--line-strong); padding-top: 6px; color: var(--muted); font-size: .9rem; min-height: 60px; }
.doc-note { margin-top: 18px; font-size: .88rem; color: var(--muted); text-align: center; }
.stamp { display: inline-block; border: 2px solid currentColor; padding: .15rem .7rem; border-radius: 6px; font-weight: 800; transform: rotate(-4deg); }
.stamp.ok { color: var(--ok); }
.stamp.bad { color: var(--bad); }

/* فاتورة الطابعة الحرارية 80مم */
.thermal .doc { max-width: 76mm; padding: 4mm 2mm; border: 0; box-shadow: none; font-size: 12px; }
.thermal .doc-head { flex-direction: column; align-items: center; text-align: center; border-bottom: 1px dashed #000; }
.thermal .doc-head h1 { font-size: 15px; }
.thermal .doc-meta { grid-template-columns: 1fr; font-size: 12px; }
.thermal .doc-meta b { min-width: 60px; }
.thermal .table { font-size: 11.5px; }
.thermal .table th, .thermal .table td { padding: 2px 3px; }
.thermal .doc-foot { grid-template-columns: 1fr 1fr; }
.thermal .col-wide { display: none; }

.print-bar { display: flex; justify-content: center; gap: .5rem; flex-wrap: wrap; margin: 0 auto 16px; max-width: 860px; }
.sheet h1 { font-size: 1.3rem; }
.sheet .table { font-size: 1rem; }
.sheet .big td { font-size: 1.1rem; }
.matrix th, .matrix td { text-align: center !important; }
.matrix td:first-child, .matrix th:first-child { text-align: start !important; }
.checkbox-cell { width: 34px; }
.checkbox-cell::before { content: ""; display: inline-block; width: 16px; height: 16px; border: 1.5px solid #555; border-radius: 3px; }

pre.debug { text-align: start; direction: ltr; white-space: pre-wrap; background: #222; color: #eee; padding: 1rem; border-radius: 8px; font-size: 12px; }

/* ===== الطباعة ===== */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 12.5px; }
  .no-print, .topbar, .toast, .print-bar, .alert { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card, .doc { border: 0; box-shadow: none; padding: 0; margin: 0 0 10px; border-radius: 0; }
  .table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table tbody tr:hover { background: none; }
  .table-wrap { overflow: visible; }
  a { color: inherit; text-decoration: none; }
  .badge { border: 1px solid #999; background: none !important; color: #000 !important; }
  .page-break { page-break-after: always; }
  tr, .doc-foot { page-break-inside: avoid; }
  body.thermal { width: 80mm; }
}
@media print { body.thermal { margin: 0; } }
@page thermal { size: 80mm auto; margin: 0; }

/* ===== مراحل الطلبية ===== */
.steps { display: flex; gap: 4px; margin: 6px 0 12px; flex-wrap: wrap; justify-content: center; }
.step {
  flex: 1 1 120px; text-align: center; padding: .4rem .5rem; border-radius: 8px; font-size: .85rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.step.done { background: var(--ok-soft); color: var(--ok); border-color: #c4dfbd; }
.step.current { background: var(--brand); color: #fff; border-color: var(--brand); }
.step.bad { background: var(--bad-soft); color: var(--bad); border-color: #f0c2bc; }
.holiday-chips { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; }
.receipt-notes { margin-top: 14px; padding: 10px 14px; border: 1.5px solid #e6b2ab; background: #fff6f5; border-radius: 8px; }
.receipt-notes ul { margin: 6px 0 0; padding-inline-start: 20px; }
.receipt-notes li { margin: 2px 0; }
