/* =====================================================================
   نظام ثانوية تللسقف للبنين — التنسيقات
   الهوية: أخضر بترولي عميق + ذهبي عتيق + ورق فاتح
   ===================================================================== */

:root {
  --ink:      #0C3B39;   /* الأخضر البترولي الأساسي */
  --ink-2:    #12504C;   /* تدرّج أفتح للتفاعل */
  --ink-3:    #0A302E;   /* أغمق */
  --gold:     #C79A3B;   /* الذهبي العتيق */
  --gold-2:   #E2C371;
  --paper:    #EFF1EB;   /* الخلفية الورقية */
  --card:     #FFFFFF;
  --text:     #16211F;
  --muted:    #5C6B67;
  --line:     #DCE3DC;
  --danger:   #B4472E;
  --radius:   14px;
  --shadow:   0 10px 30px rgba(12, 59, 57, 0.10);
}

* { box-sizing: border-box; }

/* الإخفاء يتغلّب دائماً على display (يصلح تراكم الشاشات) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  direction: rtl;
  font-family: "Readex Pro", system-ui, sans-serif;
  color: var(--text);
  background: var(--paper);
}

h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input  { font-family: inherit; }

/* ---------- عناصر مشتركة ---------- */
.btn-primary {
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  transition: background .18s ease, transform .05s ease;
}
.btn-primary:hover  { background: var(--ink-2); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: .9rem;
  transition: background .18s ease;
}
.btn-ghost:hover { background: rgba(255,255,255,.12); }

.icon-btn {
  background: transparent; border: none; color: #fff;
  font-size: 1.4rem; padding: 4px 8px; display: none;
}

/* =====================================================================
   شاشة الدخول
   ===================================================================== */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(120% 120% at 100% 0%, var(--ink-2) 0%, var(--ink) 45%, var(--ink-3) 100%);
}

.login-panel {
  position: relative;
  width: 100%;
  max-width: 430px;
}

/* الشريط الذهبي المُدرّج — التوقيع البصري (يستوحي طوب المدينة) */
.motif {
  height: 10px;
  border-radius: 10px 10px 0 0;
  background: repeating-linear-gradient(90deg,
    var(--gold) 0 9px, transparent 9px 18px);
  opacity: .9;
}

.login-card {
  background: var(--card);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 40px 34px 30px;
  box-shadow: var(--shadow);
}

.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 14px;
  display: grid; place-items: center;
  background: var(--ink); color: var(--gold-2);
  font-family: "Amiri", serif; font-size: 2rem; font-weight: 700;
  border-radius: 16px;
}
.brand-name {
  font-family: "Amiri", serif;
  font-size: 1.7rem; font-weight: 700; color: var(--ink);
  line-height: 1.3;
}
.brand-sub { color: var(--muted); font-size: .92rem; margin-top: 6px; }

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field span { font-size: .9rem; font-weight: 500; color: var(--text); }
.field input {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  background: #fbfcfb;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(12,59,57,.10);
}

.error-msg {
  margin: 0;
  background: rgba(180,71,46,.08);
  color: var(--danger);
  border: 1px solid rgba(180,71,46,.25);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: .88rem;
}

.login-foot {
  text-align: center; color: var(--muted);
  font-size: .84rem; margin: 20px 0 0;
}

/* =====================================================================
   التطبيق بعد الدخول
   ===================================================================== */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--ink);
  color: #fff;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 62px;
}
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: "Amiri", serif; font-size: 1.15rem; font-weight: 700;
}
.topbar-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: rgba(255,255,255,.12); color: var(--gold-2);
  border-radius: 9px; font-size: 1.1rem;
}
.topbar-user { margin-inline-start: auto; display: flex; align-items: center; gap: 14px; }
.user-meta { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.user-name { font-weight: 600; font-size: .95rem; }
.user-role { font-size: .78rem; color: var(--gold-2); }

.motif-strip {
  height: 5px;
  background: repeating-linear-gradient(90deg,
    var(--gold) 0 8px, transparent 8px 16px);
}

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--card);
  border-inline-start: 1px solid var(--line);
  padding: 18px 12px;
}
.menu { display: flex; flex-direction: column; gap: 4px; }
.menu button {
  text-align: right;
  background: transparent; border: none;
  padding: 12px 14px; border-radius: 10px;
  font-size: .96rem; color: var(--text);
  display: flex; align-items: center; gap: 10px;
  transition: background .14s ease, color .14s ease;
}
.menu button:hover { background: var(--paper); }
.menu button.active { background: var(--ink); color: #fff; }
.menu button.active .m-dot { background: var(--gold-2); }
.m-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); flex-shrink: 0;
}

