:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #1f6feb;
  --diff: #fff6d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --panel: #1c2024; --ink: #e6e8ea; --muted: #9aa3ad;
    --line: #2b3138; --accent: #4c9aff; --diff: #3a3319;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 system-ui, "Segoe UI", Tahoma, sans-serif;
}
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.user { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

/* البحث */
.main-field { display: flex; gap: .5rem; }
.main-field input {
  flex: 1; padding: .9rem 1rem; font-size: 1.1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink);
}
.main-field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.go {
  padding: 0 1.6rem; border: 0; border-radius: 10px; background: var(--accent);
  color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.go:hover { filter: brightness(1.08); }

/* مؤشر التحميل */
.loading {
  display: none; align-items: center; gap: .3rem;
  margin: 1.25rem 0 0; color: var(--muted); font-size: .9rem;
}
.loading.htmx-request { display: flex; }
.dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; margin-inline-end: .4rem; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

.advanced { margin-top: .9rem; }
.advanced summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: .7rem; margin-top: .9rem;
}
.grid label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; color: var(--muted); }
.grid input {
  padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit; width: 100%;
}
.grid input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.clear {
  margin-top: .8rem; padding: .4rem .9rem; border: 1px solid var(--line);
  border-radius: 8px; background: transparent; color: var(--muted); font: inherit;
  font-size: .85rem; cursor: pointer;
}

/* النتائج */
.hint, .meta { color: var(--muted); font-size: .9rem; }
.hint { margin-top: 2rem; }
.meta { margin: 1.25rem 0 .5rem; }

.results, .person {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.results th, .results td, .person th, .person td {
  padding: .55rem .7rem; text-align: start; border-bottom: 1px solid var(--line);
}
.results thead th, .person thead th {
  background: color-mix(in srgb, var(--panel) 85%, var(--ink) 8%);
  font-size: .82rem; color: var(--muted); font-weight: 600; white-space: nowrap;
}
.results tbody tr { cursor: pointer; }
.results tbody tr:hover { background: color-mix(in srgb, var(--panel) 90%, var(--accent) 12%); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; direction: ltr; text-align: start; }

.years { white-space: nowrap; }
.tag {
  display: inline-block; padding: .05rem .4rem; margin-inline-end: .2rem;
  font-size: .75rem; border-radius: 5px; background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent); font-family: ui-monospace, monospace;
}

/* صفحة الشخص */
.back { margin-bottom: 1rem; }
.back a, .person-title .id { color: var(--accent); text-decoration: none; }
.person-title { font-size: 1.4rem; margin: 0 0 .25rem; }
.person-title .id { font-size: .85rem; margin-inline-start: .5rem; }
.person th:first-child { width: 12rem; color: var(--muted); font-weight: 600; }
.person tr.diff { background: var(--diff); }

/* تسجيل الدخول */
.login {
  max-width: 360px; margin: 4rem auto; padding: 1.75rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; gap: 1rem;
}
.login h1 { margin: 0; font-size: 1.2rem; }
.login label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.login input {
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: inherit;
}
.login button {
  padding: .65rem; border: 0; border-radius: 8px; background: var(--accent);
  color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.error { color: #c62828; font-size: .9rem; margin: 0; }

@media (max-width: 720px) {
  .results { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ===== صفحة توثيق API ===== */
.navlink { color: var(--accent); text-decoration: none; font-size: .9rem; }
.navlink:hover { text-decoration: underline; }

.docs { max-width: 840px; }
.docs h1 { font-size: 1.5rem; margin: 0 0 .4rem; }
.docs .lead { color: var(--muted); margin: 0 0 2rem; }
.docs section { margin-bottom: 2.5rem; }
.docs h2 {
  font-size: 1.1rem; margin: 0 0 .9rem; padding-bottom: .4rem;
  border-bottom: 1px solid var(--line);
}
.docs h3 { font-size: .98rem; margin: 1.5rem 0 .6rem; }
.docs p { margin: .6rem 0; }
.docs code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .87em;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  padding: .12em .38em; border-radius: 5px; direction: ltr; display: inline-block;
}

.method {
  display: inline-block; padding: .1rem .5rem; border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent); font-size: .78rem; font-weight: 700; letter-spacing: .04em;
}

pre.code {
  background: color-mix(in srgb, var(--ink) 6%, var(--panel));
  border: 1px solid var(--line); border-radius: 9px;
  padding: .85rem 1rem; overflow-x: auto; margin: .7rem 0;
  font-size: .84rem; line-height: 1.65;
}
pre.code code { background: none; padding: 0; border-radius: 0; display: block; }

.docs table.kv, .docs table.params {
  width: 100%; border-collapse: collapse; margin: .7rem 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
}
.docs table.kv th, .docs table.kv td,
.docs table.params th, .docs table.params td {
  padding: .5rem .7rem; text-align: start; border-bottom: 1px solid var(--line);
  font-size: .9rem; vertical-align: top;
}
.docs table.kv th { width: 34%; font-weight: 600; color: var(--muted); }
.docs table.params thead th {
  background: color-mix(in srgb, var(--panel) 85%, var(--ink) 8%);
  color: var(--muted); font-size: .82rem;
}
.docs table.params td:first-child { width: 22%; }
.docs table.params td:nth-child(2) { width: 12%; color: var(--muted); }
.docs tbody tr:last-child th, .docs tbody tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-block; padding: .08rem .45rem; border-radius: 5px;
  font-size: .75rem; font-weight: 600;
}
.badge.ok  { background: color-mix(in srgb, #2e7d32 25%, transparent); color: #66bb6a; }
.badge.off { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--muted); }

.docs .note {
  font-size: .87rem; color: var(--muted);
  border-inline-start: 3px solid var(--line); padding-inline-start: .8rem;
}
.docs ul.behaviour { padding-inline-start: 1.2rem; }
.docs ul.behaviour li { margin: .55rem 0; }

/* ===== صفحة المفاتيح ===== */
.keybox {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  border-radius: 11px; padding: 1.1rem 1.25rem; margin-bottom: 2rem;
}
.keybox h2 { border: 0; margin: 0 0 .4rem; font-size: 1.05rem; }
.keybox .warn { color: #d98324; font-size: .88rem; margin: 0 0 .8rem; font-weight: 600; }
.keyvalue { display: flex; gap: .5rem; align-items: stretch; }
.keyvalue code {
  flex: 1; padding: .6rem .8rem; font-size: .9rem; overflow-x: auto; white-space: nowrap;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; display: block;
}
.copy {
  padding: 0 1.1rem; border: 0; border-radius: 8px; background: var(--accent);
  color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}

.keyform { display: flex; gap: .5rem; }
.keyform input {
  flex: 1; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit;
}
.keyform input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.keyform button {
  padding: 0 1.4rem; border: 0; border-radius: 8px; background: var(--accent);
  color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}

.box { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1.25rem; font-size: .9rem; }
p.error.box  { background: color-mix(in srgb, #c62828 14%, transparent); color: #ef5350; }
p.notice.box { background: color-mix(in srgb, #2e7d32 16%, transparent); color: #66bb6a; }

table.keys th:first-child { width: auto; color: var(--ink); }
table.keys tr.inactive th, table.keys tr.inactive td { opacity: .55; }
table.keys td.actions { width: 9rem; white-space: nowrap; }
table.keys td.actions form { display: inline; }
table.keys td.actions form + form::before { content: "·"; color: var(--muted); margin: 0 .4rem; }
.link.danger { color: #ef5350; }
