:root {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #16203a;
  --border: #24304d;
  --text: #e8edf7;
  --muted: #8b98b5;
  --primary: #2f6df6;
  --primary-press: #2457cf;
  --green: #1fae64;
  --red: #e5484d;
  --amber: #d9a441;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Kufi Arabic", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); overscroll-behavior-y: none; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.error { color: var(--red); font-size: 14px; margin: 6px 0 0; }

/* Spacing utilities: replace former inline margin-top attributes so the CSP can
   stay style-src 'self' with no unsafe-inline. */
.mt-pull { margin-top: -4px; }
.mt-xs { margin-top: 8px; }
.mt-sm { margin-top: 10px; }
.mt-md { margin-top: 12px; }
.mt-lg { margin-top: 14px; }
.mt-xl { margin-top: 16px; }

.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* Login */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 28px 22px; box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 22px; }
.brand-badge {
  width: 62px; height: 62px; margin: 0 auto 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 18px; font-weight: 800; font-size: 22px; letter-spacing: 1px;
}
.brand h1 { margin: 0; font-size: 22px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 14px; font-size: 16px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; }

/* Buttons */
.btn {
  border-radius: 12px; padding: 14px 16px; font-size: 16px; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; transition: transform .05s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:active { background: var(--primary-press); }
.btn-green { background: var(--green); border-color: var(--green); }
.btn-red { background: var(--red); border-color: var(--red); }
.btn-block { width: 100%; display: block; margin-top: 6px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-sm { padding: 9px 12px; font-size: 14px; }
.admin-actions { display: flex; gap: 8px; margin-top: 8px; }
.admin-actions .btn-sm { flex: 1; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: 14px 12px; padding-top: calc(14px + env(safe-area-inset-top));
  background: rgba(11,17,32,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer;
}
.view { flex: 1; padding: 16px 14px 40px; max-width: 620px; margin: 0 auto; width: 100%; }

/* Home */
.greeting { margin: 4px 0 18px; }
.greeting h2 { margin: 0 0 2px; font-size: 20px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 16px; text-align: center; cursor: pointer; transition: transform .05s;
}
.tile:active { transform: scale(.97); }
.tile .emoji { font-size: 34px; display: block; margin-bottom: 8px; }
.tile .label { font-weight: 600; font-size: 15px; }

/* Cards / lists */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.section-title { font-size: 14px; color: var(--muted); margin: 18px 4px 8px; }
.stat-row { display: flex; gap: 12px; }
.stat { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat .num { font-size: 26px; font-weight: 800; }
.stat .cap { font-size: 13px; color: var(--muted); margin-top: 4px; }
.list-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.list-item .row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.list-item .row + .row { margin-top: 4px; }
.list-item .k { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { padding: 14px; text-align: center; border-radius: 12px; cursor: pointer; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; }
.choice.selected { background: var(--primary); border-color: var(--primary); }

.badge { font-size: 12px; padding: 3px 9px; border-radius: 20px; border: 1px solid var(--border); }
.badge.pending { color: var(--amber); border-color: var(--amber); }
.badge.active { color: var(--green); border-color: var(--green); }
.badge.rejected, .badge.cancelled { color: var(--red); border-color: var(--red); }

.file-preview { margin-top: 10px; }
.file-preview img { max-width: 100%; border-radius: 12px; border: 1px solid var(--border); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 50;
  max-width: 90%; text-align: center; animation: rise .2s ease;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 60; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 22px; max-width: 380px; width: 100%; }
.modal h3 { margin: 0 0 10px; }