.content { flex: 1; padding: 28px 32px; overflow: auto; }

.page-head { margin-bottom: 22px; }
.page-head h2 {
  font-family: "Amiri", serif; font-size: 1.6rem; color: var(--ink);
}
.page-head p { color: var(--muted); margin: 6px 0 0; font-size: .95rem; }

/* بطاقات الإحصائيات */
.stat-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 26px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 4px; background: var(--gold);
}
.stat-value {
  font-family: "Amiri", serif; font-size: 2.2rem; font-weight: 700;
  color: var(--ink); line-height: 1;
}
.stat-label { color: var(--muted); font-size: .92rem; margin-top: 8px; }

/* بطاقات عامة / قيد الإنشاء */
.card-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.info-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
}
.info-card h3 { font-size: 1.05rem; color: var(--ink); margin-bottom: 8px; }
.info-card p  { color: var(--muted); font-size: .9rem; margin: 0; }

.soon {
  display: inline-block; margin-top: 12px;
  background: rgba(199,154,59,.14); color: #8a6a1e;
  border-radius: 20px; padding: 4px 12px; font-size: .78rem; font-weight: 500;
}

.placeholder {
  background: var(--card); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 44px 24px; text-align: center;
}
.placeholder .big { font-family: "Amiri", serif; font-size: 1.4rem; color: var(--ink); }
.placeholder p { color: var(--muted); margin: 10px 0 0; }

/* ---------- لوحات ونماذج وجداول داخل المحتوى ---------- */
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 22px;
}
.panel-title { font-size: 1.05rem; color: var(--ink); margin-bottom: 16px; }

.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld span { font-size: .85rem; color: var(--text); font-weight: 500; }
.fld input, .fld select {
  border: 1.5px solid var(--line); border-radius: 9px;
  padding: 10px 12px; font-size: .95rem; background: #fbfcfb; min-width: 170px;
}
.fld input:focus, .fld select:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(12,59,57,.10);
}
.btn-sm { padding: 11px 22px; }

.inline-msg { margin: 14px 0 0; font-size: .88rem; border-radius: 8px; padding: 9px 13px; }
.inline-msg.ok  { background: rgba(18,80,76,.10);  color: var(--ink); }
.inline-msg.err { background: rgba(180,71,46,.10); color: var(--danger); }

.data-table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.data-table th, .data-table td {
  text-align: right; padding: 13px 16px;
  border-bottom: 1px solid var(--line); font-size: .93rem;
}
.data-table th { background: var(--paper); color: var(--muted); font-weight: 600; }
.data-table tr:last-child td { border-bottom: none; }

.btn-del {
  background: transparent; color: var(--danger);
  border: 1px solid rgba(180,71,46,.35); border-radius: 8px;
  padding: 6px 14px; font-size: .85rem; transition: background .14s ease;
}
.btn-del:hover { background: rgba(180,71,46,.08); }

.chk-row {
  display: flex; align-items: center; gap: 9px;
  margin-top: 16px; font-size: .93rem; color: var(--text); cursor: pointer;
}
.chk-row input { width: 17px; height: 17px; accent-color: var(--ink); cursor: pointer; }

