/* نظام الحضور الجامعي — dark / high-contrast RTL theme */
:root {
  --bg: #0b1220;
  --bg-2: #111a2e;
  --card: #141f36;
  --card-2: #1a2742;
  --line: #2a3a5c;
  --text: #f3f6fc;
  --muted: #a9b6d3;
  --accent: #22d3ee;
  --accent-ink: #04222a;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "Noto Kufi Arabic", "Noto Sans Arabic", Tahoma, "Geeza Pro", system-ui, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 600px at 100% -10%, #13284a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  direction: rtl;
  padding-bottom: env(safe-area-inset-bottom);
}

h1,
h2 {
  margin: 0 0 12px;
  line-height: 1.3;
}
h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.2rem;
}
p {
  margin: 0 0 12px;
}
a {
  color: var(--accent);
}

.hidden,
[hidden] {
  display: none !important;
}

/* ---------- layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}
.brand img {
  border-radius: 8px;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.who {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
.who small {
  color: var(--muted);
}

.container {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

.footer {
  text-align: center;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
  letter-spacing: 0.2px;
}
.footer span {
  color: var(--text);
  font-weight: 600;
}

.card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.center {
  text-align: center;
}
.stack {
  display: grid;
  gap: 10px;
}

.muted {
  color: var(--muted);
}
.hint {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 14px;
}
.error-text {
  color: var(--danger);
}
.credit {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}
.list {
  padding-inline-start: 22px;
  margin: 0 0 14px;
}
.list li {
  margin-bottom: 6px;
}
.pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
}
.notice {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--warn);
  background: rgba(251, 191, 36, 0.08);
}

/* ---------- forms ---------- */
.form {
  max-width: 480px;
  margin: 12px auto 16px;
}
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
label {
  font-weight: 600;
}
input,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #0a1324;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  outline: none;
}
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.25);
}
input[type="file"] {
  padding: 10px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--card-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 18px;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover {
  border-color: var(--accent);
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn.ghost {
  background: transparent;
}
.btn.small {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.9rem;
}
.btn.block {
  display: flex;
  width: 100%;
  margin-top: 8px;
}
.btn.xl {
  min-height: 60px;
  font-size: 1.15rem;
}
.btn.huge {
  min-height: 96px;
  font-size: 1.6rem;
  border-radius: 20px;
  margin: 18px 0 4px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: #0a1324;
  border: 1px solid var(--line);
}
.segmented button {
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  cursor: pointer;
}
.segmented button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.tabs button {
  flex: 0 0 auto;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  background: #0a1324;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}
.tabs button.active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
th,
td {
  padding: 10px 12px;
  text-align: start;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  background: #0a1324;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
tr:last-child td {
  border-bottom: 0;
}
td.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
td.num {
  font-variant-numeric: tabular-nums;
}
td.details {
  max-width: 420px;
  word-break: break-word;
  color: var(--muted);
}
.mono {
  font-family: ui-monospace, Consolas, monospace;
}
.nowrap {
  white-space: nowrap;
}
.row-warn td {
  background: rgba(248, 113, 113, 0.07);
}

.badge {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.live {
  color: var(--ok);
  border-color: var(--ok);
}
.badge.warn {
  color: var(--warn);
  border-color: var(--warn);
}

/* ---------- progress ---------- */
.bar {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #0a1324;
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 10px 0;
}
.bar.small {
  height: 8px;
}
.bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  transition: width 0.2s linear;
}
.progress {
  margin-top: 14px;
}

/* ---------- student ---------- */
.records {
  list-style: none;
  margin: 0;
  padding: 0;
}
.records li {
  display: grid;
  gap: 2px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.records li:last-child {
  border-bottom: 0;
}
.records span,
.records time {
  color: var(--muted);
  font-size: 0.92rem;
}

.scan-card {
  max-width: 560px;
  margin: 0 auto 16px;
}
.scanner {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  border: 2px solid var(--line);
  margin: 10px 0 12px;
}
.scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-frame {
  position: absolute;
  inset: 14%;
  border: 4px solid var(--accent);
  border-radius: 18px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.code-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 8px;
}
.code-input {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.result {
  text-align: center;
  max-width: 520px;
  margin: 24px auto;
}
.result-icon {
  width: 120px;
  height: 120px;
  margin: 8px auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 64px;
  font-weight: 900;
}
.result.ok .result-icon {
  background: rgba(52, 211, 153, 0.15);
  color: var(--ok);
  border: 4px solid var(--ok);
}
.result.fail .result-icon {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border: 4px solid var(--danger);
}
.result .big {
  font-size: 1.25rem;
  font-weight: 700;
}

/* ---------- professor emergency display ---------- */
body.presenting .topbar,
body.presenting .footer {
  display: none;
}
body.presenting .container {
  max-width: none;
  padding: 10px;
}
.present {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 6px env(safe-area-inset-bottom);
  text-align: center;
}
.present-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.1rem;
}
.qr-wrap {
  background: #fff;
  padding: 8px;
  border-radius: 14px;
  line-height: 0;
}
.qr-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}
.giant-code {
  font-size: clamp(64px, 22vw, 180px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Segoe UI", Consolas, monospace;
  color: #fff;
}
.present .bar {
  max-width: 720px;
  height: 18px;
}
.count-wrap {
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.count-wrap span {
  color: var(--muted);
  font-size: 1.3rem;
}
.giant-count {
  font-size: clamp(56px, 16vw, 140px);
  font-weight: 900;
  color: var(--ok);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.recent {
  list-style: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-height: 140px;
  overflow: hidden;
}
.present-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

/* ---------- misc ---------- */
.about summary {
  cursor: pointer;
  font-weight: 700;
}
.about[open] summary {
  margin-bottom: 12px;
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 12px auto;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 18px;
  border-radius: 14px;
  background: #0a1324;
  border: 2px solid var(--line);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show {
  opacity: 1;
  transform: none;
}
.toast.success {
  border-color: var(--ok);
}
.toast.error {
  border-color: var(--danger);
}

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }
  .card {
    padding: 16px;
  }
  .brand span {
    font-size: 0.95rem;
  }
  th,
  td {
    padding: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
