/* Pharmacist CPD — blue & white, mobile first */

/* Self-hosted Noto Sans Khmer (SIL OFL 1.1) — works offline, no third-party requests */
@font-face { font-family: 'Noto Sans Khmer'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/fonts/noto-sans-khmer-khmer-400-normal.woff2') format('woff2');
  unicode-range: U+1780-17FF, U+19E0-19FF, U+200B-200C, U+25CC; }
@font-face { font-family: 'Noto Sans Khmer'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/fonts/noto-sans-khmer-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Noto Sans Khmer'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('/fonts/noto-sans-khmer-khmer-600-normal.woff2') format('woff2');
  unicode-range: U+1780-17FF, U+19E0-19FF, U+200B-200C, U+25CC; }
@font-face { font-family: 'Noto Sans Khmer'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('/fonts/noto-sans-khmer-latin-600-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Noto Sans Khmer'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/fonts/noto-sans-khmer-khmer-700-normal.woff2') format('woff2');
  unicode-range: U+1780-17FF, U+19E0-19FF, U+200B-200C, U+25CC; }
@font-face { font-family: 'Noto Sans Khmer'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/fonts/noto-sans-khmer-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --blue-900: #0a2f63;
  --blue-800: #0c3c7d;
  --blue-700: #0f4c9c;
  --blue-600: #1a5fbf;
  --blue-100: #e3edfb;
  --blue-50: #f2f7fe;
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #102540;
  --muted: #5a6b84;
  --line: #dde5f0;
  --line-strong: #c7d3e3;
  --grey-row: #eceff4;
  --green: #15803d;
  --green-bg: #e7f6ec;
  --red: #b42318;
  --red-bg: #fdecea;
  --amber-bg: #fff5e0;
  --amber: #8a5a00;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 37, 64, 0.06), 0 4px 14px rgba(16, 37, 64, 0.05);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: 'Noto Sans Khmer', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.35rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--blue-700); }
button, input, select, textarea { font: inherit; color: inherit; }
.km { font-family: var(--font); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 24px; text-align: center; }

/* ---------- boot / spinner ---------- */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--blue-100); border-top-color: var(--blue-700);
  animation: spin 0.8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--muted); justify-content: center; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--blue-700); color: #fff;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.topbar .brand img { width: 30px; height: 30px; border-radius: 8px; background: #fff; }
.topbar .who { font-size: 0.85rem; opacity: 0.9; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45vw; }
main.content {
  flex: 1; width: 100%; max-width: 860px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }

/* bottom nav (mobile) */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
}
.nav a, .nav button {
  appearance: none; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); font-size: 0.72rem; color: var(--muted); text-decoration: none;
}
.nav svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav .active { color: var(--blue-700); font-weight: 600; }
.nav .active svg { stroke-width: 2.2; }

@media (min-width: 900px) {
  .shell { padding-left: 220px; }
  .nav {
    top: 0; bottom: 0; right: auto; width: 220px; border-top: 0; border-right: 1px solid var(--line);
    display: flex; flex-direction: column; padding: calc(16px + var(--safe-t)) 10px 16px; gap: 4px;
  }
  .nav a, .nav button { flex-direction: row; justify-content: flex-start; gap: 12px; height: 46px; padding: 0 14px; font-size: 0.95rem; border-radius: 10px; }
  .nav .active { background: var(--blue-50); }
  .nav .nav-logout { margin-top: auto; }
}

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 16px; }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat .label { font-size: 0.85rem; color: var(--muted); }
.stat .value { font-size: 1.9rem; font-weight: 700; color: var(--blue-800); line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.primary { grid-column: 1 / -1; background: linear-gradient(135deg, var(--blue-700), var(--blue-900)); color: #fff; border: 0; }
.stat.primary .label { color: rgba(255, 255, 255, 0.85); }
.stat.primary .value { color: #fff; font-size: 2.6rem; }
.stat .hint { font-size: 0.78rem; margin-top: 4px; opacity: 0.85; }
@media (min-width: 640px) { .stats { grid-template-columns: 2fr 1fr 1fr; } .stat.primary { grid-column: auto; } }

.quick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.quick a {
  display: flex; align-items: center; gap: 12px; padding: 16px; text-decoration: none; color: var(--text);
  font-weight: 600;
}
.quick a .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--blue-50); display: grid; place-items: center; color: var(--blue-700); flex: none; }
.quick a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; cursor: pointer; background: var(--blue-700); color: #fff; text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--blue-800); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--blue-700); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--blue-50); }
.btn.danger { background: var(--red); }
.btn.danger.outline { background: #fff; color: var(--red); border-color: #f0c6c2; }
.btn.ghost { background: transparent; color: var(--blue-700); }
.btn.ghost:hover { background: var(--blue-50); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 0.88rem; }
.btn.block { width: 100%; }
.btn .spinner { border-color: rgba(255, 255, 255, 0.4); border-top-color: #fff; }
.btn.secondary .spinner { border-color: var(--blue-100); border-top-color: var(--blue-700); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }

.copy-btn {
  appearance: none; border: 1px solid var(--line-strong); background: #fff; color: var(--blue-700);
  border-radius: 8px; min-height: 34px; min-width: 64px; padding: 0 10px; font-size: 0.82rem; font-weight: 600; cursor: pointer; flex: none;
}
.copy-btn:disabled { color: var(--muted); opacity: 0.5; cursor: default; }
.copy-btn.done { background: var(--green-bg); color: var(--green); border-color: #b7e2c4; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field label .km-label { display: block; font-weight: 500; color: var(--muted); font-size: 0.85rem; }
.field .req { color: var(--red); }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; font-size: 16px; /* 16px stops iOS zoom */
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: 3px solid var(--blue-100); border-color: var(--blue-600); }
.input[aria-invalid='true'] { border-color: var(--red); }
.field-error { color: var(--red); font-size: 0.83rem; }
.form-error { background: var(--red-bg); color: var(--red); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.grid-2 { display: grid; gap: 14px; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--blue-700); flex: none; }
.pw-wrap { display: flex; gap: 8px; }
.pw-wrap .input { flex: 1; min-width: 0; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); background: linear-gradient(180deg, var(--blue-700) 0, var(--blue-700) 38%, var(--bg) 38%); }
.login-card { width: 100%; max-width: 400px; padding: 26px 22px; }
.login-card .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; background: var(--blue-50); }
.login-card h1 { text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); margin: 4px 0 20px; font-size: 0.92rem; }
.login-card .login-notice { margin-bottom: 16px; }
.login-card .forgot { text-align: center; color: var(--muted); font-size: 0.88rem; margin-top: 16px; }

