/* رافدان: الألوان بالقيم المعتمدة في مواصفات التصميم */

:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --tx: #000000;
  --mut: #8E8E93;
  --pri: #007AFF;
  --on: #FFFFFF;
  --bd: #C6C6C8;
  --in: #E9E9EB;
  --ok: #34C759;
  --bad: #FF3B30;
  --warn: #FF9500;
  --bar: rgba(242, 242, 247, .8);
  --tabbar: rgba(249, 249, 249, .92);
  --scrim: rgba(0, 0, 0, .4);
  --toast-bg: rgba(0, 0, 0, .82);
  --toast-tx: #FFFFFF;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1C1C1E;
    --tx: #FFFFFF;
    --mut: #8E8E93;
    --pri: #0A84FF;
    --on: #FFFFFF;
    --bd: #38383A;
    --in: #2C2C2E;
    --ok: #30D158;
    --bad: #FF453A;
    --warn: #FF9F0A;
    --bar: rgba(0, 0, 0, .72);
    --tabbar: rgba(28, 28, 30, .92);
    --scrim: rgba(0, 0, 0, .55);
    --toast-bg: rgba(255, 255, 255, .92);
    --toast-tx: #000000;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1C1C1E;
  --tx: #FFFFFF;
  --mut: #8E8E93;
  --pri: #0A84FF;
  --on: #FFFFFF;
  --bd: #38383A;
  --in: #2C2C2E;
  --ok: #30D158;
  --bad: #FF453A;
  --warn: #FF9F0A;
  --bar: rgba(0, 0, 0, .72);
  --tabbar: rgba(28, 28, 30, .92);
  --scrim: rgba(0, 0, 0, .55);
  --toast-bg: rgba(255, 255, 255, .92);
  --toast-tx: #000000;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--tx);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; }
h1 { font-size: 34px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 600; }

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

/* ---------- الشريط العلوي والتنقل ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  padding: env(safe-area-inset-top, 0px) 16px 0;
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: .5px solid var(--bd);
}

.topbar-title { font-size: 17px; font-weight: 600; flex: 1; text-align: center; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: none;
  color: var(--pri);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--tabbar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: .5px solid var(--bd);
}

.tab {
  flex: 1;
  border: 0;
  background: none;
  color: var(--mut);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10.5px;
  padding: 4px 0;
  cursor: pointer;
}

.tab.active { color: var(--pri); font-weight: 600; }

/* ---------- البطاقات والشبكات ---------- */

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.card-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

.section-title { font-size: 13px; color: var(--mut); font-weight: 600; margin: 16px 4px 8px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat-label { font-size: 13px; color: var(--mut); }
.stat-value { font-size: 17px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }

.notice {
  border: 1.5px solid var(--warn);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}

.notice.warn { color: var(--tx); }

.empty { color: var(--mut); font-size: 15px; text-align: center; padding: 40px 0; }
.muted { color: var(--mut); }
.hint { font-size: 13px; color: var(--mut); line-height: 1.5; margin: 8px 0; }
.sub { font-size: 13px; color: var(--mut); padding: 4px 0 4px 8px; }

/* ---------- الأزرار والحقول ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  background: var(--pri);
  color: var(--on);
  cursor: pointer;
  text-decoration: none;
}

.btn.ghost { background: var(--in); color: var(--pri); }
.btn.danger { background: var(--bad); color: #FFFFFF; }
.btn.block { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }

.input {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--in);
  color: var(--tx);
  font-size: 16px;
  outline: none;
  display: block;
}

.input:focus { box-shadow: 0 0 0 2px var(--pri); }
.input.small { width: auto; padding: 6px 8px; font-size: 14px; }
.input:disabled { opacity: .6; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--mut);
}

.form { display: block; }

.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form .input { flex: 1; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .input { flex: 1; min-width: 180px; }

.inline-field { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--mut); }
.inline-field .input { width: auto; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- القوائم والصفوف ---------- */

.list { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 12px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: .5px solid var(--bd);
  background: none;
  color: var(--tx);
  text-align: start;
  font: inherit;
  cursor: pointer;
}

.row:last-child { border-bottom: 0; }
.row.static { cursor: default; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { font-size: 13px; color: var(--mut); }
.row-end { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: .5px solid var(--bd);
  font-size: 14px;
}

.kv:last-child { border-bottom: 0; }
.kv > span { color: var(--mut); }
.kv > strong { font-weight: 600; text-align: end; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block;
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--in);
  color: var(--mut);
  font-weight: 600;
  white-space: nowrap;
  margin-inline-start: 4px;
}

.tag.ok { color: var(--ok); }
.tag.bad { color: var(--bad); }
.tag.warn { color: var(--warn); }

.class-block { padding: 8px 0; border-bottom: .5px solid var(--bd); }
.user-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: .5px solid var(--bd); flex-wrap: wrap; }

