/* خط Cairo محفوظ داخل التطبيق (يعمل بدون إنترنت ولا يعتمد على Google). رخصة SIL OFL 1.1 */
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(fonts/cairo-arabic.woff2) format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(fonts/cairo-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* ألوان العلامة: أداة tools/new-client.js تستبدل هذه الأربعة بلون الزبون */
  --teal-900: #094944;
  --teal-700: #0f766e;
  --teal-600: #338b84;
  --teal-100: #e7f1f1;
  --amber: #b45309;
  --amber-bg: #fef3e0;
  --red: #b91c1c;
  --red-bg: #fde8e8;
  --green: #15803d;
  --green-bg: #e7f7ec;
  --gray-50: #f4f6f6;
  --gray-100: #eaeeee;
  --gray-300: #d3d9d9;
  --gray-500: #6b7776;
  --gray-700: #374241;
  --gray-900: #182120;
  --white: #ffffff;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 14px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, 0.12);
  --ring: 0 0 0 4px color-mix(in srgb, var(--teal-600) 18%, transparent);
  --brand-gradient: linear-gradient(135deg, var(--teal-900), var(--teal-700));
  --nav-h: 68px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  direction: rtl;
  font-family: 'Cairo', 'Segoe UI', Tahoma, Roboto, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  padding: 14px 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)) 14px;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px;
}

b, strong { font-weight: 700; }

/* ===== شريط علوي ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand-gradient);
  color: var(--white);
  padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
  margin: -14px -14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 0 0 22px 22px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--teal-900) 25%, transparent);
}
.top-bar h1 {
  font-size: 19px;
  margin: 0;
  flex: 1;
  font-weight: 800;
  letter-spacing: 0;
}
.top-bar .back-btn,
.top-bar .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  color: var(--white);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s var(--ease);
}
.top-bar .back-btn { font-size: 20px; min-width: 40px; padding: 0 10px; }
.top-bar .icon-btn { font-size: 14.5px; padding: 0 14px; }
.top-bar .back-btn:active,
.top-bar .icon-btn:active { background: rgba(255, 255, 255, 0.28); transform: scale(0.95); }

/* ===== شريط تنقل سفلي ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--gray-100);
  display: flex;
  z-index: 30;
  box-shadow: 0 -4px 20px rgba(16, 24, 40, 0.06);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--gray-500);
  font-size: 12px;
  font-weight: 600;
  transition: color 0.15s;
}
.bottom-nav .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 30px;
  border-radius: 15px;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}
.bottom-nav .nav-icon svg { width: 23px; height: 23px; }
.bottom-nav a.active { color: var(--teal-700); font-weight: 800; }
.bottom-nav a.active .nav-icon { background: var(--teal-100); }
.bottom-nav a:active .nav-icon { transform: scale(0.9); }

/* أيقونات الخطوط (SVG) */
.ico {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ===== بطاقات ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-100);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-title {
  font-weight: 800;
  font-size: 15.5px;
  margin: 0 0 10px 0;
  color: var(--teal-900);
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
}
.card-row + .card-row { border-top: 1px dashed var(--gray-100); }

