:root {
  --bg: #0f1720;
  --surface: #182230;
  --surface-2: #1f2c3d;
  --line: #2a3a4f;
  --text: #e8eef5;
  --muted: #93a4b8;
  --brand: #ffc940;          /* للخلفيات والأزرار */
  --brand-ink: #ffc940;      /* للنصوص (قابل للقراءة حسب الثيم) */
  --green: #34d399;
  --red: #f87171;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --body-bg: radial-gradient(1200px 600px at 80% -10%, #1c2940, var(--bg));
  --header-bg: rgba(15,23,32,.72);
  --solar-bg: linear-gradient(135deg, #2a2410, var(--surface));
  --gate-bg: radial-gradient(900px 500px at 50% 0%, #1c2940, var(--bg));
}

/* ثيم فاتح */
html[data-theme="light"] {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #eef3f9;
  --line: #d6dee8;
  --text: #14202e;
  --muted: #5b6b7d;
  --brand-ink: #9a6a00;      /* أمبر غامق ليُقرأ ع الأبيض */
  --shadow: 0 8px 24px rgba(20,40,70,.10);
  --body-bg: radial-gradient(1200px 600px at 80% -10%, #dde7f3, var(--bg));
  --header-bg: rgba(255,255,255,.82);
  --solar-bg: linear-gradient(135deg, #fff6db, var(--surface));
  --gate-bg: radial-gradient(900px 500px at 50% 0%, #dde7f3, var(--bg));
}

* { box-sizing: border-box; }

/* خاصية hidden لازم تتغلّب على display تبع الكلاسات (auth-gate, btn-row, chart...) */
[hidden] { display: none !important; }

/* انتقال سلس عند تبديل الثيم */
body, .card, .site-header, .field input, .field select, .btn-secondary, .nav-links a {
  transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ظهور البطاقات */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.card { animation: rise .45s ease both; }
.btn-primary:active, .btn-secondary:active, .btn-solar:active, .admin-link:active { transform: scale(.97); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--body-bg);
  color: var(--text);
  line-height: 1.7;
}

.container { max-width: 820px; margin: 0 auto; padding: 0 18px; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.header-inner {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 10px 12px; padding: 12px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-inline-end: auto; }
.logo { font-size: 28px; }
.site-header h1 { margin: 0; font-size: 21px; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }
.header-icons { display: flex; align-items: center; gap: 8px; }
.tariff-badge {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 999px; font-size: 13px;
  color: var(--brand-ink); white-space: nowrap; font-weight: 600;
}

/* موبايل: brand + أزرار بصف، التنقّل بصف، البطاقة بصف */
@media (max-width: 720px) {
  .brand { margin-inline-end: 0; flex: 1 1 auto; min-width: 0; }
  .site-header h1 { font-size: 19px; }
  .logo { font-size: 24px; }
  .header-icons { order: 2; flex: 0 0 auto; }
  .nav-links { order: 3; flex: 1 1 100%; }
  .nav-links a { flex: 1; text-align: center; }
  .tariff-badge { order: 4; flex: 1 1 100%; text-align: center; }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin: 18px 0;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 19px; }
.intro p { margin: 0; color: var(--text); }
.muted { color: var(--muted); font-size: 14px; }

/* Form */
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; }
.field input[type="number"], .field select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 15px; font-family: inherit;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--brand);
}
.hint { color: var(--muted); font-size: 12px; }

.field.checkbox {
  flex-direction: row; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; cursor: pointer;
}
.field.checkbox span { font-weight: 500; font-size: 14px; }
.field.checkbox input { width: 18px; height: 18px; accent-color: var(--brand); }

/* Result */
.result { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 14px; }
.result-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; color: var(--muted);
}
.result-row b { color: var(--text); font-size: 16px; }
.result-row.total {
  border-top: 1px solid var(--line); margin-top: 8px; padding-top: 14px;
  color: var(--text); font-size: 17px;
}
.result-row.total b { color: var(--brand-ink); font-size: 22px; }

/* Buttons */
.btn-primary {
  margin-top: 18px; width: 100%;
  background: var(--brand); color: #1a1300; border: none;
  border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.btn-primary:hover { filter: brightness(1.07); }

/* Verdict */
.verdict { margin-top: 18px; border-radius: 12px; padding: 16px; }
.verdict.ok { background: rgba(52,211,153,.12); border: 1px solid var(--green); }
.verdict.bad { background: rgba(248,113,113,.10); border: 1px solid var(--red); }
.verdict h3 { margin: 0 0 8px; }
.verdict .overcharge { font-size: 24px; font-weight: 800; }
.verdict.bad .overcharge { color: var(--red); }
.verdict ul { margin: 12px 0 0; padding-inline-start: 20px; }
.verdict li { margin: 4px 0; }

/* Solar */
.solar { background: var(--solar-bg); }
.solar h2 { color: var(--brand-ink); }
.btn-solar {
  display: inline-block; margin: 6px 0 10px;
  background: var(--green); color: #062b1c; text-decoration: none;
  border-radius: 12px; padding: 12px 22px; font-weight: 700;
}
.btn-solar:hover { filter: brightness(1.07); }

/* Rights */
.rights-list { margin: 0; padding-inline-start: 20px; }
.rights-list li { margin: 8px 0; }
.rights-list b { color: var(--brand-ink); }

/* Header extras */
.header-right { display: flex; align-items: center; gap: 10px; }
.admin-link {
  background: var(--surface-2); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; text-decoration: none; font-size: 18px;
}
.admin-link:hover { border-color: var(--brand); }

/* Buttons row & variants */
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.btn-secondary {
  margin-top: 14px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-secondary:hover { border-color: var(--brand); }
.btn-row .btn-secondary { margin-top: 0; }
.btn-danger {
  background: rgba(248,113,113,.12); color: var(--red);
  border: 1px solid var(--red); border-radius: 12px; padding: 12px 16px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-whatsapp {
  display: inline-block; background: #25d366; color: #062b1c;
  text-decoration: none; border-radius: 12px; padding: 12px 16px; font-weight: 700;
}
.btn-whatsapp:hover { filter: brightness(1.05); }
.link-btn {
  background: none; border: none; color: var(--brand-ink); cursor: pointer;
  font-family: inherit; font-size: 14px; padding: 0;
}
.link-btn.danger { color: var(--red); }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td {
  text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line);
}
.tbl th { color: var(--muted); font-weight: 600; }
.tbl code { color: var(--brand-ink); }

/* زر تثبيت التطبيق (PWA) */
.install-btn {
  position: fixed; bottom: 18px; inset-inline-start: 18px; z-index: 60;
  background: var(--brand); color: #1a1300; border: none;
  border-radius: 999px; padding: 12px 18px; font-weight: 700; font-family: inherit;
  cursor: pointer; box-shadow: var(--shadow);
}
.install-btn:hover { filter: brightness(1.07); }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #062b1c; padding: 12px 22px;
  border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); z-index: 50;
}

code {
  background: var(--surface-2); padding: 2px 6px; border-radius: 6px;
  font-size: 13px; color: var(--brand-ink);
}

/* Auth gate */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: var(--gate-bg);
}
.auth-box { max-width: 380px; width: 100%; text-align: center; }
.auth-box .field { text-align: right; margin: 12px 0; }
.auth-logo { font-size: 40px; margin-bottom: 6px; }

/* Validation */
.err {
  color: var(--red); font-size: 13px;
  background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.4);
  border-radius: 8px; padding: 6px 10px; margin-top: 4px;
}
input.invalid, select.invalid { border-color: var(--red) !important; }

