:root {
  --navy: #1F3864;
  --steel: #2E5F8A;
  --light-blue: #D6E4F0;
  --white: #ffffff;
  --green: #375623;
  --green-bg: #E2EFDA;
  --green-border: #375623;
  --amber: #854F0B;
  --amber-bg: #FFF2CC;
  --amber-border: #FFC000;
  --red: #C00000;
  --red-bg: #FFE0E0;
  --red-border: #C00000;
  --orange: #E26B0A;
  --orange-bg: #FCE4D6;
  --grey: #F2F2F2;
  --mid-grey: #D9D9D9;
  --text: #1F1F1F;
  --text-muted: #666666;
  --text-hint: #999999;
  --border: rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-pill: 20px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: #f0f2f5;
  height: 100%;
  overscroll-behavior: none;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--white);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Top bar ────────────────────────────────────────────────────── */
.topbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 52px;
}
.topbar-title { font-size: 16px; font-weight: 600; flex: 1; }
.role-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--grey);
  color: var(--text-muted);
  font-weight: 500;
}
.role-badge.ap { background: var(--light-blue); color: var(--steel); }
.role-badge.supervisor { background: var(--amber-bg); color: var(--amber); }
.role-badge.manager { background: var(--green-bg); color: var(--green); }
.back-btn {
  background: none; border: none; cursor: pointer;
  color: var(--steel); font-size: 22px; line-height: 1;
  padding: 0 2px; display: none;
}
.notif-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 20px;
  position: relative; padding: 0 2px;
}
.notif-dot {
  position: absolute; top: 0; right: 0;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); border: 2px solid white;
  display: none;
}
.notif-dot.visible { display: block; }

/* ── Nav tabs ───────────────────────────────────────────────────── */
.nav-tabs {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}
.nav-tab {
  flex: 1; padding: 10px 4px;
  text-align: center; font-size: 12px; font-weight: 500;
  cursor: pointer; color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all .15s; user-select: none;
}
.nav-tab.active { color: var(--steel); border-bottom-color: var(--steel); }

/* ── Screens ────────────────────────────────────────────────────── */
.screen { display: none; flex: 1; padding: 16px; overflow-y: auto; }
.screen.active { display: block; }

/* ── Progress ───────────────────────────────────────────────────── */
.progress-bar { height: 3px; background: var(--grey); border-radius: 2px; margin-bottom: 16px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--steel); border-radius: 2px; transition: width .3s; }
.step-label { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; font-weight: 500; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.card-sub { font-size: 12px; color: var(--text-muted); }
.card.clickable { cursor: pointer; transition: opacity .15s; }
.card.clickable:active { opacity: 0.75; }
.card.danger-border { border-color: var(--red-border); }
.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-muted);
  margin: 16px 0 8px;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: block; width: 100%; padding: 13px;
  border-radius: var(--radius); font-size: 14px; font-weight: 600;
  cursor: pointer; text-align: center;
  border: 1px solid var(--mid-grey);
  background: var(--grey); color: var(--text);
  transition: opacity .15s; margin-bottom: 8px;
}
.btn:active { opacity: .75; }
.btn:disabled, .btn.disabled { opacity: .38; pointer-events: none; }
.btn-primary { background: var(--steel); border-color: var(--steel); color: white; }
.btn-success { background: var(--green); border-color: var(--green); color: white; }
.btn-danger  { background: var(--red);   border-color: var(--red);   color: white; }
.btn-warning { background: var(--amber); border-color: var(--amber); color: white; }
.btn-outline { background: white; border-color: var(--steel); color: var(--steel); }

/* ── Form fields ────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
.field input,
.field select,
.field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--mid-grey); border-radius: var(--radius-sm);
  font-size: 14px; background: white; color: var(--text);
  appearance: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none; border-color: var(--steel);
  box-shadow: 0 0 0 3px rgba(46,95,138,.15);
}
.field textarea { min-height: 72px; resize: vertical; }
.field input[type=number] { font-weight: 600; font-size: 16px; }

/* ── Banners ────────────────────────────────────────────────────── */
.banner {
  border-radius: var(--radius-sm); padding: 11px 13px;
  margin-bottom: 12px; display: flex; align-items: flex-start; gap: 9px;
  font-size: 13px; line-height: 1.5;
}
.banner.info    { background: var(--light-blue); color: var(--steel); border: 1px solid rgba(46,95,138,.3); }
.banner.warning { background: var(--amber-bg);   color: var(--amber); border: 1px solid var(--amber-border); }
.banner.danger  { background: var(--red-bg);     color: var(--red);   border: 1px solid var(--red-border); }
.banner.success { background: var(--green-bg);   color: var(--green); border: 1px solid var(--green-border); }
.banner-icon {
  width: 16px; height: 16px; border-radius: 50%;
  flex-shrink: 0; margin-top: 1px;
  display: flex; align-items: center; justify-content: center;
}
.banner.warning .banner-icon { background: var(--amber); }
.banner.danger  .banner-icon { background: var(--red); }
.banner.info    .banner-icon { background: var(--steel); }
.banner-icon::after { content: ''; width: 2px; height: 7px; background: white; border-radius: 1px; }