/* ---------- profile definition list ---------- */
.kv { margin: 0; }
.kv-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .kv-text { flex: 1; min-width: 0; }
.kv-row dt { font-size: 0.82rem; color: var(--muted); }
.kv-row dt .km-label { display: block; }
.kv-row dd { margin: 2px 0 0; font-weight: 600; word-break: break-word; }
.kv-row dd.empty { color: var(--muted); font-weight: 400; font-style: italic; }
.kv-actions { display: flex; gap: 6px; flex: none; }
.lic-meta { font-size: 0.8rem; color: var(--muted); font-weight: 400; margin-top: 2px; }

/* ---------- CPD ---------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--blue-50); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { appearance: none; border: 0; background: none; border-radius: 9px; min-height: 40px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected='true'] { background: #fff; color: var(--blue-700); box-shadow: var(--shadow); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; }
.search .input { padding-left: 38px; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 16px; background: var(--blue-50); border-radius: 12px; border: 1px solid var(--line); }
.total-line strong { white-space: nowrap; font-size: 1.4rem; color: var(--blue-800); font-variant-numeric: tabular-nums; }

.list-tools { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; border-bottom: 1px solid var(--line-strong); background: #fafcff; border-radius: var(--radius) var(--radius) 0 0; }
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--line-strong); cursor: pointer; background: #fff;
}
.row:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
.row:hover { background: var(--blue-50); }
.row.submitted { background: var(--grey-row); }
.row.submitted:hover { background: #e4e8ee; }
.row .sel { padding-top: 2px; }
.row .sel input { width: 22px; height: 22px; accent-color: var(--blue-700); cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .topic { font-weight: 600; word-break: break-word; }
.row .meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; word-break: break-word; }
.row .side { display: flex; align-items: center; gap: 8px; flex: none; }
.row .score { font-weight: 700; color: var(--blue-800); font-variant-numeric: tabular-nums; text-align: right; min-width: 44px; }
.row .score small { display: block; font-weight: 500; color: var(--muted); font-size: 0.7rem; }
.tick { color: var(--green); font-weight: 700; font-size: 1.25rem; width: 22px; text-align: center; }
.tick.none { visibility: hidden; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.02em; }
.badge.submitted { background: #d9dee6; color: #3d4a5c; }
.badge.unsubmitted { background: var(--blue-100); color: var(--blue-800); }
.badge.active { background: var(--green-bg); color: var(--green); }
.badge.disabled { background: var(--red-bg); color: var(--red); }
.badge.admin { background: var(--amber-bg); color: var(--amber); }
.badge.cert { background: var(--green-bg); color: var(--green); }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); }

.submit-bar {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 14px; padding: 10px 12px 10px 16px;
  box-shadow: 0 6px 24px rgba(16, 37, 64, 0.14); margin-top: 14px;
}
@media (min-width: 900px) { .submit-bar { bottom: 16px; } }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 25, 50, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; background: #fff; border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; animation: up 0.18s ease-out;
  padding-bottom: var(--safe-b);
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } .modal { border-radius: 18px; } }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head .x { appearance: none; border: 0; background: var(--blue-50); width: 36px; height: 36px; border-radius: 50%; font-size: 1.2rem; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { padding: 12px 18px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .btn { flex: 1 1 auto; }
@media (min-width: 640px) { .modal-foot .btn { flex: 0 0 auto; } }
.detail { margin: 0; display: grid; gap: 12px; }
.detail dt { font-size: 0.82rem; color: var(--muted); }
.detail dd { margin: 2px 0 0; font-weight: 600; word-break: break-word; }
.notice { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--blue-50); color: var(--blue-900); font-size: 0.88rem; }
.notice.warn { background: var(--amber-bg); color: var(--amber); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; top: calc(12px + var(--safe-t)); z-index: 100; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 420px; width: 100%; padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: 0.92rem;
  background: var(--text); color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); animation: up 0.18s ease-out;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ---------- admin ---------- */
.user-card { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.user-card:last-child { border-bottom: 0; }
.user-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.user-name { font-weight: 700; }
.user-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.user-figs { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.user-figs b { color: var(--text); }
.audit-row { padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 0.86rem; }
.audit-row:last-child { border-bottom: 0; }
.back-link { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 600; margin-bottom: 10px; }

.install-steps { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 4px; }

/* ---------- misc ---------- */
.stats + .notice { margin-top: 12px; }
.quick-admin { text-decoration: none; color: var(--text); }
.quick-admin .btn-row { align-items: center; }
.quick-admin svg { width: 22px; height: 22px; stroke: var(--blue-700); fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.version { text-align: center; margin-top: 12px; }
.user-badges { margin-top: 4px; }