:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #1e2a3a; --muted: #6b7a90;
  --primary: #2563eb; --primary-dark: #1d4ed8; --ok: #16a34a; --warn: #d97706;
  --bad: #dc2626; --border: #e3e8f0; --shadow: 0 1px 3px rgba(15,23,42,.08);
}
[data-theme="dark"] {
  --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; --muted: #94a3b8;
  --border: #334155; --shadow: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg); color: var(--text); direction: rtl;
  min-height: 100vh; -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 10px 20px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow);
}
.topbar .brand { font-size: 1.25rem; font-weight: 800; color: var(--primary); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: .9rem; }

.btn {
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 1rem; font-weight: 700; transition: background .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn.ghost:hover { background: rgba(37,99,235,.08); }
.btn.ok { background: var(--ok); } .btn.ok:hover { background: #15803d; }
.btn.danger { background: var(--bad); } .btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 5px 12px; font-size: .85rem; border-radius: 8px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px;
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { background: var(--bg); font-weight: 700; color: var(--muted); position: sticky; top: 0; }
tr:hover td { background: rgba(37,99,235,.04); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge.present { background: #dcfce7; color: #166534; }
.badge.late { background: #fef3c7; color: #92400e; }
.badge.absent { background: #fee2e2; color: #991b1b; }
.badge.checked_out { background: #e0e7ff; color: #3730a3; }
.badge.on_leave, .badge.mission { background: #f3e8ff; color: #6b21a8; }
.badge.day_off, .badge.not_checked_in, .badge.absent_pending { background: #f1f5f9; color: #475569; }
[data-theme="dark"] .badge.present { background: #14532d; color: #bbf7d0; }
[data-theme="dark"] .badge.late { background: #78350f; color: #fde68a; }
[data-theme="dark"] .badge.absent { background: #7f1d1d; color: #fecaca; }
[data-theme="dark"] .badge.checked_out { background: #312e81; color: #c7d2fe; }
[data-theme="dark"] .badge.on_leave, [data-theme="dark"] .badge.mission { background: #4c1d95; color: #e9d5ff; }
[data-theme="dark"] .badge.day_off, [data-theme="dark"] .badge.not_checked_in, [data-theme="dark"] .badge.absent_pending { background: #1e293b; color: #94a3b8; }

.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--border); display: inline-block; vertical-align: middle; }
.avatar.big { width: 72px; height: 72px; }
.avatar-placeholder { display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: var(--muted); }

.msg { padding: 12px 16px; border-radius: 10px; margin: 10px 0; font-weight: 600; }
.msg.ok { background: #dcfce7; color: #166534; }
.msg.err { background: #fee2e2; color: #991b1b; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 10px 20px 0; }
.tabs button {
  background: transparent; border: none; color: var(--muted); font-size: .95rem;
  font-weight: 700; padding: 10px 14px; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--card); }

.page { padding: 18px 20px; max-width: 1200px; margin: 0 auto; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { text-align: center; padding: 14px 8px; }
.stat .num { font-size: 1.8rem; font-weight: 800; }
.stat .lbl { color: var(--muted); font-size: .82rem; font-weight: 600; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; padding: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-bottom: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: .85rem; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }

@media (max-width: 640px) {
  .row2, .row3 { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  th, td { padding: 6px 8px; font-size: .82rem; }
}

@media print {
  .topbar, .tabs, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
}
