/* تصميم عصري RTL — بلا مكتبات خارجية */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
}

body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}

a { color: var(--primary); text-decoration: none; }

/* هيكل الصفحة */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px; background: #0b3d3a; color: #d1e7e5;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #14b8a6, #0f766e);
  display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 800; color: #fff;
}
.brand-name { font-weight: 700; font-size: 16px; color: #fff; }
.sidebar nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  color: #b8d4d1; font-weight: 500; transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 4px 10px rgba(15,118,110,.35); }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: #14b8a6; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.user-name { color: #fff; font-size: 14px; font-weight: 600; }
.user-out { color: #8fc7c2; font-size: 12.5px; }
.user-out:hover { color: #fff; }

.main { flex: 1; padding: 26px 30px; max-width: 1200px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 800; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* بطاقات */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; border: 1px solid var(--border); }
.card h2 { font-size: 16px; margin-bottom: 14px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--border); border-inline-start: 4px solid var(--primary);
}
.stat .num { font-size: 24px; font-weight: 800; margin-top: 4px; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.teal { border-inline-start-color: var(--primary); }
.stat.blue { border-inline-start-color: #2563eb; }
.stat.amber { border-inline-start-color: var(--warn); }
.stat.red { border-inline-start-color: var(--danger); }
.stat.green { border-inline-start-color: var(--ok); }

/* جداول */
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: right; padding: 11px 12px; background: #f8fafc; color: var(--muted);
  font-size: 12.5px; font-weight: 700; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tr:hover td { background: #fafcfd; }
.tbl .actions { white-space: nowrap; display: flex; gap: 6px; }
.tbl-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.gray { background: #e2e8f0; color: #334155; }

/* أزرار */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 18px; border-radius: 10px;
  border: none; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600;
  background: var(--primary); color: #fff; transition: all .15s; text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f8fafc; }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.danger:hover { background: #fecaca; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; justify-content: center; }

/* نماذج */
label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 6px; }
input[type=text], input[type=number], input[type=password], input[type=email], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px; background: #fff; color: var(--text); transition: border .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-row { margin-bottom: 14px; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

/* رسائل */
.flash { padding: 12px 18px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.flash-ok { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* مودال */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: none;
  align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px; overflow-y: auto;
}
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 640px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { font-size: 17px; margin-bottom: 18px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; margin-top: 20px; }

/* صفحة الدخول */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, #0b3d3a 0%, #0f766e 55%, #14b8a6 100%); }
.login-card { background: #fff; border-radius: 20px; padding: 36px 32px; width: 100%; max-width: 420px; box-shadow: 0 25px 70px rgba(0,0,0,.3); }
.login-logo {
  width: 62px; height: 62px; border-radius: 18px; background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; margin: 0 auto 14px;
}
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.login-hint { background: #f0fdfa; border: 1px dashed #5eead4; color: #115e59; padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; text-align: center; }

/* مفتاح API */
.api-key-box {
  display: flex; align-items: center; gap: 10px; background: #0f172a; color: #a5f3fc;
  padding: 12px 16px; border-radius: 10px; font-family: monospace; font-size: 14px; direction: ltr; text-align: left;
  word-break: break-all;
}
.api-doc { font-size: 13.5px; }
.api-doc code { background: #f1f5f9; padding: 2px 8px; border-radius: 6px; font-size: 12.5px; direction: ltr; display: inline-block; }
.api-doc pre {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px; overflow-x: auto;
  direction: ltr; text-align: left; font-size: 12.5px; line-height: 1.8; margin: 10px 0;
}
.endpoint { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.method { padding: 2px 9px; border-radius: 6px; font-size: 11.5px; font-weight: 800; direction: ltr; font-family: monospace; }
.method.GET { background: #dbeafe; color: #1d4ed8; }
.method.POST { background: #d1fae5; color: #047857; }
.method.PUT { background: #fef3c7; color: #92400e; }
.method.DELETE { background: #fee2e2; color: #b91c1c; }

/* فاتورة للطباعة */
.invoice-print { background: #fff; max-width: 800px; margin: 0 auto; padding: 34px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.inv-head { display: flex; justify-content: space-between; border-bottom: 3px solid var(--primary); padding-bottom: 16px; margin-bottom: 20px; gap: 20px; flex-wrap: wrap; }
.inv-head h2 { font-size: 20px; }
.inv-meta { font-size: 13.5px; color: var(--muted); }
.inv-total-row { font-size: 17px; font-weight: 800; }
@media print {
  .sidebar, .page-head, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: 100%; }
  .invoice-print { box-shadow: none; border: none; }
}

/* استجابة الشاشات الصغيرة */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar nav { flex-direction: row; padding: 8px; }
  .sidebar-foot { display: none; }
  .brand { padding: 12px 16px; border: none; }
  .brand-name { display: none; }
  .nav-item span { display: none; }
  .main { padding: 18px 14px; }
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar input { max-width: 300px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 8px 18px; border-radius: 999px; background: #fff; border: 1px solid var(--border); font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
/* ===== إضافات الإصدار 2.0 ===== */

/* شبكة الكاشير */
.pos-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .pos-grid { grid-template-columns: 1fr; } }

.pos-results {
  border: 1.5px solid var(--border); border-radius: 10px; margin-top: 6px;
  max-height: 260px; overflow-y: auto; background: #fff; box-shadow: var(--shadow);
  position: relative; z-index: 20;
}
.pos-result {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.pos-result:hover { background: #f0fdfa; }
.pos-result:last-child { border-bottom: none; }
.pos-price { font-weight: 800; color: var(--primary); white-space: nowrap; }

.pos-today-num { font-size: 30px; font-weight: 800; color: var(--primary); margin: 4px 0; }

/* الوصل (80mm) */
.receipt-wrap { display: flex; flex-direction: column; align-items: center; }
.receipt {
  width: 320px; background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px;
  font-family: "Segoe UI", Tahoma, monospace;
}
@media print {
  .sidebar, .page-head, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .receipt { border: none; box-shadow: none; width: 300px; }
}

/* تاريخ التقرير */
.report-filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.report-filters .field { display: flex; flex-direction: column; gap: 4px; }
.report-filters label { margin: 0; }
.preset { font-size: 12px; padding: 5px 12px; }

.report-total-row { font-weight: 800; background: #f0fdfa; }
.report-total-row td { border-top: 2px solid var(--primary); }

/* تابات الإعدادات الداخلية */
.setting-section-title { font-size: 15px; margin: 18px 0 8px; color: var(--primary-dark); }

.badge.blue { background: #dbeafe; color: #1d4ed8; }
.badge.purple { background: #ede9fe; color: #6d28d9; }

/* ===== أشكال الفواتير (v3) ===== */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 12px; }
.tpl-card input { display: none; }
.tpl-body { display: flex; flex-direction: column; gap: 7px; border: 2px solid var(--border); border-radius: 12px; padding: 10px; cursor: pointer; background: #fff; height: 100%; transition: border-color .15s, box-shadow .15s; }
.tpl-card input:checked + .tpl-body { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.14); }
.tpl-body b { font-size: 13.5px; }
.tpl-body small { color: var(--muted); font-size: 11.5px; line-height: 1.65; min-height: 38px; }
.tpv { display: block; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; height: 96px; }
.tpv u, .tpv i { text-decoration: none; font-style: normal; }
.tpv-open { font-size: 11.5px; font-weight: 700; color: var(--primary); text-decoration: none; }
.color-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.color-item { display: flex; align-items: center; gap: 8px; background: #f8fafc; border: 1px solid var(--border); padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.color-item input[type=color] { width: 44px; height: 32px; border: none; background: none; cursor: pointer; padding: 0; }
.swatch-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 34px; height: 34px; border-radius: 10px; cursor: pointer; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); padding: 0; }
.logo-preview { width: 110px; height: 110px; border: 1.5px dashed var(--border); border-radius: 14px; display: flex; align-items: center; justify-content: center; background: #f8fafc; overflow: hidden; flex-shrink: 0; }
.logo-preview img { max-width: 100px; max-height: 100px; object-fit: contain; }

/* ===== شريط أدوات الطباعة ===== */
.print-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); }
.pb-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pb-left { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pb-btn { border: none; cursor: pointer; border-radius: 9px; padding: 9px 16px; font-family: inherit; font-size: 13px; font-weight: 700; text-decoration: none; display: inline-block; }
.pb-primary { background: #0f172a; color: #fff; }
.pb-ghost { background: #f1f5f9; color: #0f172a; }
.pb-sel { padding: 8px 12px; border-radius: 9px; border: 1px solid var(--border); font-family: inherit; font-size: 13px; background: #fff; }
.pb-label { font-size: 12.5px; font-weight: 700; color: #475569; }
.pb-hint { font-size: 11.5px; color: #94a3b8; }
.pb-note { font-size: 11px; background: #fef3c7; color: #92400e; padding: 4px 10px; border-radius: 8px; font-weight: 700; }