/* ===== عناصر قائمة ===== */
.list-item {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-100);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  display: block;
  transition: transform 0.12s var(--ease), box-shadow 0.15s, border-color 0.15s;
}
a.list-item:active { transform: scale(0.985); border-color: color-mix(in srgb, var(--teal-600) 35%, transparent); }
.list-item-title {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.list-item-sub {
  color: var(--gray-500);
  font-size: 13.5px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.list-item-meta {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== شارات ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.8;
}
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-teal { background: var(--teal-100); color: var(--teal-700); }
.badge-gray { background: var(--gray-100); color: var(--gray-700); }

/* ===== أزرار ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1.5px solid transparent;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
  width: 100%;
  min-height: 52px;
  text-align: center;
  user-select: none;
  transition: transform 0.12s var(--ease), box-shadow 0.15s, background 0.15s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary {
  background: linear-gradient(180deg, var(--teal-600), var(--teal-700));
  color: var(--white);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--teal-700) 30%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-primary:active { filter: brightness(0.94); }
.btn-secondary { background: var(--teal-100); color: var(--teal-700); }
.btn-secondary:active { background: color-mix(in srgb, var(--teal-100) 80%, var(--teal-600)); }
.btn-outline {
  background: var(--white);
  color: var(--teal-700);
  border-color: color-mix(in srgb, var(--teal-600) 45%, transparent);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}
.btn-outline:active { background: var(--teal-100); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:active { background: color-mix(in srgb, var(--red-bg) 85%, var(--red)); }
.btn-whatsapp {
  background: linear-gradient(180deg, #2bd46d, #1fb85a);
  color: var(--white);
  box-shadow: 0 4px 14px rgba(31, 184, 90, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.btn-sm { padding: 8px 14px; font-size: 14px; min-height: 40px; width: auto; border-radius: 12px; }
.btn-sm.btn-primary, .btn-sm.btn-whatsapp { box-shadow: 0 2px 8px color-mix(in srgb, var(--teal-700) 22%, transparent); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
  left: 18px;
  width: 60px;
  height: 60px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-700));
  color: var(--white);
  font-size: 28px;
  border: none;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--teal-700) 40%, transparent);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s var(--ease);
}
.fab:active { transform: scale(0.92); }

/* ===== نماذج ===== */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--gray-700);
}
.field input[type="text"],
.field input[type="number"],
.field input[type="tel"],
.field input[type="email"],
.field input[type="password"],
.field input[type="date"],
.field input[type="file"],
.field select,
.field textarea,
.search-box,
.qty-stepper input {
  border: 1.5px solid var(--gray-300);
  background: var(--white);
  color: var(--gray-900);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="tel"],
.field input[type="email"],
.field input[type="password"],
.field input[type="date"],
.field input[type="file"],
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  min-height: 50px;
  border-radius: 14px;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.search-box:focus,
.qty-stepper input:focus {
  border-color: var(--teal-600);
  box-shadow: var(--ring);
}
.field input::placeholder, .field textarea::placeholder, .search-box::placeholder { color: #9aa5a4; }
.field textarea { min-height: 88px; resize: vertical; }
.field .hint { font-size: 12.5px; color: var(--gray-500); margin-top: 5px; }
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-chip {
  flex: 1;
  text-align: center;
  padding: 11px 8px;
  border-radius: 14px;
  border: 1.5px solid var(--gray-300);
  background: var(--white);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: var(--gray-700);
  min-width: 90px;
  transition: all 0.15s var(--ease);
}
.radio-chip:active { transform: scale(0.97); }
.radio-chip input { display: none; }
.radio-chip.checked {
  border-color: var(--teal-700);
  background: var(--teal-100);
  color: var(--teal-700);
  box-shadow: inset 0 0 0 1px var(--teal-700);
}

/* ===== أخرى ===== */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
  color: var(--gray-700);
  margin: 22px 0 10px 0;
}
.section-title::before {
  content: '';
  width: 4px;
  height: 18px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--teal-600), var(--teal-700));
  flex-shrink: 0;
}
.empty-state {
  text-align: center;
  color: var(--gray-500);
  padding: 40px 20px;
  font-size: 15px;
}
.search-box {
  width: 100%;
  padding: 12px 44px 12px 14px;
  min-height: 50px;
  border-radius: 14px;
  margin-bottom: 14px;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236b7776' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat right 14px center;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.divider { height: 1px; background: var(--gray-100); margin: 10px 0; }
.qty-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-stepper button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1.5px solid var(--gray-300);
  background: var(--white);
  color: var(--teal-700);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s var(--ease), background 0.15s;
}
.qty-stepper button:active { transform: scale(0.9); background: var(--teal-100); }
.qty-stepper input {
  width: 52px;
  text-align: center;
  padding: 7px 4px;
  border-radius: 12px;
}
.product-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}
.total-bar {
  position: sticky;
  bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom));
  background: var(--white);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--gray-100);
  box-shadow: var(--shadow-lg);
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

