:root {
  --navy: #1E3A6B;
  --gold: #D4A437;
  --maroon: #6B1A2B;
  --bg: #F7F5F0;
  --dark: #0F1D36;
  --surface: #FFFFFF;
  --text: #0F1D36;
  --muted: #5A6478;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 29, 54, .12);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1D36;
    --surface: #17294A;
    --text: #F7F5F0;
    --muted: #B7C0D1;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Cairo', 'Tajawal', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
}
.btn {
  font: inherit; font-weight: 600;
  border: 0; border-radius: var(--radius);
  padding: .75rem 2rem; cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .7; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; border-bottom: 3px solid var(--gold); }
@media (prefers-color-scheme: dark) { .btn-primary { background: var(--gold); color: var(--dark); border-bottom-color: var(--maroon); } }

.welcome {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; padding: 2rem 16px; text-align: center;
}
.logo {
  width: 160px; height: 160px; object-fit: cover;
  border-radius: 50%; background: var(--surface);
  box-shadow: var(--shadow); border: 3px solid var(--gold);
}
.welcome h1 { margin: .5rem 0 0; font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; color: var(--navy); }
@media (prefers-color-scheme: dark) { .welcome h1 { color: var(--gold); } }
.slogan { margin: 0 0 1rem; font-size: clamp(1rem, 3.5vw, 1.25rem); color: var(--maroon); font-weight: 600; }
@media (prefers-color-scheme: dark) { .slogan { color: var(--muted); } }
.welcome a.btn { text-decoration: none; }

/* ---------- shared components ---------- */
:root { --line: rgba(15, 29, 54, .14); --ok: #1C7C4A; --err: #6B1A2B; }
@media (prefers-color-scheme: dark) { :root { --line: rgba(247, 245, 240, .18); --ok: #6FD39C; --err: #F0A3B1; } }
.btn-gold { background: var(--gold); color: var(--dark); border-bottom: 3px solid var(--maroon); }
.btn-ghost { background: transparent; color: inherit; box-shadow: none; border: 1px solid var(--line); text-decoration: none; text-align: center; }
.btn-danger { background: transparent; color: var(--err); box-shadow: none; border: 1px solid var(--err); }
.btn-sm { padding: .35rem .9rem; font-size: .9rem; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-weight: 600; font-size: .95rem; }
.field input, .field select, .search input, .search select, .toolbar select {
  font: inherit; width: 100%; padding: .65rem .9rem;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .search input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.pass { position: relative; }
/* Password inputs are LTR, so the toggle sits on the physical right, away from the typed text. */
.pass input { padding-right: 4.5rem; }
.pass button {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: .85rem; background: none; border: 0; color: var(--muted); cursor: pointer; padding: .3rem .5rem;
}
.ltr { direction: ltr; text-align: left; }
.msg { min-height: 1.6em; margin: 0; font-weight: 600; color: var(--err); text-align: center; }
.msg.ok { color: var(--ok); }

/* auth pages (login / password) */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 2rem 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow); padding: 1.75rem 1.25rem; display: flex; flex-direction: column; gap: 1rem;
  border-top: 4px solid var(--gold);
}
.auth-card[hidden] { display: none; }
.auth-card .logo { width: 96px; height: 96px; margin: 0 auto; }
.auth-card h1 { margin: 0; text-align: center; font-size: 1.5rem; color: var(--navy); }
.auth-card .sub { margin: -.6rem 0 .2rem; text-align: center; color: var(--muted); }
@media (prefers-color-scheme: dark) { .auth-card h1 { color: var(--gold); } }
.auth-card .btn-gold { font-size: 1.15rem; padding: .85rem; }
.note { background: rgba(212, 164, 55, .18); border-radius: 12px; padding: .7rem .9rem; margin: 0; font-size: .95rem; }

/* app shell */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .75rem; padding: .55rem 16px;
  background: var(--navy); color: #fff; border-bottom: 3px solid var(--gold);
}
.topbar .brand { display: flex; align-items: center; gap: .5rem; text-decoration: none; font-weight: 800; }
.topbar .brand img { border-radius: 50%; border: 2px solid var(--gold); object-fit: cover; }
.topbar .who { margin-inline-start: auto; display: flex; flex-direction: column; line-height: 1.25; text-align: left; min-width: 0; }
.topbar .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who small { color: var(--gold); }
.topbar .btn-ghost { border-color: rgba(255, 255, 255, .45); }
@media (max-width: 480px) { .topbar .brand span { display: none; } }
.page { max-width: 960px; margin: 0 auto; padding: 1.25rem 16px 6rem; }
.page h2 { margin: 0 0 1rem; color: var(--navy); font-size: 1.3rem; }
@media (prefers-color-scheme: dark) { .page h2 { color: var(--gold); } }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem; }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(3, 1fr); } }
.card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem;
  min-height: 110px; padding: 1rem .5rem; text-align: center; text-decoration: none;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border-bottom: 3px solid var(--gold); font-weight: 700;
}
.card .ico { font-size: 1.8rem; line-height: 1; }
.card.soon { opacity: .65; border-bottom-color: var(--line); }
.card.soon small { font-weight: 400; color: var(--muted); font-size: .8rem; }

