/* Fata design system.
   Brand: navy #233E7D, teal #56AEAB (sampled from the logo).
   Type:  Noto Kufi Arabic for Arabic, Century Gothic for Latin with
          Questrial as the free geometric stand-in.
   Layout uses CSS logical properties everywhere (margin-inline,
   inset-inline, text-align:start) so RTL and LTR share one stylesheet. */

:root {
  --navy:        #233E7D;
  --navy-600:    #1b3063;
  --navy-100:    #e8ecf6;
  --teal:        #56AEAB;
  --teal-600:    #3f918e;

  --bg:          #f4f6fa;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --ink:         #14203f;
  --ink-soft:    #5b6b83;
  --ink-faint:   #8a99b0;
  --line:        #e2e8f2;

  --ok:          #12a150;
  --warn:        #c07800;
  --danger:      #c0392b;

  --radius:      12px;
  --radius-lg:   18px;
  --shadow:      0 1px 2px rgba(20,32,63,.05), 0 12px 32px -16px rgba(20,32,63,.22);
  --shadow-lg:   0 24px 60px -24px rgba(20,32,63,.35);

  --font: 'Century Gothic', Questrial, 'Noto Kufi Arabic', system-ui, -apple-system, sans-serif;
  --font-ar: 'Noto Kufi Arabic', 'Century Gothic', Questrial, system-ui, sans-serif;
}

:root[data-theme="dark"] {
  --bg:        #0a1020;
  --surface:   #111a2e;
  --surface-2: #16223a;
  --ink:       #e8eefc;
  --ink-soft:  #9aabc6;
  --ink-faint: #6b7d99;
  --line:      #22304d;
  --navy-100:  #1a2744;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 12px 32px -16px rgba(0,0,0,.7);
  --shadow-lg: 0 24px 60px -24px rgba(0,0,0,.85);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0a1020;
    --surface:   #111a2e;
    --surface-2: #16223a;
    --ink:       #e8eefc;
    --ink-soft:  #9aabc6;
    --ink-faint: #6b7d99;
    --line:      #22304d;
    --navy-100:  #1a2744;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 12px 32px -16px rgba(0,0,0,.7);
    --shadow-lg: 0 24px 60px -24px rgba(0,0,0,.85);
  }
}

* { box-sizing: border-box; }

html[lang="ar"] body { font-family: var(--font-ar); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 1em; }

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

.center-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex: 0 0 250px;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.content { flex: 1; padding: 28px 32px 60px; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.topbar .spacer { flex: 1; }

.brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; }
.brand img { height: 34px; width: auto; }

/* Logo swaps with the theme. Not scoped to a container, so it works
   anywhere the two variants appear together. */
img.on-dark { display: none; }
:root[data-theme="dark"] img.on-light { display: none; }
:root[data-theme="dark"] img.on-dark  { display: inline-block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) img.on-light { display: none; }
  :root:not([data-theme="light"]) img.on-dark  { display: inline-block; }
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }

.auth-card { width: min(430px, 100%); }
.muted { color: var(--ink-soft); font-size: .9rem; }
.faint { color: var(--ink-faint); font-size: .82rem; }

/* ---------- forms ---------- */

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--navy) 16%, transparent);
}
input::placeholder { color: var(--ink-faint); }

/* Codes, URLs and tokens are Latin regardless of interface language. */
.ltr { direction: ltr; text-align: start; unicode-bidi: isolate; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--navy);
  color: #fff;
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .05s, opacity .15s;
}
.btn:hover  { background: var(--navy-600); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--surface-2); }
.btn.teal { background: var(--teal); }
.btn.teal:hover { background: var(--teal-600); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 7px 13px; font-size: .82rem; }

.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--navy);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
:root[data-theme="dark"] .linkbtn, :root[data-theme="dark"] a { color: var(--teal); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .linkbtn,
  :root:not([data-theme="light"]) a { color: var(--teal); }
}

/* ---------- nav ---------- */

.navlink {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  background: none;
  font-family: inherit;
  width: 100%;
  text-align: start;
}
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink.active { background: var(--navy-100); color: var(--navy); }
:root[data-theme="dark"] .navlink.active { color: var(--teal); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .navlink.active { color: var(--teal); }
}

/* ---------- table ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 11px 12px; text-align: start; border-bottom: 1px solid var(--line); }
th {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-faint);
  font-weight: 700;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }
th.sorted { color: var(--navy); }
:root[data-theme="dark"] th.sorted { color: var(--teal); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) th.sorted { color: var(--teal); }
}
tbody tr:hover { background: var(--surface-2); }
.empty { padding: 34px; text-align: center; color: var(--ink-faint); }

/* ---------- misc ---------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  background: var(--navy-100);
  color: var(--navy);
  white-space: nowrap;
}
.badge.ok      { background: color-mix(in srgb, var(--ok) 14%, transparent);     color: var(--ok); }
.badge.warn    { background: color-mix(in srgb, var(--warn) 16%, transparent);   color: var(--warn); }
.badge.danger  { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.teal    { background: color-mix(in srgb, var(--teal) 18%, transparent);   color: var(--teal-600); }

.alert {
  padding: 12px 15px;
  border-radius: var(--radius);
  font-size: .88rem;
  margin-bottom: 15px;
  border: 1px solid transparent;
}
.alert.error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.alert.ok    { background: color-mix(in srgb, var(--ok) 10%, transparent);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 28%, transparent); }
.alert.info  { background: var(--navy-100); color: var(--navy); border-color: var(--line); }
.alert:empty { display: none; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  padding: 10px 16px;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--navy); border-bottom-color: var(--navy); }
:root[data-theme="dark"] .tab.active { color: var(--teal); border-bottom-color: var(--teal); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tab.active { color: var(--teal); border-bottom-color: var(--teal); }
}
.panel[hidden] { display: none; }

.switcher { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.switcher button {
  border: 0; background: none; font: inherit; font-size: .78rem; font-weight: 700;
  padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--ink-soft);
}
.switcher button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex: none; flex-direction: row; overflow-x: auto; border-inline-end: 0; border-block-end: 1px solid var(--line); }
  .sidebar .brand { display: none; }
  .content { padding: 20px 16px 50px; }
}

/* ---------- toggle switch ---------- */

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--line);
  border-radius: 999px;
  transition: background .18s ease;
  pointer-events: none;
}
.switch .track::before {
  content: '';
  position: absolute;
  height: 18px; width: 18px;
  inset-block-start: 3px;
  inset-inline-start: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.28);
  transition: transform .18s ease;
}
.switch input:checked + .track { background: var(--teal); }
.switch input:checked + .track::before { transform: translateX(20px); }
/* The knob starts at the inline-start edge, so in RTL it travels the other
   way. CSS has no logical transform, hence the explicit direction rule. */
[dir="rtl"] .switch input:checked + .track::before { transform: translateX(-20px); }
.switch input:focus-visible + .track {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + .track { opacity: .5; }

/* ---------- sidebar module list ---------- */

.nav-version {
  text-align: center;
  font-size: .72rem;
  color: var(--ink-faint);
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}
@media (max-width: 760px) { .nav-version { display: none; } }

.nav-section {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-faint);
  font-weight: 700;
  margin: 16px 13px 6px;
}
@media (max-width: 760px) { .nav-version {
  text-align: center;
  font-size: .72rem;
  color: var(--ink-faint);
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}
@media (max-width: 760px) { .nav-version { display: none; } }

.nav-section { display: none; } }
