/* ============================================================
   BORSUP — Components & App Shell
   ============================================================ */

/* ---------- App layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: linear-gradient(180deg, var(--ink-850) 0%, var(--ink-900) 100%);
  color: #cdd2d9; display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  border-right: 1px solid rgba(255,255,255,.05);
}
.sidebar-brand {
  height: var(--topbar-h); display: flex; align-items: center; gap: 11px;
  padding: 0 22px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-logo-img {
  height: 24px; width: auto; max-width: 190px; object-fit: contain;
  /* black wordmark → white for the dark sidebar */
  filter: brightness(0) invert(1);
  opacity: .95;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(145deg, var(--gold-400), var(--gold-600));
  display: grid; place-items: center; color: var(--ink-900);
  box-shadow: 0 4px 14px rgba(191,155,73,.35); font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-head); font-weight: 600; font-size: 18px; letter-spacing: .14em; color: #fff; }
.brand-sub { font-size: 10.5px; color: var(--gold-300); letter-spacing: .22em; text-transform: uppercase; margin-top: 2px; }

.nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section-label { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #6b7480; padding: 14px 12px 7px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: var(--r-sm); border: none; background: none;
  color: #aab1ba; font-size: 14.5px; text-align: left; margin-bottom: 2px;
  transition: all .2s ease; position: relative; font-weight: 500; white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(191,155,73,.18), rgba(191,155,73,.04)); color: var(--gold-300); }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  background: var(--gold-400); border-radius: 0 3px 3px 0;
}
.nav-item .nav-ic { flex-shrink: 0; opacity: .9; }
.nav-badge { margin-left: auto; background: var(--wine-600); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 20px; min-width: 20px; text-align: center; }
.nav-item.active .nav-badge { background: var(--gold-500); color: var(--ink-900); }

/* Expandable submenu */
.nav-group { display: flex; flex-direction: column; }
.nav-caret { margin-left: 6px; display: inline-flex; color: #6b7480; transition: transform .22s ease; }
.nav-item .nav-badge + .nav-caret { margin-left: 6px; }
.nav-caret.open { transform: rotate(180deg); }
.nav-item.parent-active .nav-caret { color: var(--gold-300); }
.nav-sub { overflow: hidden; max-height: 0; transition: max-height .28s cubic-bezier(.22,.61,.36,1); }
.nav-sub.open { max-height: 160px; }
.nav-subitem { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px 8px 22px; border: none; background: none; color: #99a0a9; font-size: 13.5px; text-align: left; border-radius: var(--r-sm); margin: 1px 0; transition: all .18s; font-weight: 500; white-space: nowrap; }
.nav-subitem:hover { background: rgba(255,255,255,.04); color: #fff; }
.nav-subitem.active { color: var(--gold-300); background: rgba(191,155,73,.1); }
.nav-sub-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; opacity: .6; }
.nav-subitem.active .nav-sub-dot { opacity: 1; }

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--r-sm); transition: background .2s; cursor: pointer; }
.user-chip:hover { background: rgba(255,255,255,.05); }
.user-chip-name { font-size: 13.5px; color: #fff; font-weight: 600; }
.user-chip-role { font-size: 11.5px; color: #7a828c; }

/* ---------- Main area ---------- */
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px; padding: 0 28px;
  background: rgba(247,245,241,.82); backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-family: var(--font-head); font-size: 17px; font-weight: 500; color: var(--text-900); white-space: nowrap; flex-shrink: 0; }
.topbar-spacer { flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text-700); display: grid; place-items: center;
  transition: all .18s ease; position: relative;
}
.icon-btn:hover { border-color: var(--gold-400); color: var(--ink-900); box-shadow: var(--sh-sm); transform: translateY(-1px); }
.icon-btn .dot { position: absolute; top: 9px; right: 10px; width: 7px; height: 7px; background: var(--wine-500); border-radius: 50%; border: 1.5px solid var(--surface); }
.menu-toggle { display: none; }

