@import url("https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap");
  :root {
    font-family: "Kanit", sans-serif;
    color: #24384b;
    background: #ecfeff;
  }
  body {
    margin: 0;
    background: radial-gradient(ellipse at 90% 0, #cffafe80, transparent 50%), #f0fcfd;
    min-height: 100vh;
  }
  button,
  input,
  select,
  textarea {
    font: inherit;
  }
  button,
  a,
  input,
  select,
  textarea {
    outline-offset: 3px;
  }
  button:disabled {
    opacity: 0.5;
    cursor: wait;
  }
  a {
    color: inherit;
    text-decoration: none;
  }
  .topbar {
    background: #ffffffed;
    border-bottom: 1px solid #d9eff1;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 16px 4%;
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(16px);
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 22px;
    font-weight: 600;
    white-space: nowrap;
  }
  .brand small {
    display: block;
    font-size: 10px;
    color: #6f8492;
    font-weight: 400;
  }
  .brand-icon {
    padding: 12px;
    background: #cffafe;
    color: #0891b2;
    border-radius: 17px;
  }
  .topbar nav {
    display: flex;
    gap: 6px;
    flex: 1;
    flex-wrap: wrap;
  }
  .nav-link {
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 14px;
    color: #64748b;
  }
  .nav-link.active {
    background: #cffafe;
    color: #0e7490;
  }
  .icon-btn {
    border: 0;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 9px;
    cursor: pointer;
  }
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #0891b2;
    color: white;
    border: 0;
    border-radius: 12px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background 0.15s;
  }
  .btn:hover {
    background: #0e7490;
  }
  .btn.secondary {
    background: #e5f4f6;
    color: #0e7490;
  }
  .btn.danger {
    background: #fff1f2;
    color: #be123c;
  }
  .btn.small {
    font-size: 12px;
    padding: 6px 10px;
  }
  .card {
    background: white;
    border: 1px solid #deedf0;
    border-radius: 22px;
    padding: 24px;
    box-shadow: 0 5px 24px #164e6305;
  }
  .kpi {
    font-size: 36px;
    font-weight: 600;
    line-height: 1.4;
  }
  .muted {
    color: #81909f;
    font-size: 13px;
  }
  .page-title {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.4px;
  }
  .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 14px 0;
  }
  .field label {
    font-size: 13px;
    color: #52677a;
  }
  .field input,
  .field select,
  .field textarea,
  input.control,
  select.control {
    padding: 11px 13px;
    border: 1px solid #dce8ed;
    border-radius: 11px;
    background: #fff;
    min-width: 0;
    width: 100%;
  }
  .field textarea {
    min-height: 100px;
  }

  .remember-login {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 14px 0 4px;
    padding: 12px 13px;
    border: 1px solid #dce8ed;
    border-radius: 12px;
    background: #f8fcfd;
    cursor: pointer;
  }
  .remember-login input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex: 0 0 auto;
    accent-color: #0891b2;
  }
  .remember-login span {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: #40596b;
    font-size: 13px;
  }
  .remember-login small {
    color: #81909f;
    font-size: 11px;
    font-weight: 400;
  }

  .table-wrap {
    overflow: auto;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
  }
  th {
    font-weight: 500;
    background: #f5fafb;
    color: #65808d;
    white-space: nowrap;
  }
  td,
  th {
    padding: 13px 14px;
    border-bottom: 1px solid #edf2f5;
  }
  td {
    vertical-align: middle;
  }
  .pill {
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 12px;
    display: inline-block;
    white-space: nowrap;
  }
  .green {
    background: #dcfce7;
    color: #15803d;
  }
  .yellow {
    background: #fef3c7;
    color: #a16207;
  }
  .red {
    background: #ffe4e6;
    color: #be123c;
  }
  .gray {
    background: #f1f5f9;
    color: #64748b;
  }
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: #0f253c77;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(5px);
  }
  .modal-card {
    background: white;
    border-radius: 24px;
    padding: 24px;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow: auto;
  }
  .qr-panel,
  .qr-scan-panel {
    text-align: center;
  }
  .qr-code-box {
    width: 292px;
    min-height: 292px;
    margin: 0 auto;
    padding: 16px;
    border: 1px solid #d9eff1;
    border-radius: 20px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .qr-code-box img,
  .qr-code-box canvas {
    max-width: 100%;
    height: auto !important;
  }
  #qr-reader {
    width: min(460px, 100%);
    margin: 0 auto;
    overflow: hidden;
    border-radius: 16px;
    background: #f8fafc;
  }

  .hidden {
    display: none !important;
  }
  .loading {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: #f0fdffb8;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
  }
  .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #cffafe;
    border-top-color: #0891b2;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }
  .empty {
    padding: 40px;
    text-align: center;
    color: #94a3b8;
  }
  .chart-box {
    height: 270px;
    position: relative;
  }
  .task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
    gap: 18px;
  }
  .badge-card {
    background: linear-gradient(135deg, #fffbeb, #fff);
    border: 1px solid #fde68a;
    border-radius: 18px;
    padding: 18px;
  }
  .swal2-popup {
    font-family: "Kanit", sans-serif;
  }
  .certificate {
    border: 8px double #d1a341;
    text-align: center;
    padding: 45px 25px;
    background: #fffdf5;
  }
  .certificate h2 {
    font-size: 34px;
    color: #876620;
    margin: 20px 0;
  }
  .certificate h3 {
    font-size: 25px;
    margin: 20px 0;
  }
  .certificate p {
    margin: 15px 0;
  }
  .photo {
    max-width: 100%;
    max-height: 65vh;
    margin: auto;
    border-radius: 16px;
  }
  @media (min-width: 901px) { #hamburger { display: none; } }
  @media (max-width: 900px) {
    #hamburger { display: inline-flex !important; }
    .topbar {
      flex-wrap: wrap;
      gap: 12px;
    }
    .topbar nav {
      order: 3;
      width: 100%;
      flex-basis: 100%;
      display: none;
    }
    .topbar nav.open {
      display: flex;
    }
    .brand {
      flex: 1;
    }
    .brand small {
      font-size: 9px;
    }
    #account {
      font-size: 12px;
    }
    .card {
      padding: 18px;
    }
    .page-title {
      font-size: 23px;
    }
  }
  @media print {
    body > * {
      display: none !important;
    }
    #modal {
      display: block !important;
      position: static;
      padding: 0;
      background: white;
    }
    #modal .modal-card {
      width: 100%;
      max-height: none;
      padding: 0;
    }
    #modal-title,
    #modal-close,
    .no-print {
      display: none !important;
    }
    .certificate {
      margin: 10mm;
    }
    footer {
      display: none !important;
    }
  }

  /* iOS-safe QR capture: use the system camera/file picker, then decode the still image. */
  .qr-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }
  .qr-photo-btn {
    cursor: pointer;
  }
  .qr-image-reader {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }
</style>

<style>
  .qr-photo-tip {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    color: #466374;
    font-size: 13px;
    line-height: 1.6;
  }

  .duty-days { display:flex; flex-wrap:wrap; gap:9px; }
  .duty-check { display:inline-flex; align-items:center; gap:7px; padding:9px 13px; border:1px solid #dce8ed; border-radius:12px; background:#fff; cursor:pointer; }
  .duty-check input { width:auto; }
  .notice-duty { border-left:4px solid #0891b2; background:#ecfeff; padding:13px 15px; border-radius:10px; color:#33566a; font-size:13px; }

/* v2.0 external PWA / live QR */
.live-qr-reader{width:100%;min-height:280px;border-radius:18px;overflow:hidden;background:#0f172a;margin:12px 0}
.live-qr-reader video{width:100%!important;height:auto!important;object-fit:cover}
.live-qr-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}
.install-note{background:#ecfeff;border:1px solid #bae6fd;border-radius:14px;padding:12px 14px;margin-top:14px}
.api-offline{position:fixed;left:50%;bottom:18px;transform:translateX(-50%);z-index:100;background:#7f1d1d;color:#fff;padding:9px 14px;border-radius:999px;font-size:12px;box-shadow:0 8px 24px #0002}