/* ===== تنبيهات ===== */
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  margin-bottom: 8px;
  border-inline-start: 4px solid transparent;
}
.alert-item.warn { background: var(--amber-bg); border-inline-start-color: var(--amber); }
.alert-item.danger { background: var(--red-bg); border-inline-start-color: var(--red); }
.alert-item.due { background: var(--green-bg); border-inline-start-color: var(--green); align-items: center; }
.alert-item.due .txt { color: inherit; }
.alert-item.due .btn { flex-shrink: 0; }
.alert-item .icon { font-size: 20px; }
.alert-item .txt { flex: 1; font-size: 14px; }
.alert-item .txt b { display: block; margin-bottom: 2px; }

/* ===== توست ===== */
#toast-host {
  position: fixed;
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  right: 0;
  left: 0;
  display: flex;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--gray-900);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: all 0.25s var(--ease);
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast-error { background: var(--red); }
.toast-success { background: var(--green); }

/* ===== الاشتراك: شاشة الانتهاء + شريط العدّ ===== */
.lock-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 48px 8px 24px;
}
.lock-screen .lock-icon {
  font-size: 44px;
  width: 92px;
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 28px;
  background: var(--teal-100);
  margin-bottom: 4px;
}
.lock-screen h1 { font-size: 23px; font-weight: 800; color: var(--teal-900); margin: 0; }
.lock-screen p { margin: 0; line-height: 1.9; }
.lock-screen .lock-note { color: var(--gray-500); font-size: 14px; margin-bottom: 8px; }
.btn-link {
  background: none;
  border: none;
  color: var(--gray-500);
  text-decoration: underline;
  text-underline-offset: 4px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
}
.license-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--amber-bg);
  border: 1px solid color-mix(in srgb, var(--amber) 22%, transparent);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}
.license-banner .txt { flex: 1; }
.license-banner .btn { flex-shrink: 0; }

/* ===== شاشة الدخول ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: -14px -14px 0;
  padding: 0 18px 24px;
}
.login-hero {
  background: var(--brand-gradient);
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  margin: 0 -18px -36px;
  padding: calc(48px + env(safe-area-inset-top)) 20px 64px;
  border-radius: 0 0 32px 32px;
  font-size: 15px;
}
.login-hero h1 { color: var(--white); font-size: 26px; font-weight: 800; margin: 14px 0 2px; }
.login-logo {
  width: 84px;
  height: 84px;
  border-radius: 24px;
  background: var(--white);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  border: 3px solid rgba(255, 255, 255, 0.85);
}
.login-card { position: relative; padding: 22px 18px 14px; box-shadow: var(--shadow-lg); }

/* ===== شبكة "المزيد" ===== */
.grid-menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-menu a {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-100);
  box-shadow: var(--shadow);
  padding: 18px 12px;
  text-align: center;
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--gray-900);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: transform 0.12s var(--ease);
}
.grid-menu a:active { transform: scale(0.97); }
.grid-menu .nav-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal-100);
  color: var(--teal-700);
  font-size: 26px;
}

.kv { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14.5px; }
.kv .k { color: var(--gray-500); }
.kv .v { font-weight: 700; }

@media (hover: hover) {
  .btn-primary:hover, .btn-whatsapp:hover { filter: brightness(1.05); }
  .btn-outline:hover, .btn-secondary:hover { filter: brightness(0.98); }
  a.list-item:hover, .grid-menu a:hover { border-color: color-mix(in srgb, var(--teal-600) 30%, transparent); }
}

@media (min-width: 600px) {
  #app { padding-bottom: calc(var(--nav-h) + 28px); }
}

/* ===== الفاتورة ===== */
.invoice-sheet {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  color: #111;
}
.invoice-header { text-align: center; }
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 12.5px;
}
.invoice-table th, .invoice-table td {
  border: 1px solid #ccc;
  padding: 6px 4px;
  text-align: center;
}
.invoice-table thead { background: var(--gray-100); }
.invoice-total-row td { font-weight: 700; background: #fafafa; }

@media print {
  .no-print, .bottom-nav, .fab { display: none !important; }
  body { background: #fff; }
  #app { max-width: 100%; padding: 0; margin: 0; }
  .invoice-sheet { box-shadow: none; border-radius: 0; padding: 0; }
  .top-bar { display: none; }
}