.content { flex: 1; padding: 28px; max-width: 1320px; width: 100%; margin: 0 auto; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 28px; font-weight: 600; color: var(--text-900); margin: 0; letter-spacing: -.01em; white-space: nowrap; }
.page-sub { color: var(--text-500); font-size: 14.5px; margin: 5px 0 0; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--r-sm); font-weight: 600;
  transition: all .18s ease; white-space: nowrap; line-height: 1;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-md { padding: 10px 17px; font-size: 14px; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: var(--r-xs); }
.btn-lg { padding: 13px 24px; font-size: 15px; }
.btn-full { width: 100%; }
.btn-primary { background: linear-gradient(135deg, var(--ink-800), var(--ink-900)); color: #fff; box-shadow: var(--sh-sm); }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--sh-md); }
.btn-gold { background: linear-gradient(135deg, var(--gold-400), var(--gold-600)); color: var(--ink-900); box-shadow: var(--sh-gold); }
.btn-gold:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(159,123,50,.32); }
.btn-secondary { background: var(--surface); color: var(--text-900); border-color: var(--line); box-shadow: var(--sh-xs); }
.btn-secondary:hover:not(:disabled) { border-color: var(--gold-400); transform: translateY(-1px); box-shadow: var(--sh-sm); }
.btn-ghost { background: transparent; color: var(--text-700); }
.btn-ghost:hover:not(:disabled) { background: var(--paper-2); color: var(--text-900); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a93226; transform: translateY(-1px); }
.btn-wine { background: linear-gradient(135deg, var(--wine-500), var(--wine-700)); color: #fff; box-shadow: var(--sh-sm); }
.btn-wine:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--sh-md); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-sm); }
.card-hover { transition: transform .24s cubic-bezier(.22,.61,.36,1), box-shadow .24s, border-color .24s; cursor: pointer; }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--sh-lg); border-color: var(--gold-300); }
.card-pad { padding: 20px; }

