/* قوائم التلاوة — calm mushaf-inspired palette, RTL-first via logical props. */

:root {
  --bg: #f5f1e6;
  --panel: #fffdf6;
  --panel-2: #faf6ea;
  --ink: #26221a;
  --muted: #7d7563;
  --line: #e4dcc8;
  --accent: #0e6b4f;
  --accent-ink: #0a5740;
  --gold: #b08a2e;
  --danger: #a63a3a;
  --shadow: 0 1px 3px rgba(60, 50, 20, 0.08), 0 8px 24px rgba(60, 50, 20, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* the layout never scrolls sideways; this also suppresses a classic-
     scrollbar artifact that inflates scrollWidth on RTL pages */
  overflow-x: clip;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Geeza Pro", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

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

.muted { color: var(--muted); font-size: 0.85em; }

/* ------------------------------------------------------------- layout */

#app {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
}

#sidebar {
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#menu-btn { display: none; font-size: 1.1rem; }

#sidebar-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

#menu-backdrop { display: none; }

.brand h1 { margin: 0; font-size: 1.35rem; }
.brand h1 a { color: var(--accent-ink); text-decoration: none; }
.brand p { margin: 2px 0 0; }

/* keep the sidebar's bottom (user chip / logout) clear of the fixed player */
@media (min-width: 901px) {
  body.has-player #sidebar { padding-block-end: 118px; }
}

#main {
  padding: 24px clamp(16px, 4vw, 44px) 140px;
  max-width: 1100px;
  width: 100%;
  margin-inline: auto;
}

/* ------------------------------------------------------------ sidebar */

#new-list-form {
  display: flex;
  gap: 8px;
}

#new-list-form input {
  flex: 1;
  min-width: 0;
}

#lists-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--ink);
}

.nav-item:hover { background: var(--panel-2); }

.nav-item.active {
  background: var(--accent);
  color: #fff;
}

.nav-item.active .nav-count { background: rgba(255, 255, 255, 0.25); color: #fff; }

.nav-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-count {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0 8px;
  min-width: 26px;
  text-align: center;
}

.nav-empty { color: var(--muted); text-align: center; margin-top: 24px; }

/* ------------------------------------------------------------- inputs */

input, select {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
}

input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) { background: var(--panel-2); border-color: #d5cbb0; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #f9ecec; border-color: #e3bcbc; }

.btn-icon {
  padding: 6px 10px;
  line-height: 1;
}

.btn-icon svg { display: block; margin-inline: auto; }

/* -------------------------------------------------------------- cards */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-block-end: 20px;
}

.card h3 { margin: 0 0 12px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block-end: 8px;
}

.card-header h3 { margin: 0; }

.home h2 { margin-top: 0; color: var(--accent-ink); }
.home-features { padding-inline-start: 20px; }
.home-features li { margin-block: 4px; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-block-end: 16px;
}

.list-title { margin: 0; color: var(--accent-ink); }

.list-header-actions { position: relative; display: flex; align-items: center; gap: 8px; }

.list-actions { display: flex; gap: 8px; }

.list-menu-btn { display: none; font-size: 1.15rem; }

.rename-input { font-size: 1.3rem; font-weight: 600; }

/* ----------------------------------------------------------- auth view */

body.auth-mode #sidebar,
body.auth-mode #player-bar,
body.auth-mode #live-panel { display: none; }

body.auth-mode #app { grid-template-columns: 1fr; }

.auth-card {
  max-width: 400px;
  margin: 10vh auto 0;
  text-align: center;
}

.auth-card h2 { margin: 0 0 4px; color: var(--accent-ink); }
.auth-card > .muted { margin-top: 0; }

.auth-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  margin-block: 18px 14px;
}

.auth-tab {
  flex: 1;
  border: 0;
  background: var(--panel-2);
  padding: 10px;
  font: inherit;
  cursor: pointer;
  color: var(--muted);
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-error {
  color: var(--danger);
  min-height: 1.3em;
  margin: 0;
  font-size: 0.9rem;
}

.btn-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding-block: 10px;
}