/* ---------- شاشة الدخول والإعداد ---------- */

.auth { max-width: 420px; margin: 40px auto 0; padding: 0 16px; text-align: center; }
.auth .card { text-align: start; margin-top: 16px; }
.auth .muted { margin: 4px 0 0; }
.mark { width: 72px; height: 72px; }

/* ---------- النوافذ المنبثقة ---------- */

#sheet-host { position: fixed; inset: 0; z-index: 20; }
.scrim { position: absolute; inset: 0; background: var(--scrim); }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 680px;
  margin: 0 auto;
  max-height: 88%;
  overflow: auto;
  background: var(--card);
  border-radius: 14px 14px 0 0;
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom, 0px));
  animation: rise .3s ease-out;
}

.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--bd); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }

@keyframes rise {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- الإشعارات المؤقتة ---------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  background: var(--toast-bg);
  color: var(--toast-tx);
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  z-index: 30;
  max-width: 90%;
  text-align: center;
}

.toast.err { background: var(--bad); color: #FFFFFF; }

/* ---------- الإيصال ---------- */

.receipt-wrap { overflow-x: auto; margin-bottom: 12px; }

.receipt {
  background: #FDFBF4;
  color: #1B1B1B;
  border: 2px solid #E7B84A;
  border-radius: 14px;
  padding: 14px;
  margin: 0 auto;
  font-size: 13px;
  direction: rtl;
}

.receipt.s58 { width: 58mm; max-width: 100%; font-size: 11px; padding: 6px; }
.receipt.s80 { width: 80mm; max-width: 100%; }
.receipt.sA4 { width: 100%; max-width: 180mm; font-size: 14px; }

.rc-school { font-size: 17px; font-weight: 700; text-align: center; color: #0F4A38; }
.rc-title {
  text-align: center;
  border: 1px solid #0F4A38;
  border-radius: 8px;
  padding: 4px;
  margin: 8px 0;
  color: #0F4A38;
  font-weight: 600;
}

.rc-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed #9AA6B2;
}

.rc-row span { color: #4B5A54; }
.rc-amount {
  background: #FBF3D6;
  border: 1.5px solid #E7B84A;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  margin: 8px 0;
}

.rc-amount strong { display: block; font-size: 18px; }
.rc-verify { font-size: 11px; color: #4B5A54; text-align: center; margin-top: 8px; }
.rc-foot { font-size: 11px; color: #4B5A54; text-align: center; margin-top: 6px; }

/* ---------- الطباعة ---------- */

@media print {
  .topbar, .tabbar, .toast, .no-print { display: none !important; }
  body { background: #FFFFFF; color: #000000; }
  .card, .stat, .list { box-shadow: none; border: 0; }
  .page { padding: 0; max-width: none; }
}

body.printing-receipt * { visibility: hidden; }
body.printing-receipt #print-area,
body.printing-receipt #print-area * { visibility: visible; }

@media print {
  body.printing-receipt #print-area {
    position: fixed;
    left: 0;
    top: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
}
