/* الخط محلي حتى يعمل على شبكة بدون إنترنت */
@font-face { font-family: Plex; font-weight: 400; font-display: swap; src: url(/fonts/plex-arabic-400.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: Plex; font-weight: 500; font-display: swap; src: url(/fonts/plex-arabic-500.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: Plex; font-weight: 600; font-display: swap; src: url(/fonts/plex-arabic-600.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: Plex; font-weight: 700; font-display: swap; src: url(/fonts/plex-arabic-700.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: Plex; font-weight: 400; font-display: swap; src: url(/fonts/plex-latin-400.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: Plex; font-weight: 500; font-display: swap; src: url(/fonts/plex-latin-500.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: Plex; font-weight: 600; font-display: swap; src: url(/fonts/plex-latin-600.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: Plex; font-weight: 700; font-display: swap; src: url(/fonts/plex-latin-700.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }

:root {
  --obsidian: #0d1311;
  --obsidian-2: #151d1a;
  --obsidian-3: #1f2a26;
  --obsidian-line: #2d3a35;
  --ivory: #f5f0e6;
  --ivory-2: #fffcf5;
  --ivory-line: #e3dccd;
  --ink: #17201c;
  --ink-soft: #5d6a63;
  --mist: #9faca5;
  --brass: #d9a441;
  --brass-deep: #9a6f17;
  --brass-soft: #f6e8c8;
  --go: #43d296;
  --go-deep: #0d7a50;
  --go-soft: #d9f3e6;
  --stop: #f4796a;
  --stop-deep: #b13a2b;
  --stop-soft: #fbe4df;
  --warn-deep: #8a5d05;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: Plex, -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.005em; }
a { color: var(--brass-deep); }
.muted { color: var(--ink-soft); font-size: .9rem; }
.ltr { direction: ltr; unicode-bidi: isolate; }
html[dir="rtl"] input.ltr, html[dir="rtl"] textarea.ltr { text-align: left; }

label { display: block; font-size: .88rem; font-weight: 600; }
label > input, label > select, label > textarea { margin-top: 7px; font-weight: 400; }

input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1px solid var(--ivory-line);
  border-radius: 11px;
  background: var(--ivory-2);
  color: inherit;
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 92px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #cfc6b3; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 0;
  border-color: var(--brass-deep);
  box-shadow: 0 0 0 3px rgba(217, 164, 65, .28);
}
button:focus-visible, a:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }
input[type="checkbox"], input[type="radio"] { width: 22px; min-height: 22px; height: 22px; margin: 0; padding: 0; accent-color: var(--brass-deep); flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--ivory-line);
  border-radius: 11px;
  background: var(--ivory-2);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { border-color: #bfb49d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--obsidian); border-color: var(--obsidian); color: var(--ivory); }
.btn.primary:hover:not(:disabled) { background: var(--obsidian-3); }
.btn.danger { color: var(--stop-deep); }
.btn.small { min-height: 36px; padding: 5px 12px; font-size: .86rem; border-radius: 9px; }
.btn.block { width: 100%; }

.notice { padding: 12px 14px; border-radius: 11px; font-size: .92rem; }
.notice.bad { background: var(--stop-soft); color: var(--stop-deep); }
.notice.ok { background: var(--go-soft); color: var(--go-deep); }
.notice.warn { background: var(--brass-soft); color: var(--warn-deep); }

.card {
  background: var(--ivory-2);
  border: 1px solid var(--ivory-line);
  border-radius: var(--radius);
  padding: 24px;
}

.stack { display: grid; gap: 16px; }
.stack > * { min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.field-hint { display: block; margin-top: 5px; font-weight: 400; font-size: .83rem; color: var(--ink-soft); }

/* ---------- الدخول ---------- */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 72px 16px 32px;
  background: var(--obsidian) url(/ridges.svg) center -60px / min(900px, 170vw) no-repeat;
  color: var(--ivory);
}
.login-lang { position: fixed; inset-block-start: 16px; inset-inline-end: 16px; }
.login-card {
  width: min(410px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  border-radius: 22px;
  background: var(--ivory-2);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.brand-mark { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.brand-mark img { width: 52px; height: 52px; }
.brand-mark h1 { font-size: 1.7rem; line-height: 1.15; font-weight: 700; }

.ghost {
  min-height: 38px;
  padding: 6px 13px;
  border: 1px solid var(--obsidian-line);
  border-radius: 10px;
  background: transparent;
  color: var(--ivory);
  font: inherit;
  font-size: .86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.ghost:hover { background: var(--obsidian-3); border-color: #43534c; }

/* ---------- صفحة الموظف ---------- */
.punch-body { min-height: 100dvh; background: var(--obsidian); color: var(--ivory); }
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 14px 16px 0;
}
.app-bar .who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-bar img { width: 34px; height: 34px; flex: none; }
.app-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: .95rem; }
.app-bar .who-text { min-width: 0; display: grid; line-height: 1.25; }
.app-bar .who-text span { color: var(--mist); font-size: .76rem; justify-self: start; }
.app-bar .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; flex: none; }
.app-bar .ghost { min-height: 34px; padding: 4px 9px; font-size: .78rem; }

.punch-page { width: min(520px, 100%); margin: 0 auto; padding: 18px 16px 36px; display: grid; gap: 18px; }

.clock { text-align: center; }
.clock .time { font-size: clamp(3rem, 15vw, 3.9rem); font-weight: 500; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.clock .date { color: var(--mist); font-size: .95rem; margin-top: 4px; }

.dial {
  --tick: var(--obsidian-line);
  --glow: transparent;
  position: relative;
  width: min(300px, 76vw);
  aspect-ratio: 1;
  margin: 2px auto;
  padding: 20px;
  transition: --tick .3s;
}
.dial::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(var(--tick) 0 1.2deg, transparent 1.2deg 6deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 11px), #000 calc(100% - 11px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 11px), #000 calc(100% - 11px));
}
.dial.in-range { --tick: var(--go); }
.dial.out-range { --tick: var(--stop); }
.dial.scanning::before { animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.camera {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background: var(--obsidian-2);
  box-shadow: 0 0 0 1px var(--obsidian-line), 0 18px 50px rgba(0, 0, 0, .5);
}
.camera video, .camera img { width: 100%; height: 100%; object-fit: cover; display: block; transform: scaleX(-1); }
.camera .overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
  text-align: center;
  color: var(--mist);
  font-size: .92rem;
}
.camera .done {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 92, 60, .72);
  color: #fff;
  font-size: 4.4rem;
  animation: pop .28s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.9); } }

.status-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 26px;
  color: var(--mist);
  font-weight: 500;
  font-size: .95rem;
  text-align: center;
}
.status-pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.status-pill.ok { color: var(--go); }
.status-pill.bad { color: var(--stop); }
.status-pill.warn { color: var(--brass); }

.punch-page .notice.bad { background: rgba(244, 121, 106, .14); color: #ffb3a8; }
.punch-page .notice.warn { background: rgba(217, 164, 65, .14); color: #efcb82; }

.punch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  border: 1px solid var(--brass);
  border-radius: 18px;
  background: var(--brass);
  color: #1c1503;
  font: inherit;
  font-size: 1.22rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .08s, opacity .15s;
}
.punch-btn:hover:not(:disabled) { background: #e5b558; }
.punch-btn:active:not(:disabled) { transform: scale(.985); }
.punch-btn:disabled { background: var(--obsidian-3); border-color: var(--obsidian-line); color: var(--mist); cursor: not-allowed; }
.punch-btn.out:not(:disabled) { background: var(--ivory); border-color: var(--ivory); color: var(--ink); }
.punch-btn svg { width: 26px; height: 26px; flex: none; }

.today { padding-top: 6px; border-top: 1px solid var(--obsidian-3); }
.today h2 { font-size: .86rem; font-weight: 600; color: var(--mist); margin-bottom: 10px; }
.today .muted { color: var(--mist); }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.timeline li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 14px; background: var(--obsidian-2); border-radius: 12px; font-size: .95rem; }
.timeline time { font-variant-numeric: tabular-nums; font-weight: 600; }
.timeline .kind { display: flex; align-items: center; gap: 9px; }
.timeline .kind::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--go); }
.timeline .kind.out::before { background: var(--brass); }

/* ---------- لوحة الأدمن ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100dvh; }
.rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 22px 14px;
  background: var(--obsidian);
  color: var(--ivory);
}
.rail-brand { display: flex; align-items: center; gap: 11px; padding-inline: 8px; }
.rail-brand img { width: 38px; height: 38px; }
.rail-brand strong { display: block; font-size: 1.1rem; line-height: 1.2; }
.rail-brand span { display: block; color: var(--mist); font-size: .8rem; }
.tabs { display: flex; flex-direction: column; gap: 3px; }
.tab {
  flex: none;
  min-height: 44px;
  padding: 9px 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-weight: 500;
  font-size: .95rem;
  text-align: start;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--ivory); background: var(--obsidian-2); }
.tab[aria-selected="true"] { background: var(--obsidian-3); color: var(--brass); font-weight: 600; }
.rail-foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; }

.admin-page { padding: 30px clamp(16px, 3vw, 38px) 48px; display: grid; gap: 18px; align-content: start; max-width: 1180px; width: 100%; }
.admin-page > * { min-width: 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { padding: 18px 20px; background: var(--ivory-2); border: 1px solid var(--ivory-line); border-radius: var(--radius); }
.stat b { display: block; font-size: 2.3rem; line-height: 1.1; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat.lead { background: var(--obsidian); border-color: var(--obsidian); color: var(--ivory); }
.stat.lead b { color: var(--brass); }
.stat.lead .muted { color: var(--mist); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 18px; }
.toolbar label { flex: 1 1 140px; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 12px 10px; text-align: start; border-bottom: 1px solid var(--ivory-line); white-space: nowrap; }
th { color: var(--ink-soft); font-size: .8rem; font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; }
td.emp-no { font-weight: 600; text-align: start; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #faf5ea; }
.row-actions { display: flex; gap: 6px; }
.thumb { width: 44px; height: 44px; padding: 0; border: 2px solid var(--ivory-line); border-radius: 50%; overflow: hidden; cursor: zoom-in; background: var(--ivory-line); display: block; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transform: scaleX(-1); }

.tag { display: inline-block; padding: 2px 11px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.tag.in { background: var(--go-soft); color: var(--go-deep); }
.tag.out { background: var(--brass-soft); color: var(--warn-deep); }
.tag.off { background: #ebe6da; color: var(--ink-soft); }
.tag.bad { background: var(--stop-soft); color: var(--stop-deep); }
.empty { padding: 34px 12px; text-align: center; color: var(--ink-soft); }

.check { display: flex; align-items: flex-start; gap: 11px; font-weight: 600; cursor: pointer; }
.check span small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .86rem; }
.url-box { padding: 13px 16px; background: var(--obsidian); color: var(--brass); border-radius: 11px; font-weight: 600; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* التحديث المباشر */
.live { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: .85rem; min-height: 22px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--go-deep); animation: live-pulse 2s ease-in-out infinite; flex: none; }
.live:empty { visibility: hidden; }
.live.failed { color: var(--stop-deep); }
.live.failed::before { background: var(--stop-deep); animation: none; }
@keyframes live-pulse { 50% { opacity: .35; } }
tr.is-new td { animation: new-row 4s ease-out; }
@keyframes new-row { from { background: var(--brass-soft); } to { background: transparent; } }

/* التقارير */
.report-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: end; }
.report-form .wide { grid-column: 1 / -1; }
.report-card { display: grid; gap: 14px; }
.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 24px; }
.report-head h3 { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }
.emp-badge { display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--obsidian); color: var(--brass); font-size: .8rem; font-weight: 600; }
.report-totals { display: flex; flex-wrap: wrap; gap: 8px 26px; margin: 0; }
.report-totals dt { color: var(--ink-soft); font-size: .78rem; }
.report-totals dd { margin: 0; font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* صفحة سجلّي للموظف */
.my-link { display: flex; align-items: center; justify-content: center; min-height: 48px; text-decoration: none; font-size: .95rem; }
.my-bar { background: var(--obsidian); color: var(--ivory); }
.my-bar-inner { width: min(860px, 100%); margin: 0 auto; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.my-back { display: inline-flex; align-items: center; text-decoration: none; }
.my-page { width: min(860px, 100%); margin: 0 auto; padding: 18px 16px 40px; }

/* بطاقتا اختيار طريقة التحقق */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.choice {
  display: flex;
  gap: 12px;
  padding: 18px;
  border: 1.5px solid var(--ivory-line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  font-weight: 400;
  transition: border-color .15s, background .15s;
}
.choice:hover { border-color: #bfb49d; }
.choice:has(input:checked) { border-color: var(--brass-deep); background: #fdf6e4; }
.choice strong { display: block; font-size: 1.05rem; margin-bottom: 3px; }
.choice small { color: var(--ink-soft); font-size: .88rem; line-height: 1.5; display: block; }

/* النوافذ */
dialog {
  width: min(460px, calc(100vw - 32px));
  border: 0;
  border-radius: 20px;
  padding: 24px;
  background: var(--ivory-2);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(8, 12, 10, .62); }
.photo-dialog { padding: 12px; width: min(520px, calc(100vw - 32px)); }
.photo-dialog img { width: 100%; border-radius: 12px; display: block; transform: scaleX(-1); }
.photo-dialog p { margin: 10px 4px; }
.enroll-view { position: relative; width: min(260px, 100%); aspect-ratio: 1; margin: 0 auto; border-radius: 50%; overflow: hidden; background: var(--obsidian); }
.enroll-view video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.enroll-view p { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--mist); font-size: .88rem; }
.file-btn input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; }
.file-btn:focus-within { outline: 3px solid var(--brass); outline-offset: 2px; }

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: 20px;
  z-index: 20;
  width: fit-content;
  max-width: calc(100vw - 32px);
  margin-inline: auto;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--obsidian);
  color: var(--ivory);
  font-size: .93rem;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .3);
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; padding: 14px 16px 10px; gap: 12px; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .rail-foot { margin: 0; order: 2; }
  .rail-brand { padding: 0; order: 1; }
  .rail-brand span { display: none; }
  .rail-foot .ghost { min-height: 34px; padding: 4px 9px; font-size: .78rem; }
  .tabs { order: 3; width: calc(100% + 32px); margin-inline: -16px; padding-inline: 16px; flex-direction: row; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; min-height: 40px; }
  .admin-page { padding-top: 18px; }
}

@media (max-width: 720px) {
  .report-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .card { padding: 18px; }
  .stat { padding: 13px; }
  .stat b { font-size: 1.7rem; }
  .stat .muted { font-size: .76rem; }
  .login-card { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
