/* Mujaz viewer: one hand-written style file (the page header allows no inline styles). */

:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #17212e;
  --muted: #5a6676;
  --line: #e2e7ee;
  --line-strong: #cbd3de;
  --control-line: #848fa0;
  --accent: #003468;
  --accent-text: #0b4f8a;
  --accent-soft: #e6eef7;
  --focus: #2f7fd0;
  --hover: #f1f5fa;
  --new-bg: #dcebfb; --new-fg: #0b4f8a;
  --seen-bg: #fbefc7; --seen-fg: #6b5000;
  --done-bg: #d9f1de; --done-fg: #1c6a2c;
  --problem-bg: #fbe3e1; --problem-fg: #8f2a22;
  --idea-bg: #e9e6fa; --idea-fg: #4a3c99;
  --warn-bg: #fdecc8; --warn-fg: #6b3d00; --warn-line: #e6bd6a;
  --error: #b3261e;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 32, 56, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1b2330;
    --text: #e4e9f0;
    --muted: #9aa6b5;
    --line: #263140;
    --line-strong: #344256;
    --control-line: #5f7088;
    --accent: #7fb2e5;
    --accent-text: #8fbdec;
    --accent-soft: #1d2d42;
    --focus: #7fb2e5;
    --hover: #1d2633;
    --new-bg: #17314d; --new-fg: #a9cdf3;
    --seen-bg: #3a3014; --seen-fg: #f0d27a;
    --done-bg: #173621; --done-fg: #9edcaa;
    --problem-bg: #43201e; --problem-fg: #f3aaa3;
    --idea-bg: #2a2547; --idea-fg: #c3b9f5;
    --warn-bg: #3b2b10; --warn-fg: #f3cf8a; --warn-line: #6b5120;
    --error: #f2948c;
    --shadow: none;
  }
}

/* --- base ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", "Geeza Pro", "Noto Sans Arabic", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
main { max-width: 72rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
h1 { font-size: 1.6rem; line-height: 1.25; font-weight: 650; margin: 0.25rem 0 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 2rem 0 0.6rem; }
p { margin: 0.4rem 0; }
a { color: var(--accent-text); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }

/* --- top bar --------------------------------------------------------------- */

header.topbar {
  display: flex; align-items: center; gap: 0.5rem 1.25rem; flex-wrap: wrap;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-top: 3px solid var(--accent);
}
.brand { font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
header.topbar nav { display: flex; gap: 0.25rem; flex: 1; }
header.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 0.35rem 0.7rem; border-radius: var(--radius-sm);
  transition: background-color 0.15s, color 0.15s;
}
header.topbar nav a:hover { background: var(--hover); color: var(--text); }
header.topbar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
form.logout { margin: 0; }
form.logout button { background: transparent; color: var(--muted); border-color: var(--line-strong); }
form.logout button:hover { color: var(--text); background: var(--hover); }

.banner { margin: 0; padding: 0.6rem 1rem; background: var(--warn-bg); color: var(--warn-fg); border-bottom: 1px solid var(--warn-line); }

/* --- controls -------------------------------------------------------------- */

button, input, select, textarea { font: inherit; color: inherit; }
button {
  padding: 0.4rem 0.95rem; cursor: pointer;
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--accent); color: var(--surface); font-weight: 550;
  transition: background-color 0.15s, filter 0.15s;
}
button:hover { filter: brightness(1.12); }
input, select, textarea {
  padding: 0.4rem 0.6rem; min-width: 0;
  background: var(--surface); border: 1px solid var(--control-line); border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--focus); }
label { color: var(--muted); font-size: 0.92rem; }
.message { color: var(--error); }

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

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.signin { max-width: 22rem; margin: 3rem auto 0; padding: 1.5rem; }
.signin h1 { font-size: 1.35rem; }
form.login { display: flex; flex-direction: column; gap: 0.85rem; }
form.login label { display: flex; flex-direction: column; gap: 0.3rem; }
form.login button { margin-top: 0.3rem; padding: 0.55rem; }

/* --- pills ------------------------------------------------------------------ */

.pill {
  display: inline-block; padding: 0.05rem 0.55rem; border-radius: 1rem;
  font-size: 0.8rem; font-weight: 550; line-height: 1.6;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.pill-new, .pill-seen, .pill-done, .pill-problem, .pill-idea, .pill-ok, .pill-down { border-color: transparent; }
.pill-new { background: var(--new-bg); color: var(--new-fg); }
.pill-seen { background: var(--seen-bg); color: var(--seen-fg); }
.pill-done, .pill-ok { background: var(--done-bg); color: var(--done-fg); }
.pill-problem, .pill-down { background: var(--problem-bg); color: var(--problem-fg); }
.pill-idea { background: var(--idea-bg); color: var(--idea-fg); }
h1 .pill { font-size: 0.55em; vertical-align: middle; margin-inline-start: 0.3rem; }

/* --- filters and search: one row ------------------------------------------- */

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
  padding: 0.6rem 0.8rem; margin: 0 0 0.75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem; margin: 0; }
