:root {
  --navy: #0f172a;
  --blue: #2563eb;
  --cyan: #06b6d4;
  --green: #059669;
  --gold: #d97706;
  --red: #dc2626;
  --muted: #64748b;
  --bg: #edf3fa;
  --card: #ffffff;
  --line: #dbe7f6;
  --shadow: 0 18px 46px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  font-family: "Sarabun", system-ui, sans-serif;
  color: var(--navy);
  background: linear-gradient(180deg, #edf3fa 0%, #f8fafc 42%, #e9f2ff 100%);
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px;
  color: #fff;
  background: linear-gradient(180deg, #0f172a, #1e3a8a);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.logo {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, #22d3ee, #2563eb 55%, #7c3aed);
  box-shadow: 0 18px 42px rgba(0, 0, 0, .25);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

.brand p {
  margin: 4px 0 0;
  color: #bfdbfe;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 10px;
}

.nav button {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  color: #dbeafe;
  background: rgba(255, 255, 255, .10);
  font-weight: 800;
  transition: transform .16s ease, background .16s ease;
}

.nav button:hover,
.nav button.active {
  transform: translateX(3px);
  color: #fff;
  background: rgba(255, 255, 255, .20);
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  padding: 30px 30px 82px;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.title h2 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  min-height: 68px;
  padding: 14px 24px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 58%, #06b6d4 100%);
  box-shadow: 0 18px 40px rgba(37, 99, 235, .22);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.15;
  font-weight: 800;
}

.clock {
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .08);
  color: #475569;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.page {
  display: none;
  min-width: 0;
  animation: fade .2s ease;
}

.page.active { display: block; }

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

.card {
  position: relative;
  overflow: hidden;
  min-width: 0;
  border: 1px solid rgba(191, 219, 254, .86);
  border-radius: 22px;
  padding: 24px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
}

.card::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 0;
  height: 5px;
  border-radius: 0 0 999px 999px;
  background: linear-gradient(90deg, #0f172a, #1d4ed8, #06b6d4);
}

.section-title {
  display: inline-flex;
  align-items: center;
  margin: 0 0 18px;
  padding: 9px 15px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 58%, #06b6d4 100%);
  box-shadow: 0 14px 28px rgba(37, 99, 235, .16);
  font-size: 18px;
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}

.stat {
  min-height: 142px;
  padding-top: 28px;
}

.stat label {
  display: block;
  color: #334155;
  font-size: 15px;
  font-weight: 800;
}

.num {
  margin: 13px 0 8px;
  color: var(--blue);
  font-size: 40px;
  line-height: 1;
  font-weight: 800;
}

.pct,
.hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.grid2 {
  display: grid;
  grid-template-columns: minmax(280px, .95fr) minmax(520px, 2.05fr);
  gap: 18px;
}

.bar-list {
  display: grid;
  gap: 14px;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

.track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe7ff;
}

.fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1d4ed8, #06b6d4, #22c55e);
}

.form-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px dashed var(--line);
}

