/* Field RA — app styles. Colours come only from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { flex-shrink: 0; }

/* ---------- App frame ---------- */
#app {
  height: 100vh; height: 100dvh;
  max-width: 640px; margin: 0 auto;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); position: relative;
}
.topbar {
  flex-shrink: 0; background: var(--primary); color: var(--on-primary);
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 8px; min-height: 64px;
}
.icon-btn {
  width: var(--tap); height: var(--tap); border: 0; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14); color: var(--on-primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.26); }
.topbar-logo { height: 30px; width: auto; display: block; }
.topbar-titles { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-title, .bar-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.bar-title { font-size: 15px; font-weight: 700; }
.bar-sub { font-size: 12px; opacity: 0.88; }
.icon-btn.hidden { visibility: hidden; }

.banner-offline {
  flex-shrink: 0; background: var(--warn-bg); color: var(--warn-tx);
  font-size: 13px; font-weight: 600; padding: 6px 14px;
  display: flex; align-items: center; gap: 8px;
}
.banner-offline[hidden] { display: none; }

.view { flex-grow: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.page { padding: 18px 16px 28px; display: flex; flex-direction: column; gap: 12px; }
.page-head { display: flex; flex-direction: column; gap: 2px; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 800; line-height: 1.35; }
.page-head p { margin: 0; font-size: 14px; color: var(--text2); }
.page-head.lg h1 { font-size: 22px; }
.center-msg { padding: 80px 24px; text-align: center; color: var(--text2); font-size: 15px; line-height: 1.8; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

/* ---------- Home ---------- */
.dept-card {
  border: 1px solid var(--border); background: var(--card); border-radius: var(--radius-xl);
  padding: 18px 14px 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  text-align: right; min-height: 160px; box-shadow: var(--shadow-sm);
}
.dept-card:active, .list-btn:active, .act-row:active { background: var(--input-bg); }
.dept-icon { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.dept-civil { background: var(--dept-civil-bg); color: var(--dept-civil-tx); }
.dept-rollout { background: var(--dept-rollout-bg); color: var(--dept-rollout-tx); }
.dept-fiber { background: var(--dept-fiber-bg); color: var(--dept-fiber-tx); }
.dept-telecom { background: var(--dept-telecom-bg); color: var(--dept-telecom-tx); }
.dept-name { font-size: 17px; font-weight: 700; line-height: 1.3; }
.dept-en { font-size: 12px; color: var(--text2); }
.dept-count { font-size: 13px; font-weight: 600; color: var(--primary); }

.row-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; display: flex; align-items: center; gap: 12px; text-align: right; width: 100%;
  min-height: 72px;
}
button.row-card:active { background: var(--input-bg); }
.row-card.resume { border: 2px solid var(--primary); }
.row-icon {
  width: 40px; height: 40px; border-radius: var(--radius); background: var(--primary-tint); color: var(--primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 800; font-size: 15px;
}
.row-icon.warn { background: var(--warn-bg); color: var(--warn-tx); }
.row-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-size: 15px; font-weight: 700; line-height: 1.35; }
.row-sub { font-size: 13px; color: var(--text2); line-height: 1.5; }
.row-en { font-size: 12px; color: var(--text2); direction: ltr; text-align: right; }
.count-pill {
  font-size: 12px; font-weight: 700; color: var(--text2); background: var(--muted-bg);
  border-radius: 999px; padding: 4px 10px; white-space: nowrap; flex-shrink: 0;
}
.chev { color: var(--text2); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 700; }
.field input, .field textarea {
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--input-bg);
  font-size: 16px; font-weight: 400; width: 100%;
}
.field input { height: 48px; padding: 0 14px; }
.field textarea { padding: 10px 14px; resize: vertical; line-height: 1.6; min-height: 92px; font-size: 15px; }
.field input:focus, .field textarea:focus { border-color: var(--primary); outline: 2px solid var(--primary-tint); }
.field input.ltr-input { direction: ltr; text-align: right; }
.field .hint { font-size: 12px; font-weight: 600; color: var(--text2); }
.field .hint.err { color: var(--band-red-tx); }
.field.invalid input { border-color: var(--band-red-tx); }
.info-tile { background: var(--bg); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.info-tile .k { font-size: 12px; color: var(--text2); font-weight: 600; }
.info-tile .v { font-size: 14px; font-weight: 700; }
.info-tile .v.ok { color: var(--band-green-tx); }
.info-tile .v.bad { color: var(--warn-tx); }
.link-btn { border: 0; background: transparent; color: var(--primary); font-size: 13px; font-weight: 700; padding: 0; min-height: 32px; text-align: right; }
.note { margin: 0; font-size: 12px; color: var(--text2); line-height: 1.6; }

/* ---------- Activities list ---------- */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; }
.progress-head .t { font-size: 15px; font-weight: 700; }
.progress-head .n { font-size: 15px; font-weight: 800; color: var(--primary); }
.progress { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; }
.progress > div { height: 8px; background: var(--primary); border-radius: 99px; transition: width .25s; }
.act-row {
  border: 1px solid var(--border); background: var(--card); border-radius: var(--radius-lg);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; text-align: right; min-height: 68px; width: 100%;
}
.act-row.done { border-color: var(--ok-border); }
.act-dot {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800;
  background: var(--band-none-bg); color: var(--band-none-tx);
}
.act-dot.started { background: var(--warn-bg); color: var(--warn-tx); }
.act-dot.done { background: var(--ok); color: var(--on-primary); }
.score-pair { display: flex; align-items: center; gap: 4px; direction: ltr; flex-shrink: 0; }
.chip { font-size: 12px; font-weight: 800; border-radius: var(--radius-sm); padding: 3px 7px; white-space: nowrap; }

/* Risk band colours */
.b-0 { background: var(--band-none-bg); color: var(--band-none-tx); }
.b-g { background: var(--band-green-bg); color: var(--band-green-tx); }
.b-y { background: var(--band-yellow-bg); color: var(--band-yellow-tx); }
.b-o { background: var(--band-orange-bg); color: var(--band-orange-tx); }
.b-r { background: var(--band-red-bg); color: var(--band-red-tx); }

/* ---------- Activity detail ---------- */
.act-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.act-meta .pos { font-size: 13px; font-weight: 700; color: var(--text2); }
.act-meta .sev { font-size: 12px; font-weight: 700; color: var(--text2); background: var(--track); border-radius: 99px; padding: 3px 10px; }
.act-title { margin: -4px 0 0; font-size: 21px; font-weight: 800; line-height: 1.35; }
.haz-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.haz-toggle {
  width: 100%; border: 0; background: var(--card); padding: 12px 14px; display: flex; align-items: center; gap: 8px;
  text-align: right; min-height: 48px;
}
.haz-toggle .t { flex-grow: 1; font-size: 15px; font-weight: 700; }
.haz-toggle .a { font-size: 13px; color: var(--primary); font-weight: 700; }
.haz-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.haz-body[hidden] { display: none; }
.bullets { display: flex; flex-direction: column; gap: 6px; }
.bullets .lbl { font-size: 12px; font-weight: 700; color: var(--text2); }
.bullet { display: flex; gap: 8px; font-size: 14px; line-height: 1.6; }
.bullet::before { content: '•'; font-weight: 800; color: var(--hazard-ink); }
.bullet.c::before { color: var(--band-red-tx); }

.step { transition: opacity .2s; }
.step.dim { opacity: 0.55; }
.step-head { display: flex; align-items: center; gap: 8px; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: var(--on-primary);
  font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.step-title { font-size: 15px; font-weight: 700; flex-grow: 1; }
.step-tag { font-size: 12px; font-weight: 700; color: var(--text2); background: var(--muted-bg); border-radius: 99px; padding: 3px 10px; }
.step-sub { font-size: 14px; font-weight: 700; }
.step-desc { margin: 0; font-size: 13px; color: var(--text2); line-height: 1.6; }
.step.extra4 { border: 2px solid var(--extra-border); }
.step.extra4 .step-num { background: var(--extra-ink); }
.step.extra4 .step-desc { color: var(--band-orange-tx); }

.controls-list { margin: 0; padding: 0 22px 0 0; display: flex; flex-direction: column; gap: 6px; }
.controls-list li { font-size: 14px; line-height: 1.6; }
.dashed-btn {
  border: 1px dashed var(--border-dashed); background: var(--input-bg); border-radius: var(--radius);
  min-height: var(--tap); font-size: 14px; font-weight: 700; color: var(--primary);
}

.pills { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.pill {
  border: 1px solid var(--border-strong); background: var(--card); color: var(--text);
  border-radius: var(--radius); padding: 8px 2px; min-height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.pill .v { font-size: 18px; font-weight: 800; line-height: 1; }
.pill .l { font-size: 10.5px; font-weight: 600; line-height: 1.25; text-align: center; }
.pill.sel { border: 2px solid var(--text); }
.pill.sel.b-g { background: var(--band-green-bg); color: var(--band-green-tx); }
.pill.sel.b-y { background: var(--band-yellow-bg); color: var(--band-yellow-tx); }
.pill.sel.b-o { background: var(--band-orange-bg); color: var(--band-orange-tx); }
.pill.sel.b-r { background: var(--band-red-bg); color: var(--band-red-tx); }
.pill:disabled { border: 1px dashed var(--disabled-bg); background: var(--bg); color: var(--text-disabled); }

.formula { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg); border-radius: var(--radius); padding: 8px 12px; }
.formula .f { font-size: 13px; color: var(--text2); font-weight: 600; }
.formula .s { font-size: 13px; font-weight: 800; border-radius: 10px; padding: 4px 10px; white-space: nowrap; }

.toggle2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.toggle2 button {
  min-height: 48px; border-radius: var(--radius); font-size: 15px; font-weight: 700;
  border: 1px solid var(--border-strong); background: var(--card);
}
.toggle2 button.no.on { border: 2px solid var(--band-green-tx); background: var(--band-green-bg); color: var(--band-green-tx); }
.toggle2 button.yes.on { border: 2px solid var(--extra-ink); background: var(--band-orange-bg); color: var(--band-orange-tx); }
.extra-fields { display: flex; flex-direction: column; gap: 12px; }
.extra-fields[hidden] { display: none; }

.stop-banner {
  background: var(--danger); color: var(--on-primary); border-radius: var(--radius-lg); padding: 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.stop-banner .t { font-size: 16px; font-weight: 800; display: block; }
.stop-banner .d { font-size: 13px; line-height: 1.6; display: block; }

/* ---------- Review ---------- */
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.summary-grid > div { display: flex; flex-direction: column; min-width: 0; }
.summary-grid .k { font-size: 12px; color: var(--text2); font-weight: 600; }
.summary-grid .v { font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.rev-table { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.rev-row { display: grid; grid-template-columns: minmax(0, 1fr) 54px 54px 54px; gap: 4px; padding: 10px 12px; border-top: 1px solid var(--muted-bg); align-items: center; }
.rev-row.head { background: var(--muted-bg); font-size: 12px; font-weight: 700; color: var(--text2); border-top: 0; }
.rev-row .n { font-size: 13px; font-weight: 600; line-height: 1.4; }
.rev-row .c { text-align: center; font-size: 13px; font-weight: 800; border-radius: var(--radius-sm); padding: 3px 0; }
.rev-row.head .c { font-weight: 700; }
.sig-head { display: flex; justify-content: space-between; align-items: center; }
.sig-head .t { font-size: 15px; font-weight: 700; }
.sig-head button { border: 0; background: transparent; color: var(--primary); font-size: 14px; font-weight: 700; min-height: var(--tap); padding: 0 8px; }
.sig-canvas {
  width: 100%; height: 170px; border: 1.5px dashed var(--border-dashed); border-radius: var(--radius);
  background: var(--input-bg); touch-action: none; display: block;
}
.alert-warn { background: var(--warn-bg); color: var(--warn-tx); border-radius: 14px; padding: 10px 14px; font-size: 13px; font-weight: 600; line-height: 1.6; }

/* ---------- Done ---------- */
.done-wrap { padding: 32px 20px 28px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.done-badge { width: 84px; height: 84px; border-radius: 50%; background: var(--band-green-bg); color: var(--band-green-tx); display: flex; align-items: center; justify-content: center; }
.done-wrap h1 { margin: 0; font-size: 22px; font-weight: 800; }
.done-wrap p { margin: 0; font-size: 14px; color: var(--text2); line-height: 1.7; }
.file-card { width: 100%; text-align: right; flex-direction: row; align-items: center; }
.pdf-ico { width: 44px; height: 52px; border-radius: var(--radius-sm); background: var(--band-red-bg); color: var(--band-red-tx); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; flex-shrink: 0; }
.file-name { font-size: 13px; font-weight: 700; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 52px; border-radius: 14px; font-size: 16px; font-weight: 800; border: 0; padding: 0 18px;
  display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none;
}
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { background: var(--disabled-bg); color: var(--disabled-tx); }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border-strong); font-size: 15px; font-weight: 700; }
.btn-wa { background: var(--whatsapp); color: var(--on-primary); width: 100%; min-height: 54px; }
.btn-block { width: 100%; }
.btn-text { border: 0; background: transparent; color: var(--primary); font-size: 15px; font-weight: 700; min-height: var(--tap); padding: 0 12px; }
.btn-danger-text { color: var(--band-red-tx); }
.btn-sm { min-height: var(--tap); font-size: 14px; padding: 0 14px; border-radius: var(--radius); }

.actionbar {
  flex-shrink: 0; background: var(--card); border-top: 1px solid var(--border);
  padding: 10px 14px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; gap: 10px;
}
.actionbar[hidden] { display: none; }
.actionbar .btn-primary { flex-grow: 1; }

/* ---------- History ---------- */
.hist-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hist-actions .btn { flex: 1 1 auto; }
.status-tag { font-size: 12px; font-weight: 700; border-radius: 99px; padding: 2px 10px; white-space: nowrap; }
.status-tag.shared { background: var(--band-green-bg); color: var(--band-green-tx); }
.status-tag.pending { background: var(--warn-bg); color: var(--warn-tx); }
.hist-top { display: flex; gap: 10px; align-items: flex-start; }

/* ---------- Sheet / modal / busy ---------- */
.overlay { position: absolute; inset: 0; background: var(--overlay); display: flex; flex-direction: column; justify-content: flex-end; z-index: 20; }
.overlay.center { justify-content: center; padding: 20px; }
.sheet {
  background: var(--card); border-radius: 22px 22px 0 0; padding: 16px 16px 22px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; max-height: 88%; overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.close-btn { width: var(--tap); height: var(--tap); border: 0; border-radius: var(--radius); background: var(--muted-bg); display: flex; align-items: center; justify-content: center; }
.matrix { display: grid; grid-template-columns: 70px repeat(5, minmax(0, 1fr)); gap: 4px; }
.matrix .corner { font-size: 10px; font-weight: 700; color: var(--text2); display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.3; }
.matrix .h { font-size: 12px; font-weight: 800; text-align: center; padding: 4px 0; line-height: 1.3; }
.matrix .h small { display: block; font-size: 9.5px; font-weight: 600; color: var(--text2); }
.matrix .rl { background: var(--muted-bg); font-size: 11px; font-weight: 700; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.25; padding: 2px; }
.matrix .cell { height: 40px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; }
.legend { display: flex; flex-direction: column; gap: 6px; }
.legend > div { display: flex; gap: 10px; align-items: flex-start; }
.legend .r { min-width: 54px; text-align: center; font-size: 12px; font-weight: 800; border-radius: var(--radius-sm); padding: 3px 4px; direction: ltr; flex-shrink: 0; }
.legend .t { font-size: 13px; line-height: 1.6; }
.defs { display: flex; flex-direction: column; gap: 4px; font-size: 13px; line-height: 1.6; }
.defs h3 { margin: 6px 0 2px; font-size: 14px; font-weight: 800; }

.modal { background: var(--card); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 420px; margin: 0 auto; }
.modal h2 { margin: 0; font-size: 18px; font-weight: 800; }
.modal p { margin: 0; font-size: 14px; line-height: 1.7; color: var(--text2); }
.modal .acts { display: flex; gap: 10px; }
.modal .acts .btn { flex: 1; }

.busy { position: absolute; inset: 0; background: rgba(245, 246, 250, 0.94); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.busy .t { font-size: 16px; font-weight: 800; }
.busy .d { font-size: 13px; color: var(--text2); }
.spinner { width: 48px; height: 48px; border-radius: 50%; border: 5px solid var(--track); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute; left: 16px; right: 16px; bottom: 90px; z-index: 40; background: var(--text); color: var(--on-primary);
  border-radius: 14px; padding: 12px 16px; font-size: 14px; font-weight: 600; text-align: center; line-height: 1.6;
  box-shadow: 0 6px 20px rgba(26, 29, 46, 0.25);
}

/* Hidden render area for the PDF (laid out at A4 landscape size, behind everything). */
#pdf-stage { position: fixed; top: 0; left: 0; z-index: -10; pointer-events: none; opacity: 1; }
h1:focus { outline: none; }
