/* ===== المتغيرات ===== */
:root {
  --bg: #eef1f7;
  --surface: #ffffff;
  --text: #1e2939;
  --muted: #6b7689;
  --border: #e3e8f0;
  --border-strong: #cfd7e3;
  --primary: #1a73e8;
  --primary-dark: #1559b8;
  --primary-soft: #eaf2fe;
  --success: #15a34a;
  --success-dark: #11803b;
  --danger: #dc2626;
  --warn-bg: #fef6e0;
  --warn-text: #92590e;
  --star: #f5a524;
  --shadow-sm: 0 1px 2px rgba(16,30,54,.06);
  --shadow: 0 2px 8px rgba(16,30,54,.08);
  --shadow-lg: 0 18px 40px rgba(16,30,54,.14);
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { width: 100%; max-width: 1140px; margin-inline: auto; padding-inline: 16px; }
.muted { color: var(--muted); font-weight: 400; }

/* ===== الأيقونات ===== */
.ico { width: 20px; height: 20px; flex: 0 0 auto; vertical-align: -4px; }
.ico-sm { width: 16px; height: 16px; vertical-align: -3px; }
.ico-xs { width: 13px; height: 13px; vertical-align: -2px; }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 11px 18px; font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .15s, box-shadow .15s, transform .05s, border-color .15s;
  background: #eef2f7; color: var(--text); text-decoration: none; line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(26,115,232,.28); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 4px 12px rgba(21,163,74,.25); }
.btn-success:hover { background: var(--success-dark); }
.btn-ghost { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: #f3f6fb; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 13px; font-size: 14px; }
.btn-lg { padding: 15px 34px; font-size: 17px; }

/* ===== الشريط العلوي ===== */
.topbar {
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding-block: 13px; gap: 12px; }
.brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 9px; }
.brand .ico { color: var(--primary); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* عدّاد الرصيد */
.credit-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-soft); color: var(--primary-dark);
  border: 1px solid #cfe1fd; border-radius: var(--radius-pill);
  padding: 6px 13px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.credit-badge.low { background: var(--warn-bg); color: var(--warn-text); border-color: #f5e2b0; }
.credit-badge.empty { background: #fde8e8; color: var(--danger); border-color: #f6c6c6; }
/* الشارة زر قابل للنقر لتحديث الرصيد */
button.credit-badge { font-family: inherit; cursor: pointer; }
button.credit-badge:hover { filter: brightness(.97); }
.credit-badge.loading { opacity: .6; cursor: progress; }

/* ===== تسجيل الدخول ===== */
.auth-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 500px at 80% -10%, #6f9eff33, transparent),
              linear-gradient(135deg, #1a73e8 0%, #5b3fc4 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface); width: 100%; max-width: 410px;
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 36px 30px; text-align: center;
}
.auth-logo { font-size: 46px; }
.auth-card h1 { margin: 8px 0 4px; font-size: 25px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.auth-card form { text-align: start; }
.auth-card label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.auth-card input {
  width: 100%; padding: 12px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-size: 15px; font-family: inherit;
}
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.auth-card button { margin-top: 24px; }
.auth-note { font-size: 12px; color: var(--muted); margin-top: 18px; }
.auth-note code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 8px; }
.alert-error { background: #fde8e8; color: var(--danger); }

/* ===== صفحة الهبوط ===== */
.hero { text-align: center; padding-block: 60px 36px; }
.hero h1 { font-size: clamp(25px, 5vw, 42px); margin: 0 0 16px; line-height: 1.3; }
.hero-sub { font-size: clamp(15px, 2.5vw, 19px); color: var(--muted); max-width: 700px; margin: 0 auto 30px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; padding-block: 20px 64px; }
.feature-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px 22px; box-shadow: var(--shadow); text-align: center;
  transition: transform .15s, box-shadow .15s;
}
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.feature-icon {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary);
}
.feature-icon .ico { width: 28px; height: 28px; }
.feature-card h2 { font-size: 18px; margin: 6px 0; }
.feature-card p { color: var(--muted); font-size: 14px; margin: 0; }
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding-block: 22px; text-align: center; color: var(--muted); font-size: 14px; }

/* ===== لوحة التطبيق ===== */
.app { padding-block: 26px 64px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px;
}
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 18px; margin: 0 0 18px; }
.panel-title .ico { color: var(--primary); }
.panel-title.sm { font-size: 15px; margin-bottom: 14px; color: var(--muted); }
.panel-title.sm .ico { color: var(--muted); }

