/* واجهة التطبيق — هادئة وخفيفة، RTL بالكامل */
@import url('fonts.css');

:root {
  --bg: #f5f5f1;
  --surface: #ffffff;
  --surface-2: #fbfbf8;
  --ink: #23271f;
  --muted: #6f7568;
  --line: #e3e5da;
  --line-strong: #cfd3c4;
  --accent: #5a6b4c;
  --accent-deep: #3c4832;
  --accent-soft: #eef1e8;
  --danger: #a1443a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(35, 39, 31, .05), 0 8px 24px -16px rgba(35, 39, 31, .25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body { direction: rtl; }

h1, h2, h3, .display { font-family: var(--font-display); font-weight: 700; letter-spacing: 0; }
h1 { font-size: 1.55rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 .2rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 .6rem; }
a { color: var(--accent-deep); }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.app-bar__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.12rem;
  color: var(--accent-deep);
  white-space: nowrap;
}

.brand__mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: .85rem;
}

.nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }

.nav a {
  padding: 7px 13px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: .93rem;
  white-space: nowrap;
}

.nav a:hover { background: var(--accent-soft); color: var(--accent-deep); }
.nav a.is-active { background: var(--accent); color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 26px 20px 80px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-head p { color: var(--muted); margin: 2px 0 0; font-size: .92rem; }

/* ----------------------------- عناصر ----------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .93rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn--primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--accent-soft); color: var(--accent-deep); }
.btn--danger { color: var(--danger); border-color: #e7d3d0; }
.btn--danger:hover { background: #fbf1f0; border-color: var(--danger); }
.btn--sm { padding: 5px 11px; font-size: .85rem; }
.btn--icon { padding: 5px 9px; font-size: .95rem; line-height: 1; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card__hint { color: var(--muted); font-size: .88rem; }

.grid { display: grid; gap: 14px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .84rem; color: var(--muted); margin-bottom: 5px; }

.input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
}

textarea { resize: vertical; min-height: 96px; line-height: 1.7; }
.input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type='number'] { direction: ltr; text-align: right; }
input[type='date'] { direction: ltr; text-align: right; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: .82rem;
  font-weight: 600;
}

.chip--muted { background: #eeefe9; color: var(--muted); }

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  cursor: pointer;
  font-size: .9rem;
  background: var(--surface);
  user-select: none;
}

.checkbox input { accent-color: var(--accent); }
.checkbox.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }

.empty {
  text-align: center;
  padding: 34px 18px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.empty strong { display: block; color: var(--ink); font-family: var(--font-display); margin-bottom: 4px; }

/* ----------------------------- قوائم ----------------------------- */

.list { display: grid; gap: 10px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .15s, background .15s;
}

.list-item:hover { border-color: var(--line-strong); background: var(--surface-2); }
.list-item__main { flex: 1; min-width: 0; }
.list-item__title { font-weight: 600; }
.list-item__meta { font-size: .84rem; color: var(--muted); }
.list-item__actions { display: flex; gap: 4px; flex-wrap: wrap; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }

.tile {
  display: block;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
}

.tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.tile__title { font-family: var(--font-display); font-weight: 700; }
.tile__meta { font-size: .84rem; color: var(--muted); }

/* ----------------------------- جدول الخطة ----------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 7px 9px; text-align: right; vertical-align: middle; }
table.data thead th { background: var(--surface-2); font-size: .82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td input, table.data td textarea {
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 7px;
  border-radius: 7px;
  font-size: .92rem;
}
table.data td input:hover, table.data td textarea:hover { border-color: var(--line); }
table.data td textarea { min-height: 36px; }
.cell-tools { display: flex; gap: 2px; white-space: nowrap; }
.col-narrow { width: 118px; }
.col-mini { width: 96px; }

/* ----------------------------- الخطوات ----------------------------- */

.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
}

.step__num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  display: grid; place-items: center;
  font-size: .78rem; font-weight: 700;
}