.bottomnav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 5; display: flex;
  background: var(--surface); box-shadow: 0 -2px 10px rgba(15, 29, 54, .12); border-top: 2px solid var(--gold);
}
.bottomnav a, .bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .4rem 0 .5rem;
  font: inherit; font-size: .8rem; text-decoration: none; background: none; border: 0; color: var(--muted); cursor: pointer;
}
.bottomnav .on { color: var(--navy); font-weight: 700; }
@media (prefers-color-scheme: dark) { .bottomnav .on { color: var(--gold); } }
.bottomnav span { font-size: 1.25rem; line-height: 1.2; }
@media (min-width: 720px) { .bottomnav { display: none; } .page { padding-bottom: 2rem; } }

/* accounts */
.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.tabs button {
  font: inherit; font-size: .9rem; padding: .3rem .9rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.tabs button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
@media (prefers-color-scheme: dark) { .tabs button.on { background: var(--gold); color: var(--dark); border-color: var(--gold); } }
.search { display: grid; grid-template-columns: 1fr auto; gap: .5rem; margin-bottom: .8rem; }
.search select { width: auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.page-head h2 { margin: 0; }
.page-head .btn { padding-inline: 1.2rem; }
.toolbar { margin-bottom: .8rem; }
.toolbar select { width: 100%; padding: .5rem .8rem; }
.msg.inline:empty { display: none; }
.msg.inline { margin-bottom: .6rem; }
.list { display: flex; flex-direction: column; gap: .6rem; }
.row { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: .75rem 1rem; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.row-head b { overflow-wrap: anywhere; }
.row-meta { color: var(--muted); font-size: .9rem; display: flex; flex-wrap: wrap; gap: .1rem .9rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.badge { font-size: .75rem; padding: .1rem .55rem; border-radius: 999px; white-space: nowrap; background: rgba(28, 124, 74, .15); color: var(--ok); }
.badge.off { background: rgba(107, 26, 43, .12); color: var(--err); }
.badge.temp { background: rgba(212, 164, 55, .22); color: inherit; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }

dialog {
  width: min(420px, calc(100vw - 32px)); border: 0; border-radius: 18px; padding: 1.25rem;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); border-top: 4px solid var(--gold);
}
dialog::backdrop { background: rgba(15, 29, 54, .55); }
dialog form { display: flex; flex-direction: column; gap: .85rem; }
dialog h3 { margin: 0; }
.dlg-actions { display: flex; gap: .5rem; }
.dlg-actions .btn { flex: 1; padding-inline: 1rem; }
.cred { background: var(--bg); border-radius: 12px; padding: .8rem 1rem; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .3rem .8rem; }
.cred b { font-size: 1.3rem; letter-spacing: .05em; direction: ltr; text-align: right; }
.btn-wa { background: #25D366; color: #fff; text-decoration: none; text-align: center; }
