:root {
  --bg: #f4f6f4;
  --card: #ffffff;
  --ink: #1d2b24;
  --muted: #6b7a72;
  --line: #e2e8e4;
  --brand: #1f7a4d;
  --brand-2: #e7f3ec;
  --ok: #1f7a4d; --ok-bg: #e3f4ea;
  --warn: #9a6100; --warn-bg: #fdf1dc;
  --bad: #b3261e; --bad-bg: #fbe7e6;
  --info: #2c5d8f; --info-bg: #e6eef8;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 'Tajawal', system-ui, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------- sidebar layout ---------- */
.side { position: fixed; top: 0; bottom: 0; right: 0; width: 248px; background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 20; }
.side::before { content: ''; display: block; height: 4px; background: repeating-linear-gradient(90deg, var(--brand) 0 6px, #2e9a63 6px 12px); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; }
.side-brand b { display: block; font-size: 16px; line-height: 1.2; }
.side-brand small { color: var(--muted); font-size: 12px; }
.logo-mark { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #1f7a4d, #145236); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; }
.side-nav { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.side-label { font-size: 12px; color: #a07c2c; font-weight: 700; margin: 16px 10px 6px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--ink); font-size: 14.5px; margin-bottom: 2px; }
.side-nav a svg { width: 19px; height: 19px; flex: none; color: var(--muted); }
.side-nav a:hover { background: var(--bg); text-decoration: none; }
.side-nav a.on { background: linear-gradient(135deg, #1f7a4d, #145236); color: #fff; font-weight: 700; box-shadow: 0 4px 12px #1f7a4d33; }
.side-nav a.on svg { color: #fff; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.side-user form { margin: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-2); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar:hover { text-decoration: none; }
.side-user-name { flex: 1; min-width: 0; color: var(--ink); }
.side-user-name:hover { text-decoration: none; }
.side-user-name b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-name small { color: var(--muted); font-size: 12px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--bg); color: var(--bad); }
.icon-btn svg { width: 19px; height: 19px; }
body.has-side main { margin-right: 248px; max-width: none; padding: 24px 28px 60px; }
.mobile-top, .side-backdrop { display: none; }
@media (max-width: 960px) {
  .side { transform: translateX(100%); transition: transform .2s; box-shadow: -8px 0 24px #0002; }
  body.side-open .side { transform: none; }
  body.side-open .side-backdrop { display: block; position: fixed; inset: 0; background: #0004; z-index: 15; }
  .mobile-top { display: flex; align-items: center; gap: 10px; background: #fff; border-bottom: 1px solid var(--line); padding: 8px 12px; position: sticky; top: 0; z-index: 10; }
  .mobile-top .icon-btn:hover { color: var(--ink); }
  body.has-side main { margin-right: 0; padding: 16px 12px 40px; }
}

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.pill { display: inline-block; background: var(--brand-2); color: var(--brand); border-radius: 999px; padding: 2px 12px; font-size: 14px; font-weight: 500; vertical-align: middle; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; overflow-x: auto; }
.card.narrow { max-width: 520px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2.wide-first { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
@media (max-width: 900px) { .grid2, .grid2.wide-first { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--ink); display: flex; flex-direction: column; }
a.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat b { font-size: 28px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 14px; }
.stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); } .stat.bad b { color: var(--bad); }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: right; font-weight: 500; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); padding: 6px 8px; white-space: nowrap; }
.tbl td { border-bottom: 1px solid var(--line); padding: 7px 8px; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fafcfb; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; text-align: right; }
.tbl td.num { text-align: right; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.wrap-any { word-break: break-all; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.dim td { opacity: .55; }
.strike td:first-child { text-decoration: line-through; }
.bad-t { color: var(--bad); font-weight: 700; } .warn-t { color: var(--warn); font-weight: 700; }

.badge { display: inline-block; border-radius: 6px; padding: 1px 8px; font-size: 12px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok, .badge.present { background: var(--ok-bg); color: var(--ok); }
.badge.warn, .badge.late, .badge.incomplete { background: var(--warn-bg); color: var(--warn); }
.badge.bad, .badge.absent { background: var(--bad-bg); color: var(--bad); }
.badge.in_progress, .badge.leave, .badge.off_work { background: var(--info-bg); color: var(--info); }
.badge.not_yet { background: #f0f0f0; color: #555; }

.led { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #c5ccc8; vertical-align: middle; }
.led.on { background: #2fbf6b; box-shadow: 0 0 0 3px #2fbf6b33; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--bad-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

input, select, button { font: inherit; }
input, select { border: 1px solid #cfd8d3; border-radius: 7px; padding: 7px 10px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--brand-2); border-color: var(--brand); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); vertical-align: middle; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.stack label input, .stack label select { color: var(--ink); }
label.inline, .stack label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > label { flex: 1; }
.row.between { justify-content: space-between; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row form { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters label { display: flex; gap: 6px; align-items: center; }
.days { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; }

.btn { display: inline-block; border: 1px solid #cfd8d3; background: #fff; color: var(--ink); border-radius: 7px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #196640; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; }
.link.danger { color: var(--bad); }
.help summary { cursor: pointer; font-weight: 700; }
.help ol { margin: 10px 0; padding-inline-start: 22px; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; }

.login { max-width: 380px; margin: 10vh auto; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login h1 { color: var(--brand); }

@media (max-width: 640px) {
  main { padding: 14px 12px 40px; }
  .row { flex-direction: column; align-items: stretch; }
  .stat b { font-size: 22px; }
}
@media print {
  .no-print { display: none !important; }
  body.has-side main { margin: 0; }
  body { background: #fff; font-size: 11px; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; }
  .tbl td, .tbl th { padding: 3px 5px; }
  a { color: inherit; }
}

/* ---------- device assignment ---------- */
.card { border-radius: 14px; }
.dev-list { display: flex; flex-direction: column; gap: 8px; }
.stack label.dev-item, .dev-item { display: flex; flex-direction: row; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; color: var(--ink); }
.dev-item:hover { border-color: var(--brand); }
.dev-item:has(input:checked) { background: var(--brand-2); border-color: #bfdcc9; }
.dev-item > span:not(.badge) { flex: 1; }
.dev-item b { display: block; font-weight: 500; }
.dev-item small { color: var(--muted); font-size: 12px; }
.save-bar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 35%); padding: 16px 0 8px; margin-bottom: 8px; z-index: 5; }
.save-bar .btn { min-width: 160px; }
.bulk { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
details summary { cursor: pointer; color: var(--brand); }
.dev-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.dev-actions form { margin: 0; }
.login .logo-mark { width: 46px; height: 46px; font-size: 22px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.login-brand h1 { font-size: 20px; }
.login-brand p { margin: 0; }
.center { text-align: center; }
.login .btn { text-align: center; }

/* ---------- detailed report ---------- */
.filter-card { box-shadow: 0 6px 24px #1f7a4d0f; }
.filter-title { color: var(--brand); margin: 0; }
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 16px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); font-weight: 700; box-shadow: 0 1px 4px #0001; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip-btn { border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px; color: var(--ink); font-size: 14px; background: #fff; }
.chip-btn:hover { border-color: var(--brand); text-decoration: none; }
.chip-btn.on { background: var(--brand-2); border-color: #bfdcc9; color: var(--brand); font-weight: 700; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.filter-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filter-grid input, .filter-grid select { padding: 9px 10px; color: var(--ink); }
.btn.grow { flex: 1; padding: 10px; background: linear-gradient(90deg, #145236, #1f7a4d); }
.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { min-width: 260px; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; }
.col-menu { position: relative; }
.col-menu summary { list-style: none; color: var(--ink); }
.col-menu summary::-webkit-details-marker { display: none; }
.col-pop { position: absolute; left: 0; top: 110%; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; box-shadow: 0 8px 24px #0002; z-index: 10; display: flex; flex-direction: column; gap: 6px; min-width: 180px; white-space: nowrap; }
.detailed .sum-row { cursor: pointer; }
.detailed .sum-row td { padding: 11px 8px; }
.detailed .chev { display: inline-block; color: var(--muted); font-size: 18px; transition: transform .15s; }
.detailed tbody.open .chev { transform: rotate(-90deg); }
.detailed .det-row { display: none; }
.detailed tbody.open .det-row, body.print-details .detailed .det-row { display: table-row; }
.detailed .det-row > td { background: #f8faf9; padding: 6px 12px 14px; }
.tbl.inner { background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.chip { display: inline-block; border-radius: 7px; padding: 2px 10px; font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.grey { background: #eceeed; color: #444; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.round-btn { width: 30px; height: 30px; border: 1.5px solid var(--brand); border-radius: 50%; display: inline-grid; place-items: center; color: var(--brand); }
.round-btn svg { width: 15px; height: 15px; }
.round-btn:hover { background: var(--brand-2); }
.print-only { display: none; }
@media print {
  .print-only { display: block; }
  .print-title { margin-bottom: 10px; }
  .detailed .det-row > td { background: none; }
  .chip { padding: 0; background: none !important; }
}
.side-credit { font-size: 11px; color: #9aa6a0; text-align: center; padding: 0 12px 10px; }
.side-credit span { color: var(--muted); font-weight: 500; }

fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain:disabled .dev-item { cursor: default; opacity: .75; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.perm-group { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 7px; background: #fbfcfb; }
.perm-group .perm-head { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 2px; color: var(--brand); }
.perm-group label { font-size: 14px; }
.perm-group label.na { opacity: .45; }
.role-card fieldset:disabled .perm-group { opacity: .8; }
.scope-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.scope-list { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.scope-box.all .scope-list { opacity: .4; pointer-events: none; }
.user-card.inactive { opacity: .7; }
