:root {
  --green: #1658a8;
  --green-2: #3d97dc;
  --green-soft: #e8f3fc;
  --gold: #4aa3e8;
  --gold-soft: #fbf4dc;
  --bg: #f4f8fc;
  --card: #ffffff;
  --text: #1c2522;
  --muted: #66736e;
  --line: #d9e2ec;
  --red: #d0342c;
  --red-soft: #fdecea;
  --amber: #b86e00;
  --amber-soft: #fff4e0;
  --ok: #1d8a52;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(22,88,168,.06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px; line-height: 1.6;
}
.hidden { display: none !important; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--green); color: #fff;
  padding: 10px 16px 0; padding-top: max(10px, env(safe-area-inset-top));
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 12px; max-width: 760px; margin: 0 auto; padding-bottom: 10px; }
.logo svg { width: 42px; height: 42px; display: block; }
.school { font-size: 13px; opacity: .85; }
.ftitle { font-weight: 700; font-size: 16px; line-height: 1.35; }
.progress { height: 4px; background: rgba(255,255,255,.15); margin: 0 -16px; }
.progress .bar { height: 100%; width: 0; background: var(--gold); transition: width .3s; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 12px 40px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }

.intro { font-size: 14px; color: var(--muted); display: grid; gap: 6px; margin-bottom: 14px; border-right: 4px solid var(--gold); }
.intro-row { display: flex; align-items: center; gap: 8px; }
.req-dot { color: var(--red); font-weight: 700; font-size: 18px; width: 18px; text-align: center; }
.flag-demo { background: var(--amber-soft); color: var(--amber); border-radius: 20px; padding: 0 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.ok-demo { color: var(--ok); font-weight: 700; width: 18px; text-align: center; }
.draft-note { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--green-soft); color: var(--green); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }

