/* الخطوط مستضافة محلياً؛ نطاقات unicode-range تتيح للمتصفح جلب الملف المناسب لكل مقطع فقط */
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Amiri-400-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC7, U+10EC9-10EEE, U+10EF0-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Amiri-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Amiri-700-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC7, U+10EC9-10EEE, U+10EF0-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Amiri-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Aref Ruqaa';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/ArefRuqaa-400-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC7, U+10EC9-10EEE, U+10EF0-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Aref Ruqaa';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/ArefRuqaa-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Aref Ruqaa';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/ArefRuqaa-700-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC7, U+10EC9-10EEE, U+10EF0-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Aref Ruqaa';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/ArefRuqaa-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* ورق رمادي حجري بدل الكريمي الدافئ لتفريق الهوية عن قوالب الذكاء الاصطناعي الشائعة */
  --bg: #e1e0d9;
  --bg-lift: #e8e7e0;
  --ink: #1a1b16;
  --ink-soft: #52534a;
  --ink-faint: #8a8b80;
  --rule: #c6c5be;
  --accent: #6b2525;
  --accent-wash: #ede0da;
  --font-display: 'Aref Ruqaa', 'Amiri', serif;
  --font-body: 'Amiri', 'Noto Naskh Arabic', serif;
  --max-width: 640px;
}

/* لمس الهاتف: بلا تظليل النظام الأزرق فوق الأزرار */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

button:active { opacity: 0.55; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* حبيبات ورق خفيفة جداً */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ظهور الصفحة: يضيف app.js صنف is-font-loading قبل الرسم، ثم يبدّله إلى is-font-ready بعد جهوزية الخطوط */
.is-font-loading .ledger { visibility: hidden; }

.is-font-ready .ledger {
  visibility: visible;
  animation: appear 0.35s ease-out;
}

.ledger {
  position: relative;
  z-index: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 3rem 1.5rem 6rem;
}

/* الترويسة */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.5rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
}

.search { flex-shrink: 0; }

.search input {
  width: 110px;
  padding: 0.3rem 0;
  border: none;
  border-bottom: 1px solid transparent;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  transition: border-color 0.3s, width 0.3s;
}

.search input::placeholder { color: var(--ink-faint); }

.search input:focus {
  outline: none;
  width: 200px;
  border-bottom-color: var(--accent);
}

/* المُحرِّر */
.composer {
  position: relative;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2.5rem;
  background: var(--bg-lift);
}

.composer::before {
  content: '';
  position: absolute;
  inset-block: 1rem;
  inset-inline-start: 0;
  width: 3px;
  background: var(--accent);
  transition: inset-block 0.35s ease;
}

.composer:focus-within::before { inset-block: 0.35rem; }

.composer input[type="text"] {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  padding: 0.25rem 0;
  margin-bottom: 0.25rem;
}

.composer textarea {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink-soft);
  padding: 0.25rem 0;
  min-height: 60px;
  resize: vertical;
  line-height: 1.85;
}

.composer input:focus,
.composer textarea:focus { outline: none; }

.composer input::placeholder,
.composer textarea::placeholder { color: var(--ink-faint); }

.composer-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.75rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--rule);
}

.btn-add {
  background: transparent;
  border: none;
  padding: 0.35rem 0;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  border-bottom: 1px solid var(--accent);
  transition: opacity 0.2s;
}

.btn-add:hover { opacity: 0.7; }

/* القيود */
.entries { display: flex; flex-direction: column; }

.entry {
  position: relative;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.entry:last-child { border-bottom: none; }

.entry-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--ink);
  margin-bottom: 0.35rem;
  /* يحجز مساحة أزرار الإجراءات المطلقة الموضع (32px + الفجوة) حتى لا تتراكب مع العنوان */
  padding-inline-end: 5rem;
}

.entry-body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.85;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

.entry-meta { margin-top: 0.75rem; }

.entry-date {
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.entry-actions {
  position: absolute;
  inset-block-start: 1.35rem;
  inset-inline-end: 0;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.entry:hover .entry-actions,
.entry:focus-within .entry-actions { opacity: 1; }

.entry-actions button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-size: 1rem;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}

.entry-actions button:hover {
  background: var(--accent-wash);
  color: var(--accent);
}

/* حالة التعديل */
.entry-form { display: flex; flex-direction: column; gap: 0.5rem; }

.entry-form input,
.entry-form textarea {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  font-family: var(--font-body);
  padding: 0.4rem 0;
  color: var(--ink);
  transition: border-color 0.2s;
}

.entry-form input { font-size: 1.1rem; font-weight: 700; }

.entry-form textarea {
  font-size: 1rem;
  line-height: 1.85;
  min-height: 80px;
  resize: vertical;
  color: var(--ink-soft);
}

.entry-form input:focus,
.entry-form textarea:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.entry-form-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  padding-top: 0.5rem;
}