.btn-google { background: #fff; text-decoration: none; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  margin-block: 14px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

#user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#user-chip:not(:empty) {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 10px;
}

#user-chip .user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

/* ----------------------------------------------------------- add form */

.add-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 420px);
  gap: 24px;
  align-items: start;
}

.add-form { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.85rem; color: var(--muted); }
.field select { width: 100%; }

.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* numeric steppers for the ayah range — LTR internals so − / + never flip */
.stepper {
  display: flex;
  direction: ltr;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: #fff;
}

.stepper .step-btn {
  border: 0;
  border-radius: 0;
  min-width: 40px;
  font-size: 1.05rem;
  background: var(--panel-2);
}

.stepper-input {
  border: 0;
  border-radius: 0;
  width: 100%;
  min-width: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.range-hint { color: var(--muted); font-size: 0.85rem; }

.chip {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-ink); }
.chip:disabled { opacity: 0.45; cursor: default; }

.tap-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.form-actions { display: flex; gap: 8px; margin-block-start: 4px; }
.form-status { min-height: 1.2em; margin: 0; }

/* -------------------------------------------------------------- mushaf */

.mushaf {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.mushaf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-block-end: 8px;
}

.mushaf-label { font-size: 0.85rem; color: var(--muted); }

.mushaf-page {
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mushaf-page.loading { opacity: 0.6; }

.mushaf-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.mushaf-empty {
  color: var(--muted);
  text-align: center;
  margin: 24px 8px;
}

.ayah-hl { fill: rgba(176, 138, 46, 0.28); }

.ayah-hl-focus {
  fill: rgba(14, 107, 79, 0.32);
  stroke: rgba(14, 107, 79, 0.55);
  stroke-width: 0.6;
}

/* invisible per-ayah tap targets layered on top of the page */
.ayah-hit {
  fill: transparent;
  pointer-events: all;
  cursor: pointer;
}

.ayah-hit:hover { fill: rgba(14, 107, 79, 0.10); }

/* ------------------------------------------------------------ skeletons */

.skeleton {
  background: linear-gradient(100deg, #ebe4d2 40%, #f8f3e7 50%, #ebe4d2 60%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
  border-radius: 9px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.skel-title { height: 34px; width: min(40%, 220px); }
.skel-block { height: 46px; margin-block: 10px; }
.skel-row { height: 54px; margin-block: 8px; }
.skel-nav { height: 40px; margin-block: 4px; }
.mushaf-skeleton { width: 100%; height: 280px; border-radius: 8px; }

/* --------------------------------------------------------------- items */

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.items-empty { color: var(--muted); text-align: center; padding: 20px 0; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}

.item.dragging { opacity: 0.5; }
.item.drop-target { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.item.playing {
  border-color: var(--accent);
  background: #f0f7f4;
}

.item.playing .item-idx { color: var(--accent); font-weight: 700; }

.item-handle { cursor: grab; color: var(--muted); user-select: none; }

.item-idx {
  color: var(--muted);
  min-width: 1.6em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: pointer;
}

.item-main:hover .item-title { color: var(--accent-ink); }

.item-title { font-weight: 600; }
.item-range { font-weight: 400; color: var(--gold); }
.item-reciter { font-size: 0.85rem; color: var(--muted); }

.item-actions { display: flex; gap: 4px; align-items: center; }
.item-actions .btn-icon { text-decoration: none; }

/* --------------------------------------------------------------- player */

#player-bar {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  background: rgba(255, 253, 246, 0.96);
  backdrop-filter: blur(6px);
  border-block-start: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(60, 50, 20, 0.08);
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr) auto minmax(160px, 1.2fr);
  align-items: center;
  gap: 14px;
  padding: 10px clamp(12px, 3vw, 28px);
  /* must come after the shorthand or the home-indicator inset is lost */
  padding-block-end: calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
}

#pb-info { min-width: 0; }
#pb-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pb-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Media controls follow the universal LTR convention: ⏮ ▶ ⏭ order, seek bar
   filling left→right, and "elapsed / total" reading correctly (bidi-safe). */
#pb-controls { display: flex; gap: 6px; align-items: center; direction: ltr; }

#pb-seek { display: flex; align-items: center; gap: 10px; direction: ltr; }
#pb-progress { flex: 1; accent-color: var(--accent); }
#pb-time { font-variant-numeric: tabular-nums; white-space: nowrap; }

#live-panel {
  position: fixed;
  inset-inline-end: clamp(12px, 3vw, 28px);
  inset-block-end: calc(78px + env(safe-area-inset-bottom));
  width: min(400px, calc(100vw - 24px));
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  z-index: 19;
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

#live-panel .mushaf { background: var(--panel); }

/* --------------------------------------------------------------- toasts */

#toasts {
  position: fixed;
  inset-block-start: 16px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}

[dir="rtl"] #toasts { transform: translateX(50%); }

.toast {
  background: var(--ink);
  color: #fff;
  border-radius: 9px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  opacity: 0.96;
  transition: opacity 0.3s;
}

.toast-error { background: var(--danger); }
.toast-success { background: var(--accent); }
.toast-out { opacity: 0; }

/* -------------------------------------------------------------- dialog */

.confirm {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  max-width: 380px;
}

.confirm::backdrop { background: rgba(40, 34, 20, 0.35); }
.confirm p { margin-top: 0; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }

  /* compact top bar; everything else lives in the hamburger drawer */
  #sidebar {
    position: sticky;
    top: 0;
    height: auto;
    padding: 10px 16px;
    border-inline-end: 0;
    border-block-end: 1px solid var(--line);
    overflow: visible;
    z-index: 30;
  }

  .brand h1 { font-size: 1.15rem; }
  .brand p { display: none; }

  #menu-btn { display: inline-flex; align-items: center; justify-content: center; }

  #sidebar-body { display: none; }

  body.menu-open #sidebar-body {
    display: flex;
    position: fixed;
    inset-inline: 0;
    top: 63px;
    max-height: calc(100vh - 63px);
    overflow-y: auto;
    background: var(--panel);
    border-block-end: 1px solid var(--line);
    box-shadow: 0 14px 30px rgba(60, 50, 20, 0.18);
    padding: 16px;
    z-index: 29;
  }

  body.menu-open #menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    top: 63px;
    background: rgba(38, 34, 26, 0.3);
    z-index: 28;
  }

  #lists-nav { flex-direction: column; }

  /* list rename/delete collapse behind the ⋮ button */
  .list-menu-btn { display: inline-flex; align-items: center; justify-content: center; }

  .list-actions { display: none; }

  .list-actions.open {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + 6px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 8px;
    min-width: 170px;
    z-index: 15;
  }

  .list-actions.open .btn { width: 100%; text-align: center; }

  .add-grid { grid-template-columns: 1fr; }

  #main { padding-block-end: 190px; }

  #player-bar {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "mushaf info controls"
      "seek seek seek";
  }

  #pb-mushaf { grid-area: mushaf; }
  #pb-info { grid-area: info; }
  #pb-controls { grid-area: controls; }
  #pb-seek { grid-area: seek; }

  /* the player bar is two rows tall here — keep the panel above it */
  #live-panel { inset-block-end: calc(136px + env(safe-area-inset-bottom)); }
}

/* narrow screens: let item actions wrap to their own row instead of
   squeezing the title into single-word lines */
@media (max-width: 600px) {
  .item { flex-wrap: wrap; }
  .item-main { flex: 1 1 55%; }
  .item-actions {
    flex-basis: 100%;
    justify-content: flex-end;
    padding-inline-start: 40px;
  }
}

/* touch ergonomics: comfortable targets, no iOS focus-zoom (16px inputs) */
@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .btn-icon { min-width: 42px; min-height: 42px; }
  input, select { min-height: 42px; font-size: 16px; }
  .item-main { min-height: 44px; justify-content: center; }
}