/* ---------- أقسام الاستمارة ---------- */
.emis-form { display: grid; gap: 16px; }
.sec-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid transparent; transition: border-color .3s; }
.sec-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: linear-gradient(90deg, #f6faff, #eaf4fd); border-bottom: 1px solid var(--line); }
.sec-head h2 { margin: 0; font-size: 16px; flex: 1; color: #2b86cf; }
.sec-num { width: 28px; height: 28px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.sec-badge { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 20px; white-space: nowrap; }
.sec-badge:empty { display: none; }
.sec-badge.bad { background: #fdecea; color: #c0121f; }
.sec-body { padding: 14px; display: flex; flex-wrap: wrap; gap: 14px 12px; }

.field { flex: 1 1 100%; min-width: 0; position: relative; }
@media (min-width: 600px) { .field.half { flex: 1 1 calc(50% - 6px); } }
.lbl { display: flex; align-items: center; gap: 4px; font-weight: 600; font-size: 14px; margin-bottom: 6px; color: #2c3a35; }
.req { color: var(--red); font-weight: 700; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .65 } }

.field input[type=text], .field input[type=email], .field input[type=date], .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); outline: none; transition: border-color .2s, box-shadow .2s; -webkit-appearance: none; appearance: none;
}
.field select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2366736e' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; padding-left: 32px; }
.field select:disabled { opacity: .6; }
.field input[dir=ltr] { text-align: right; }
.field input[dir=ltr]:not(:placeholder-shown) { text-align: left; letter-spacing: .5px; }
.field input:focus, .field select:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(61,151,220,.12); background: #fff; }
.msg { font-size: 13px; color: #c0121f; min-height: 0; overflow: hidden; max-height: 0; transition: max-height .2s; }
.msg.on { max-height: 60px; margin-top: 4px; }

/* حالة الخطأ: إطار أحمر مع أيقونة "!" داخل الحقل ورسالة السبب تحته */
.ctl { position: relative; }
.err-ic { display: none; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; border-radius: 50%;
  background: #c0121f; color: #fff; font-weight: 700; font-size: 14px; line-height: 20px; text-align: center; pointer-events: none; }
.ctl select ~ .err-ic, .ctl .date-input ~ .err-ic { left: 40px; }
.field.is-bad .err-ic { display: block; }
.field.is-bad input, .field.is-bad select { border: 2px solid #c0121f; background: #fff; padding-left: 40px; }
.field.is-bad select, .field.is-bad .date-input { padding-left: 66px; }
.field.is-bad input:focus, .field.is-bad select:focus { box-shadow: 0 0 0 3px rgba(192,18,31,.12); }
.field.is-bad .chips { outline: 2px solid #c0121f; outline-offset: 4px; border-radius: 10px; }
.field.is-bad .agree { border: 2px solid #c0121f; }
.field.is-bad .lbl { color: #c0121f; }

.submit-wrap { margin-top: 20px; }
/* ---------- الصفحات المتتالية ---------- */
.stepper { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 14px; }
.step-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.step-top span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.step-top b { font-size: 15px; color: var(--green); }
.step-dots { display: flex; gap: 6px; margin-top: 10px; }
.step-dots span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); transition: background .3s; }
.step-dots span.done { background: var(--green-2); }
.step-dots span.on { background: var(--green); }
.step-nav { display: flex; gap: 10px; margin-top: 20px; }
.step-nav .btn { flex: 1; min-height: 54px; font-size: 17px; }
.btn-out-step { background: #fff; color: var(--green); border: 1.5px solid var(--line); }
.dup-note { margin-top: 20px; background: #fdecea; border: 2px solid #c0121f; color: #8c0d17; border-radius: 12px; padding: 14px 16px; }
.dup-note b { font-size: 16px; }
.dup-note p { margin: 6px 0 0; font-size: 14px; line-height: 1.8; }
.btn-block { width: 100%; min-height: 54px; font-size: 17px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; min-height: 42px; padding: 6px 14px; border: 1.5px solid var(--line); border-radius: 22px; background: #fff; font-size: 14px; transition: all .15s; user-select: none; }
.chip input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.chip input:checked + span::before { content: '✓'; margin-left: 6px; font-weight: 700; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(61,151,220,.25); }

.pledge { flex: 1 1 100%; margin: 0; background: var(--gold-soft); border-radius: 10px; padding: 12px; font-size: 14px; color: #5b4a12; line-height: 1.9; }
.agree { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 600; }
.agree input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }

.photo-row { display: flex; align-items: center; gap: 14px; }
.photo-box { width: 96px; height: 120px; border-radius: 10px; border: 2px dashed var(--line); display: grid; place-items: center; overflow: hidden; background: #fafbfb; flex: none; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; display: none; }
.photo-box.has img { display: block; } .photo-box.has .ph { display: none; } .photo-box.has { border-style: solid; }
.photo-box .ph { font-size: 32px; opacity: .5; }
.photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.photo-rules { margin: 10px 0 0; padding: 0 18px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.8; }
.photo-status { font-size: 13px; font-weight: 600; margin-top: 6px; }
.photo-status:empty { display: none; }
.photo-status.wait { color: var(--green-2); }
.photo-status.good { color: var(--ok); }
.photo-status.bad { color: #c0121f; }
.field.photo-field.is-bad .photo-box { border: 2px solid #c0121f; }
.photo-box.busy { opacity: .5; }
.photo-row .btn-link.danger { display: none; }
.photo-row:has(.photo-box.has) .btn-link.danger { display: inline; }

.shake { animation: shake .45s; }
@keyframes shake { 20%,60% { transform: translateX(-6px) } 40%,80% { transform: translateX(6px) } }

/* ---------- الأزرار ---------- */
.btn { border: 0; border-radius: 12px; padding: 12px 20px; font-size: 16px; font-weight: 700; cursor: pointer; min-height: 48px; transition: transform .1s, background .2s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary.ready { background: var(--ok); box-shadow: 0 4px 14px rgba(29,138,82,.35); }
.btn-soft { background: var(--green-soft); color: var(--green); font-size: 14px; min-height: 40px; padding: 8px 14px; }
.btn-link { background: none; border: 0; color: var(--green-2); text-decoration: underline; cursor: pointer; font-size: 14px; padding: 4px; }
.btn-link.danger { color: var(--red); }

.submitbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.submitbar .btn { flex: 0 1 240px; }
.sb-info { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); line-height: 1.3; }
.sb-info b { font-size: 18px; color: var(--green); }
@media (min-width: 800px) { .submitbar { justify-content: center; gap: 40px; } }

/* ---------- الشاشات ---------- */
.screen { min-height: 70vh; display: grid; place-items: center; padding: 24px 16px; }
.screen-card { background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 32px 24px; text-align: center; max-width: 420px; width: 100%; }
.screen-card h1 { font-size: 22px; margin: 12px 0; color: var(--green); }
.big-ok { width: 80px; height: 80px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 44px; display: grid; place-items: center; margin: 0 auto; }
.big-ok.warn { background: var(--amber); }
.ref { font-size: 32px; font-weight: 700; letter-spacing: 2px; color: var(--green); background: var(--green-soft); border-radius: 12px; padding: 10px; margin: 8px 0 12px; direction: ltr; }
.muted { color: var(--muted); font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1c2522; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 100; max-width: calc(100% - 32px); width: max-content; text-align: center; transition: all .25s; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--red); }

/* ---------- الصفحة الرئيسية ---------- */
.home { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--green) 0%, #0d3d78 100%); }
.home-card { width: 100%; max-width: 440px; text-align: center; color: #fff; }
.home-card .logo svg { width: 72px; height: 72px; margin: 0 auto 8px; }
.home-card h1 { font-size: 22px; margin: 4px 0; }
.home-card p { opacity: .8; margin: 0 0 24px; font-size: 14px; }
.choice { display: flex; align-items: center; gap: 14px; background: #fff; color: var(--text); text-decoration: none; padding: 18px; border-radius: 16px; margin-bottom: 12px; text-align: right; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.choice .ic { font-size: 30px; width: 56px; height: 56px; border-radius: 14px; background: var(--green-soft); display: grid; place-items: center; flex: none; }
.choice b { display: block; font-size: 17px; color: var(--green); }
.choice small { color: var(--muted); }
.home-foot { margin-top: 20px; font-size: 13px; }
.home-foot a { color: var(--gold); }
.emis-form.stepped .sec-head { display: none; }

/* ---------- منتقي التاريخ: السنة ← الشهر ← اليوم ---------- */
.field .date-input { cursor: pointer; caret-color: transparent;
  background-image: 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='%231658a8' stroke-width='2'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; padding-left: 40px; }
body.dp-open { overflow: hidden; }
.dp-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(13,40,80,.45); display: flex; align-items: flex-end; justify-content: center; }
.dp-sheet { background: #fff; width: 100%; max-width: 480px; max-height: 86vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  padding: 14px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.2); animation: dpUp .2s ease-out; }
@keyframes dpUp { from { transform: translateY(40px); opacity: 0 } to { transform: none; opacity: 1 } }
@media (min-width: 600px) { .dp-overlay { align-items: center; } .dp-sheet { border-radius: 20px; } }
.dp-head { display: flex; align-items: center; justify-content: space-between; }
.dp-title { font-size: 17px; color: var(--green); }
.dp-x { background: #f1f5f9; border: 0; width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.dp-crumbs { display: flex; gap: 8px; margin: 12px 0 6px; flex-wrap: wrap; }
.dp-crumb { border: 1.5px solid var(--line); background: #fff; color: var(--muted); border-radius: 20px; padding: 5px 14px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; }
.dp-crumb.on { background: var(--green); border-color: var(--green); color: #fff; }
.dp-hint { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.dp-grid { display: grid; gap: 8px; overflow-y: auto; padding: 2px; }
.dp-grid.years { grid-template-columns: repeat(4, 1fr); }
.dp-grid.months { grid-template-columns: repeat(3, 1fr); }
.dp-grid.days { grid-template-columns: repeat(7, 1fr); }
.dp-cell { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; min-height: 52px; font-family: inherit; font-size: 17px; font-weight: 600;
  color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; padding: 6px 2px; }
.dp-grid.days .dp-cell { min-height: 44px; font-size: 16px; }
.dp-grid.months .dp-cell { font-size: 15px; min-height: 60px; }
.dp-cell small { font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.dp-cell:hover:not(:disabled) { border-color: var(--green-2); background: var(--green-soft); }
.dp-cell.sel { background: var(--green); border-color: var(--green); color: #fff; }
.dp-cell.sel small { color: #dbe9f8; }
.dp-cell:disabled { opacity: .3; cursor: not-allowed; }

/* ---------- تثبيت التطبيق ---------- */
.topbar { position: sticky; }
.install-btn { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 20px; padding: 4px 12px; font: 600 13px inherit; font-family: inherit; cursor: pointer; }
.install-big { width: 100%; margin: 4px 0 8px; background: var(--gold); color: #fff; border: 0; border-radius: 14px; padding: 14px; font: 700 16px inherit; font-family: inherit; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
