:root {
  color-scheme: light;
  /* โทนหลัก Material Blue — base #1e88e5 */
  --primary:       #1e88e5;   /* 600 — ปุ่มหลัก, topbar */
  --primary-dark:  #1565c0;   /* 800 — hover/active */
  --primary-darker:#0d47a1;   /* 900 — text เข้มบนพื้นอ่อน */
  --primary-light: #64b5f6;   /* 300 */
  --primary-50:    #e3f2fd;   /* พื้นหลัง tint */
  --primary-100:   #bbdefb;   /* badge tint */
  --primary-2:     #1976d2;   /* 700 — alias เดิม */

  --bg: #f4f8fc;
  --card: #ffffff;
  --text: #102a43;
  --muted: #627d98;
  --border: #d9e2ec;

  --danger: #c62828;
  --warn:   #ef6c00;
  --ok:     #2e7d32;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Sarabun", "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 12px 24px;
  display: flex; align-items: center;
  flex-wrap: wrap; gap: 12px;
  box-shadow: 0 2px 8px rgba(30, 136, 229, .2);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none;
}
.brand:hover { color: #fff; text-decoration: none; opacity: .9; }
.brand img.logo { height: 28px; width: auto; display: block; }
.brand strong { font-size: 20px; letter-spacing: .5px; }
.brand .sub { margin-left: 10px; opacity: .9; font-size: 14px; }
.nav a {
  color: #fff; text-decoration: none; margin-left: 8px;
  padding: 6px 12px; border-radius: 6px; font-size: 14px;
  transition: background .15s;
}
.nav a:hover { background: rgba(255,255,255,.14); }
.nav a.active { background: rgba(255,255,255,.22); }

.env-pill {
  display: inline-flex; align-items: center;
  padding: 5px 12px; border-radius: 14px;
  font-size: 12px; font-weight: 700;
  letter-spacing: .02em;
  margin-right: 8px;
  cursor: help;
  white-space: nowrap;
}
.env-pill.env-training   { background: #1565c0; color: #fff; }
.env-pill.env-production { background: #7f1d1d; color: #fff; animation: envPulse 2s ease-in-out infinite; }
@keyframes envPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 83, 80, .6); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 83, 80, 0); }
}

