/* واجهة بنمط تطبيق جوال: عمود واحد، شريط علوي ثابت، وشريط خطوات سفلي عائم. */
@media screen {
  :root {
    --primary: #FF7171;
    --primary-press: #f25f5f;
    --on-primary: #4a1015;
    --accent: #9FA0FF;
    --accent-soft: #e9e9ff;
    --accent-ink: #34358a;
    --mint: #D5E8E6;
    --mint-press: #c3dddb;
    --mint-ink: #234b47;
    --cream: #FFF3E3;
    --surface: #fffdf9;
    --field: #ffffff;
    --line: #f0e1cc;
    --line-strong: #e3cfb4;
    --ink: #2b2d42;
    --muted: #7a7266;
    --danger-ink: #b3262b;
    --danger-soft: #ffe6e6;
    --radius: 20px;
    --radius-sm: 14px;
    --nav-space: calc(108px + env(safe-area-inset-bottom));
    --appbar: 68px;
    --appbar-bottom: calc(var(--appbar) + env(safe-area-inset-top));
    --formbar: 64px;
    color-scheme: light;
    font-family: Almarai, Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--cream);
    -webkit-text-size-adjust: 100%;
  }
  * { box-sizing: border-box; }
  [hidden] { display: none !important; }
  body { margin: 0; min-height: 100dvh; background: var(--cream); }
  body:has(dialog[open]) { overflow: hidden; }
  h1, h2, h3, p { margin: 0; }
  ul { margin: 0; padding-inline-start: 20px; }
  button, input, select, textarea, summary { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
  button, summary, label, select { touch-action: manipulation; }
  :is(button, input, select, textarea, summary, [tabindex], .file-button:has(:focus-visible)):focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
  }
  .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

  /* ── الهيكل ── */
  #app { max-width: 600px; margin: 0 auto; padding: 0 16px var(--nav-space); }
  .app-bar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: var(--appbar-bottom); margin: 0 -16px 8px; padding: env(safe-area-inset-top) 16px 0;
    background: color-mix(in srgb, var(--cream) 88%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
  .brand h1 { font-weight: 800; }
  .brand-icon {
    position: relative; display: grid; place-items: center; flex-shrink: 0;
    width: 44px; height: 44px; border-radius: 13px;
    background: var(--accent); color: #fff;
  }
  .brand h1 { font-size: 22px; line-height: 1.2; }
  .brand-subtitle { font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1.4; }
  /* نقطة حالة الحفظ على زاوية الشعار */
  .save-dot {
    position: absolute; bottom: -3px; inset-inline-start: -3px;
    width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid var(--cream);
    background: #4fb38f; transition: background .2s;
  }
  .save-dot[data-state="saving"] { background: #f2b54a; }
  .save-dot[data-state="error"] { background: var(--danger-ink); }

  /* ── العناوين ── */
  .page-heading { padding: 18px 2px 16px; }
  .eyebrow { font-size: 13px; font-weight: 700; color: var(--accent-ink); margin-bottom: 4px; }
  h2 { font-size: 24px; font-weight: 800; line-height: 1.35; }
  h3 { font-size: 18px; font-weight: 800; }
  .section-label { font-size: 14px; font-weight: 700; color: var(--muted); margin: 24px 2px 10px; }

  /* ── البطاقات ── */
  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 16px;
    box-shadow: 0 1px 2px #7a5a2e0d, 0 6px 20px #7a5a2e0a;
  }
  .card + .card { margin-top: 16px; }

  /* ── الأزرار ── */
  button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 52px; padding: 12px 18px; margin: 0;
    border: 1.5px solid transparent; border-radius: var(--radius-sm);
    background: var(--mint); color: var(--mint-ink);
    font-size: 16px; font-weight: 700; line-height: 1.4; text-align: center;
    cursor: pointer; transition: background .15s, transform .1s, box-shadow .15s;
  }
  button:active:not(:disabled) { transform: scale(.98); }
  @media (hover: hover) { button:hover:not(:disabled) { background: var(--mint-press); } }
  button:disabled { opacity: .4; cursor: default; }
  button.primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 14px #ff717140; }
  @media (hover: hover) { button.primary:hover:not(:disabled) { background: var(--primary-press); } }
  button.danger { background: transparent; border-color: var(--primary); color: var(--danger-ink); }
  @media (hover: hover) { button.danger:hover:not(:disabled) { background: var(--danger-soft); } }
  button.small { min-height: 44px; padding: 8px 14px; font-size: 14px; border-radius: 12px; }
  /* زر ثانوي بحدود موف متقطعة */
  button.outline { background: transparent; border: 1.5px dashed var(--accent); color: var(--accent-ink); }
  @media (hover: hover) { button.outline:hover:not(:disabled) { background: var(--accent-soft); } }
  button.wide { width: 100%; margin-top: 10px; }
  .icon-button {
    flex-shrink: 0; width: 44px; min-height: 44px; padding: 0;
    border-radius: 50%; background: var(--surface); border-color: var(--line);
    font-size: 24px; font-weight: 400;
  }
  .actions { display: grid; gap: 10px; margin-top: 20px; }
  .actions button { width: 100%; }
  .button-row { display: flex; flex-wrap: wrap; gap: 8px; }
  .button-row > button { flex: 1 1 auto; }

  /* ── الحقول ── */
  .field { margin: 0 0 16px; min-width: 0; }
  .field label { display: grid; gap: 6px; }
  .field-label { font-size: 14px; font-weight: 700; color: #4b4a55; }
  input:not([type="checkbox"]), select, textarea {
    display: block; width: 100%; min-width: 0; min-height: 52px; margin: 0;
    padding: 12px 14px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--field); color: var(--ink);
    font-size: 16px; font-weight: 400;
    transition: border-color .15s, box-shadow .15s;
  }
  :is(input, select, textarea):focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); outline: none; }
  select {
    appearance: none; -webkit-appearance: none;
    padding-inline-end: 42px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5l6 6 6-6' fill='none' stroke='%237a7266' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: left 16px center;
  }
  textarea { resize: vertical; }
  textarea.qpb-quran { font-size: 22px; line-height: 2; padding-block: 8px; }
  input[type="number"] { text-align: center; }

  /* مفتاح تبديل بدل مربع الاختيار */
  .check-field label {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 56px; padding: 10px 14px; border-radius: var(--radius-sm);
    background: var(--cream); cursor: pointer;
  }
  .check-field .field-label { font-size: 15px; color: var(--ink); }
  input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0;
    width: 52px; height: 32px; margin: 0; border-radius: 99px;
    background: #e3d8c8; cursor: pointer; transition: background .2s;
  }
  input[type="checkbox"]::before {
    content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
    width: 26px; height: 26px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 4px #0000002e; transition: transform .2s;
  }
  input[type="checkbox"]:checked { background: var(--accent); }
  input[type="checkbox"]:checked::before { transform: translateX(-20px); }
  [dir="ltr"] input[type="checkbox"]:checked::before { transform: translateX(20px); }

  /* ── الخطوة 1 ── */
  .basics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; padding-bottom: 2px; }
  .basics .wide, .basics > .field:last-child:nth-child(even) { grid-column: 1 / -1; }

  /* ── الخطوة 2 ── */
  .form-switcher { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
  .chips {
    flex: 1; display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px;
    scrollbar-width: none; scroll-snap-type: x proximity;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex-shrink: 0; min-height: 44px; padding: 8px 16px; border-radius: 99px;
    background: var(--surface); border-color: var(--line-strong); color: var(--ink);
    font-size: 14px; scroll-snap-align: center;
  }
  .chip[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; opacity: 1; }
  /* شريط النموذج ثابت تحت الشريط العلوي، وشريط المقطع ثابت تحته داخل بطاقته فقط. */
  .sticky-bar { position: sticky; z-index: 4; display: flex; align-items: center; gap: 6px; background: var(--surface); }
  .form-bar {
    top: var(--appbar-bottom); height: var(--formbar); padding: 0 12px 0 10px;
    border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 6px 18px #7a5a2e14;
  }
  .form-bar h3 { flex: 1; min-width: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline-start: 4px; }
  select.compact {
    width: auto; flex-shrink: 0; min-height: 44px; padding: 6px 8px; padding-inline-end: 26px;
    font-size: 13px; font-weight: 700; border-radius: 12px; background-position: left 8px center;
    background-color: var(--cream); border-color: transparent;
  }
  .icon-button svg { display: block; }
  .icon-button.delete { width: 42px; border-radius: 12px; background: var(--danger-soft); border-color: transparent; color: var(--danger-ink); }
  @media (hover: hover) { .icon-button.delete:hover:not(:disabled) { background: #ffd4d4; } }
  .passage { margin-top: 16px; padding-top: 0; min-width: 0; scroll-margin-top: calc(var(--appbar-bottom) + var(--formbar) + 12px); }
  .passage-bar {
    top: calc(var(--appbar-bottom) + var(--formbar)); z-index: 3;
    margin: 0 -16px; padding: 10px 12px 10px 10px; min-height: 64px;
    border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  }
  .passage.is-collapsed { padding-bottom: 0; }
  .passage.is-collapsed .passage-bar { border-bottom-color: transparent; border-radius: var(--radius); }
  .passage-toggle {
    flex: 1; min-width: 0; min-height: 44px; justify-content: flex-start; gap: 6px; padding: 4px;
    background: transparent; color: var(--ink); text-align: start;
  }
  @media (hover: hover) { .passage-toggle:hover:not(:disabled) { background: var(--cream); } }
  .passage-toggle .icon { flex-shrink: 0; width: 20px; color: var(--muted); transition: transform .2s; }
  .passage.is-collapsed .passage-toggle .icon { transform: rotate(90deg); }
  .passage-title { display: grid; min-width: 0; line-height: 1.35; }
  .passage-title strong { font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .passage.is-support .passage-title strong { color: var(--accent-ink); }
  .passage-range { font-size: 12px; font-weight: 700; color: var(--muted); }
  .passage-range:empty { display: none; }
  .passage-body { padding-top: 16px; }
  .passage-body > .field { margin-bottom: 14px; }
  .group { padding: 14px 0; border-top: 1px dashed var(--line-strong); }
  .group .field { margin-bottom: 10px; }
  .group > .field, .group > .with-action { margin-top: 14px; }
  .group-title { font-size: 15px; font-weight: 800; margin-bottom: 10px; }
  .pair { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 10px; }
  .with-action { display: flex; align-items: flex-end; gap: 8px; }
  .with-action > .field { flex: 1; margin-bottom: 0; }
  .with-action > .icon-button { width: 52px; min-height: 52px; border-radius: var(--radius-sm); background: var(--mint); border-color: transparent; color: var(--mint-ink); }
  button.mushaf { width: 100%; background: var(--accent-soft); color: var(--accent-ink); min-height: 48px; font-size: 15px; }
  @media (hover: hover) { button.mushaf:hover:not(:disabled) { background: #dcdcff; } }
  .inline-field label { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 14px; }
  .inline-field .field-label { font-size: 15px; color: var(--ink); }
  input.readonly { background: var(--cream); border-color: transparent; font-weight: 700; cursor: default; }
  input.readonly:focus { box-shadow: none; border-color: transparent; }
  .group:last-child { padding-bottom: 0; }

  /* مقبض السحب يظهر فقط والبطاقة مطوية. */
  .drag-handle { display: none; }
  .passage.is-collapsed .drag-handle {
    display: grid; place-items: center; flex-shrink: 0; width: 28px; min-height: 44px; border-radius: 10px;
    color: var(--muted); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  }
  .passage.is-collapsed .drag-handle:hover { background: var(--cream); }
  .is-sorting { user-select: none; -webkit-user-select: none; }
  .is-sorting .drag-handle { cursor: grabbing; }
  .passage.is-dragging { position: relative; z-index: 6; box-shadow: 0 18px 40px #4a361a40; border-color: var(--accent); }
  .passage.is-dragging .passage-bar { position: static; }

  /* ── الخطوة 3 ── */
  .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat {
    display: grid; gap: 2px; padding: 16px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--line);
  }
  .stat strong { font-size: 30px; font-weight: 800; line-height: 1.2; color: var(--accent-ink); }
  .stat span { font-size: 14px; color: var(--muted); }
  .stat:nth-child(2) strong { color: var(--mint-ink); }
  .notice { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--mint); color: var(--mint-ink); font-size: 15px; }
  .notice-title { font-weight: 800; margin-bottom: 6px; }
  .preview {
    overflow-x: auto; background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: 0 6px 20px #7a5a2e12;
    -webkit-overflow-scrolling: touch;
  }
  .preview .qpb-doc { width: 186mm; padding: 6mm; min-height: 100mm; }

  /* ── الرسائل ── */
  .alert:not(:empty) {
    margin: 12px 0 4px; padding: 14px 16px; border-radius: var(--radius-sm);
    background: var(--danger-soft); border: 1px solid #ffc4c4; color: #6d1d20; font-size: 15px;
  }
  .alert-title { font-weight: 800; margin-bottom: 8px; }
  .alert li { margin-bottom: 8px; }
  .alert li > span { display: block; margin-bottom: 6px; }
  .alert button { background: #fff; color: #6d1d20; }

  /* ── قائمة الحفظ ── */
  .menu { position: relative; flex-shrink: 0; }
  .menu > summary {
    display: grid; place-items: center; width: 44px; height: 44px; list-style: none;
    border-radius: 50%; background: var(--surface); border: 1px solid var(--line);
    font-size: 24px; font-weight: 800; line-height: 1; cursor: pointer;
  }
  .menu > summary::-webkit-details-marker { display: none; }
  .menu[open] > summary { background: var(--accent-soft); border-color: var(--accent); }
  .menu-sheet {
    position: absolute; top: calc(100% + 10px); inset-inline-end: 0; z-index: 20;
    width: min(320px, calc(100vw - 32px)); display: grid; gap: 8px; padding: 14px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 16px 48px #4a361a2e;
  }
  .menu-title { font-size: 14px; font-weight: 800; color: var(--muted); padding: 0 4px 4px; }
  .menu-sheet button, .file-button { width: 100%; justify-content: flex-start; text-align: start; font-size: 15px; }
  .file-button {
    position: relative; display: flex; align-items: center; min-height: 52px; padding: 12px 18px;
    border-radius: var(--radius-sm); background: var(--mint); color: var(--mint-ink); font-weight: 700; cursor: pointer;
  }
  .toolbar { border: 0; padding: 8px 0 0; margin: 4px 0 0; min-width: 0; border-top: 1px solid var(--line); }

  /* ── شريط الخطوات السفلي ── */
  .editor { margin: 0; padding: 0; border: 0; min-width: 0; }
  .steps {
    position: fixed; z-index: 10; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    width: min(568px, calc(100% - 24px));
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
    box-shadow: 0 10px 40px #4a361a26;
  }
  .steps button {
    flex-direction: column; gap: 4px; min-height: 64px; padding: 6px 4px; border-radius: 18px;
    background: transparent; color: var(--muted); font-size: 13px;
  }
  .steps button:disabled { opacity: 1; }
  .step-number {
    display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
    background: var(--cream); color: var(--muted); font-size: 14px; font-weight: 800;
  }
  .steps [aria-current="step"] { background: var(--accent-soft); color: var(--accent-ink); }
  .steps [aria-current="step"] .step-number { background: var(--accent); color: #fff; }

  /* ── منتقي المصحف (ورقة سفلية) ── */
  dialog.sheet {
    width: 100%; max-width: 600px; max-height: 92dvh; margin: auto auto 0; padding: 0;
    border: 0; border-radius: 26px 26px 0 0; background: var(--surface); color: var(--ink);
    overflow-y: auto; overscroll-behavior: contain;
    box-shadow: 0 -10px 50px #2b2d4233;
  }
  dialog.sheet[open] { animation: sheet-up .25s ease-out; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }
  dialog::backdrop { background: #2b2d4266; backdrop-filter: blur(3px); }
  .sheet-head {
    position: sticky; top: 0; z-index: 1;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 22px 16px 12px; background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .sheet-head::before {
    content: ""; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 5px; border-radius: 99px; background: var(--line-strong);
  }
  .sheet-head h2 { flex: 1; font-size: 19px; }
  .search-toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
  .sheet-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
  .sheet-body .field { margin-bottom: 0; }
  .browse { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
  .page-field { display: grid; gap: 6px; }
  .stepper { display: flex; align-items: center; gap: 6px; }
  .stepper input { width: 70px; padding-inline: 6px; }
  .stepper .icon-button { width: 44px; min-height: 52px; border-radius: 12px; }
  .search-panel { display: flex; gap: 8px; }
  .search-panel:not([hidden]) { animation: slide-down .22s ease-out; }
  .search-panel input { flex: 1; }
  .search-panel button { flex-shrink: 0; }
  @keyframes slide-down { from { transform: translateY(-12px); opacity: 0; } }
  .picker-status { margin: 14px 2px 10px; font-size: 14px; color: var(--muted); }
  .results > p { margin: 0 0 8px; }
  button.verse {
    display: grid; justify-content: stretch; justify-items: start; gap: 4px; width: 100%; min-height: 56px;
    padding: 10px 14px; text-align: start; font-weight: 400;
    background: var(--field); border-color: var(--line); color: var(--ink);
  }
  @media (hover: hover) { button.verse:hover:not(:disabled) { background: var(--cream); } }
  button.verse.is-selected { background: var(--accent-soft); border-color: var(--accent); }
  button.verse .qpb-quran { font-size: 22px; line-height: 2.1; }
  button.verse small { font-size: 13px; color: var(--muted); font-weight: 700; }
  button.sura-result { background: var(--mint); border-color: transparent; font-weight: 700; color: var(--mint-ink); }
  .words { display: flex; flex-wrap: wrap; gap: 8px; }
  button.word {
    min-height: 52px; padding: 4px 14px; font-size: 24px; font-weight: 400; line-height: 2;
    background: var(--field); border-color: var(--line-strong); color: var(--ink);
  }
  @media (hover: hover) { button.word:hover { background: var(--accent-soft); border-color: var(--accent); } }
  button.word.is-selected { background: var(--accent-soft); border-color: var(--accent); }

  /* ── شاشة البدء والخطأ ── */
  #app:has(> #boot-message), .splash {
    display: grid; place-content: center; justify-items: center; gap: 14px;
    min-height: 100dvh; text-align: center; padding-bottom: 0;
  }
  .splash .brand-icon, #app:has(> #boot-message)::before { width: 64px; height: 64px; border-radius: 20px; }
  .splash .brand-mark { width: 42px; height: 42px; }
  #app:has(> #boot-message)::before { content: ""; background: url("../icons/icon.svg") center / cover; }
  #app > h1, .splash h1 { font-size: 22px; font-weight: 800; }
  #boot-message, .splash p { color: var(--muted); max-width: 320px; }
  .splash button { margin-top: 8px; min-width: 200px; }

  @media (min-width: 600px) {
    .app-bar { margin-inline: 0; border-radius: 0 0 var(--radius) var(--radius); border: 1px solid var(--line); border-top: 0; }
    .card { padding: 22px 20px; }
    .passage { padding-top: 0; }
    .passage-bar { margin: 0 -20px; }
    dialog.sheet { margin: auto; border-radius: 26px; max-height: 86dvh; }
    .sheet-head::before { display: none; }
  }
  @media (max-width: 359px) {
    #app { padding-inline: 12px; }
    .app-bar { margin-inline: -12px; padding-inline: 12px; }
    .basics { grid-template-columns: 1fr; }
    .browse { grid-template-columns: 1fr; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before { transition: none !important; animation: none !important; }
  }
}
/* أثناء الطباعة يُخفى التطبيق كاملًا عبر print.css. */
