:root {
  --ink: #16202A;
  --ink-2: #55646F;
  --ink-3: #8593A0;
  --rail: #14232E;
  --rail-2: #1E3442;
  --line: #DDE1E6;
  --bg: #F1F3F5;
  --card: #FFFFFF;
  --teal: #0E7C6B;
  --teal-soft: #E3F1EE;
  --amber: #B8701A;
  --amber-soft: #FBEEDC;
  --brick: #A63D40;
  --brick-soft: #F8E6E6;
  --slate-soft: #E8EBEE;
  --r: 10px;
  --shadow: 0 1px 2px rgba(20,35,46,.06), 0 6px 18px -10px rgba(20,35,46,.22);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: 'IBM Plex Sans Arabic', system-ui, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}

h1, h2, h3, .display { font-family: 'Readex Pro', system-ui, sans-serif; font-weight: 500; letter-spacing: -.01em; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }

button, input, select { font: inherit; color: inherit; }
a { color: var(--teal); }

/* ── تسجيل الدخول ─────────────────────────────────────────── */
#login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 80% -10%, #1E3442 0%, transparent 60%),
    var(--rail);
}
.login-card {
  width: min(400px, 100%); background: var(--card);
  border-radius: 14px; padding: 34px 30px; box-shadow: 0 24px 60px -20px rgba(0,0,0,.5);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--teal);
  position: relative; flex: none;
}
.brand-mark::after {
  content: ''; position: absolute; inset: 8px 8px auto auto;
  width: 2px; height: 9px; background: #fff; border-radius: 2px;
  transform-origin: bottom center; transform: rotate(38deg);
}
.brand-mark::before {
  content: ''; position: absolute; inset: 11px auto auto 8px;
  width: 7px; height: 2px; background: #fff; border-radius: 2px;
}
.brand h1 { font-size: 21px; }
.sub { color: var(--ink-3); font-size: 13.5px; }

.field { margin-top: 16px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--r); background: #fff; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft);
}

.btn {
  padding: 10px 16px; border: 1px solid transparent; border-radius: var(--r);
  background: var(--teal); color: #fff; cursor: pointer; font-weight: 500;
  transition: filter .15s, transform .06s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--slate-soft); filter: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; margin-top: 20px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.alert {
  margin-top: 14px; padding: 9px 12px; border-radius: var(--r); font-size: 13.5px;
  background: var(--brick-soft); color: var(--brick); border: 1px solid #EBCFCF;
}

/* ── الهيكل ───────────────────────────────────────────────── */
#app { display: none; min-height: 100dvh; grid-template-columns: 236px 1fr; }
#app.on { display: grid; }

aside {
  background: var(--rail); color: #C6D2DA; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh;
}
aside .brand { padding: 0 8px 18px; color: #fff; }
aside .brand h1 { font-size: 18px; }
.nav-label {
  font-size: 11px; letter-spacing: .09em; color: #61798A;
  padding: 14px 10px 6px; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: 8px; cursor: pointer; font-size: 14.5px;
  border: none; background: none; width: 100%; text-align: right; color: inherit;
}
.nav-item:hover { background: var(--rail-2); color: #fff; }
.nav-item.active { background: var(--teal); color: #fff; }
.nav-item:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.nav-count { font-size: 12px; opacity: .8; }
.nav-foot { margin-top: auto; border-top: 1px solid #26404F; padding-top: 14px; }
.nav-user { padding: 0 10px 10px; font-size: 13px; }
.nav-user b { display: block; color: #fff; font-weight: 500; }
.nav-user span { color: #61798A; font-size: 12px; }

main { padding: 26px 30px 60px; min-width: 0; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-head h2 { font-size: 23px; }
.page-head .sub { margin-top: 2px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--teal); outline-offset: -1px; }

/* ── البطاقات والإحصاءات ──────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-head h3 { font-size: 15.5px; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); margin-bottom: 18px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 15px 16px; }
.stat .k { font-size: 12.5px; color: var(--ink-3); }
.stat .v { font-family: 'Readex Pro', sans-serif; font-size: 27px; line-height: 1.25; margin-top: 2px; }
.stat .m { font-size: 12px; color: var(--ink-3); }
.stat.teal { border-inline-start: 3px solid var(--teal); }
.stat.amber { border-inline-start: 3px solid var(--amber); }
.stat.brick { border-inline-start: 3px solid var(--brick); }
.stat.rail { border-inline-start: 3px solid var(--rail); }

/* ── شريط اليوم: العنصر المميّز ───────────────────────────── */
.rail-legend {
  display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px;
  color: var(--ink-3); padding: 0 18px 12px;
}
.rail-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-inline-end: 5px; }
.rail-scale {
  position: relative; height: 18px; margin: 0 18px 4px;
  border-bottom: 1px solid var(--line);
}
.rail-scale span {
  position: absolute; transform: translateX(50%); font-size: 11px; color: var(--ink-3);
}
.rail-row {
  display: grid; grid-template-columns: 190px 1fr 96px; align-items: center;
  gap: 12px; padding: 7px 18px; border-bottom: 1px solid #F0F2F4;
}
.rail-row:last-child { border-bottom: none; }
.rail-row:hover { background: #FAFBFC; }
.rail-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-name small { display: block; color: var(--ink-3); font-size: 11.5px; }
.rail-track {
  position: relative; height: 22px; background: var(--slate-soft);
  border-radius: 4px; overflow: visible;
}
.rail-shift {
  position: absolute; top: 0; bottom: 0; background: #fff;
  border: 1px dashed #BFC8D0; border-radius: 4px;
}
.rail-span { position: absolute; top: 4px; bottom: 4px; border-radius: 3px; background: var(--teal); }
.rail-span.late { background: var(--amber); }
.rail-span.open {
  background: repeating-linear-gradient(45deg, var(--ink-3) 0 4px, #B6C0C8 4px 8px);
}
.rail-tick {
  position: absolute; top: -2px; width: 2px; height: 26px;
  background: var(--rail); border-radius: 2px;
}
.rail-meta { font-size: 12.5px; color: var(--ink-2); text-align: end; }

/* ── الجداول ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: right; font-weight: 500; font-size: 12.5px; color: var(--ink-3);
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid #F0F2F4; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFBFC; }
td .em { display: block; font-size: 12px; color: var(--ink-3); }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px;
  border-radius: 20px; font-size: 12.5px; background: var(--slate-soft); color: var(--ink-2);
}
.pill.ok { background: var(--teal-soft); color: var(--teal); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--brick-soft); color: var(--brick); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-family: 'Readex Pro', sans-serif; margin-bottom: 4px; }

/* ── النافذة المنبثقة ─────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20,35,46,.45); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; width: min(480px, 100%);
  max-height: 88dvh; overflow: auto; box-shadow: 0 30px 70px -20px rgba(0,0,0,.5);
}
.modal h3 { padding: 18px 22px 0; font-size: 17px; }
.modal .modal-body { padding: 4px 22px 22px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 22px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast {
  position: fixed; inset-block-end: 22px; inset-inline-start: 22px; z-index: 60;
  background: var(--rail); color: #fff; padding: 11px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; animation: rise .2s ease-out;
}
.toast.bad { background: var(--brick); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.days { display: flex; gap: 5px; flex-wrap: wrap; }
.days label {
  padding: 5px 9px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.days input { display: none; }
.days input:checked + span { color: var(--teal); font-weight: 500; }
.days label:has(input:checked) { border-color: var(--teal); background: var(--teal-soft); }

code.sn { background: var(--slate-soft); padding: 1px 6px; border-radius: 5px; font-size: 13px; }

@media (max-width: 860px) {
  #app.on { grid-template-columns: 1fr; }
  aside { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  aside .brand, .nav-label { padding-bottom: 0; width: 100%; }
  .nav-item { width: auto; }
  .nav-foot { margin: 0; border: none; padding: 0; }
  main { padding: 18px 14px 50px; }
  .rail-row { grid-template-columns: 130px 1fr; }
  .rail-meta { grid-column: 1 / -1; text-align: start; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