.form-section:last-of-type {
  margin-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field.full { grid-column: 1 / -1; }

.field label {
  color: #1e293b;
  font-size: 14px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  outline: none;
  background: linear-gradient(180deg, #fff, #f8fafc);
  padding: 12px 14px;
  font-size: 14px;
}

textarea {
  min-height: 104px;
  line-height: 1.65;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.primary { color: #fff; background: linear-gradient(135deg, var(--blue), #7c3aed); }
.light { color: var(--navy); background: #e2e8f0; }
.green { color: #fff; background: var(--green); }
.gold { color: #fff; background: var(--gold); }
.red { color: #fff; background: var(--red); }
.sm { min-height: 34px; padding: 7px 9px; border-radius: 11px; font-size: 12px; }

.filters {
  display: grid;
  grid-template-columns: 1.45fr .75fr .85fr .7fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  border: 1px solid #cfe0ff;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(15, 23, 42, .06);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 13px;
  border-bottom: 1px solid #dbe7f6;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  color: #fff;
  background: linear-gradient(180deg, #0f172a, #1e40af);
  font-weight: 800;
  white-space: nowrap;
}

tbody tr:hover td { background: #eff6ff; }

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.complete { color: #047857; background: #dcfce7; }

.manage-cell {
  min-width: 186px;
  white-space: nowrap;
}

.icon-actions {
  display: inline-flex;
  gap: 6px;
}

.modal,
.loading {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .58);
}

.hidden { display: none !important; }

.modal-card {
  width: min(980px, 96vw);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid #d9e6fb;
  border-radius: 24px;
  background: linear-gradient(180deg, #fff, #f8fbff);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .35);
  padding: 24px;
}

.confirm-card { max-width: 540px; }

.confirm-card p {
  line-height: 1.75;
  color: #334155;
}

.danger-text { color: var(--red); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.modal-head .section-title { margin: 0; }

.loading {
  z-index: 100;
  background: rgba(248, 250, 252, .78);
  backdrop-filter: blur(5px);
}

.loadbox {
  min-width: 240px;
  border-radius: 20px;
  padding: 24px 28px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
  color: var(--blue);
  font-weight: 800;
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 4px solid #dbeafe;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  display: none;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 16px;
  padding: 14px 18px;
  background: #0f172a;
  box-shadow: var(--shadow);
  color: #fff;
  line-height: 1.55;
}

.report-title {
  margin-bottom: 18px;
  text-align: center;
  line-height: 1.55;
}

.report-title h2 {
  display: inline-flex;
  margin: 0 0 4px;
  border-radius: 14px;
  padding: 10px 16px;
  color: #fff;
  background: linear-gradient(135deg, #0f172a, #1d4ed8 58%, #06b6d4);
  font-size: 22px;
}

.report-box {
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid #d9e6fb;
  border-radius: 18px;
  background: #fff;
}

.report-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  border-bottom: 1px solid #dbe7f6;
}

.report-row:last-child { border-bottom: 0; }

.report-label {
  padding: 12px 14px;
  color: #0f172a;
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  font-weight: 800;
}

.report-val {
  padding: 12px 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.evidence-preview {
  display: inline-block;
  max-width: 100%;
  margin-top: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 8px;
  background: #f8fafc;
}

.evidence-preview img {
  display: block;
  max-width: 100%;
  max-height: 520px;
  border-radius: 12px;
  object-fit: contain;
}

.activity-board { display: grid; gap: 22px; }

.activity-hero {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 18px;
  align-items: stretch;
}

.activity-spotlight {
  min-height: 150px;
  border-radius: 24px;
  padding: 24px;
  color: #fff;
  background: linear-gradient(135deg, #0f172a, #1d4ed8 58%, #06b6d4);
  box-shadow: 0 22px 52px rgba(37, 99, 235, .20);
}

.activity-spotlight h3 {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
}

.activity-mini {
  border: 1px solid #bfdbfe;
  border-radius: 24px;
  padding: 22px;
  background: linear-gradient(180deg, #fff, #eff6ff);
  box-shadow: 0 16px 38px rgba(15, 23, 42, .10);
}

.mini-num {
  color: var(--blue);
  font-size: 42px;
  line-height: 1;
  font-weight: 800;
}

.mini-text {
  margin-top: 8px;
  color: #334155;
  font-weight: 800;
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.activity-card {
  overflow: hidden;
  border: 1px solid rgba(191, 219, 254, .88);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 20px 52px rgba(15, 23, 42, .13);
}

.activity-content {
  padding: 18px;
  background: linear-gradient(180deg, #fff, #eff6ff);
}

.activity-topic {
  display: -webkit-box;
  margin: 0 0 10px;
  overflow: hidden;
  color: #0f172a;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 800;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.activity-meta {
  display: grid;
  gap: 5px;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
}

.activity-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-top: 1px solid #dbeafe;
  color: #fff;
  background: linear-gradient(135deg, #0f172a, #1d4ed8 55%, #06b6d4);
  font-size: 56px;
  font-weight: 800;
}

.activity-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-footer {
  margin-top: auto;
  border-top: 1px solid rgba(226, 232, 240, .85);
  padding: 24px 8px 0;
  color: #64748b;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

#printArea { display: none; }

@media (max-width: 1100px) {
  .app { display: block; }
  .side {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    top: auto;
    z-index: 50;
    height: auto;
    padding: 10px;
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .42);
  }
  .brand { display: none; }
  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .nav button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 62px;
    padding: 8px 4px;
    text-align: center;
    font-size: clamp(13px, 3.8vw, 17px);
    line-height: 1.18;
    white-space: normal;
    transform: none !important;
  }
  .main { padding: 12px 10px calc(118px + env(safe-area-inset-bottom)); }
  .clock { display: none; }
  .top { margin-bottom: 14px; }
  .title h2 { width: 100%; min-height: 58px; font-size: 24px; }
  .stats,
  .grid2,
  .activity-hero,
  .activity-grid {
    grid-template-columns: 1fr;
  }
  .filters,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .report-row { grid-template-columns: 1fr; }
  .report-label { border-bottom: 1px solid #dbe7f6; }
}

@media print {
  @page { size: A4 portrait; margin: 12mm 14mm; }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app,
  .modal,
  .loading,
  .toast {
    display: none !important;
  }

  #printArea {
    display: block !important;
    width: 168mm !important;
    margin: 0 auto !important;
    font-family: "Sarabun", "TH Sarabun New", sans-serif;
    color: #000 !important;
    font-size: 13pt !important;
    line-height: 1.34 !important;
  }

  .official-title {
    margin: 0 0 5mm;
    text-align: center;
    line-height: 1.38;
  }

  .official-title h2 {
    margin: 0 0 1.5mm;
    font-size: 19pt !important;
  }

  .official-title div { font-size: 15pt !important; }

  .official-section {
    width: 150mm;
    margin: 5mm auto 2mm;
    font-size: 15pt !important;
    font-weight: 800;
  }

  .official-grid {
    width: 150mm;
    margin: 0 auto 4mm;
    border: 1.15pt solid #000;
  }

  .official-row {
    display: grid;
    grid-template-columns: 43mm 1fr;
    border-bottom: 1.15pt solid #000;
    break-inside: avoid;
  }

  .official-row:last-child { border-bottom: 0; }

  .official-label,
  .official-value {
    padding: 3.5px 7px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    color: #000 !important;
  }

  .official-label {
    border-right: 1.15pt solid #000;
    font-size: 15pt !important;
    font-weight: 800;
  }

  .official-value { font-size: 13pt !important; }

  .official-list div { margin-bottom: 1mm; }

  .official-evidence-block {
    width: 150mm;
    margin: 0 auto 5mm;
    break-inside: avoid;
  }

  .official-evidence-heading {
    margin-bottom: 2mm;
    font-size: 15pt;
    font-weight: 800;
  }

  .official-evidence-image-box {
    min-height: 32mm;
    border: 1.15pt solid #000;
    padding: 3mm;
    text-align: center;
  }

  .official-evidence-image-box img {
    max-width: 138mm;
    max-height: 82mm;
    object-fit: contain;
  }

  .official-sign {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8mm;
    width: 150mm;
    margin: 8mm auto 0;
    font-size: 13pt;
    line-height: 1.55;
  }

  .sign-box { text-align: center; }
}
