/* Calm, formal, two appearances. The device setting decides unless the user
   picked one with the "المظهر" button (data-theme on <html>). */

:root {
  color-scheme: light dark;
  --bg: #f3f1eb;
  --surface: #fbfaf7;
  --text: #1f2832;
  --muted: #5d6873;
  --border: #d8d4ca;
  --control: #7c838a;
  --accent: #2f4f66;
  --on-accent: #ffffff;
  --danger: #8c3b32;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d;
    --surface: #1c2128;
    --text: #e2e0da;
    --muted: #98a2ac;
    --border: #303741;
    --control: #737e8a;
    --accent: #9dbbd0;
    --on-accent: #12161a;
    --danger: #e0a096;
  }
}

:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14181d;
  --surface: #1c2128;
  --text: #e2e0da;
  --muted: #98a2ac;
  --border: #303741;
  --control: #737e8a;
  --accent: #9dbbd0;
  --on-accent: #12161a;
  --danger: #e0a096;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "SF Arabic", "Noto Sans Arabic", Tahoma, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; }

.brand { font-size: 1.15rem; letter-spacing: 0.04em; direction: ltr; }

button, input, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--control);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 44px;
  padding: 0 14px;
}

button { cursor: pointer; }
button:disabled { opacity: 0.55; cursor: default; }
button.primary,
button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

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

label { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label input, label select { color: var(--text); width: 100%; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }
.error { color: var(--danger); font-size: 0.9rem; margin: 0; }
.notice {
  margin: 0;
  padding: 10px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.9rem;
}

/* password screens */
.gate {
  max-width: 420px;
  margin: 0 auto;
  padding: 12vh 18px 40px;
  display: grid;
  gap: 22px;
}
.gate .brand { text-align: center; font-size: 1.5rem; }

/* main page */
.bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.bar .sync { margin-inline-start: auto; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.bar button { padding: 0 10px; }
/* narrow screens: the status line drops below the buttons */
@media (max-width: 560px) {
  .bar { flex-wrap: wrap; }
  .bar .brand { margin-inline-end: auto; }
  .bar .sync { order: 1; flex-basis: 100%; margin: 0; }
}

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 18px 18px 60px;
  display: grid;
  gap: 22px;
}

.add { grid-template-columns: 1fr auto auto; align-items: end; }
@media (max-width: 560px) { .add { grid-template-columns: 1fr; } }

section { display: grid; gap: 10px; }
section h2 { padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.count { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.items:empty::after { content: "لا شيء"; color: var(--muted); font-size: 0.9rem; }

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 8px;
}
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.item .ref { font-size: 0.85rem; color: var(--muted); direction: ltr; text-align: right; overflow-wrap: anywhere; }

.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { flex: 1 1 auto; font-size: 0.9rem; padding: 0 10px; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; }