/* ---------- الدرجات: رقائق الامتحانات وحقول الإدخال ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card);
  border-radius: 22px; padding: 8px 17px; font-size: .9rem;
  color: var(--text); cursor: pointer; transition: all .14s ease;
}
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.mark-input {
  width: 90px; border: 1.5px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-size: .95rem; text-align: center;
}
.mark-input:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(12,59,57,.10);
}
.muted-note { color: var(--muted); font-size: .88rem; margin: 4px 0 12px; }

/* ---------- الحضور: أزرار الحالة والشارات ---------- */
.att-group { display: flex; gap: 5px; flex-wrap: wrap; }
.att-btn {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 8px;
  padding: 5px 13px; font-size: .85rem; cursor: pointer; color: var(--muted);
  transition: all .12s ease;
}
.att-btn:hover { border-color: var(--ink); }
.att-btn.active { color: #fff; border-color: transparent; }
.att-btn.active[data-v="present"] { background: var(--ink); }
.att-btn.active[data-v="absent"]  { background: var(--danger); }
.att-btn.active[data-v="late"]    { background: var(--gold); }
.att-btn.active[data-v="excused"] { background: var(--muted); }

.badge {
  display: inline-block; padding: 3px 13px; border-radius: 20px;
  font-size: .82rem; color: #fff;
}
.badge[data-v="present"] { background: var(--ink); }
.badge[data-v="absent"]  { background: var(--danger); }
.badge[data-v="late"]    { background: var(--gold); }
.badge[data-v="excused"] { background: var(--muted); }

/* ---------- الإعلانات ---------- */
.txt {
  border: 1.5px solid var(--line); border-radius: 9px; padding: 10px 12px;
  font-size: .95rem; font-family: inherit; background: #fbfcfb;
  width: 100%; box-sizing: border-box; resize: vertical; line-height: 1.6;
}
.txt:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(12,59,57,.10); }

.an-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px;
  position: relative; overflow: hidden;
}
.an-card::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 4px; background: var(--gold);
}
.an-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.an-head h3 { font-size: 1.05rem; color: var(--ink); }
.an-target {
  font-size: .78rem; background: rgba(199,154,59,.14); color: #8a6a1e;
  border-radius: 20px; padding: 4px 12px; white-space: nowrap;
}
.an-body { color: var(--text); font-size: .95rem; margin: 10px 0 0; white-space: pre-wrap; line-height: 1.75; }
.an-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.an-date { color: var(--muted); font-size: .82rem; }