/* ── FOS boxes ──────────────────────────────────────────────────── */
.fos-box { border-radius: var(--radius-sm); padding: 13px; margin-bottom: 10px; border: 1px solid var(--mid-grey); background: var(--grey); }
.fos-box.pass { background: var(--green-bg); border-color: var(--green-border); }
.fos-box.fail { background: var(--red-bg);   border-color: var(--red-border); }
.fos-box.pending { background: var(--orange-bg); border-color: var(--orange); }
.fos-title { font-size: 12px; font-weight: 600; margin-bottom: 3px; }
.fos-box.pass .fos-title { color: var(--green); }
.fos-box.fail .fos-title { color: var(--red); }
.fos-box.pending .fos-title { color: var(--orange); }
.fos-figure { font-size: 20px; font-weight: 700; margin-bottom: 3px; }
.fos-box.pass .fos-figure { color: var(--green); }
.fos-box.fail .fos-figure { color: var(--red); }
.fos-verdict { font-size: 12px; }

/* ── Check rows ─────────────────────────────────────────────────── */
.check-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
.check-row:last-child { border-bottom: none; }
.check-label { flex: 1; font-size: 13px; line-height: 1.4; }
.check-box {
  width: 22px; height: 22px; border-radius: 5px; flex-shrink: 0;
  border: 1.5px solid var(--mid-grey); background: var(--grey);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.check-box.ticked { background: var(--green); border-color: var(--green); }
.check-box.ticked::after { content: ''; width: 5px; height: 9px; border: 2.5px solid white; border-top: none; border-left: none; transform: rotate(45deg) translate(-1px,-1px); }
.check-box.flagged { background: var(--red); border-color: var(--red); }
.check-box.flagged::after { content: '✕'; font-size: 12px; color: white; font-weight: 700; }

/* ── Signature pads ─────────────────────────────────────────────── */
.sig-pad {
  background: var(--grey); border: 1px dashed var(--mid-grey);
  border-radius: var(--radius-sm); padding: 14px;
  text-align: center; cursor: pointer; font-size: 13px;
  color: var(--text-hint); margin-bottom: 8px; transition: all .15s;
  min-height: 52px; display: flex; align-items: center; justify-content: center;
}
.sig-pad:active { opacity: .75; }
.sig-pad.signed {
  background: var(--green-bg); border: 1px solid var(--green-border);
  color: var(--green); font-weight: 500;
}

/* ── Pills & badges ─────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.pill-green  { background: var(--green-bg);  color: var(--green);  }
.pill-amber  { background: var(--amber-bg);  color: var(--amber);  }
.pill-red    { background: var(--red-bg);    color: var(--red);    }
.pill-blue   { background: var(--light-blue);color: var(--steel);  }
.pill-grey   { background: var(--grey);      color: var(--text-muted); }
.tier-tag {
  display: inline-block; padding: 2px 8px;
  border-radius: 4px; font-size: 11px; font-weight: 600;
  margin-bottom: 8px;
}
.tier1 { background: var(--light-blue); color: var(--steel); }
.tier2 { background: var(--amber-bg);   color: var(--amber); }
.tier3 { background: var(--red-bg);     color: var(--red);   }

/* ── List rows ──────────────────────────────────────────────────── */
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { opacity: .75; }
.list-row-left { flex: 1; margin-right: 10px; }
.list-row-title { font-size: 14px; font-weight: 500; }
.list-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.chevron { color: var(--text-hint); font-size: 18px; }

/* ── Stat cards ─────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card { background: var(--grey); border-radius: var(--radius-sm); padding: 12px; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-value.warn { color: var(--amber); }
.stat-value.danger { color: var(--red); }
.stat-value.good  { color: var(--green); }

/* ── Cert rows ──────────────────────────────────────────────────── */
.cert-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.cert-row:last-child { border-bottom: none; }

/* ── Alert dot ──────────────────────────────────────────────────── */
.alert-dot { width: 8px; height: 8px; background: var(--red); border-radius: 50%; flex-shrink: 0; }

/* ── User avatar ────────────────────────────────────────────────── */
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.avatar-blue  { background: var(--light-blue); color: var(--steel); }
.avatar-amber { background: var(--amber-bg);   color: var(--amber); }
.avatar-green { background: var(--green-bg);   color: var(--green); }

/* ── Login ──────────────────────────────────────────────────────── */
.login-hero {
  padding: 36px 0 28px;
  text-align: center;
}
.login-icon {
  width: 58px; height: 58px; border-radius: 14px;
  background: var(--navy); margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
}
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-muted); }

/* ── Offline banner ─────────────────────────────────────────────── */
#offline-banner {
  display: none; position: sticky; top: 52px; z-index: 99;
  background: var(--amber); color: white;
  text-align: center; font-size: 12px; font-weight: 600;
  padding: 6px; letter-spacing: .02em;
}
#offline-banner.visible { display: block; }

/* ── Loading ────────────────────────────────────────────────────── */
.loader {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px; color: var(--text-muted); gap: 12px;
}
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--grey);
  border-top-color: var(--steel); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text); }

/* ── Success screen ─────────────────────────────────────────────── */
.success-hero { text-align: center; padding: 32px 0 20px; }
.success-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--green-bg); margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Table ──────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table tr td { padding: 5px 0; vertical-align: top; }
.data-table tr td:first-child { color: var(--text-muted); width: 45%; }
.data-table tr td:last-child { font-weight: 500; text-align: right; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

@media (max-width: 400px) {
  .screen { padding: 12px; }
  .topbar { padding: 10px 12px; }
}