.step.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.is-active .step__num { background: rgba(255, 255, 255, .22); color: #fff; }
.step.is-done .step__num { background: var(--accent); color: #fff; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }

.tab {
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .93rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.is-active { color: var(--accent-deep); border-bottom-color: var(--accent); font-weight: 600; }

/* ----------------------------- رسائل ----------------------------- */

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .9rem;
  margin-bottom: 12px;
  border: 1px solid;
}

.alert--error { background: #fbf1f0; border-color: #e7d3d0; color: #7d332b; }
.alert--warn { background: #fdf7e9; border-color: #eee0c0; color: #7a5f20; }
.alert--info { background: var(--accent-soft); border-color: #dbe2d0; color: var(--accent-deep); }
.alert ul { margin: 4px 0 0; padding-inline-start: 18px; }

.toast {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 50%;
  transform: translate(50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .5);
}

.toast.is-visible { opacity: 1; transform: translate(50%, 0); }
.toast--error { background: #7d332b; }
.toast--success { background: var(--accent-deep); }

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 39, 31, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(980px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, .5);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.modal__body { padding: 18px; overflow: auto; }
.modal__foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  background: var(--surface-2);
  flex-wrap: wrap;
}

.modal--wide { width: min(1240px, 100%); }

/* ----------------------------- المعاينة ----------------------------- */

.preview-holder {
  background: #e8e8e4;
  border-radius: var(--radius-sm);
  padding: 4px;
  overflow: auto;
  max-height: 64vh;
}

.preview-stage { margin: 0 auto; }
.preview-frame { border: 0; display: block; background: #fff; }
.print-frame { position: fixed; inset-inline-start: -10000px; top: 0; width: 1200px; height: 900px; border: 0; visibility: hidden; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }

.swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}

.swatch.is-on { border-color: var(--ink); }

.student-picker {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

.student-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-size: .9rem;
}

.student-pick:hover { background: var(--surface-2); }
.student-pick input { accent-color: var(--accent); }

.hint { font-size: .84rem; color: var(--muted); }
.mono-num { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  main { padding: 18px 14px 70px; }
  .app-bar__inner { padding: 10px 14px; gap: 10px; }
  .modal { max-height: 96vh; }
  .card { padding: 14px; }
}

@media print {
  .app-bar, .no-print { display: none !important; }
}

/* ----------------------------- نافذة التصدير ----------------------------- */

.export-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; }
.export-panel { display: grid; gap: 14px; align-content: start; }
.export-section { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.export-section h3 { font-size: .92rem; margin-bottom: 9px; color: var(--accent-deep); }
.export-choices { display: grid; gap: 6px; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .92rem;
}

.choice:hover { background: var(--surface-2); }
.choice.is-on { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 4px; accent-color: var(--accent); }
.choice small { display: block; color: var(--muted); font-size: .8rem; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 13px; font: inherit; font-size: .87rem; cursor: pointer; color: var(--muted); }
.seg button.is-on { background: var(--accent); color: #fff; font-weight: 600; }

@media (max-width: 900px) {
  .export-grid { grid-template-columns: 1fr; }
  .preview-holder { max-height: 46vh; }
}

/* ----------------------------- مقاطع السور ----------------------------- */

.segments { display: grid; gap: 8px; }

.segment-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 110px 110px auto;
  gap: 8px;
  align-items: center;
}

.segment-row__num { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.segment-row__num input { width: 100%; }

@media (max-width: 640px) {
  .segment-row { grid-template-columns: 1fr 1fr; }
  .segment-row__surah { grid-column: 1 / -1; }
}

/* ----------------------------- الاستيراد ----------------------------- */

.import-preview { display: grid; gap: 10px; }

.import-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface);
}

.import-card h4 { margin: 0 0 6px; font-family: var(--font-display); font-size: 1rem; }
.import-card .line { font-size: .9rem; color: var(--muted); }
.import-card .line b { color: var(--ink); font-weight: 600; }


/* ----------------------------- بطاقة فيها زر حذف ----------------------------- */

.tile--with-action {
  position: relative;
  padding: 0;
  overflow: hidden;
}

.tile--with-action:hover { border-color: var(--accent); background: var(--accent-soft); }

.tile__link {
  display: block;
  padding: 14px 40px 14px 14px;
  text-decoration: none;
  color: inherit;
}

.tile__delete {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 2px 7px;
  font: inherit;
  font-size: .85rem;
  line-height: 1.4;
  cursor: pointer;
  opacity: .55;
}

.tile__delete:hover {
  opacity: 1;
  color: var(--danger);
  border-color: #e7d3d0;
  background: #fbf1f0;
}

.hint--warn { color: #7a5f20; font-weight: 600; }
.measure-frame { position: fixed; inset-inline-start: -10000px; top: 0; border: 0; visibility: hidden; }

/* ----------------------------- التذييل: توقيع المصمم (الواجهة فقط، لا يُطبع) ----------------------------- */
.app-footer { max-width: 1180px; margin: -40px auto 0; padding: 14px 20px 28px; border-top: 1px solid var(--line); display: flex; justify-content: flex-start; align-items: center; }
.ft-credit { position: relative; }
#ft-credit-btn { display: inline-flex; align-items: center; gap: 10px; border: 0; background: none; padding: 4px 2px; cursor: pointer; color: var(--muted); font: inherit; }
.ft-credit-label { font-size: 12.5px; opacity: .85; padding-inline-end: 10px; border-inline-end: 1px solid var(--line-strong); line-height: 1.2; }
.ft-sig { display: block; height: 46px; width: auto; opacity: .82; transition: opacity .2s, transform .2s; }
#ft-credit-btn:hover .ft-sig, #ft-credit-btn[aria-expanded="true"] .ft-sig { opacity: 1; transform: translateY(-1px); }
.ft-card { position: absolute; bottom: calc(100% + 10px); inset-inline-start: 0; width: max-content; max-width: calc(100vw - 32px); background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 16px; padding: 16px 18px; box-shadow: 0 18px 50px rgba(35, 39, 31, .22); z-index: 5; }
.ft-card-role { display: block; font-size: 12px; color: var(--accent); margin-bottom: 4px; }
.ft-card strong { display: block; font-family: var(--font-display); font-size: 16.5px; line-height: 1.5; }
.ft-card a { display: inline-block; margin-top: 6px; font-size: 14px; text-decoration: none; color: var(--accent-deep); border-bottom: 1px dashed var(--accent); word-break: break-all; }
@media (max-width: 720px) { .app-footer { padding: 12px 14px 24px; margin-top: -34px; } }
@media print { .app-footer, .ft-credit, .ft-card { display: none !important; } }