/* ---------- الواجبات ---------- */
.btn-mini {
  background: var(--ink); color: #fff; border: none; border-radius: 8px;
  padding: 6px 15px; font-size: .83rem; cursor: pointer; transition: background .14s ease;
}
.btn-mini:hover { background: var(--ink-2); }
.row-actions { display: inline-flex; gap: 8px; align-items: center; }
.submit-box { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

.btn-ghost-dark {
  background: transparent; color: var(--muted);
  border: 1.5px solid var(--line); border-radius: 9px;
  padding: 10px 20px; font-size: .9rem; transition: all .14s ease;
}
.btn-ghost-dark:hover { border-color: var(--ink); color: var(--ink); }
.edit-panel { border: 2px solid var(--gold); }

/* ---------- الأسئلة وورقة الامتحان ---------- */
.q-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  margin-bottom: 8px; cursor: pointer;
}
.q-item:hover { border-color: var(--ink); }
.q-pick { width: 16px; height: 16px; accent-color: var(--ink); flex-shrink: 0; }
.q-badge {
  font-size: .72rem; background: rgba(18,80,76,.10); color: var(--ink);
  border-radius: 20px; padding: 3px 10px; white-space: nowrap; flex-shrink: 0;
}
.q-text { flex: 1; font-size: .93rem; }
.q-marks { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.q-item .q-del { flex-shrink: 0; }

.math-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.mbtn {
  background: var(--paper); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 11px; font-size: .82rem; color: var(--ink); cursor: pointer;
  transition: all .12s ease;
}
.mbtn:hover { background: var(--ink); color: #fff; border-color: var(--ink); }
.mbtn-alt { background: var(--ink); color: #fff; }

/* لوحة الرموز */
.math-palette {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 5px; padding: 10px; margin-bottom: 8px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
}
.pal-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 4px; font-size: .85rem; cursor: pointer; color: var(--ink);
}
.pal-btn:hover { background: var(--ink); color: #fff; border-color: var(--ink); }

/* معاينة فورية */
.q-preview-wrap { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; }
.q-preview-label { font-size: .85rem; color: var(--muted); padding-top: 8px; }
.q-preview {
  flex: 1; min-height: 40px; border: 1px dashed var(--line); border-radius: 9px;
  padding: 8px 12px; background: #fbfcfb; font-size: 1rem; overflow-x: auto;
}

/* الفروع والصور في الورقة */
.exam-parts { padding-inline-start: 20px; margin: 6px 0 0; }
.exam-parts > li { margin-bottom: 8px; }
.exam-img { margin: 8px 0; }
.exam-img img { max-width: 100%; max-height: 260px; border-radius: 6px; }

/* أدوات الورقة والترتيب */
.exam-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.exam-q-ctrl { display: inline-flex; gap: 3px; margin-inline-start: 8px; }
.exam-q-ctrl button {
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  width: 24px; height: 22px; font-size: .7rem; cursor: pointer; color: var(--ink);
}
.exam-q-ctrl button:hover { background: var(--ink); color: #fff; }

.exam-answer-key {
  margin-top: 6px; color: #8a1f1f; font-size: .92rem; font-weight: 600;
}
.answer-key-badge {
  display: inline-block; background: #8a1f1f; color: #fff;
  padding: 3px 16px; border-radius: 20px; font-size: .82rem; margin-bottom: 8px;
}

@media print {
  .answer-key-badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .exam-answer-key { color: #000; }
}

.exam-head { text-align: center; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 18px; }
.exam-head-top { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); gap: 12px; }
.exam-head h2 { font-family: "Amiri", serif; color: var(--ink); font-size: 1.4rem; margin: 10px 0; }
.exam-meta { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; font-size: .85rem; }
.exam-student { margin-top: 14px; text-align: right; font-size: .95rem; }
.exam-qs { padding-inline-start: 22px; line-height: 1.9; }
.exam-qs > li { margin-bottom: 16px; }
.exam-q-text { font-size: .98rem; }
.q-mark-print { color: var(--muted); font-size: .82rem; }
.exam-opts { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 6px; font-size: .93rem; }
.exam-answer-space { margin-top: 8px; }
.exam-answer-space div { border-bottom: 1px solid #bbb; height: 26px; }

@media print {
  .exam-paper { border: none !important; }
  .exam-answer-space div { border-bottom: 1px solid #666; }
}

/* ---------- الجدول الأسبوعي ---------- */
.tt-wrap { overflow-x: auto; }
.tt-table th, .tt-table td { text-align: center; padding: 9px 10px; white-space: nowrap; }
.tt-table .tt-day { background: var(--paper); font-weight: 600; color: var(--ink); }
.tt-cell {
  border: 1.5px solid var(--line); border-radius: 7px;
  padding: 5px 6px; font-size: .82rem; min-width: 95px; background: #fbfcfb;
}
.tt-cell:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 2px rgba(12,59,57,.10); }

/* ---------- التقارير والطباعة ---------- */
.report-head { text-align: center; margin-bottom: 18px; }
.report-head h2 { font-family: "Amiri", serif; color: var(--ink); font-size: 1.5rem; }
.report-head h3 { color: var(--ink); font-size: 1.15rem; margin-top: 4px; }
.report-head p { color: var(--muted); font-size: .9rem; margin: 2px 0; }
.report-table th, .report-table td { text-align: center; }
.rp-max { color: var(--muted); font-weight: 400; font-size: .78rem; }
.rp-date-print { display: none; }

@media print {
  .topbar, .sidebar, .motif-strip, .no-print { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; overflow: visible; }
  .app-view, body { background: #fff; }
  .panel, .tt-wrap { border: none; box-shadow: none; padding: 0; overflow: visible; }
  .report-table { border: 1px solid #999; }
  .report-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-date-print { display: block; }
}

/* =====================================================================
   الاستجابة للموبايل
   ===================================================================== */
@media (max-width: 760px) {
  .icon-btn { display: block; }
  .sidebar {
    position: fixed; inset-block: 62px 0; inset-inline-end: 0;
    z-index: 30; box-shadow: -8px 0 24px rgba(0,0,0,.12);
    transform: translateX(100%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 20px 16px; }
  .topbar-brand { font-size: 1rem; }
  .user-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