.btn-text {
  background: transparent;
  border: none;
  padding: 0.25rem 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-text.save,
.btn-text.danger { color: var(--accent); border-bottom: 1px solid var(--accent); }
.btn-text.cancel { color: var(--ink-faint); border-bottom: 1px solid var(--ink-faint); }
.btn-text:hover { opacity: 0.7; }

/* حوار تأكيد الحذف */
/* توسيط الحوارين: إعادة الضبط العامة تلغي margin auto الأصلي لعناصر dialog */
.confirm,
.popup {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
}

.confirm {
  border: 1px solid var(--rule);
  background: var(--bg-lift);
  color: var(--ink);
  font-family: var(--font-body);
  padding: 1.25rem 1.5rem;
  width: min(85vw, 320px);
}

.confirm::backdrop {
  background: rgba(26, 27, 22, 0.4);
}

.confirm[open] { animation: rise 0.25s ease-out; }

.confirm-text {
  line-height: 1.7;
  margin-bottom: 1rem;
}

.confirm-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

/* نافذة الترحيب: تفتحها app.js في أول زيارة، وتُسجَّل رؤيتها عند أي إغلاق */
.popup {
  border: 1px solid var(--rule);
  background: var(--bg-lift);
  color: var(--ink);
  font-family: var(--font-body);
  padding: 1.75rem 1.75rem 1.25rem;
  width: min(85vw, 360px);
  animation: rise 0.25s ease-out;
}

.popup::backdrop { background: rgba(26, 27, 22, 0.4); }

.popup-wordmark {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 400;
  line-height: 1;
}

.popup-title {
  font-weight: 700;
  font-size: 1.15rem;
  margin-top: 1rem;
}

.popup-text {
  color: var(--ink-soft);
  margin-top: 0.35rem;
  font-size: 1rem;
}

/* قيود: ثلاث نقاط بفواصل قصيرة كخطوط الدفتر */
.popup-points {
  list-style: none;
  margin-top: 1rem;
}

.popup-points li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
}

.popup-points li:last-child { border-bottom: none; }

.popup-points li::before {
  content: '';
  flex-shrink: 0;
  width: 0.4rem;
  height: 1px;
  background: var(--accent);
  transform: translateY(-0.3rem);
}

.popup-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
}

.btn-start {
  background: transparent;
  border: none;
  padding: 0.35rem 0;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  border-bottom: 1px solid var(--accent);
}

.btn-quiet {
  background: transparent;
  border: none;
  padding: 0.35rem 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--ink-faint);
  cursor: pointer;
  border-bottom: 1px solid var(--ink-faint);
}

.btn-start:hover, .btn-quiet:hover { opacity: 0.7; }

/* تذييل المؤلف: سطر باهت صغير، والروابط بلا زخرفة حتى لا تنافس زر البدء */
.popup-footer {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-top: 0.9rem;
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.popup-link {
  color: var(--ink-faint);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: color 0.2s, border-color 0.2s;
}

.popup-link:hover {
  color: var(--ink-soft);
  border-bottom-color: var(--ink-faint);
}

/* الحالة الفارغة */
.empty {
  padding: 4rem 0;
  text-align: center;
  color: var(--ink-faint);
}

.empty-mark {
  display: inline-block;
  width: 1px;
  height: 2.5rem;
  background: var(--rule);
  margin-bottom: 1.25rem;
}

.empty p { font-size: 1rem; }

/* الحركة */
@keyframes appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.entry.is-new { animation: rise 0.4s ease-out; }
.entry.is-leaving { animation: fade 0.2s ease-in forwards; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* لون تحديد النص من هوية دفتر بدل الأزرق الافتراضي */
::selection {
  background: var(--accent);
  color: var(--bg-lift);
}

/* تذييل الصفحة: إصدار بسيط ورابط GitHub بهوية هادئة */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.site-version {
  letter-spacing: 0.02em;
}

.site-github {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  text-decoration: none;
  transition: color 0.2s, opacity 0.2s;
}

.site-github:hover {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 520px) {
  .ledger { padding: 2rem 1rem 4rem; }
  .wordmark { font-size: 2rem; }
  .masthead { margin-bottom: 1.75rem; }
  .composer { padding: 1rem 1.1rem; }
  .entry-title {
    padding-inline-end: 4.5rem; /* نفس حجز مساحة الأزرار، بمقاس مضغوط للجوال */
  }
  .entry-actions { opacity: 1; }
  .search input { width: 80px; }
  .search input:focus { width: 130px; }
}
