/* ═══════════════════════════════════════════════════════════════════
   book.css — الكتاب التفاعلي
   ورق فاتح للقراءة، ذهبي للهوية، بلا اعتماد على أي مكتبة.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --paper: #fbf9f4;
  --paper-2: #f3efe6;
  --ink: #1d1b16;
  --ink-soft: #4a463d;
  --ink-muted: #7a756a;
  --gold: #a8863f;
  --gold-soft: #f0e6cf;
  --line: #ded6c5;
  --ok: #2f6f4f;
  --warn: #9a5a12;
  --danger: #a3342c;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Tajawal', system-ui, sans-serif;
  line-height: 1.9;
  font-size: 17px;
}

h1, h2, h3, h4 {
  font-family: 'Amiri', serif;
  line-height: 1.4;
  margin: 0 0 10px;
}

a { color: var(--gold); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 18px; }

/* ── الترويسة ── */
.book-top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(251, 249, 244, .96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.book-top .inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  max-width: 1080px;
  margin: 0 auto;
}
.book-top .brand {
  font-family: 'Amiri', serif;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.book-top .brand span { color: var(--gold); }
.book-top nav { display: flex; gap: 6px; flex-wrap: wrap; margin-inline-start: auto; }
.book-top nav a {
  font-size: .8rem;
  text-decoration: none;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
}
.book-top nav a:hover { border-color: var(--gold); color: var(--gold); }

.progress {
  height: 3px;
  background: var(--line);
}
.progress i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .3s; }

/* ── الغلاف ── */
.book-hero {
  padding: 54px 0 34px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--paper-2), var(--paper));
}
.book-hero .kicker { letter-spacing: .25em; font-size: .72rem; color: var(--gold); font-weight: 700; }
.book-hero h1 { font-size: clamp(1.9rem, 5vw, 3rem); margin: 10px 0 12px; }
.book-hero p { color: var(--ink-soft); max-width: 62ch; margin: 0 auto; }

/* ── الأقسام ── */
section { padding: 40px 0; border-bottom: 1px solid var(--line); }
section > .wrap > h2 { font-size: clamp(1.4rem, 3.2vw, 2rem); }
.lead { color: var(--ink-soft); max-width: 70ch; }

.note {
  background: var(--gold-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: .92rem;
  color: var(--ink-soft);
  margin: 16px 0;
}
.note strong { color: var(--ink); }

/* ── الحاسبات ── */
.calc {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 18px 0;
  box-shadow: 0 6px 20px rgba(29, 27, 22, .04);
}
.calc h3 { font-size: 1.25rem; margin-bottom: 4px; }
.calc .sub { font-size: .84rem; color: var(--ink-muted); margin-bottom: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.field label { display: block; font-size: .78rem; color: var(--ink-muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  font-family: inherit;
  font-size: .95rem;
  color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }

.out {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.out .cell {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.out .cell b { display: block; font-size: 1.25rem; color: var(--ink); }
.out .cell span { font-size: .72rem; color: var(--ink-muted); }

.formula {
  margin-top: 12px;
  font-size: .8rem;
  color: var(--ink-muted);
  direction: ltr;
  text-align: left;
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: ui-monospace, Consolas, monospace;
}

.msg { margin-top: 12px; font-size: .88rem; padding: 10px 12px; border-radius: 10px; }
.msg.ok { background: #e8f3ec; color: var(--ok); border: 1px solid #cbe3d6; }
.msg.warn { background: #fbf1e0; color: var(--warn); border: 1px solid #eedcbd; }
.msg.bad { background: #fbeae8; color: var(--danger); border: 1px solid #efd0cc; }

/* ── الجداول ── */
table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .9rem; }
th, td { border: 1px solid var(--line); padding: 8px 10px; text-align: right; }
th { background: var(--paper-2); font-weight: 700; }

/* ── قائمة الفحص ── */
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 8px;
}
.checklist input { margin-top: 7px; accent-color: var(--gold); }
.checklist li.done { background: var(--gold-soft); }
.checklist li.done span { text-decoration: line-through; color: var(--ink-muted); }

/* ── التشخيص ── */
.diag-out { margin-top: 12px; }
.diag-out h4 { font-size: 1rem; margin: 12px 0 6px; }
.diag-out ul { margin: 0 0 10px; padding-inline-start: 20px; }
.diag-out li { margin-bottom: 6px; font-size: .9rem; }

/* ── التذييل ── */
.book-foot {
  padding: 30px 0 50px;
  color: var(--ink-muted);
  font-size: .82rem;
  text-align: center;
}
.book-foot a { color: var(--gold); }

/* ── الطباعة ── */
@media print {
  .book-top, .book-hero, .progress { display: none; }
  body { background: #fff; font-size: 11pt; }
  section { break-inside: avoid; border: 0; padding: 12pt 0; }
  .calc { break-inside: avoid; box-shadow: none; }
  .formula { display: block; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .book-top .inner { padding: 8px 12px; gap: 8px; }
  .book-top nav { width: 100%; margin-inline-start: 0; }
}

/* ── أزرار الحفظ والجدول ── */
.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.actions button {
  font-family: inherit;
  font-size: .85rem;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: var(--gold);
  color: #0a0a0a;
  cursor: pointer;
}
.actions button.ghost { background: transparent; color: var(--gold); }
.actions button:hover { opacity: .88; }

.saved-table { margin-top: 12px; font-size: .85rem; }
.saved-table td, .saved-table th { padding: 6px 8px; }
.saved-table button {
  background: none; border: 0; color: var(--danger);
  cursor: pointer; font-size: 1rem; line-height: 1;
}
