@font-face { font-family: 'Plex Arabic'; font-weight: 400; font-display: swap; src: url('/fonts/plex-arabic-400.woff2') format('woff2'); }
@font-face { font-family: 'Plex Arabic'; font-weight: 600; font-display: swap; src: url('/fonts/plex-arabic-600.woff2') format('woff2'); }
@font-face { font-family: 'Plex Arabic'; font-weight: 700; font-display: swap; src: url('/fonts/plex-arabic-700.woff2') format('woff2'); }

:root {
  --bg: #f4f6f8; --surface: #fff; --text: #1b2733; --muted: #5d6b79; --line: #dde3e9;
  --primary: #0f5e63; --primary-dark: #0a4549; --primary-soft: #e3f1f1;
  --danger: #b3261e; --danger-soft: #fdeceb; --ok: #1b6e3c; --ok-soft: #e6f4ea; --warn-soft: #fff4d6;
  --radius: 10px; --tap: 44px; --sidebar: 252px;
  font-family: 'Plex Arabic', 'Noto Naskh Arabic', Tahoma, 'Segoe UI', Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.7; }
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.num { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: var(--primary); color: #fff; padding: .5rem .75rem; padding-top: calc(.5rem + env(safe-area-inset-top, 0px)); }
.topbar .brand { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; min-width: var(--tap); min-height: var(--tap);
  border-radius: var(--radius); font: inherit; cursor: pointer; }
.sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(80vw, var(--sidebar)); background: var(--surface);
  border-inline-end: 1px solid var(--line); z-index: 40; padding: 1rem .75rem; overflow-y: auto;
  transform: translateX(100%); transition: transform .2s; padding-top: calc(1rem + env(safe-area-inset-top, 0px)); }
.sidebar.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
.sidebar nav a { display: flex; align-items: center; min-height: var(--tap); padding: 0 .85rem; border-radius: var(--radius);
  text-decoration: none; color: var(--text); font-weight: 600; margin-bottom: .2rem; }
.sidebar nav a:hover { background: var(--primary-soft); }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .who { padding: .5rem .85rem 1rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; }
main { padding: 1rem; padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)); max-width: 1200px; margin-inline: auto; }
.building-switch { display: flex; gap: .4rem; align-items: center; }
.building-switch select { min-height: var(--tap); max-width: 55vw; }
@media (min-width: 900px) {
  .menu-btn { display: none; }
  .sidebar { transform: none; top: 0; }
  .topbar, main { margin-inline-start: var(--sidebar); }
  .scrim { display: none !important; }
}
@media (max-width: 899px) { .sidebar { transform: translateX(100%); } [dir=rtl] .sidebar { inset-inline-start: auto; inset-inline-end: 0; } }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stat .v { font-size: 1.9rem; font-weight: 700; color: var(--primary); line-height: 1.2; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); min-width: var(--tap); padding: 0 1.1rem;
  border-radius: var(--radius); border: 1px solid var(--primary); background: var(--primary); color: #fff; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger.secondary { background: var(--surface); color: var(--danger); }
.btn[disabled] { opacity: .6; cursor: wait; }
.badge { display: inline-block; padding: .05rem .6rem; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--primary-soft); color: var(--primary-dark); }
.badge.off { background: #eceff2; color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: #7a5a00; }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert.ok { background: var(--ok-soft); border-color: #b9dfc6; color: var(--ok); }
.alert.err { background: var(--danger-soft); border-color: #f2c3bf; color: var(--danger); }
.secret { font-family: ui-monospace, Consolas, monospace; direction: ltr; text-align: left; user-select: all; font-size: 1.1rem; padding: .6rem; background: var(--warn-soft); border-radius: var(--radius); margin-bottom: 1rem; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.field label, .field .lbl { display: block; font-weight: 600; margin-bottom: .25rem; }
.field .hint { color: var(--muted); font-size: .85rem; }
.field .err { color: var(--danger); font-size: .9rem; margin-top: .2rem; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], select, textarea {
  width: 100%; min-height: var(--tap); padding: .5rem .75rem; font: inherit; color: inherit; background: #fff;
  border: 1px solid #b8c2cc; border-radius: var(--radius); }
textarea { min-height: 96px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid #7fb8bb; outline-offset: 1px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
input.ltr { direction: ltr; text-align: left; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.checks { display: grid; gap: .4rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.check { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); padding: 0 .75rem; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.check input { width: 22px; height: 22px; flex: none; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters .field { flex: 1 1 160px; }

/* ---------- tables: cards on small screens ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: start; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef2f5; font-size: .9rem; }
@media (max-width: 719px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; padding: .35rem .25rem; }
  table.cards td { border: 0; display: flex; justify-content: space-between; gap: 1rem; padding: .35rem .75rem; }
  table.cards td::before { content: attr(data-label); font-weight: 600; color: var(--muted); flex: none; }
}
.pager { display: flex; gap: .5rem; align-items: center; justify-content: center; flex-wrap: wrap; margin: 1rem 0; }
details pre { direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: #f0f3f6; padding: .5rem; border-radius: 8px; max-width: 100%; overflow-x: auto; }

/* ---------- bare (login) ---------- */
body.bare main { margin: 0 auto; max-width: 440px; padding-top: 12vh; }
body.bare .topbar { display: none; }
.login-title { text-align: center; color: var(--primary); }
