:root {
  --brand-dark: #1e3a8a;
  --brand: #2563eb;
  --brand-light: #dbeafe;
  --text: #1f2937;
  --muted: #6b7280;
  --bg: #f3f6fb;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(30, 58, 138, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.container-wide {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ---- Header / brand ---- */
.brand-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 4px;
}
.brand-header .logo-posyandu {
  width: 48px !important;
  height: 48px !important;
  max-width: 48px !important;
  max-height: 48px !important;
  min-width: 48px;
  min-height: 48px;
  object-fit: contain;
  display: block;
  flex: 0 0 48px;
}
.brand-header h1 {
  font-size: 18px;
  margin: 0;
  color: var(--brand-dark);
  line-height: 1.2;
}
.brand-header p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.top-meta {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}
.top-meta .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 5px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ---- Cards ---- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.big-btn {
  display: block;
  width: 100%;
  padding: 18px;
  border-radius: 14px;
  border: none;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 14px;
  text-align: center;
}
.big-btn.primary { background: var(--brand); color: #fff; }
.big-btn.secondary { background: #fff; color: var(--brand); border: 2px solid var(--brand); }
.big-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Category list ---- */
.kategori-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .1s;
}
.kategori-item:active { transform: scale(0.98); }
.kategori-item .icon {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kategori-item .info strong { display: block; font-size: 15px; }
.kategori-item .info span { font-size: 12px; color: var(--muted); }
.kategori-item .arrow { margin-left: auto; color: var(--muted); font-size: 18px; }

/* ---- Forms ---- */
label { font-size: 13px; font-weight: 600; color: var(--text); display: block; margin-bottom: 6px; }
input[type=text], input[type=password], textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 15px;
  margin-bottom: 16px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.field-error { color: #dc2626; font-size: 13px; margin-top: -10px; margin-bottom: 12px; }

/* ---- Big queue number ---- */
.nomor-besar {
  text-align: center;
  padding: 28px 10px;
}
.nomor-besar .label-kategori {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 14px;
}
.nomor-besar .angka {
  font-size: 64px;
  font-weight: 800;
  color: var(--brand-dark);
  letter-spacing: 1px;
  line-height: 1;
}

.info-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--muted); }
.info-row .v { font-weight: 600; text-align: right; max-width: 60%; }

/* ---- Public monitor page ---- */
.monitor-current {
  background: var(--brand-dark);
  color: #fff;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 18px;
}
.monitor-current .tag {
  display: inline-block;
  background: rgba(255,255,255,.15);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}
.monitor-current .angka {
  font-size: 72px;
  font-weight: 800;
  line-height: 1;
  margin: 6px 0;
}
.monitor-current .nama { font-size: 16px; opacity: .9; }

.kategori-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (min-width: 700px) {
  .kategori-grid { grid-template-columns: repeat(5, 1fr); }
}
.kategori-box {
  border-radius: 14px;
  padding: 16px 12px;
  text-align: center;
}
.kategori-box .nama-kat { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.kategori-box .status-txt { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.kategori-box .no-sedang { font-size: 28px; font-weight: 800; margin-bottom: 6px; }
.kategori-box .no-berikut { font-size: 13px; font-weight: 600; opacity: .85; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}
.badge.menunggu { background: #fef3c7; color: #92400e; }
.badge.dilayani { background: #dbeafe; color: #1e40af; }
.badge.selesai { background: #d1fae5; color: #065f46; }


/* ---- Thermal queue ticket ---- */
.print-options {
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  margin:0 0 12px;
}
.print-options label { margin:0; font-size:12px; color:var(--muted); }
.print-options select {
  padding:7px 10px;
  border:1px solid var(--border);
  border-radius:8px;
  font-size:12px;
}
.thermal-ticket-card { overflow:hidden; }
.thermal-ticket .nomor-besar { padding:20px 6px 14px; }
.thermal-ticket .nomor-besar .angka { font-size:58px; }
.thermal-ticket .thermal-ticket-card .info-row { font-size:12px; }
.thermal-ticket .thermal-brand { padding-top:4px; }

@media print {
  @page { margin: 0; }
  html, body { background:#fff !important; }
  body.thermal-58 .thermal-ticket {
    width:58mm;
    max-width:58mm;
    margin:0 auto;
    padding:0 3mm;
  }
  body.thermal-80 .thermal-ticket {
    width:80mm;
    max-width:80mm;
    margin:0 auto;
    padding:0 4mm;
  }
  .thermal-ticket .thermal-ticket-card {
    box-shadow:none;
    border-radius:0;
    padding:0;
    margin:0;
  }
  .thermal-ticket .brand-header {
    padding:4mm 0 2mm;
  }
  .thermal-ticket .brand-header .logo-posyandu { display:none; }
  .thermal-ticket .brand-header h1 { font-size:14px; }
  .thermal-ticket .brand-header p { font-size:9px; }
  .thermal-ticket .nomor-besar .angka { font-size:48px; }
  .thermal-ticket .nomor-besar .label-kategori { font-size:10px; padding:4px 9px; }
  .thermal-ticket .info-row { padding:5px 0; }
  .thermal-ticket svg#barcode { max-width:100%; height:auto; }
}

.print-hide { }
@media print {
  .print-hide { display: none !important; }
  body { background: #fff; }
}

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 20px;
}

.center-actions { display: flex; gap: 10px; }
.center-actions .big-btn { flex: 1; margin-bottom: 0; }

.public-controls { display:flex; justify-content:flex-end; margin:0 0 10px; }
.screen-btn { border:1px solid var(--border); background:#fff; color:var(--brand-dark); border-radius:10px; padding:9px 14px; font-weight:700; cursor:pointer; }
body:fullscreen { background:var(--bg); overflow:auto; }
body:fullscreen .container-wide { max-width:1400px; min-height:100vh; padding:24px 32px 40px; }
body:fullscreen .monitor-current .angka { font-size:clamp(80px, 12vw, 160px); }
body:fullscreen .kategori-box .no-sedang { font-size:clamp(30px, 4vw, 52px); }


/* ---- Public queue controls / mobile fullscreen ---- */
.public-controls {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin:0 0 10px;
}
.public-controls .screen-btn {
  min-height:42px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:10px 14px;
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
}
.back-btn { color:var(--brand-dark); }

/* Fallback fullscreen khusus perangkat yang tidak mendukung Fullscreen API,
   terutama iPhone/iPad Safari. */
body.pseudo-fullscreen {
  position:fixed;
  inset:0;
  width:100%;
  height:100dvh;
  min-height:100dvh;
  overflow:auto;
  z-index:2147483647;
  background:var(--bg);
  padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.pseudo-fullscreen .container-wide {
  max-width:1400px;
  min-height:100dvh;
  padding:20px 24px 36px;
}
body.pseudo-fullscreen .monitor-current .angka {
  font-size:clamp(72px, 12vw, 160px);
}
body.pseudo-fullscreen .kategori-box .no-sedang {
  font-size:clamp(28px, 4vw, 52px);
}

@media (max-width: 600px) {
  .container-wide { padding:12px 10px 28px; }
  .brand-header { padding:10px 2px; gap:9px; }
  .brand-header .logo-posyandu { width:42px !important; height:42px !important; max-width:42px !important; max-height:42px !important; min-width:42px; min-height:42px; flex-basis:42px; }
  .brand-header h1 { font-size:16px; }
  .brand-header p { font-size:11px; }
  .public-controls { margin-bottom:8px; }
  .public-controls .screen-btn { flex:1; min-width:0; padding:10px 8px; font-size:13px; }
  .top-meta { font-size:11px; margin-bottom:10px; }
  .monitor-current { padding:18px 16px; border-radius:14px; }
  .monitor-current .angka { font-size:clamp(58px, 20vw, 90px); }
  .monitor-current .nama { font-size:14px; }
  .kategori-grid { grid-template-columns:1fr 1fr; gap:8px; }
  .kategori-box { padding:13px 8px; border-radius:12px; }
  .kategori-box .nama-kat { font-size:12px; }
  .kategori-box .no-sedang { font-size:25px; }
  .kategori-box .no-berikut { font-size:12px; }
  #form-cari { gap:6px !important; }
  #form-cari input { min-width:0; }
  #form-cari button { padding:11px 14px !important; }
}

@media (max-width: 380px) {
  .kategori-grid { grid-template-columns:1fr; }
}

@media (max-width: 600px) {
  body.pseudo-fullscreen .container-wide { padding:14px 12px 28px; }
  body.pseudo-fullscreen .brand-header { padding-top:4px; }
  body.pseudo-fullscreen .kategori-grid { grid-template-columns:1fr 1fr; }
  body.pseudo-fullscreen .monitor-current { margin-bottom:10px; }
}


/* Final header logo sizing: keep the Posyandu mark compact and proportional. */
.brand-header > .logo-posyandu {
  width: 48px !important;
  height: 48px !important;
  max-width: 48px !important;
  max-height: 48px !important;
  object-fit: contain !important;
  display: block !important;
  flex: 0 0 48px !important;
}
@media (max-width: 600px) {
  .brand-header > .logo-posyandu {
    width: 42px !important;
    height: 42px !important;
    max-width: 42px !important;
    max-height: 42px !important;
    flex-basis: 42px !important;
  }
}