/* FAQ accordion */
.faq details {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 0 14px; margin: 10px 0; background: var(--surface-2);
}
.faq summary {
  cursor: pointer; padding: 14px 0; font-weight: 600; list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::before { content: "＋ "; color: var(--brand-ink); font-weight: 700; }
.faq details[open] summary::before { content: "－ "; }
.faq details p { margin: 0 0 14px; color: var(--muted); }

/* History chart */
.chart {
  display: flex; align-items: flex-end; gap: 8px; height: 120px;
  margin: 6px 0 16px; padding: 8px; border-bottom: 1px solid var(--line);
}
.chart .bar {
  flex: 1; background: linear-gradient(var(--brand), #b8860b);
  border-radius: 6px 6px 0 0; min-height: 4px; position: relative;
}
.chart .bar span {
  position: absolute; top: -18px; left: 0; right: 0; text-align: center;
  font-size: 10px; color: var(--muted);
}
.chart .bar small {
  position: absolute; bottom: -18px; left: 0; right: 0; text-align: center;
  font-size: 10px; color: var(--muted);
}

/* Nav links in header */
.nav-links { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nav-links a {
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600;
  padding: 7px 12px; border-radius: 9px; border: 1px solid transparent;
}
.nav-links a:hover, .nav-links a.active {
  border-color: var(--line); background: var(--surface-2); color: var(--brand-ink);
}

/* Generators directory */
.fair-tag {
  display: inline-block; background: rgba(52,211,153,.15); color: var(--green);
  border: 1px solid var(--green); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 700; margin-inline-start: 6px;
}
.gen-card .gen-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.gen-card h3 { margin: 0 0 4px; font-size: 17px; }
.gen-card .muted { margin: 0; }
.gen-stars { color: var(--brand-ink); font-size: 17px; white-space: nowrap; }
.gen-stars small { color: var(--muted); }
.gen-price { margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.gen-notes { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--line); margin-top: 30px;
  padding: 20px 0; color: var(--muted); font-size: 13px; text-align: center;
}

/* طباعة */
@media print {
  .site-header, .site-footer, .btn-row, .btn-primary, .btn-secondary,
  #checkCard, #historyCard, #solarCard, .faq, .nav-links, .admin-link { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
