/* ============================================================
   Sistem Automasi Pengurusan Program — stylesheet
   Palette: deep teal (#0f766e) accent, slate neutrals
   ============================================================ */

:root {
  --teal-900: #0b4f4a;
  --teal-700: #0f766e;
  --teal-600: #0d9488;
  --teal-100: #ccfbf1;
  --teal-50: #f0fdfa;

  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  --bg: #f5f7fb;
  --card: #ffffff;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --red: #b91c1c;
  --red-bg: #fef2f2;
  --green: #047857;
  --green-bg: #ecfdf5;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 32px -18px rgba(15, 23, 42, .28);
  --shadow-lg: 0 24px 60px -30px rgba(15, 23, 42, .45);
  --font: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* the [hidden] attribute must beat component display rules (e.g. .detail-list{display:grid}) */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 420px at 12% -10%, #e6fffb 0%, transparent 60%),
    radial-gradient(900px 380px at 92% 0%, #eef2ff 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .86em; background: #eef2f7; padding: 1px 5px; border-radius: 5px; }
.en { color: var(--muted); font-weight: 400; font-size: .78em; letter-spacing: 0; }

/* ---------------- Header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 44px);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 260px; }

.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--teal-600), var(--teal-900));
  color: #fff; font-weight: 800; letter-spacing: .5px;
  box-shadow: 0 8px 20px -10px rgba(13, 148, 136, .9);
}

.brand-text h1 { font-size: clamp(15px, 1.5vw, 18px); font-weight: 700; }
.brand-text p { font-size: 12px; color: var(--muted); }
.brand-text .dot { margin: 0 4px; }

.header-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* connection badge */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: 6px 11px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-checking { color: var(--muted); background: #f1f5f9; border-color: var(--line); }
.badge-live { color: var(--green); background: var(--green-bg); border-color: #a7f3d0; }
.badge-demo { color: var(--amber); background: var(--amber-bg); border-color: #fde68a; }
.badge-offline { color: var(--red); background: var(--red-bg); border-color: #fecaca; }

/* tabs */
.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: #eef2f7; border: 1px solid var(--line); border-radius: 999px;
}
.tab {
  appearance: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  padding: 7px 16px; border-radius: 999px;
  background: transparent; color: var(--ink-soft);
  font-family: inherit; font-size: 13px; font-weight: 600;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tab .tab-en { font-size: 10px; font-weight: 500; color: var(--muted); }
.tab:hover { background: rgba(255, 255, 255, .75); }
.tab.is-active {
  background: var(--card); color: var(--teal-700);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}
.tab.is-active .tab-en { color: var(--teal-600); }

/* ---------------- Layout ---------------- */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px) clamp(16px, 4vw, 44px) 48px;
}

.view { display: none; animation: fadeUp .28s ease both; }
.view.is-active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.view-intro {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: 20px;
}
.view-intro h2 { font-size: clamp(20px, 2.4vw, 26px); font-weight: 700; }
.view-intro h2 .en { display: block; margin-top: 2px; font-size: 13px; }
.view-intro p { margin-top: 8px; color: var(--ink-soft); font-size: 14px; max-width: 62ch; }

.flow-chips { display: flex; gap: 8px; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; }
.flow-chips li {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--teal-900); background: var(--teal-50);
  border: 1px solid #b8f0e6; padding: 6px 11px; border-radius: 999px;
}
.flow-chips b {
  width: 17px; height: 17px; border-radius: 50%;
  display: grid; place-items: center; font-size: 10px;
  background: var(--teal-700); color: #fff;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 20px;
  align-items: start;
}
.grid-scan { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-charts { margin-bottom: 20px; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------------- Cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card-soft { background: linear-gradient(180deg, #fbfdff, #f7fafc); box-shadow: none; }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 16px; }
.card-title .en { display: block; font-size: 11.5px; margin-top: 1px; }
.card h4 { font-size: 14px; font-weight: 700; margin-bottom: 14px; }
.card h4 .en { margin-left: 6px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 20px 0 16px; }

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.req { color: #dc2626; }
.opt { font-weight: 400; color: var(--muted); }

input[type="text"], input[type="email"], input[type="tel"], input[type="search"], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  transition: border-color .16s, box-shadow .16s;
}
input::placeholder { color: #9aa8ba; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .14);
}
input.is-invalid, select.is-invalid { border-color: #f87171; box-shadow: 0 0 0 3px rgba(248, 113, 113, .12); }
.hint { font-size: 11.5px; color: var(--muted); }
.hint.is-error { color: var(--red); }

.checkbox {
  display: flex; gap: 9px; align-items: flex-start;
  font-size: 12.5px; font-weight: 500; color: var(--ink-soft);
  margin: 4px 0 18px; line-height: 1.45;
}
.checkbox input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--teal-700); }

.inline-form { display: flex; gap: 8px; margin-bottom: 14px; }
.inline-form input { flex: 1; }

.select-inline { width: auto; max-width: 190px; padding: 9px 11px; font-size: 12.5px; }

/* ---------------- Buttons ---------------- */
.btn {
  appearance: none; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13.5px; font-weight: 650;
  padding: 11px 18px; border-radius: 11px; border: 1px solid transparent;
  text-decoration: none; white-space: nowrap;
  transition: transform .12s, box-shadow .16s, background .16s, color .16s, border-color .16s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, var(--teal-600), var(--teal-700));
  color: #fff; box-shadow: 0 10px 22px -14px rgba(13, 148, 136, .95);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 26px -14px rgba(13, 148, 136, 1); }
.btn-secondary { background: #eef2f7; color: var(--teal-900); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: #e4ebf3; }
.btn-ghost { background: #fff; color: var(--ink-soft); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { border-color: var(--teal-600); color: var(--teal-700); }
.btn-block { width: 100%; padding: 13px; font-size: 14.5px; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.spinner {
  display: none; width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading .btn-label { opacity: .8; }
@keyframes spin { to { transform: rotate(360deg); } }

.form-note { margin-top: 12px; font-size: 12.5px; min-height: 18px; color: var(--muted); }
.form-note.is-error { color: var(--red); }
.form-note.is-ok { color: var(--green); }

/* ---------------- Registration success ---------------- */
.success-head { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 16px; }
.success-head h3 { font-size: 16px; }
.success-icon {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%;
  display: grid; place-items: center; font-size: 19px; font-weight: 700;
  color: #fff; background: linear-gradient(145deg, #10b981, #047857);
}
.qr-box {
  text-align: center; padding: 16px; border-radius: var(--radius-sm);
  border: 2px dashed #99f6e4; background: var(--teal-50); margin-bottom: 16px;
}
.qr-box img { display: block; margin: 0 auto 8px; max-width: 100%; height: auto; border-radius: 8px; background: #fff; }
.qr-token { font-family: var(--mono); font-size: 11.5px; color: var(--teal-900); word-break: break-all; }

.detail-list { margin: 0 0 16px; display: grid; gap: 9px; }
.detail-list > div { display: flex; justify-content: space-between; gap: 14px; font-size: 13px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }

.steps { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-soft); display: grid; gap: 9px; }
.steps b { color: var(--ink); }

/* ---------------- Scanner ---------------- */
.reader-shell {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0b1220;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #0f172a;
  margin-bottom: 14px;
}
.qr-reader { width: 100%; height: 100%; }
.qr-reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
#qr-reader__scan_region { background: transparent !important; }
#qr-reader__dashboard_section { display: none !important; }
.reader-placeholder {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 12px; color: #93a4bd; text-align: center; padding: 24px; font-size: 13px;
}
.reader-placeholder svg { opacity: .75; }
.reader-shell.is-live .reader-placeholder { display: none; }

.scan-stats { display: flex; gap: 10px; }
.scan-stats > div {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; text-align: center; box-shadow: var(--shadow);
}
.scan-stats span { display: block; font-size: 20px; font-weight: 750; color: var(--teal-700); }
.scan-stats small { font-size: 11px; color: var(--muted); }

.scan-result { border-left: 5px solid var(--line-strong); transition: border-color .2s, background .2s; }
.scan-result[data-state="valid"] { border-left-color: #059669; background: linear-gradient(180deg, #f0fdf7, #fff); }
.scan-result[data-state="already"] { border-left-color: #d97706; background: linear-gradient(180deg, #fffdf3, #fff); }
.scan-result[data-state="invalid"] { border-left-color: #dc2626; background: linear-gradient(180deg, #fff5f5, #fff); }
.scan-result[data-state="loading"] { border-left-color: var(--teal-600); }

.result-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.result-icon {
  width: 46px; height: 46px; flex: 0 0 46px; border-radius: 14px;
  display: grid; place-items: center; font-size: 22px; font-weight: 800;
  background: #eef2f7; color: var(--muted);
}
[data-state="valid"] .result-icon { background: #d1fae5; color: #047857; }
[data-state="already"] .result-icon { background: #fef3c7; color: #b45309; }
[data-state="invalid"] .result-icon { background: #fee2e2; color: #b91c1c; }
.result-head h3 { font-size: 16px; }
.result-head p { font-size: 12.5px; margin-top: 2px; }

.scan-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 300px; overflow: auto; }
.scan-log li {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 9px 12px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--line);
  font-size: 12.5px;
}
.scan-log li.is-valid { background: var(--green-bg); border-color: #bbf7d0; }
.scan-log li.is-already { background: var(--amber-bg); border-color: #fde68a; }
.scan-log li.is-invalid { background: var(--red-bg); border-color: #fecaca; }
.scan-log .who { font-weight: 600; }
.scan-log .when { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------------- Dashboard ---------------- */
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.toolbar select { width: auto; min-width: 170px; }

.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.kpi-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi strong { font-size: clamp(24px, 3vw, 30px); font-weight: 750; letter-spacing: -.02em; color: var(--teal-900); }
.kpi small { font-size: 11px; color: var(--muted); }

.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut {
  --pct: 0;
  width: 168px; height: 168px; flex: 0 0 168px; border-radius: 50%;
  background: conic-gradient(var(--teal-600) calc(var(--pct) * 1%), #e6ebf2 0);
  display: grid; place-items: center; position: relative;
  transition: background .4s ease;
}
.donut::after {
  content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: var(--card); box-shadow: inset 0 1px 3px rgba(15, 23, 42, .06);
}
.donut-hole { position: relative; z-index: 1; text-align: center; }
.donut-hole strong { display: block; font-size: 30px; font-weight: 750; color: var(--teal-900); }
.donut-hole small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); }
.legend b { margin-left: auto; color: var(--ink); }
.swatch { width: 11px; height: 11px; border-radius: 3px; }
.swatch-present { background: var(--teal-600); }
.swatch-absent { background: #e6ebf2; }
.swatch-cert { background: #6366f1; }

.program-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.program-bars li { display: grid; gap: 6px; }
.program-bars .pb-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.program-bars .pb-head span { color: var(--ink-soft); font-weight: 600; }
.program-bars .pb-head b { color: var(--teal-700); }
.program-bars .track { height: 9px; border-radius: 999px; background: #eef2f7; overflow: hidden; }
.program-bars .fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--teal-600), #34d399); transition: width .5s ease; }
.program-bars .pb-meta { font-size: 11.5px; color: var(--muted); }

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.table-head h4 { margin: 0; }
.table-head input { max-width: 280px; }

.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); background: #f8fafc; padding: 11px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafcff; }
.data-table .name { font-weight: 600; }
.data-table .sub { display: block; font-size: 11.5px; color: var(--muted); }
.data-table .empty, .empty { text-align: center; color: var(--muted); padding: 26px 12px; font-size: 13px; list-style: none; }
.table-foot { margin-top: 10px; font-size: 12px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.pill-present { color: var(--green); background: var(--green-bg); border-color: #a7f3d0; }
.pill-absent { color: var(--muted); background: #f1f5f9; border-color: var(--line); }
.pill-cert { color: #4338ca; background: #eef2ff; border-color: #c7d2fe; }
.pill-nocert { color: var(--amber); background: var(--amber-bg); border-color: #fde68a; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.timeline li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 13px;
}
.timeline li:last-child { border-bottom: 0; }
.timeline .marker {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: 0 0 9px;
  background: var(--teal-600); box-shadow: 0 0 0 3px var(--teal-100);
}
.timeline .when { margin-left: auto; color: var(--muted); font-size: 11.5px; white-space: nowrap; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 24px);
  max-width: min(92vw, 520px);
  background: #0f172a; color: #fff; font-size: 13px;
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s; z-index: 60;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: #7f1d1d; }
.toast[data-kind="success"] { background: #065f46; }
.toast[data-kind="warn"] { background: #92400e; }

/* ---------------- Footer ---------------- */
.app-footer {
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 16px clamp(16px, 4vw, 44px);
  font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .6);
}

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
  .grid-2, .grid-scan { grid-template-columns: minmax(0, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .app-header { position: static; }
}

@media (max-width: 720px) {
  .app-header { flex-direction: column; align-items: stretch; }
  .header-actions { justify-content: space-between; }
  .tabs { width: 100%; justify-content: space-between; }
  .tab { flex: 1; padding: 7px 8px; font-size: 12px; }
  .view-intro { align-items: flex-start; }
  .toolbar { width: 100%; }
  .toolbar select { flex: 1; }
  .table-head input { max-width: none; width: 100%; }
  .donut { width: 140px; height: 140px; flex-basis: 140px; }
  .card { padding: 17px; }
  .toast { bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .app-header, .app-footer, .toolbar, .row-actions, .toast { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #cbd5e1; }
}