.userbox {
  position: relative;
  margin-left: auto;
}
.userbox-trigger {
  background: transparent; border: 0; padding: 0; margin: 0;
  cursor: pointer; line-height: 0; border-radius: 50%;
  transition: box-shadow .15s;
}
.userbox-trigger:hover { box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.userbox-trigger .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  object-fit: cover; background: rgba(255,255,255,.25);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 14px;
}
.userbox-popup {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: #fff; color: var(--text);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
  min-width: 240px; max-width: 90vw;
  padding: 14px; z-index: 100;
  display: none;
  border: 1px solid var(--border);
}
.userbox-popup.open { display: block; animation: popupFadeIn .12s ease; }
@keyframes popupFadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.userbox-popup-head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 12px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.userbox-popup-head .avatar {
  width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; background: var(--primary-100);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--primary-darker); font-size: 18px;
  flex: 0 0 auto;
}
.userbox-popup-info { flex: 1; min-width: 0; }
.userbox-popup-name { font-weight: 600; font-size: 14px; color: var(--primary-darker); word-break: break-word; }
.userbox-popup-pos { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.userbox-popup-dept { font-size: 11px; color: var(--muted); margin-top: 1px; word-break: break-word; }
.userbox-popup-actions { margin: 0; }
.userbox-popup-actions .btn-logout {
  display: block; width: 100%;
  padding: 8px 12px; border-radius: 8px;
  background: var(--danger); color: #fff; border: 0;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.userbox-popup-actions .btn-logout:hover { background: #a52020; }

.nav-toggle {
  display: none;
  background: rgba(255,255,255,.18); color: #fff;
  border: none; border-radius: 8px;
  padding: 6px 10px; font-size: 18px;
  cursor: pointer;
}

/* Mobile — ซ่อน nav ไว้, toggle ด้วยปุ่ม ☰ */
@media (max-width: 820px) {
  .topbar {
    padding: 10px 14px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .brand .sub { display: none; }
  .nav-toggle { display: inline-flex; order: -1; }
  .nav {
    order: 99;
    flex-basis: 100%;
    display: none;
    flex-direction: column;
    background: rgba(0,0,0,.1);
    border-radius: 8px;
    padding: 8px;
    margin-top: 4px;
  }
  body.nav-open .nav { display: flex; }
  .nav a { margin: 2px 0; padding: 10px 14px; }
  .userbox-trigger .avatar { width: 32px; height: 32px; font-size: 13px; }
}

@media (max-width: 480px) {
  .userbox-popup { right: -8px; min-width: 220px; }
}

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }

.hero h1 { margin: 0 0 4px 0; color: var(--primary-darker); }
.muted { color: var(--muted); }
.danger { color: var(--danger); }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 20px; margin-bottom: 20px;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; color: var(--primary-darker); }

/* ---- Page tabs (top-level navigation within a page) ---- */
.page-tabs {
  display: flex; gap: 4px;
  border-bottom: 2px solid var(--border);
  margin: 0 0 16px;
  flex-wrap: wrap;
}
.page-tab {
  background: transparent; border: 0;
  padding: 10px 18px; border-radius: 8px 8px 0 0;
  color: var(--muted); font: inherit; font-size: 15px; font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: background .15s, color .15s, border-color .15s;
}
.page-tab:hover { background: var(--primary-50); color: var(--primary-dark); }
.page-tab.active {
  color: var(--primary-dark); background: var(--primary-50);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tab-panel[hidden] { display: none; }

.stat-chips {
  display: flex; flex-wrap: wrap; gap: 4px 6px;
  margin-top: 4px; font-size: 13px; color: var(--muted);
}
.stat-chips a {
  color: var(--primary-darker); text-decoration: none;
  padding: 1px 4px; border-radius: 4px;
  transition: background .15s;
}
.stat-chips a:hover { background: var(--primary-50); }
.stat-chips a b { font-weight: 700; }
.stat-chips a.warn { color: var(--warn); }
.stat-chips a.danger { color: var(--danger); }
.stat-chips .sep { color: #cfd8dc; }

.btn {
  display: inline-block; padding: 8px 14px; margin-right: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--primary-50); border-color: var(--primary-light); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #a52020; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.tbl th { background: var(--primary-50); font-weight: 600; color: var(--primary-darker); }
.tbl tr:hover td { background: #fafdff; }

/* ---- Recent table — desktop: ผู้ออกเลข/สถานะ ไม่ตัดบรรทัด, ตัดที่เรื่องแทน ---- */
@media (min-width: 821px) {
  .tbl-recent .col-officer,
  .tbl-recent .col-status {
    white-space: nowrap;
    width: 1%;        /* shrink-to-fit content */
  }
  .tbl-recent .col-subject {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
}

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: #eef2f6; color: var(--text);
}
.badge.pending { background: #fff4d6; color: var(--warn); }
.badge.syncing { background: var(--primary-100); color: var(--primary-dark); }
.badge.synced  { background: #d4edda; color: var(--ok); }
.badge.error   { background: #fadbd8; color: var(--danger); }
.badge.reserved  { background: #fff3cd; color: #a66a00; border: 1px solid #ffc107; font-weight: 600; }
.badge.sent      { background: #d4edda; color: var(--ok); font-weight: 600; }
.badge.cancelled { background: #e0e0e0; color: #757575; }
.badge.closed    { background: #e1f0ff; color: #1565c0; border: 1px solid #90caf9; font-weight: 600; }
.badge.warn { background: #fff4d6; color: var(--warn); }

/* ── รับหนังสือ: camera shot + AI extract ── */
.recv-shot {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  background: #fafbfd;
  margin: 6px 0 4px;
}
.recv-shot-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.recv-shot-btn {
  font-size: 16px;
  padding: 12px 20px;
  min-height: 48px;
}
@media (max-width: 480px) {
  .recv-shot-buttons { flex-direction: column; align-items: stretch; }
  .recv-shot-btn { width: 100%; }
}
.recv-shot-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.recv-preview {
  margin: 6px 0 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #fafbfd;
}
.recv-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.recv-preview-grid:has(.recv-preview-slot[hidden]) {
  grid-template-columns: 1fr;
}
.recv-preview-slot {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}
.recv-preview-img,
.recv-preview img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #000;
}
.recv-slot-label {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  pointer-events: none;
}
@media (max-width: 600px) {
  .recv-preview-grid { grid-template-columns: 1fr; }
}
.recv-preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.recv-ocr-status {
  font-size: 13px;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.recv-ocr-status.loading { color: var(--primary-dark); }
.recv-ocr-status.ok { color: var(--ok); }
.recv-ocr-status.warn { color: var(--warn); }
.recv-ocr-status.err { color: var(--danger); }

/* ── Scan Inbox: ภาพจากเครื่องสแกน (drop folder) ── */
.scan-inbox-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.scan-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfd;
}
.scan-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: #eee;
}
.scan-meta { flex: 1; min-width: 0; }
.scan-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scan-sub { font-size: 11px; color: var(--muted); }
.scan-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.scan-actions .btn-small { padding: 3px 8px; font-size: 11px; }
@media (max-width: 480px) {
  .scan-inbox-list { grid-template-columns: 1fr; }
}

/* ---- stage indicator (หน้า new + send) ---- */
.stage-wrap {
  display: flex; align-items: center; gap: 10px;
  margin: -4px 0 18px; padding: 10px 14px;
  background: #f5f9ff; border: 1px solid #bbdefb; border-radius: 10px;
  flex-wrap: wrap;
}
.stage {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  font-size: 13px; color: #90a4ae;
}
.stage.active { background: #1565c0; color: #fff; font-weight: 600; }
.stage.done   { background: #2e7d32; color: #fff; }
.stage .stage-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,.3); font-weight: 700; font-size: 12px;
}
.stage:not(.active):not(.done) .stage-n { background: #cfd8dc; color: #fff; }
.stage-sep { color: #90a4ae; font-size: 18px; }

/* ---- stage tabs (list) ---- */
.stage-tabs { display: flex; gap: 4px; border-bottom: 2px solid #e0e0e0; margin: 10px 0 16px; flex-wrap: wrap; }
.stage-tab {
  padding: 8px 16px; border-radius: 8px 8px 0 0; color: #546e7a;
  font-size: 14px; font-weight: 500; border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.stage-tab:hover { background: #eceff1; text-decoration: none; }
.stage-tab.active { color: #1565c0; border-bottom-color: #1565c0; background: #e3f2fd; }
.tab-count {
  display: inline-block; margin-left: 6px;
  background: #ff6f00; color: #fff;
  padding: 1px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700;
}

/* ---- attach list (send page) ---- */
.attach-list { list-style: none; padding: 0; margin: 0; }
.attach-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 6px;
  background: #fff;
}
.attach-name { flex: 1; font-weight: 500; word-break: break-all; color: var(--primary-darker); text-decoration: none; }
.attach-name:hover { text-decoration: underline; }
.attach-meta { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }

/* ---- attach thumbnail (view page) ---- */
.attach-thumb {
  flex-shrink: 0;
  width: 72px; height: 72px;
  border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #f7f7f7;
  text-decoration: none;
}
.attach-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.attach-thumb-doc {
  background: linear-gradient(135deg, #fff 0%, #eef3fa 100%);
}
.attach-icon { font-size: 32px; line-height: 1; }
.attach-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.attach-dl {
  align-self: flex-start;
  margin-top: 4px;
  font-size: 12px;
  color: var(--primary-darker);
  text-decoration: none;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.attach-dl:hover { background: var(--primary-darker); color: #fff; border-color: var(--primary-darker); }

.btn-danger-small {
  padding: 4px 10px; font-size: 12px;
  background: #fadbd8; color: var(--danger);
  border: 1px solid #f5b7b1; border-radius: 6px; cursor: pointer;
}
.btn-danger-small:hover { background: #f5b7b1; }

/* ---- detail grid (send/view page) ---- */
.detail-grid {
  display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px;
  margin: 12px 0;
}
.detail-k { color: var(--muted); font-size: 13px; padding-top: 2px; }
.detail-v { font-size: 14px; }

/* ---- finalize box ---- */
.finalize-box {
  margin-top: 18px; padding: 14px 16px;
  background: #fff8e1; border: 1px solid #ffca28; border-radius: 10px;
}

.alert { padding: 10px 14px; border-radius: 8px; margin: 12px 0; font-size: 14px; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

.btn-small { padding: 4px 10px; font-size: 12px; border-radius: 6px; background: #eceff1; color: #455a64; text-decoration: none; }
.btn-small.primary { background: #1565c0; color: #fff; }
.btn-small:hover { background: #cfd8dc; text-decoration: none; }
.btn-small.primary:hover { background: #0d47a1; }

.form label { display: block; margin: 10px 0; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
@media (max-width: 600px) { .form-row-2 { grid-template-columns: 1fr; } }
.form input[type=text], .form input[type=date], .form textarea, .form select {
  width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
.form input[type=text]:focus, .form input[type=date]:focus,
.form textarea:focus, .form select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 136, 229, .15);
}
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .actions { margin-top: 16px; }

.filter { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.filter input, .filter select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.filter button {
  padding: 6px 14px; background: var(--primary); color: #fff; border: 0; border-radius: 6px; cursor: pointer;
  transition: background .15s;
}
.filter button:hover { background: var(--primary-dark); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }

.actions { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { display: inline; }

.foot {
  text-align: center; padding: 24px; color: var(--muted);
}
.foot-link {
  color: var(--muted); text-decoration: none;
  padding: 2px 6px; border-radius: 4px;
  transition: background .15s, color .15s;
}
.foot-link:hover { background: var(--primary-50); color: var(--primary-dark); text-decoration: none; }

/* ---- Loading overlay (spinner) ---- */
.loading-overlay {
  position: fixed; inset: 0;
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 18px;
  background: rgba(15, 42, 67, .78);
  backdrop-filter: blur(3px);
  z-index: 9999;
  color: #fff;
}
.loading-overlay.show { display: flex; animation: overlayFadeIn .2s ease; }
.loading-overlay .spinner {
  width: 72px; height: 72px;
  border: 6px solid rgba(255,255,255,.25);
  border-top-color: #ffca28;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-overlay .spinner-text {
  font-size: 1.05rem; font-weight: 600;
  text-align: center; max-width: 85vw;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.loading-overlay .spinner-sub {
  font-size: .85rem; opacity: .85; max-width: 85vw; text-align: center;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes overlayFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* link ทั่วไป */
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
.topbar a, .nav a, .btn { text-decoration: none; }
.topbar a:hover, .nav a:hover { text-decoration: none; }

@media (max-width: 820px) {
  .container { margin: 12px auto; padding: 0 12px; }
  .card { padding: 12px; margin-bottom: 12px; }
  .card-head { margin-bottom: 8px; }
  .card-head h2 { font-size: 18px; }
  .form label { margin: 6px 0; }
  .form-row-2 { margin: 6px 0; gap: 8px; }
  .form .row { grid-template-columns: 1fr; gap: 8px; }
  .form input[type=text], .form input[type=date], .form textarea, .form select {
    padding: 8px 10px; font-size: 16px; /* 16px กัน iOS zoom */
  }
  .form .actions, .actions { margin-top: 10px; }
  .kv { grid-template-columns: 120px 1fr; font-size: 14px; }
  .tbl { font-size: 13px; }
  .tbl th, .tbl td { padding: 8px 6px; }
  .filter { gap: 6px; }
  .filter input, .filter select { padding: 8px 10px; font-size: 15px; flex: 1 1 auto; }
}

@media (max-width: 480px) {
  .btn { padding: 10px 14px; font-size: 15px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; margin-bottom: 10px; }
  .kv dt { font-size: 12px; margin-top: 8px; }

  /* ── Responsive table — stack แต่ละแถวเป็น card ── */
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr {
    border: 1px solid var(--border); border-radius: 8px;
    margin-bottom: 10px; padding: 8px 10px;
    background: var(--card);
  }
  .tbl tr:hover td { background: transparent; }
  .tbl td {
    display: flex; align-items: flex-start; gap: 8px;
    padding: 4px 0; border: 0;
    font-size: 14px; min-height: 0;
  }
  .tbl td:empty { display: none; }
  .tbl td::before {
    content: attr(data-label);
    flex: 0 0 72px; min-width: 72px;
    font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
    padding-top: 2px;
  }
  .tbl td[data-label='']::before,
  .tbl td:last-child::before { display: none; flex: none; min-width: 0; }
  .tbl td:last-child { justify-content: flex-end; margin-top: 2px; }
}

/* ---- Thai Buddhist date picker ---- */
.thai-cal-pop {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.22);
  padding: 14px;
  width: 360px;
  z-index: 1000;
  font-family: inherit;
  user-select: none;
}
.thai-cal-head {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 10px;
}
.thai-cal-head select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
}
.thai-cal-head select:focus { outline: none; border-color: var(--primary); }
.thai-cal-nav {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  color: var(--primary-dark);
  flex: 0 0 auto;
}
.thai-cal-nav:hover { background: var(--primary-50); border-color: var(--primary-light); }
.thai-cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.thai-cal-week span {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 0;
}
.thai-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.thai-cal-grid .d {
  aspect-ratio: 1 / 1;
  min-height: 40px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  padding: 0;
  transition: background .1s;
}
.thai-cal-grid .d:hover:not(:disabled) { background: var(--primary-50); }
.thai-cal-grid .d.off { color: #cbd5e0; cursor: default; }
.thai-cal-grid .d.today { border-color: var(--primary-light); font-weight: 700; }
.thai-cal-grid .d.selected { background: var(--primary); color: #fff; font-weight: 700; }
.thai-cal-grid .d:disabled { cursor: not-allowed; opacity: .4; }
.thai-cal-foot {
  margin-top: 10px;
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.thai-cal-today {
  background: transparent;
  border: 0;
  color: var(--primary-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 6px;
}
.thai-cal-today:hover { background: var(--primary-50); }
@media (max-width: 480px) {
  .thai-cal-pop { width: 92vw; max-width: 360px; }
}