.filters span { color: var(--muted); font-size: 0.88rem; margin-inline-end: 0.3rem; }
.filters a {
  padding: 0.15rem 0.6rem; border-radius: 1rem; text-decoration: none; font-size: 0.9rem;
  transition: background-color 0.15s;
}
.filters a:hover { background: var(--hover); }
.filters a.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
form.search { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0; margin-inline-start: auto; }
form.search label { display: flex; align-items: center; gap: 0.35rem; }
form.search input[type="search"] { width: 16rem; max-width: 100%; }
form.search input[name="day"] { width: 8.5rem; }
form.search input[name="surah"] { width: 4rem; }
.total, .voice-filter { color: var(--muted); font-size: 0.9rem; }
.lead { color: var(--muted); }

/* --- tables ------------------------------------------------------------------ */

.scroll {
  overflow-x: auto; max-width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin: 0.5rem 0 1rem;
}
table { border-collapse: collapse; margin: 0; max-width: 100%; font-variant-numeric: tabular-nums; }
th, td {
  border-bottom: 1px solid var(--line); padding: 0.5rem 0.75rem;
  text-align: start; vertical-align: top; white-space: nowrap;
}
thead th {
  background: var(--surface-2); color: var(--muted);
  font-size: 0.82rem; font-weight: 600;
  border-bottom-color: var(--line-strong);
}
tbody tr:last-child > * { border-bottom: 0; }
tbody tr { transition: background-color 0.12s; }
table.list tbody tr:hover, table.events tbody tr:hover { background: var(--hover); }
.free { white-space: normal; min-width: 8rem; }
.free, pre.text { overflow-wrap: anywhere; }
table.list, table.events, table.words { width: 100%; }
table.reports td:nth-child(4) { min-width: 14rem; max-width: 30rem; }
table.reports td:nth-child(4) a { text-decoration: none; }
table.reports td:nth-child(4) a:hover { text-decoration: underline; }
td[dir="auto"] { unicode-bidi: plaintext; }
caption { text-align: start; font-weight: 600; padding: 0.6rem 0.75rem 0.3rem; color: var(--text); }
.role { color: var(--muted); font-size: 0.9em; }

/* numbers line up on the right edge of their column */
table.events th + th, table.events td + td,
table.voices td:nth-child(3), table.voices th:nth-child(3),
table.count td + td { text-align: end; }

/* labels on a voice share: key column quiet */
table.labels { width: 100%; }
table.labels th { width: 12rem; color: var(--muted); font-weight: 500; }

.counts { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-start; margin-bottom: 1.25rem; }
.counts .scroll { margin: 0; }
table.count { min-width: 11rem; }

.pager { display: flex; gap: 1rem; align-items: center; color: var(--muted); font-size: 0.9rem; }
.pager a {
  padding: 0.3rem 0.8rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); text-decoration: none;
}
.pager a:hover { background: var(--hover); }

/* --- detail pages ------------------------------------------------------------- */

.back { font-size: 0.9rem; margin-bottom: 0.6rem; }
dl.details {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0; margin: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
dl.details dt, dl.details dd { padding: 0.45rem 0.85rem; border-bottom: 1px solid var(--line); }
dl.details dt { color: var(--muted); font-weight: 500; font-size: 0.92rem; }
dl.details dd { margin: 0; }
dl.details dt:nth-last-of-type(1), dl.details dd:last-child { border-bottom: 0; }
pre.text {
  white-space: pre-wrap; font-family: inherit; font-size: 1.02rem; line-height: 1.75; margin: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem 1.1rem; unicode-bidi: plaintext;
}
.media {
  margin: 0.6rem 0; padding: 0.75rem; background: var(--surface);
  width: fit-content; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.media .name { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
.media img, .media video { display: block; max-width: 100%; max-height: 32rem; border-radius: var(--radius-sm); }
.media audio { display: block; width: 100%; max-width: 32rem; }
.unavailable { color: var(--warn-fg); }
.hint { color: var(--muted); font-style: italic; }
form.status {
  display: flex; flex-direction: column; gap: 0.85rem; max-width: 34rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
form.status label { display: flex; flex-direction: column; gap: 0.3rem; }
form.status select { max-width: 12rem; }
form.status textarea { width: 100%; resize: vertical; }
form.status button { align-self: flex-start; }

/* --- health ---------------------------------------------------------------------- */

.bars { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 0.75rem; }
.bar { display: flex; flex-direction: column; gap: 0.45rem; }
.bar-label { margin: 0; color: var(--muted); font-size: 0.9rem; }
.bar span[title] { font-weight: 600; font-variant-numeric: tabular-nums; }
progress {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 0.6rem; border: 0; border-radius: 1rem;
  background: var(--line); color: var(--accent); overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--line); border-radius: 1rem; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 1rem; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 1rem; }
.sync { display: flex; flex-direction: column; gap: 0.2rem; max-width: 34rem; }
.sync p { margin: 0.15rem 0; }
.sync form { margin-top: 0.6rem; }

/* --- small screens ----------------------------------------------------------------- */

@media (max-width: 600px) {
  main { padding: 1rem 0.75rem 2.5rem; }
  h1 { font-size: 1.35rem; }
  header.topbar { padding: 0.45rem 0.75rem; gap: 0.25rem 0.5rem; }
  .brand { flex: 1; }
  header.topbar nav { order: 3; flex-basis: 100%; }
  table.labels th { width: 8rem; }
  form.search { margin-inline-start: 0; width: 100%; }
  form.search input[type="search"] { flex: 1; width: auto; }
  dl.details { grid-template-columns: minmax(0, 1fr); }
  dl.details dt { border-bottom: 0; padding-bottom: 0; font-size: 0.82rem; }
  .signin { margin-top: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