/* ---------- Stat cards ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 20px; box-shadow: var(--sh-sm); position: relative; overflow: hidden;
  transition: transform .24s cubic-bezier(.22,.61,.36,1), box-shadow .24s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--sh-md); }
.stat-card::after { content: ""; position: absolute; top: 0; right: 0; width: 120px; height: 120px; border-radius: 50%; transform: translate(40%, -40%); opacity: .5; }
.stat-gold::after { background: radial-gradient(circle, var(--gold-100), transparent 70%); }
.stat-wine::after { background: radial-gradient(circle, var(--wine-100), transparent 70%); }
.stat-green::after { background: radial-gradient(circle, var(--green-100), transparent 70%); }
.stat-blue::after { background: radial-gradient(circle, var(--blue-100), transparent 70%); }
.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; position: relative; }
.stat-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; }
.stat-ic-gold { background: linear-gradient(145deg, var(--gold-100), var(--gold-tint)); color: var(--gold-600); }
.stat-ic-wine { background: var(--wine-100); color: var(--wine-600); }
.stat-ic-green { background: var(--green-100); color: var(--green-600); }
.stat-ic-blue { background: var(--blue-100); color: var(--blue-600); }
.stat-delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12.5px; font-weight: 600; padding: 3px 8px; border-radius: 20px; }
.stat-delta.up { color: var(--green-600); background: var(--green-100); }
.stat-delta.down { color: var(--red-600); background: var(--red-100); }
.stat-val { font-size: 27px; font-weight: 700; color: var(--text-900); letter-spacing: -.02em; line-height: 1; position: relative; }
.stat-label { font-size: 13.5px; color: var(--text-500); margin-top: 7px; position: relative; }
.stat-sub { font-size: 12px; color: var(--text-400); margin-top: 3px; position: relative; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.soft.badge-slate { background: var(--slate-100); color: var(--slate-600); }
.badge.soft.badge-green { background: var(--green-100); color: var(--green-600); }
.badge.soft.badge-amber { background: var(--amber-100); color: var(--amber-600); }
.badge.soft.badge-red { background: var(--red-100); color: var(--red-600); }
.badge.soft.badge-blue { background: var(--blue-100); color: var(--blue-600); }
.badge.soft.badge-gold { background: var(--gold-100); color: var(--gold-600); }
.badge.soft.badge-wine { background: var(--wine-100); color: var(--wine-600); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast {
  display: flex; align-items: flex-start; gap: 12px; min-width: 290px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 13px 14px; box-shadow: var(--sh-lg); pointer-events: auto;
  animation: slideInRight .4s cubic-bezier(.22,.61,.36,1) both;
}
.toast-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.toast-msg { font-weight: 600; font-size: 14px; color: var(--text-900); }
.toast-sub { font-size: 12.5px; color: var(--text-500); margin-top: 2px; }
.toast-x { border: none; background: none; color: var(--text-400); padding: 2px; border-radius: 6px; }
.toast-x:hover { color: var(--text-900); background: var(--paper-2); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 150; background: rgba(20,24,29,.5); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; animation: fadeIn .2s ease; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: 100%; animation: scaleIn .32s cubic-bezier(.22,.61,.36,1) both; display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-sm { max-width: 440px; }
.modal-md { max-width: 600px; }
.modal-lg { max-width: 860px; }
.modal-xl { max-width: 1120px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.modal-title { font-size: 20px; font-weight: 600; margin: 0; color: var(--text-900); }
.modal-sub { font-size: 13.5px; color: var(--text-500); margin: 4px 0 0; }
.modal-x { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-500); display: grid; place-items: center; transition: all .18s; flex-shrink: 0; }
.modal-x:hover { color: var(--text-900); border-color: var(--text-400); }
.modal-body { padding: 22px 24px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); flex-shrink: 0; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-700); }
.req { color: var(--wine-500); }
.field-hint { font-size: 12px; color: var(--text-400); }
.field-error { font-size: 12px; color: var(--red-600); }
.input {
  width: 100%; padding: 10px 13px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); font-size: 14px; color: var(--text-900); transition: all .16s ease;
}
.input::placeholder { color: var(--text-400); }
.input:focus { outline: none; border-color: var(--gold-400); box-shadow: 0 0 0 3.5px rgba(191,155,73,.15); }
.input:hover:not(:focus) { border-color: #d6cfc1; }
.textarea { resize: vertical; line-height: 1.6; min-height: 70px; }
.input-wrap { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); transition: all .16s; overflow: hidden; }
.input-wrap:focus-within { border-color: var(--gold-400); box-shadow: 0 0 0 3.5px rgba(191,155,73,.15); }
.input-wrap .input { border: none; box-shadow: none; }
.input-wrap .input:focus { box-shadow: none; }
.input-affix { padding: 0 12px; color: var(--text-500); font-size: 13.5px; font-weight: 600; background: var(--surface-2); align-self: stretch; display: flex; align-items: center; border-right: 1px solid var(--line); }
.input-affix.suffix { border-right: none; border-left: 1px solid var(--line); }
.select-wrap { position: relative; }
.select { appearance: none; padding-right: 38px; cursor: pointer; }
.select-chev { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-500); pointer-events: none; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .col-span-2 { grid-column: 1 / -1; }
.form-section-title { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--gold-600); margin: 4px 0 0; display: flex; align-items: center; gap: 8px; }
.form-section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Search ---------- */
.search-input { display: flex; align-items: center; gap: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0 12px; min-width: 200px; transition: all .16s; color: var(--text-400); }
.search-input:focus-within { border-color: var(--gold-400); box-shadow: 0 0 0 3.5px rgba(191,155,73,.15); color: var(--text-700); }
.search-input input { border: none; outline: none; background: none; padding: 10px 0; font-size: 14px; flex: 1; color: var(--text-900); min-width: 0; }
.search-clear { border: none; background: none; color: var(--text-400); padding: 3px; border-radius: 5px; display: grid; place-items: center; }
.search-clear:hover { color: var(--text-900); background: var(--paper-2); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th { text-align: left; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-500); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.table thead th.right { text-align: right; }
.table tbody td { padding: 14px 16px; border-bottom: 1px solid var(--line-2); color: var(--text-700); vertical-align: middle; }
.table tbody tr { transition: background .14s; }
.table tbody tr:hover { background: var(--gold-tint); }
.table tbody tr:last-child td { border-bottom: none; }
.table td.right { text-align: right; }
.td-strong { font-weight: 600; color: var(--text-900); }
.row-click { cursor: pointer; }

/* ---------- Misc ---------- */
.segmented { display: inline-flex; background: var(--paper-2); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg-btn { border: none; background: none; padding: 7px 15px; border-radius: 7px; font-size: 13.5px; font-weight: 600; color: var(--text-500); transition: all .18s; }
.seg-btn:hover { color: var(--text-900); }
.seg-btn.active { background: var(--surface); color: var(--ink-900); box-shadow: var(--sh-xs); }

.empty-state { text-align: center; padding: 56px 24px; }
.empty-ic { width: 72px; height: 72px; border-radius: 20px; background: var(--gold-tint); color: var(--gold-500); display: grid; place-items: center; margin: 0 auto 16px; }
.empty-state h4 { font-family: var(--font-head); font-size: 18px; color: var(--text-900); margin: 0 0 6px; }
.empty-state p { color: var(--text-500); font-size: 14px; margin: 0 auto 18px; max-width: 340px; line-height: 1.6; }

.avatar { border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex-shrink: 0; }
.avatar-gold { background: linear-gradient(145deg, var(--gold-400), var(--gold-600)); color: var(--ink-900); }
.avatar-wine { background: linear-gradient(145deg, var(--wine-500), var(--wine-700)); }
.avatar-blue { background: linear-gradient(145deg, #4a90c2, var(--blue-600)); }
.avatar-green { background: linear-gradient(145deg, #4aa676, var(--green-600)); }
.avatar-slate { background: linear-gradient(145deg, #7585969e, var(--slate-600)); }

.stars { display: inline-flex; align-items: center; gap: 2px; }
.stars-val { font-size: 12.5px; color: var(--text-500); margin-left: 5px; font-weight: 600; }

.progress { height: 7px; background: var(--paper-2); border-radius: 20px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 20px; transition: width .6s cubic-bezier(.22,.61,.36,1); }
.progress-gold { background: linear-gradient(90deg, var(--gold-400), var(--gold-600)); }
.progress-green { background: linear-gradient(90deg, #4aa676, var(--green-600)); }
.progress-wine { background: linear-gradient(90deg, var(--wine-500), var(--wine-700)); }
.progress-red { background: linear-gradient(90deg, #e06657, var(--red-600)); }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, #ece8e0 25%, #f4f1ea 50%, #ece8e0 75%); background-size: 800px 100%; animation: shimmer 1.4s infinite linear; border-radius: 6px; }

/* Section title */
.section-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; color: var(--text-900); margin: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }

/* Definition list */
.dl { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; font-size: 14px; }
.dl dt { color: var(--text-500); }
.dl dd { margin: 0; color: var(--text-900); font-weight: 500; text-align: right; }

/* Dividers & chips */
.divider { height: 1px; background: var(--line); margin: 20px 0; border: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 20px; background: var(--paper-2); font-size: 12.5px; color: var(--text-700); font-weight: 500; }
.chip-ic { color: var(--text-400); }

/* Pill tabs */
.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-tab { padding: 8px 16px; border-radius: 22px; border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--text-500); transition: all .18s; }
.pill-tab:hover { border-color: var(--gold-300); color: var(--text-900); }
.pill-tab.active { background: var(--ink-900); border-color: var(--ink-900); color: #fff; }

/* Cloud sync status badge (topbar) */
.sync-badge {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px;
  border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line); transition: all .2s ease;
}
.sync-badge .sync-badge-label { line-height: 1; }
.sync-syncing { background: rgba(191,155,73,.12); color: var(--gold-600); border-color: rgba(191,155,73,.3); }
.sync-synced  { background: rgba(46,125,50,.10); color: var(--green-600); border-color: rgba(46,125,50,.28); }
.sync-offline { background: rgba(176,42,42,.10); color: var(--red-600); border-color: rgba(176,42,42,.3); }
.sync-spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(191,155,73,.35); border-top-color: var(--gold-600);
  animation: sync-spin .7s linear infinite; flex-shrink: 0;
}
@keyframes sync-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sync-spinner { animation-duration: 2s; } }

/* Responsive */
@media (max-width: 1024px) {
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .3s cubic-bezier(.22,.61,.36,1); width: 256px; box-shadow: var(--sh-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: grid; }
  .content { padding: 18px; }
  .topbar { padding: 0 16px; }
  .scrim { position: fixed; inset: 0; background: rgba(20,24,29,.4); z-index: 55; backdrop-filter: blur(2px); animation: fadeIn .2s; }
  .page-title { font-size: 23px; }
}

/* Mobile-first: ปุ่ม/ช่องกรอกสูง 44–48px กดด้วยนิ้วสะดวก + ตารางเลื่อนได้ ไม่ล้นจอ */
@media (max-width: 768px) {
  /* บังคับ font-size 16px ใน input/select/textarea กัน iOS ซูมอัตโนมัติตอนโฟกัส */
  input, select, textarea { font-size: 16px !important; }
  /* Touch targets ≥48px (Apple HIG) */
  .btn { min-height: 48px !important; }
  .btn-md { padding: 13px 18px; }
  .btn-sm { padding: 11px 15px; font-size: 14px; min-height: 44px; }
  .btn-lg { padding: 15px 24px; }
  .icon-btn { width: 46px; height: 46px; }
  .modal-x { width: 44px; height: 44px; }

  /* ช่องกรอกข้อมูลสูง ≥48px (font 16px กัน iOS ซูมอัตโนมัติตอนโฟกัส) */
  .input { min-height: 48px; padding: 12px 14px; font-size: 16px; }
  .textarea { min-height: 96px; }
  .input-wrap { min-height: 48px; }
  .input-affix { min-height: 48px; }
  .select { min-height: 48px; }
  .search-input { min-height: 48px; }
  .search-input input { padding: 14px 0; font-size: 16px; }

  /* ตาราง: เลื่อนแนวนอนภายใน container ไม่ดันให้หน้าจอล้น */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .table { min-width: 560px; }
  .content { padding: 14px; }

  /* สถานะซิงค์: เหลือไอคอน/วงกลมหมุน ประหยัดพื้นที่บนมือถือ */
  .sync-badge { padding: 0 8px; height: 36px; }
  .sync-badge .sync-badge-label { display: none; }

  /* Modal → Bottom Sheet เลื่อนขึ้นจากด้านล่าง เต็มความกว้าง */
  .modal-overlay { padding: 0; align-items: flex-end; }
  /* ตำแหน่งพักอยู่ชิดล่างเสมอ (ไม่ใส่ fill-mode both เพื่อกันค้างนอกจอถ้าแอนิเมชันไม่จบ) */
  .modal { width: 100%; max-width: 100% !important; max-height: 92vh; max-height: 92dvh;
    border-radius: 18px 18px 0 0; animation: sheetUp .3s cubic-bezier(.22,.61,.36,1); }
  .modal-head { padding: 16px 18px 12px; position: relative; }
  /* ขีดจับด้านบน bottom sheet */
  .modal-head::before { content: ""; position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 3px; background: var(--line); }
  .modal-body { padding: 16px 18px; overscroll-behavior: contain; }
  /* ปุ่ม บันทึก/ยกเลิก ยึดล่างสุดเสมอ ไม่หายใต้คีย์บอร์ด */
  .modal-foot { position: sticky; bottom: 0; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }

  /* ฟอร์ม: คอลัมน์เดียวทั้งหมด ไม่มี col-span ทำเลย์เอาต์พัง */
  .form-grid { grid-template-columns: 1fr !important; gap: 14px; }
  .form-grid .col-span-2 { grid-column: auto !important; }
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }
