/* ═══════════════════════════════════════════════════════════════
   KADER MIS — interface
   Navy chrome, cyan signal, red alert, light working surface.
   Colours sampled from the KADER MIS brochure.

   The deliberate choice: the frame is the brand, the data area is
   paper-white. A fully dark application would be a cliché and would
   make a thirty-column attendance grid harder to read for an hour
   at a stretch. The brochure is dark; the spreadsheet is white.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --ink:        #0B1F3A;   /* brochure background */
  --ink-2:      #16304F;
  --ink-3:      #1C2D47;
  --signal:     #4EC0F2;   /* brochure cyan */
  --signal-dim: #2E93BF;
  --alert:      #EB515D;   /* brochure red */

  --paper:      #F4F7FA;
  --surface:    #FFFFFF;
  --line:       #DCE3EC;
  --line-soft:  #EDF1F6;

  --text:       #16243A;
  --text-2:     #5A6B84;
  --text-3:     #8A98AC;
  --on-ink:     #E8F1F9;
  --on-ink-2:   #9DB2CC;

  /* money states — semantic, not decorative */
  --settled:    #17805A;
  --settled-bg: #E4F4EC;
  --due:        #B57414;
  --due-bg:     #FCF1DF;
  --muted-bg:   #EEF1F5;

  --rail: 228px;
  --topbar: 56px;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-pop: 0 12px 34px rgba(11,31,58,.18);
  --shadow-soft: 0 1px 2px rgba(11,31,58,.06);

  /* Arabic must render properly; this stack is chosen for that, not for fashion */
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Noto Sans Arabic",
          "Geeza Pro", "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--paper); -webkit-font-smoothing: antialiased;
}
h1,h2,h3 { margin: 0; font-weight: 650; letter-spacing: -.012em; }
h1 { font-size: 21px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
p { margin: 0 0 10px; }
a { color: var(--signal-dim); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 3px; }

/* Every number in this product is money, minutes or a count. Line them up. */
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Arabic names sit inside an English table — let the browser decide per cell */
[dir="auto"] { unicode-bidi: plaintext; }

/* ── boot & sign-in ───────────────────────────────────────── */
.boot { min-height: 100vh; display: grid; place-content: center; gap: 18px;
  justify-items: center; background: var(--ink); color: var(--on-ink-2); }
.boot__mark { width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid rgba(78,192,242,.25); border-top-color: var(--signal);
  animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.signin { min-height: 100vh; display: grid; grid-template-columns: 1fr; background: var(--ink); }
@media (min-width: 880px) { .signin { grid-template-columns: 1.15fr .85fr; } }
.signin__brand { position: relative; overflow: hidden; color: var(--on-ink);
  padding: 44px 40px; display: flex; flex-direction: column; justify-content: space-between; }
.signin__brand::after { content: ""; position: absolute; inset: auto -180px -260px auto;
  width: 620px; height: 620px; border-radius: 50%; border: 1px solid rgba(78,192,242,.16);
  box-shadow: 0 0 0 90px rgba(78,192,242,.045), 0 0 0 180px rgba(78,192,242,.03); }
.signin__headline { font-size: clamp(26px,4vw,40px); line-height: 1.12; max-width: 14ch; position: relative; }
.signin__headline span { display: block; color: var(--signal); }
.signin__tag { color: var(--on-ink-2); max-width: 46ch; margin-top: 14px; position: relative; }
.signin__foot { color: var(--on-ink-2); font-size: 12.5px; position: relative; }
.signin__panel { background: var(--surface); padding: 40px 32px; display: grid; align-content: center; }
.signin__form { width: min(370px,100%); margin: 0 auto; }

.wordmark { display: flex; align-items: baseline; gap: 6px; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.wordmark b { color: #fff; } .wordmark i { font-style: normal; color: var(--signal); }
.wordmark--sub { display: block; font-size: 9.5px; letter-spacing: .1em; color: var(--on-ink-2); margin-top: 3px; }

/* ── frame ────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail { background: var(--ink); color: var(--on-ink-2); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; }
.rail__head { padding: 18px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.07); }
.rail__nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.rail__group { margin: 14px 0 6px; padding: 0 10px; font-size: 10.5px; letter-spacing: .09em;
  color: #62789A; font-weight: 600; }
.rail a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 1px;
  border-radius: var(--radius-sm); color: var(--on-ink-2); text-decoration: none;
  font-size: 13.5px; font-weight: 500; transition: background .12s, color .12s; }
.rail a:hover { background: rgba(255,255,255,.055); color: #fff; }
.rail a.is-active { background: var(--ink-3); color: #fff; box-shadow: inset 2px 0 0 var(--signal); }
.rail .glyph { width: 17px; text-align: center; opacity: .85; flex: none; }
.rail .pill { margin-left: auto; background: var(--alert); color: #fff; font-size: 10.5px;
  font-weight: 700; padding: 1px 6px; border-radius: 9px; min-width: 18px; text-align: center; }
.rail__foot { padding: 12px 16px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; }
.rail__who { color: #fff; font-weight: 600; font-size: 13px; }
.rail__role { color: #62789A; font-size: 11.5px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30; }
.topbar__title { font-weight: 650; font-size: 15px; }
.topbar__spacer { flex: 1; }
.view { padding: 20px 24px 60px; max-width: 1500px; width: 100%; }
.view__head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.view__head p { color: var(--text-2); margin: 3px 0 0; }
.view__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── controls ─────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
input[type=text],input[type=password],input[type=email],input[type=number],
input[type=date],input[type=time],input[type=search],select,textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s; }
input:focus,select:focus,textarea:focus { outline: none; border-color: var(--signal);
  box-shadow: 0 0 0 3px rgba(78,192,242,.18); }
textarea { min-height: 76px; resize: vertical; }
select { appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235A6B84' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; font: inherit; font-weight: 600; font-size: 13.5px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--ink); color: #fff; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s; }
.btn:hover { background: var(--ink-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--signal-dim); } .btn--primary:hover { background: #2681AA; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn--ghost:hover { background: var(--line-soft); }
.btn--danger { background: var(--alert); } .btn--danger:hover { background: #D44551; }
.btn--sm { padding: 5px 10px; font-size: 12.5px; }
.btn--block { width: 100%; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 16px; }
.toolbar .field { margin: 0; min-width: 160px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar .right { margin-left: auto; display: flex; gap: 8px; align-items: flex-end; }

/* ── panels & tables ──────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); overflow: hidden; }
.panel + .panel { margin-top: 16px; }
.panel__head { padding: 12px 15px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel__head .right { margin-left: auto; display: flex; gap: 8px; }
.panel__body { padding: 15px; }
.panel__body--flush { padding: 0; }

.table-wrap { overflow: auto; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.grid th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2);
  padding: 9px 12px; background: #F8FAFC; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2; white-space: nowrap; }
table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tbody tr:hover td { background: #FAFCFE; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid .sub { display: block; font-size: 12px; color: var(--text-3); }
table.grid .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty { padding: 44px 24px; text-align: center; color: var(--text-2); }
.empty h3 { margin-bottom: 6px; color: var(--text); }
.empty p { max-width: 46ch; margin: 0 auto 14px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--muted-bg); color: var(--text-2); }
.badge--paid { background: var(--settled-bg); color: var(--settled); }
.badge--due { background: var(--due-bg); color: var(--due); }
.badge--alert { background: #FDECEE; color: #C33642; }
.badge--info { background: #E4F3FB; color: #1E708F; }
.badge--ink { background: #E7EBF1; color: var(--ink); }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit,minmax(178px,1fr)); margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: var(--shadow-soft); }
.stat__label { font-size: 12.5px; color: var(--text-2); }
.stat__value { font-size: 25px; font-weight: 680; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin-top: 3px; }
.stat__note { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stat--money .stat__value { color: var(--settled); }
.stat--due .stat__value { color: var(--due); }

.bars { display: grid; gap: 9px; }
.bars__row { display: grid; grid-template-columns: minmax(84px,26%) 1fr auto; gap: 10px;
  align-items: center; font-size: 13px; }
.bars__track { background: var(--line-soft); border-radius: 3px; height: 9px; overflow: hidden; }
.bars__fill { height: 100%; background: var(--signal-dim); border-radius: 3px; }
.bars__val { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 12.5px; }

/* ── the attendance grid — the centre of the product ──────── */
.sheet-wrap { overflow: auto; max-height: calc(100vh - 260px); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
table.sheet th, table.sheet td { border-bottom: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); }
table.sheet thead th { position: sticky; top: 0; z-index: 3; background: #F8FAFC;
  padding: 7px 9px; font-size: 11.5px; font-weight: 600; color: var(--text-2);
  border-bottom: 1px solid var(--line); vertical-align: bottom; text-align: center; min-width: 86px; }
table.sheet thead th .ch-title { display: block; color: var(--text); font-size: 12.5px; font-weight: 650; }
table.sheet thead th .ch-meta { display: block; font-size: 10.5px; color: var(--text-3); font-weight: 500; }
table.sheet thead th button.ch-menu { margin-top: 4px; border: 1px solid var(--line); background: #fff;
  border-radius: 4px; font: inherit; font-size: 10.5px; padding: 1px 6px; cursor: pointer; color: var(--text-2); }
table.sheet thead th button.ch-menu:hover { border-color: var(--signal); color: var(--signal-dim); }
table.sheet th.stick-l, table.sheet td.stick-l { position: sticky; left: 0; z-index: 2;
  background: var(--surface); border-right: 1px solid var(--line);
  text-align: left; min-width: 200px; max-width: 280px; }
table.sheet thead th.stick-l { z-index: 4; background: #F8FAFC; }
table.sheet tbody tr:hover td { background: #FAFCFE; }
table.sheet tbody tr:hover td.stick-l { background: #F5F9FD; }
.sheet__name { font-weight: 600; }
.sheet__meta { font-size: 11.5px; color: var(--text-3); }

td.cell { padding: 4px; text-align: center; }
.mark { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font: inherit; padding: 3px 4px 5px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: border-color .12s, background .12s, transform .1s; }
.mark:hover { border-color: var(--signal); }
.mark:active { transform: scale(.97); }
.mark[aria-busy="true"] { opacity: .55; }
.mark__icon { font-size: 13px; font-weight: 700; line-height: 1.15; color: var(--text-3); }
.mark__money { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-3); }

.mark--attended  { background: #F2FAF6; border-color: #BFE3D1; }
.mark--attended  .mark__icon { color: var(--settled); }
.mark--recorded  { background: #F1F8FD; border-color: #C3DFF0; }
.mark--recorded  .mark__icon { color: #1E708F; }
.mark--files_only{ background: #F7F4FD; border-color: #D6CCEC; }
.mark--files_only .mark__icon { color: #6A4FB0; }
.mark--absent    { background: #FDF3F4; border-color: #F0C9CD; }
.mark--absent    .mark__icon { color: var(--alert); }
.mark--not_taken { background: var(--surface); border-style: dashed; }

/* the payment underline — the one place colour carries money state */
.mark[data-pay="settled"] { box-shadow: inset 0 -3px 0 var(--settled); }
.mark[data-pay="due"]     { box-shadow: inset 0 -3px 0 var(--due); }

tr.sheet__totals td { background: #F8FAFC; font-weight: 600; border-top: 1px solid var(--line); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2);
  padding: 10px 15px; border-top: 1px solid var(--line-soft); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; border: 1px solid var(--line); display: inline-block; }

/* ── modal, toast, alert ──────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11,31,58,.5);
  display: grid; place-items: center; padding: 18px; z-index: 100; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-pop);
  width: min(560px,100%); max-height: 92vh; display: flex; flex-direction: column; }
.modal--wide { width: min(880px,100%); }
.modal__head { padding: 16px 20px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; gap: 10px; }
.modal__close { margin-left: auto; border: 0; background: none; font-size: 22px; line-height: 1;
  cursor: pointer; color: var(--text-3); padding: 0 4px; }
.modal__body { padding: 20px; overflow-y: auto; }
.modal__foot { padding: 14px 20px; border-top: 1px solid var(--line-soft);
  display: flex; gap: 9px; justify-content: flex-end; }
.grid2 { display: grid; gap: 0 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200;
  max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow-pop); font-size: 13.5px; }
.toast--error { background: #9E2A34; }
.toast--ok { background: #12684A; }

.alert { padding: 11px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.alert--error { background: #FDECEE; color: #9E2A34; border: 1px solid #F5C9CE; }
.alert--info { background: #E9F5FC; color: #185874; border: 1px solid #C7E4F3; }
.alert--warn { background: var(--due-bg); color: #8A570C; border: 1px solid #F0DCB6; }

.muted { color: var(--text-2); } .small { font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.cols2 { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 1000px) { .cols2 { grid-template-columns: 1fr; } }

/* ── responsive ───────────────────────────────────────────── */
.rail__toggle { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60;
    transform: translateX(-100%); transition: transform .18s ease; }
  .rail.is-open { transform: none; box-shadow: var(--shadow-pop); }
  .rail__toggle { display: inline-flex; }
  .view { padding: 16px 14px 60px; }
  .topbar { padding: 0 12px; }
  .scrim { position: fixed; inset: 0; background: rgba(11,31,58,.45); z-index: 50; }
}
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
@media print {
  .rail, .topbar, .view__actions, .toolbar, .btn { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .panel { border: 1px solid #999; box-shadow: none; }
  body { background: #fff; }
  .sheet-wrap { max-height: none; overflow: visible; }
}
