:root {
  --bg: #f4efe6;
  --ink: #1c1915;
  --muted: #6d645b;
  --card: #fffaf3;
  --line: #e6dccb;
  --accent: #0f6e62;
  --accent-ink: #f4fffc;
  --copper: #b85c38;
  --sidebar: #141c1b;
  --sidebar-ink: #e7f2ef;
  --danger: #9f2d2d;
  --ok: #1f7a4d;
  --shadow: 0 18px 40px rgba(40, 28, 16, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: light;
}
html.dark {
  --bg: #101614;
  --ink: #edf4f1;
  --muted: #a7b5b0;
  --card: #18211e;
  --line: #2c3b36;
  --accent: #3cbea8;
  --accent-ink: #06211c;
  --copper: #e39a72;
  --sidebar: #0b100f;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: clip;
}
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "IBM Plex Sans Arabic", "Cairo", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
body.nav-open { overflow: hidden; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
a, button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: calc(22px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 18px; }
.mark {
  width: 36px; height: 36px; border-radius: 12px; flex: none;
  background: conic-gradient(from 210deg, #f2c14e, #0f6e62 40%, #173f3b 70%, #f2c14e);
}
.brand strong { display: block; letter-spacing: 0.14em; font-size: 14px; }
.brand span { color: #9fb2ac; font-size: 12px; }
.nav a, .nav button.linkish {
  display: flex; align-items: center; justify-content: flex-start; width: 100%; text-align: right; text-decoration: none;
  min-height: 44px; padding: 10px 12px; border-radius: 10px; color: #d5e4df; background: transparent; border: 0;
}
.nav a.active, .nav a:hover, .nav a:active { background: rgba(255,255,255,.08); color: white; }
.main {
  min-width: 0;
  padding: 22px 28px calc(48px + var(--safe-bottom));
}
.topbar {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  margin-bottom: 18px; flex-wrap: wrap;
}
.topbar h1, h1 { margin: 0; font-size: clamp(22px, 5vw, 28px); font-weight: 650; overflow-wrap: anywhere; }
h2 { overflow-wrap: anywhere; }
.who {
  color: var(--muted); font-size: 13px;
  max-width: min(46vw, 220px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card:has(table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { grid-template-columns: 1.2fr .8fr; }
.split.even { grid-template-columns: 1fr 1fr; }
.stat b { display: block; font-size: clamp(20px, 5vw, 26px); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat span { color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.row { flex-wrap: nowrap; }
.btn, button.btn, a.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 9px 16px; min-height: 44px; text-decoration: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: white; }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
input, select, textarea {
  background: transparent; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; width: 100%; min-height: 44px; font-size: 16px;
}
textarea { min-height: 90px; }
input[type="checkbox"], input[type="radio"] {
  width: 22px; height: 22px; min-height: 22px; accent-color: var(--accent);
}
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fields .wide { grid-column: 1 / -1; }
.flash { padding: 10px 12px; border-radius: 12px; background: #e7f6ee; color: var(--ok); margin-bottom: 12px; }
.flash.err { background: #fde8e4; color: var(--danger); }
html.dark .flash { background: #143026; }
html.dark .flash.err { background: #3a1c1c; }
.pill { border-radius: 999px; padding: 4px 10px; background: rgba(15,110,98,.12); font-size: 12px; }
.site-footer {
  margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
}
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 2px; }
.guest {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: calc(24px + var(--safe-top)) calc(16px + var(--safe-left)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-right));
  background:
    radial-gradient(circle at top right, rgba(184,92,56,.18), transparent 30%),
    var(--bg);
}
.guest > div { width: min(460px, 100%); }
.guest .card { width: 100%; }
.guest .btn { width: 100%; }
.guest h1 { margin: 8px 0 4px; }
.menu-btn, .drawer-close, .scrim { display: none; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.pager-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.break { overflow-wrap: anywhere; }
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(6, 10, 9, .55); }
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; z-index: 40;
    top: 0; bottom: 0; right: 0; left: auto;
    width: min(340px, calc(100vw - 36px));
    height: 100dvh;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
    padding-inline-start: max(16px, var(--safe-right));
    transform: translate3d(110%, 0, 0);
    transition: transform .22s ease;
    box-shadow: -12px 0 40px rgba(0, 0, 0, .28);
  }
  .sidebar.open { transform: none; }
  .drawer-close { display: inline-flex; margin-inline-start: auto; }
  .menu-btn { display: inline-flex; }
  .stats { grid-template-columns: 1fr 1fr; }
  .split, .split.even, .fields { grid-template-columns: minmax(0, 1fr); }
  .guest { justify-content: flex-start; }
  .main { padding: 0 16px calc(28px + var(--safe-bottom)); }
  .topbar {
    position: sticky; top: 0; z-index: 20;
    margin: 0 -16px 16px;
    padding: calc(8px + var(--safe-top)) 16px 10px;
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  .topbar .row { width: 100%; }
  .topbar input, .search { width: 100%; max-width: none; flex: 1 1 180px; }
  form.row input { flex: 1 1 160px; min-width: 0; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px; border-radius: 16px; }
  .topbar h1, h1 { font-size: 22px; }
}
@media print {
  .sidebar, .topbar, .scrim, .no-print { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  body { background: white; color: black; }
  .site-footer { position: fixed; bottom: 0; left: 0; right: 0; }
  table { min-width: 0; }
}
