:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Myanmar", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

.topbar .btn-ghost {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.main-content {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem 0.9rem 5.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.main-content.is-login {
  justify-content: center;
  padding-bottom: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom, 0));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
}

.nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.25rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  gap: 0.15rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 800;
  box-shadow: inset 0 3px 0 var(--primary);
}

.nav-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.85rem;
  box-shadow: var(--shadow);
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.login-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.login-header img {
  width: 56px;
  height: 56px;
  margin-bottom: 0.5rem;
}

h1, h2, h3 {
  margin: 0 0 0.5rem;
  line-height: 1.25;
}

h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.field {
  margin-bottom: 0.75rem;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text);
}

input, select, textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, select:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.input-row input {
  flex: 1;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

@media (min-width: 560px) {
  .stats-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.stat-val {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 40px;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  line-height: 1.2;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 0.35rem 0.65rem; font-size: 0.8rem; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.35rem;
  background: var(--bg);
  padding: 0.3rem;
  border-radius: 12px;
  margin-bottom: 0.9rem;
}

.segmented.tri {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0.45rem 0.5rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 700;
  font-size: 0.86rem;
  line-height: 1.2;
  color: var(--muted);
  cursor: pointer;
}

.activity-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.media-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.thumb-book {
  width: 52px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.thumb-user {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.photo-preview-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.45rem;
}

.photo-preview-img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.clickable-photo {
  cursor: pointer;
}

.photo-enlarged {
  display: block;
  width: 100%;
  max-height: 55dvh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  margin-bottom: 0.85rem;
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--primary-soft); color: var(--primary-dark); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
  font-weight: 600;
  cursor: pointer;
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.list-item {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.list-item:first-child { padding-top: 0; }

.item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.item-title {
  font-weight: 700;
  font-size: 0.98rem;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.preview-box {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  margin-top: 0.4rem;
  font-size: 0.85rem;
}

.preview-box.found {
  background: var(--ok-soft);
  border-color: #86efac;
}

.preview-box.missing {
  background: var(--danger-soft);
  border-color: #fca5a5;
  color: var(--danger);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.scanner-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

#scannerVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-reticle {
  position: absolute;
  inset: 18%;
  border: 2px solid #2dd4bf;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.35);
  pointer-events: none;
}

.toast {
  position: fixed;
  bottom: 4.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #0f172a;
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  text-align: center;
}

.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sync-status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.sync-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