.field { display: flex; flex-direction: column; min-width: 0; }
.field label { font-size: 14px; font-weight: 600; margin-bottom: 7px; display: flex; align-items: center; gap: 6px; }
.field label .ico { color: var(--muted); }
.field input[type="text"], .field select {
  padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; background: #fff; width: 100%; color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field-action { justify-content: flex-end; }

.search-form {
  display: grid; gap: 16px;
  grid-template-columns: 1fr 1fr 1fr auto;
  align-items: end;
}
.search-form .field-wide { grid-column: 1 / -1; }

/* ===== القائمة المتعددة ===== */
.multiselect { position: relative; }
.ms-control {
  min-height: 46px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 6px 12px; background: #fff; cursor: pointer;
}
.ms-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ms-placeholder { color: var(--muted); font-size: 15px; }
.ms-caret { color: var(--muted); margin-inline-start: auto; transition: transform .15s; }
.ms-control[aria-expanded="true"] .ms-caret { transform: rotate(180deg); }
.ms-chips { display: contents; }
.ms-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--primary-soft); color: var(--primary-dark);
  border: 1px solid #cfe1fd; border-radius: var(--radius-pill);
  padding: 4px 6px 4px 11px; font-size: 13px; font-weight: 600;
}
.ms-chip-x {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: #cfe1fd; color: var(--primary-dark);
  width: 18px; height: 18px; border-radius: 50%; cursor: pointer; padding: 0;
}
.ms-chip-x:hover { background: var(--primary); color: #fff; }
.ms-dropdown {
  position: absolute; top: calc(100% + 6px); inset-inline: 0; z-index: 60;
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 8px; max-height: 320px; display: flex; flex-direction: column;
}
.ms-dropdown[hidden] { display: none; }
.ms-search-wrap {
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px;
}
.ms-search-wrap .ico { color: var(--muted); }
.ms-search-wrap input { flex: 1; border: none; outline: none; padding: 9px 0; font-family: inherit; font-size: 14px; background: transparent; }
.ms-options { overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.ms-option {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 7px; cursor: pointer; font-size: 14px;
}
.ms-option:hover { background: var(--primary-soft); }
.ms-option input { width: 17px; height: 17px; accent-color: var(--primary); }

/* ===== شريط الأدوات ===== */
.toolbar-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.toolbar-row .field { min-width: 140px; flex: 0 1 auto; }
.checkbox-field { justify-content: center; }
.switch-label { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; font-size: 14px; }
.switch-label input { width: 18px; height: 18px; accent-color: var(--primary); }
.result-meta {
  display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border); font-size: 14px; color: var(--muted);
}
.result-meta strong { color: var(--text); font-size: 16px; }

/* ===== الحالة ===== */
.status { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 14px; font-weight: 500; }
.status.loading { background: var(--primary-soft); color: var(--primary-dark); }
.status.error { background: #fde8e8; color: var(--danger); }
.status.warn { background: var(--warn-bg); color: var(--warn-text); }

/* ===== جدول النتائج ===== */
.results { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.results-table { width: 100%; border-collapse: collapse; }
.results-table th, .results-table td { padding: 13px 16px; text-align: start; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.results-table thead th { background: #f6f8fc; font-weight: 700; color: var(--muted); font-size: 13px; }
.results-table tbody tr { transition: background .12s; }
.results-table tbody tr:hover { background: #f8fafd; }
.results-table tbody tr:last-child td { border-bottom: none; }
.cell-name { font-weight: 600; }
.cell-cat { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rating { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.rating .star { color: var(--star); }
.cell-link { display: inline-flex; align-items: center; gap: 5px; color: var(--primary); font-weight: 500; }

/* ===== التجاوب ===== */
@media (max-width: 880px) {
  .search-form { grid-template-columns: 1fr 1fr; }
  .search-form .field-action { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .search-form { grid-template-columns: 1fr; }
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .toolbar-row .field { min-width: 0; width: 100%; }
  .ms-options { grid-template-columns: 1fr; }
  .brand { font-size: 16px; }
  .credit-badge { padding: 6px 10px; }

  .results-table thead { display: none; }
  .results-table, .results-table tbody, .results-table tr, .results-table td { display: block; width: 100%; }
  .results-table tr { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 12px; padding: 4px 0; box-shadow: var(--shadow-sm); }
  .results-table td { border: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; }
  .results-table td::before { content: attr(data-label); font-weight: 700; color: var(--muted); flex: 0 0 auto; font-size: 13px; }
  .results-table td .cell-name, .results-table td .cell-cat { text-align: end; }
}
