/* =========================================================
   SolarStock — mobile-first UI
   ========================================================= */
:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e5e9f1;
  --navy: #0b1736;
  --navy-2: #172a5c;
  --sun: #f59e0b;
  --sun-2: #f97316;
  --sun-soft: #fff6e5;
  --sun-ink: #2b1700;

  --blue: #2563eb;   --blue-soft: #eaf1ff;
  --green: #15803d;  --green-soft: #e7f6ec;
  --red: #dc2626;    --red-soft: #fdecec;
  --amber: #b45309;  --amber-soft: #fff3d6;
  --purple: #7c3aed; --purple-soft: #f1eaff;
  --teal: #0f766e;   --teal-soft: #e0f5f2;
  --gray: #475569;   --gray-soft: #eef1f5;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 60px rgba(11, 23, 54, .22);
  --ring: 0 0 0 4px rgba(245, 158, 11, .22);

  --sidebar-w: 264px;
  --topbar-h: 62px;
  --bn-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Anuphan', 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
.sidebar { display: none; }
.main { min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  background: rgba(243, 245, 250, .86);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid rgba(229, 233, 241, .7);
}
.topbar-title { flex: 1; min-width: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content {
  padding: 16px 16px calc(var(--bn-h) + var(--safe-b) + 28px);
  max-width: 1180px;
  margin: 0 auto;
}

.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, #fbbf24, var(--sun-2));
  color: #fff; font-size: 20px;
  box-shadow: 0 6px 16px rgba(249, 115, 22, .35);
}
.brand-logo.sm { width: 36px; height: 36px; font-size: 18px; border-radius: 11px; }

/* bottom nav (mobile) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--bn-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.bottom-nav > a, .bottom-nav > button:not(.bn-plus) {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 100%; border: 0; background: none; cursor: pointer;
  font-size: 11.5px; font-weight: 500; color: var(--muted);
}
.bottom-nav i { font-size: 21px; line-height: 1; }
.bottom-nav .active { color: var(--navy); font-weight: 700; }
.bottom-nav .active i { color: var(--sun-2); }
.bn-plus {
  justify-self: center;
  width: 54px; height: 54px; margin-top: -26px;
  border: 4px solid var(--bg); border-radius: 20px;
  background: linear-gradient(135deg, #fbbf24, var(--sun-2));
  color: #fff; font-size: 24px; cursor: pointer;
  box-shadow: 0 10px 22px rgba(249, 115, 22, .4);
  display: grid; place-items: center;
}
.bn-plus i { font-size: 24px; }

.mobile-only { display: inline-grid; }
.desktop-only { display: none !important; }

@media (min-width: 1024px) {
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    background: var(--navy);
    background-image: radial-gradient(600px 300px at -10% -10%, rgba(245, 158, 11, .18), transparent 60%);
    color: #cbd5e1; padding: 22px 16px; z-index: 60;
  }
  .brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; color: #fff; }
  .brand-text { display: flex; flex-direction: column; line-height: 1.25; }
  .brand-text b { font-size: 18px; letter-spacing: .2px; }
  .brand-text small { color: #94a3b8; font-size: 12.5px; }
  .side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
  .side-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: 12px; font-weight: 500; color: #cbd5e1;
    transition: background .15s, color .15s;
  }
  .side-nav a i { font-size: 18px; width: 20px; text-align: center; }
  .side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
  .side-nav a.active { background: rgba(245, 158, 11, .14); color: #fff; box-shadow: inset 3px 0 0 var(--sun); }
  .side-nav a.active i { color: var(--sun); }
  .side-user {
    display: flex; align-items: center; gap: 10px;
    padding: 12px; border-radius: 14px; background: rgba(255, 255, 255, .05);
  }
  .side-user .avatar { background: rgba(245, 158, 11, .2); color: var(--sun); }
  .su-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
  .su-text b { color: #fff; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .su-text small { color: #94a3b8; font-size: 12px; }
  .side-user .icon-btn { color: #94a3b8; }
  .side-user .icon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }

  .main { margin-left: var(--sidebar-w); }
  .topbar { padding: 0 32px; }
  .topbar-title { font-size: 21px; }
  .content { padding: 26px 32px 48px; }
  .bottom-nav { display: none; }
  .mobile-only { display: none !important; }
  .desktop-only { display: inline-flex !important; }
}

/* ---------- Typography helpers ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.nowrap { white-space: nowrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pre { white-space: pre-line; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.p-0 { padding: 0 !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.flex-1 { flex: 1; min-width: 0; }
.w-100 { width: 100%; }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid > *, .job-list > * { min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 16px; }
}
@media (min-width: 1024px) {
  .grid-main { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(229, 233, 241, .6);
}
.card-body { padding: 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px 0;
}
.card-head h2, .card-head h3 { font-size: 16px; font-weight: 700; }
.card-head + .card-body { padding-top: 12px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 26px 0 12px; }
.section-head:first-child { margin-top: 4px; }
.section-head h2 { font-size: 17px; font-weight: 700; }
.section-head a.link { font-size: 14px; color: var(--blue); font-weight: 600; }

.stat-card {
  position: relative; overflow: hidden;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid rgba(229, 233, 241, .6);
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; letter-spacing: -.3px; }
.stat-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.stat-card.hero {
  background: linear-gradient(140deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff; border: 0;
}
.stat-card.hero .stat-label { color: #a5b4d4; }
.stat-card.hero::after {
  content: ''; position: absolute; right: -40px; top: -40px; width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, .55), rgba(249, 115, 22, 0) 70%);
}

.bg-sun { background: var(--sun-soft); color: var(--sun-2); }
.bg-blue { background: var(--blue-soft); color: var(--blue); }
.bg-green { background: var(--green-soft); color: var(--green); }
.bg-red { background: var(--red-soft); color: var(--red); }
.bg-purple { background: var(--purple-soft); color: var(--purple); }
.bg-teal { background: var(--teal-soft); color: var(--teal); }
.bg-amber { background: var(--amber-soft); color: var(--amber); }
.bg-gray { background: var(--gray-soft); color: var(--gray); }
.bg-glass { background: rgba(255, 255, 255, .12); color: #fde68a; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 18px;
  border-radius: 13px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 15px; line-height: 1;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: transform .08s, background .15s, box-shadow .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn i { font-size: 17px; }
.btn-primary { background: var(--navy); color: #fff; box-shadow: 0 6px 16px rgba(11, 23, 54, .18); }
.btn-primary:hover { background: var(--navy-2); }
.btn-sun { background: linear-gradient(135deg, #fbbf24, var(--sun-2)); color: var(--sun-ink); box-shadow: 0 8px 18px rgba(249, 115, 22, .28); }
.btn-light { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-light:hover { background: var(--surface-2); }
.btn-soft { background: var(--gray-soft); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #fbdcdc; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-sm i { font-size: 15px; }
.btn-lg { height: 54px; font-size: 16px; border-radius: 15px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; box-shadow: none; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-light.loading::after, .btn-soft.loading::after { border-color: rgba(15, 23, 42, .2); border-top-color: var(--text); }

.icon-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  display: inline-grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  font-size: 18px; cursor: pointer; color: var(--text);
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: var(--gray-soft); }
.icon-btn.danger { color: var(--red); }
.icon-btn.sm { width: 34px; height: 34px; font-size: 15px; border-radius: 10px; }

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

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field > label, .label {
  display: block; margin-bottom: 7px;
  font-size: 14px; font-weight: 600; color: var(--text-2);
}
.req { color: var(--red); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.input, .select, .textarea {
  width: 100%; height: 48px; padding: 0 14px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 13px;
  outline: none; transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--sun); box-shadow: var(--ring); }
.textarea { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
.select {
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 12px;
}
.input-group { position: relative; }
.input-group > i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 17px; pointer-events: none; }
.input-group > .input { padding-left: 44px; }
.input-group .addon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

.form-grid { display: grid; gap: 0 16px; }
@media (min-width: 768px) {
  .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
  .span-all { grid-column: 1 / -1; }
}

.segmented { display: flex; background: var(--gray-soft); padding: 4px; border-radius: 14px; gap: 4px; }
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; border-radius: 11px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted); transition: all .15s;
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }

.form-actions {
  display: flex; gap: 10px; margin-top: 8px;
}
.form-actions .btn { flex: 1; }
@media (min-width: 768px) {
  .form-actions { justify-content: flex-end; }
  .form-actions .btn { flex: 0 0 auto; min-width: 140px; }
}
.sticky-actions {
  position: sticky; bottom: calc(var(--bn-h) + var(--safe-b) + 10px); z-index: 30;
  padding: 10px; margin: 16px -4px 0; border-radius: 18px;
  background: rgba(255, 255, 255, .9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 1024px) {
  .sticky-actions { position: static; background: none; box-shadow: none; padding: 0; margin: 16px 0 0; backdrop-filter: none; }
}

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.pill i { font-size: 12px; }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-blue { background: var(--blue-soft); color: var(--blue); }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-red { background: var(--red-soft); color: var(--red); }
.pill-teal { background: var(--teal-soft); color: var(--teal); }
.pill-purple { background: var(--purple-soft); color: var(--purple); }
.pill-gray { background: var(--gray-soft); color: var(--gray); }
.pill-sun { background: var(--sun-soft); color: #c2410c; }

.avatar {
  width: 40px; height: 40px; border-radius: 13px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
  background: var(--sun-soft); color: #c2410c;
}

/* ---------- Search & chips ---------- */
.toolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
@media (min-width: 768px) { .toolbar { flex-direction: row; align-items: center; } .toolbar .search { flex: 1; } }
.search { position: relative; }
.search i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 16px; }
.search .input { padding-left: 42px; border-color: transparent; box-shadow: var(--shadow); }
.search .input:focus { border-color: var(--sun); box-shadow: var(--ring); }

.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 16px; padding: 2px 16px;
}
.chips::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .chips { margin-left: 0; margin-right: 0; padding: 2px 0; flex-wrap: wrap; } }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 7px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14px; font-weight: 500; color: var(--text-2); white-space: nowrap;
}
.chip .count { font-size: 12px; font-weight: 700; padding: 0 7px; border-radius: 999px; background: var(--gray-soft); color: var(--muted); line-height: 1.6; }
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.active .count { background: rgba(255, 255, 255, .16); color: #fff; }
.chip.warn { border-color: #fcd9b6; color: #c2410c; }
.chip.warn.active { background: var(--sun-2); border-color: var(--sun-2); color: #fff; }

/* ---------- Lists ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid rgba(229, 233, 241, .6); }
.list.flat { box-shadow: none; border: 0; border-radius: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, .list-item[data-href]:hover { background: var(--surface-2); cursor: pointer; }
.li-icon {
  width: 44px; height: 44px; border-radius: 13px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 20px;
}
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub i { font-size: 12px; }
.li-end { text-align: right; flex-shrink: 0; }
.li-qty { font-size: 18px; font-weight: 700; line-height: 1.2; }
.li-qty small { font-size: 12px; font-weight: 500; color: var(--muted); }
.li-qty.low { color: #c2410c; }
.li-qty.out { color: var(--red); }
.dot-sep::before { content: '·'; margin: 0 6px; color: #cbd5e1; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th {
  text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 4px; border-radius: 15px; background: #e7ebf3;
  position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 6px); z-index: 20;
  margin-bottom: 16px;
}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; border: 0; border-radius: 12px; background: none; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tab .count { font-size: 12px; padding: 0 7px; border-radius: 999px; background: rgba(15, 23, 42, .07); line-height: 1.6; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 10px rgba(15, 23, 42, .08); }
.tab.active .count { background: var(--sun-soft); color: #c2410c; }
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Key-value ---------- */
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 10px 14px; font-size: 14.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Modal / bottom sheet ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: flex-end; justify-content: center;
  background: rgba(11, 23, 54, .48);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal.open { display: flex; animation: fade .2s ease; }
.modal-box {
  width: 100%; max-width: 560px; max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-lg);
  animation: slideUp .26s cubic-bezier(.2, .9, .3, 1);
}
.sheet-handle { width: 42px; height: 5px; border-radius: 99px; background: #d5dbe6; margin: 10px auto 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px 12px; }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; gap: 10px; padding: 12px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--border); }
.modal-foot .btn { flex: 1; }
@media (min-width: 768px) {
  .modal { align-items: center; padding: 24px; }
  .modal-box { border-radius: 22px; animation: popIn .2s ease; }
  .sheet-handle { display: none; }
  .modal-head { padding-top: 18px; }
  .modal-foot { padding-bottom: 16px; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes popIn { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding-bottom: calc(6px + var(--safe-b)); }
.quick-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 16px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600;
}
.qi-icon { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 20px; }
.qi-icon.sun { background: var(--sun-soft); color: var(--sun-2); }
.qi-icon.green { background: var(--green-soft); color: var(--green); }
.qi-icon.blue { background: var(--blue-soft); color: var(--blue); }
.qi-icon.purple { background: var(--purple-soft); color: var(--purple); }

.menu-list { padding-bottom: calc(8px + var(--safe-b)); }
.menu-list a {
  display: flex; align-items: center; gap: 14px; padding: 15px 20px; font-weight: 500;
  border-top: 1px solid var(--border);
}
.menu-list a i:first-child { font-size: 20px; color: var(--muted); width: 22px; }
.menu-list a i:last-child { margin-left: auto; color: #cbd5e1; }
.menu-list a.danger, .menu-list a.danger i:first-child { color: var(--red); }

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed; z-index: 400; left: 50%; transform: translateX(-50%);
  top: calc(10px + env(safe-area-inset-top, 0px));
  width: calc(100% - 24px); max-width: 440px;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 16px; border-radius: 15px;
  background: var(--navy); color: #fff; font-weight: 500; font-size: 14.5px;
  box-shadow: var(--shadow-lg); pointer-events: auto;
  animation: toastIn .3s cubic-bezier(.2, .9, .3, 1.2);
  transition: opacity .3s, transform .3s;
}
.toast i { font-size: 18px; color: #4ade80; margin-top: 1px; }
.toast.error { background: #7f1d1d; }
.toast.error i { color: #fca5a5; }
.toast.hide { opacity: 0; transform: translateY(-10px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty > i { font-size: 44px; color: #cbd5e1; display: block; margin-bottom: 10px; }
.empty h3 { font-size: 16px; color: var(--text-2); margin-bottom: 4px; }
.empty p { margin: 0 0 14px; font-size: 14px; }

/* ---------- Pager ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 18px; }
.pager-info { font-size: 14px; color: var(--muted); }

/* ---------- Dashboard ---------- */
.hello { margin-bottom: 18px; }
.hello h2 { font-size: 22px; font-weight: 700; }
.hello p { margin: 2px 0 0; color: var(--muted); }
.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0 4px; }
.qa {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 6px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
  font-size: 13px; font-weight: 600; text-align: center; line-height: 1.3;
  transition: transform .1s;
}
.qa:active { transform: scale(.97); }
.qa .qi-icon { width: 44px; height: 44px; }

/* ---------- Job cards ---------- */
.job-list { display: grid; gap: 12px; }
@media (min-width: 768px) { .job-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .job-list.wide { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.job-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow); border: 1px solid rgba(229, 233, 241, .6);
  transition: transform .12s, box-shadow .15s;
  position: relative; overflow: hidden;
}
.job-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--status-color, #cbd5e1); }
.job-card:hover { box-shadow: 0 10px 30px rgba(15, 23, 42, .09); }
.job-card:active { transform: scale(.99); }
.job-card.s-pending { --status-color: #f59e0b; }
.job-card.s-in_progress { --status-color: #2563eb; }
.job-card.s-completed { --status-color: #16a34a; }
.job-card.s-cancelled { --status-color: #94a3b8; }
.jc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.jc-no { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: .3px; }
.jc-title { font-size: 16px; font-weight: 700; line-height: 1.35; }
.jc-customer { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.jc-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.jc-meta span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Job detail ---------- */
.job-hero {
  border-radius: 22px; padding: 20px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(140deg, var(--navy) 0%, #1d3274 100%);
  box-shadow: 0 14px 34px rgba(11, 23, 54, .25);
}
.job-hero::after {
  content: ''; position: absolute; right: -60px; top: -70px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, .45), rgba(249, 115, 22, 0) 68%);
  pointer-events: none;
}
.job-hero .jc-no { color: #a5b4d4; }
.job-hero h2 { font-size: 21px; font-weight: 700; margin: 6px 0 12px; position: relative; z-index: 1; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 8px; position: relative; z-index: 1; }
.hero-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: rgba(255, 255, 255, .1); font-size: 13px; font-weight: 500; }
.hero-chip i { color: #fcd34d; }
.hero-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; position: relative; z-index: 1; }
.hero-actions a {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 14px; background: rgba(255, 255, 255, .08);
  font-size: 12.5px; font-weight: 600; color: #e2e8f0;
}
.hero-actions a i { font-size: 19px; color: #fcd34d; }
.hero-actions a:hover { background: rgba(255, 255, 255, .14); }

.status-switch { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.status-switch button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px; border-radius: 13px; border: 1.5px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.status-switch button i { font-size: 18px; }
.status-switch button.on.pending { border-color: var(--sun); background: var(--amber-soft); color: var(--amber); }
.status-switch button.on.in_progress { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.status-switch button.on.completed { border-color: #22c55e; background: var(--green-soft); color: var(--green); }
.status-switch button.on.cancelled { border-color: #94a3b8; background: var(--gray-soft); color: var(--gray); }

.item-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.item-row:last-child { border-bottom: 0; }
.item-figs { display: flex; gap: 12px; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item-figs b { color: var(--text-2); font-weight: 600; }
.summary-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--surface-2); border-top: 1px solid var(--border);
  font-size: 14px;
}
.summary-bar b { font-size: 17px; }

/* ---------- Product picker ---------- */
.picker-rows { display: flex; flex-direction: column; gap: 8px; }
.pick-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 15px; background: var(--surface); border: 1.5px solid var(--border);
  animation: fadeIn .2s ease;
}
.pick-row.over { border-color: #fca5a5; background: #fffafa; }
.pick-row.flash { animation: flashRow .6s ease; }
@keyframes flashRow { 0% { background: var(--sun-soft); } 100% { background: var(--surface); } }
.pr-main { flex: 1; min-width: 0; }
.pr-main b { display: block; font-size: 14.5px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pr-main small { display: block; color: var(--muted); font-size: 12.5px; }
.pr-warn { color: var(--red) !important; font-weight: 600; }
.pr-cost { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.pr-cost input { width: 96px; height: 32px; border: 1.5px solid var(--border); border-radius: 9px; padding: 0 8px; font: inherit; font-size: 14px; }
.pr-cost input:focus { outline: none; border-color: var(--sun); }
.stepper { display: flex; align-items: center; border: 1.5px solid var(--border); border-radius: 12px; overflow: hidden; flex-shrink: 0; background: var(--surface); }
.stepper button { width: 34px; height: 40px; border: 0; background: var(--surface-2); font-size: 19px; cursor: pointer; color: var(--text-2); }
.stepper button:active { background: var(--gray-soft); }
.stepper input { width: 56px; height: 40px; border: 0; text-align: center; font: inherit; font-size: 16px; font-weight: 700; outline: none; }
.picker-empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px;
  border: 2px dashed var(--border); border-radius: 16px; color: var(--muted); text-align: center; font-size: 14px;
}
.picker-empty i { font-size: 30px; color: #cbd5e1; }
.pick-list { display: flex; flex-direction: column; }
.pick-opt {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 4px; border: 0; border-bottom: 1px solid var(--border); background: none;
  text-align: left; cursor: pointer;
}
.pick-opt:last-child { border-bottom: 0; }
.pick-opt:hover { background: var(--surface-2); }
.po-main { flex: 1; min-width: 0; }
.po-main b { display: block; font-weight: 600; font-size: 14.5px; }
.po-main small { color: var(--muted); font-size: 12.5px; }
.po-qty { font-weight: 700; white-space: nowrap; }
.po-qty small { font-weight: 500; color: var(--muted); }
.po-qty.low { color: #c2410c; }
.pick-opt.disabled { opacity: .45; cursor: not-allowed; }
.pick-opt.chosen .po-main b::after { content: ' ✓'; color: var(--green); }
.modal-search { position: sticky; top: 0; background: var(--surface); padding-bottom: 8px; z-index: 2; }

/* ---------- Photos ---------- */
.photo-toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.photo-toolbar .btn { flex: 1; }
.photo-toolbar.disabled .btn { opacity: .5; pointer-events: none; }
.photo-quota { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 13.5px; color: var(--muted); }
.quota-bar { flex: 1; height: 6px; border-radius: 99px; background: #e2e8f0; overflow: hidden; }
.quota-bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #fbbf24, var(--sun-2)); transition: width .3s; }

.queue-wrap { margin-bottom: 18px; padding: 14px; border-radius: 18px; background: var(--sun-soft); border: 1.5px dashed #fcd29a; }
.queue-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 700; font-size: 14.5px; }
.upload-queue { display: grid; gap: 10px; }
@media (min-width: 768px) { .upload-queue { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.queue-item { display: flex; gap: 10px; padding: 10px; border-radius: 14px; background: var(--surface); align-items: flex-start; position: relative; }
.queue-item img { width: 76px; height: 76px; border-radius: 11px; object-fit: cover; flex-shrink: 0; background: #e2e8f0; }
.qi-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.qi-main textarea {
  width: 100%; min-height: 58px; resize: none; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 7px 10px; font: inherit; font-size: 15px; line-height: 1.45; outline: none;
}
.qi-main textarea:focus { border-color: var(--sun); }
.progress { height: 5px; border-radius: 99px; background: #eef1f5; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fbbf24, var(--sun-2)); transition: width .2s; }
.queue-item.busy { opacity: .75; }
.queue-item.error { outline: 2px solid #fca5a5; }

.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .photo-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.photo-card {
  background: var(--surface); border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid rgba(229, 233, 241, .6);
  display: flex; flex-direction: column; animation: fadeIn .25s ease;
}
.ph-media { position: relative; aspect-ratio: 4 / 3; background: #e2e8f0; }
.ph-media img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.ph-num {
  position: absolute; left: 8px; top: 8px;
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 9px;
  display: grid; place-items: center;
  background: rgba(11, 23, 54, .72); color: #fff; font-size: 12.5px; font-weight: 700;
  backdrop-filter: blur(4px);
}
.ph-del {
  position: absolute; right: 8px; top: 8px; width: 32px; height: 32px; border-radius: 10px; border: 0;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, .92); color: var(--red); font-size: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.ph-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.ph-caption {
  width: 100%; min-height: 56px; resize: none; border: 1.5px solid transparent; border-radius: 10px;
  padding: 6px 8px; margin: 0 -2px; font: inherit; font-size: 14px; line-height: 1.45; color: var(--text);
  background: var(--surface-2); outline: none; transition: border-color .15s, background .15s;
}
.ph-caption:focus { border-color: var(--sun); background: var(--surface); }
.ph-caption::placeholder { color: #94a3b8; }
.ph-meta { display: flex; justify-content: space-between; gap: 6px; font-size: 11.5px; color: var(--muted); }
.ph-status { font-weight: 600; white-space: nowrap; }
.ph-status.saving { color: var(--amber); }
.ph-status.saved { color: var(--green); }
.ph-status.err { color: var(--red); }
.ph-caption-print { display: none; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 300; display: none; flex-direction: column;
  background: rgba(3, 7, 18, .96); color: #fff; user-select: none;
}
.lightbox.open { display: flex; animation: fade .2s; }
.lb-top { display: flex; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 8px; }
.lb-count { font-weight: 600; font-size: 14px; color: #cbd5e1; }
.lb-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; cursor: pointer;
  display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: #fff; font-size: 20px;
}
.lb-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 0 8px; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lb-prev, .lb-next { position: absolute; top: 50%; transform: translateY(-50%); }
.lb-prev { left: 12px; } .lb-next { right: 12px; }
.lb-caption { padding: 14px 20px calc(18px + var(--safe-b)); text-align: center; font-size: 15px; line-height: 1.55; color: #e2e8f0; white-space: pre-line; max-height: 30vh; overflow-y: auto; }
.lb-caption:empty::before { content: 'ไม่มีรายละเอียด'; color: #64748b; }
@media (max-width: 640px) { .lb-prev, .lb-next { display: none; } }

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: var(--navy);
  background-image:
    radial-gradient(700px 420px at 85% -10%, rgba(249, 115, 22, .35), transparent 60%),
    radial-gradient(600px 400px at -10% 110%, rgba(37, 99, 235, .3), transparent 60%);
}
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 26px; padding: 30px 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; text-align: center; }
.auth-brand .brand-logo { width: 62px; height: 62px; font-size: 30px; border-radius: 19px; }
.auth-brand h1 { font-size: 24px; font-weight: 700; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 14px; }
.alert { padding: 12px 14px; border-radius: 13px; font-size: 14px; margin-bottom: 16px; display: flex; gap: 8px; align-items: flex-start; }
.alert-error { background: var(--red-soft); color: #991b1b; }
.alert-info { background: var(--blue-soft); color: #1e40af; }
.alert-success { background: var(--green-soft); color: #166534; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--sun-2); }

/* ---------- Print ---------- */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 12.5px; }
  .sidebar, .topbar, .bottom-nav, .no-print, .tabs, .modal, .toast-stack, .ph-del, .ph-caption, .photo-toolbar, .photo-quota, .queue-wrap, .hero-actions, .photos-empty { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  .print-only { display: block; }
  .tab-pane { display: block !important; break-inside: auto; margin-bottom: 14px; }
  .card, .list, .photo-card, .job-hero { box-shadow: none !important; border: 1px solid #d0d5dd !important; }
  .job-hero { background: #fff !important; color: #000 !important; }
  .job-hero::after { display: none; }
  .job-hero .jc-no, .hero-chip, .hero-chip i { color: #000 !important; background: #f1f5f9 !important; }
  .photo-grid { grid-template-columns: repeat(3, 1fr) !important; gap: 8px; }
  .photo-card { break-inside: avoid; }
  .ph-caption-print { display: block; font-size: 11.5px; white-space: pre-line; }
  .grid-main { display: block; }
  .grid-main > * { margin-bottom: 12px; }
}

/* ---------- Flaticon UIcons alignment ---------- */
.fi { display: inline-flex; align-items: center; justify-content: center; line-height: 1; flex-shrink: 0; }
.fi::before { display: block; line-height: 1; }
.d-block { display: block; }
.card-head h3 .fi { color: var(--sun-2); margin-right: 4px; vertical-align: -2px; display: inline-flex; }

/* ---------- Assignees / permissions ---------- */
.avatar.sm { width: 34px; height: 34px; border-radius: 11px; font-size: 14px; }
.assignee-grid { display: grid; gap: 8px; }
@media (min-width: 640px) { .assignee-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.assignee {
  display: flex; align-items: center; gap: 10px; margin: 0 !important;
  padding: 10px 12px; border-radius: 14px; border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.assignee input { position: absolute; opacity: 0; pointer-events: none; }
.assignee b { display: block; font-size: 14.5px; font-weight: 600; color: var(--text); }
.assignee small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.assignee > .fi { font-size: 20px; color: #d5dbe6; }
.assignee:has(input:checked) { border-color: var(--sun); background: var(--sun-soft); }
.assignee:has(input:checked) > .fi { color: var(--sun-2); }

.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.perm-table th.role-col, .perm-table td.role-col { width: 96px; text-align: center; }
.perm-table thead th { font-size: 12.5px; color: var(--muted); background: var(--surface-2); line-height: 1.3; }
.perm-table .group td { background: var(--surface-2); font-weight: 700; font-size: 13.5px; color: var(--text-2); }
.perm-table .perm-name { font-weight: 600; font-size: 14.5px; }
.perm-table .perm-desc { font-size: 12.5px; color: var(--muted); }
.switch { position: relative; display: inline-block; width: 46px; height: 28px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #d5dbe6; transition: background .2s; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + span { background: var(--sun-2); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:disabled + span { opacity: .55; }
.role-cards { display: grid; gap: 12px; margin-bottom: 18px; }
@media (min-width: 768px) { .role-cards { grid-template-columns: repeat(3, 1fr); } }
.role-card { padding: 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); display: flex; gap: 12px; align-items: flex-start; }
.role-card p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- System update ---------- */
.changes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 7px; font-size: 14px; }
.changes li { display: flex; gap: 8px; align-items: flex-start; }
.changes .pill { flex-shrink: 0; min-width: 62px; justify-content: center; }
.upd-log { display: grid; gap: 8px; }
.upd-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.upd-row .fi { font-size: 17px; margin-top: 1px; }
.upd-row.error { background: var(--red-soft); }
.upd-row.warning { background: var(--amber-soft); }
.spin { animation: spin 1s linear infinite; }
code { font-size: 12.5px; background: var(--gray-soft); padding: 1px 6px; border-radius: 6px; }
@media (max-width: 640px) {
  .perm-table th.role-col, .perm-table td.role-col { width: 58px; padding: 10px 4px; font-size: 11px; }
  .perm-table th, .perm-table td { padding: 10px 8px; }
  .switch { transform: scale(.85); }
}

/* ---------- Manual ---------- */
.m-hero { position: relative; overflow: hidden; border-radius: 22px; padding: 22px 18px 16px; margin-bottom: 18px;
  background: linear-gradient(140deg, var(--navy) 0%, #1d3274 100%); color: #fff; box-shadow: 0 14px 34px rgba(11, 23, 54, .22); }
.m-hero::after { content: ''; position: absolute; right: -70px; top: -80px; width: 240px; height: 240px; border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, .45), rgba(249, 115, 22, 0) 68%); pointer-events: none; }
.m-hero-text { position: relative; z-index: 1; }
.m-hero h2 { font-size: 22px; margin: 10px 0 4px; }
.m-hero p { margin: 0 0 14px; color: #c7d2ea; font-size: 14.5px; }
.m-search { position: relative; z-index: 1; margin-bottom: 12px; }
.m-search .input { box-shadow: none; }
.m-roles { position: relative; z-index: 1; margin-bottom: 0; }
.m-roles .chip { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .14); color: #e2e8f0; cursor: pointer; font: inherit; font-size: 14px; }
.m-roles .chip.active { background: #fff; color: var(--navy); border-color: #fff; }
.m-layout { display: grid; gap: 24px; }
@media (min-width: 1100px) { .m-layout { grid-template-columns: minmax(0, 1fr) 250px; } }
.m-toc.desktop-toc { display: none; }
@media (min-width: 1100px) {
  .m-toc.desktop-toc { display: block; position: sticky; top: calc(var(--topbar-h) + 16px); align-self: start; max-height: calc(100vh - var(--topbar-h) - 32px); overflow-y: auto; padding: 6px 4px 20px; }
}
.m-toc-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .5px; margin: 0 8px 8px; }
.m-toc-sec { margin-bottom: 10px; }
.m-toc-h { display: flex; gap: 8px; align-items: center; padding: 6px 8px; font-weight: 700; font-size: 14px; border-radius: 10px; }
.m-toc-h .fi { color: var(--sun-2); }
.m-toc-s { display: block; padding: 5px 8px 5px 32px; font-size: 13.5px; color: var(--muted); border-radius: 8px; }
.m-toc-s:hover, .m-toc-h:hover { background: var(--gray-soft); color: var(--text); }
.m-toc-s.active { color: var(--sun-2); font-weight: 600; background: var(--sun-soft); }
.m-section { margin-bottom: 34px; scroll-margin-top: 80px; }
.m-sec-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.m-sec-head small { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.m-sec-head h2 { font-size: 21px; }
.m-sec-icon { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, #fbbf24, var(--sun-2)); color: #fff; box-shadow: 0 8px 18px rgba(249, 115, 22, .3); flex-shrink: 0; }
.m-sub { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid rgba(229, 233, 241, .6);
  padding: 18px; margin-bottom: 14px; scroll-margin-top: 80px; font-size: 15px; line-height: 1.7; }
.m-sub h3 { font-size: 17px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.m-sub h4 { font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.m-sub p { margin: 0 0 12px; }
.m-anchor { color: #cbd5e1; font-weight: 500; }
.m-anchor:hover { color: var(--sun-2); }
.m-ui { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-radius: 7px; background: var(--gray-soft); border: 1px solid var(--border);
  font-size: 13.5px; font-weight: 600; line-height: 1.7; white-space: nowrap; vertical-align: 1px; }
.m-ui .fi { font-size: 12px; color: var(--sun-2); }
.m-steps { list-style: none; counter-reset: s; padding: 0; margin: 4px 0 14px; display: grid; gap: 10px; }
.m-steps li { counter-increment: s; position: relative; padding-left: 40px; min-height: 28px; }
.m-steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--navy); color: #fff; font-size: 13.5px; font-weight: 700; line-height: 1; }
.m-list { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 6px; }
.m-check { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 6px; counter-reset: c; }
.m-check li { counter-increment: c; padding: 8px 12px 8px 40px; border-radius: 12px; background: var(--surface-2); position: relative; }
.m-check li::before { content: counter(c); position: absolute; left: 12px; top: 8px; font-weight: 700; color: var(--sun-2); }
.m-shots { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 220px)); gap: 14px; justify-content: center; margin: 6px 0 16px; }
.m-shot { margin: 0 auto 14px; max-width: 280px; text-align: center; }
.m-shots .m-shot { margin: 0; max-width: none; }
.m-shot img { width: 100%; border-radius: 22px; border: 5px solid #0b1736; box-shadow: 0 12px 28px rgba(11, 23, 54, .18); cursor: zoom-in; background: #e2e8f0; }
.m-shot figcaption { font-size: 12.5px; color: var(--muted); margin-top: 8px; line-height: 1.4; }
.m-sub > .m-shot:only-of-type, #start-overview .m-shot, #jobs-print .m-shot { max-width: 100%; }
#start-overview .m-shot img, #jobs-print .m-shot img { border-width: 4px; border-radius: 14px; }
.m-callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; margin: 0 0 12px; font-size: 14px; line-height: 1.6; border: 1px solid; }
.m-callout > .fi { font-size: 18px; margin-top: 2px; }
.m-callout.tip { background: var(--sun-soft); border-color: #fde3b8; } .m-callout.tip > .fi { color: var(--sun-2); }
.m-callout.warn { background: var(--red-soft); border-color: #fbd0d0; } .m-callout.warn > .fi { color: var(--red); }
.m-callout.note { background: var(--blue-soft); border-color: #d4e2ff; } .m-callout.note > .fi { color: var(--blue); }
.m-callout.rule { background: var(--purple-soft); border-color: #e2d6ff; } .m-callout.rule > .fi { color: var(--purple); }
.m-table { margin-bottom: 14px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; font-size: 14px; display: table; }
.m-table td, .m-table th { padding: 9px 12px; vertical-align: top; }
.m-table td:first-child { white-space: nowrap; }
.m-flow { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; counter-reset: f; }
.m-flow span { counter-increment: f; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: var(--sun-soft); color: #9a3412; font-size: 13.5px; font-weight: 600; }
.m-flow span::before { content: counter(f); width: 20px; height: 20px; border-radius: 50%; background: var(--sun-2); color: #fff; display: grid; place-items: center; font-size: 11.5px; }
.m-cols { display: grid; gap: 12px; margin-bottom: 12px; }
@media (min-width: 768px) { .m-cols { grid-template-columns: repeat(2, 1fr); } .m-cols.three { grid-template-columns: repeat(3, 1fr); } }
.m-cols .card-body { padding: 14px; }
.m-cols .m-steps { margin-bottom: 0; }
.m-perm-grid { display: grid; gap: 6px; margin-bottom: 12px; font-size: 14px; }
@media (min-width: 640px) { .m-perm-grid { grid-template-columns: repeat(2, 1fr); } }
.m-perm-grid div { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 10px; background: var(--surface-2); }
.m-perm-grid .yes .fi { color: var(--green); } .m-perm-grid .no { color: var(--muted); } .m-perm-grid .no .fi { color: #cbd5e1; }
.m-faq { border: 1px solid var(--border); border-radius: 14px; margin-bottom: 8px; background: var(--surface); }
.m-faq summary { display: flex; gap: 10px; align-items: center; padding: 12px 14px; font-weight: 600; cursor: pointer; list-style: none; }
.m-faq summary::-webkit-details-marker { display: none; }
.m-faq summary .fi { color: var(--sun-2); }
.m-faq summary::after { content: '+'; margin-left: auto; font-size: 20px; color: var(--muted); font-weight: 400; }
.m-faq[open] summary::after { content: '−'; }
.m-faq p { margin: 0; padding: 0 14px 14px 40px; color: var(--text-2); }
.m-glossary { grid-template-columns: 150px 1fr; }
.m-contact { display: flex; gap: 14px; align-items: center; }
.m-contact > .fi { font-size: 30px; color: var(--sun-2); }
.m-sub.hit { outline: 2px solid var(--sun); }
@media print {
  .m-hero, .m-toc, #tocSheet, .m-noresult, .m-anchor { display: none !important; }
  .m-section, .m-sub { display: block !important; }
  .m-sub { box-shadow: none; border: 1px solid #d0d5dd; break-inside: auto; }
  .m-shots { grid-template-columns: repeat(3, 1fr); }
  .m-shot img { max-height: 380px; width: auto; border-width: 3px; box-shadow: none; }
  .m-section { break-before: page; }
  .m-section:first-of-type { break-before: auto; }
  .m-faq { break-inside: avoid; }
  .m-faq p { display: block; }
  .m-cols { grid-template-columns: repeat(2, 1fr) !important; }
  .m-cols.three { grid-template-columns: repeat(3, 1fr) !important; }
  .m-perm-grid { grid-template-columns: repeat(2, 1fr); }
  .m-shot { max-width: 210px; }
  .m-shot img { max-height: 340px; }
  #start-overview .m-shot, #jobs-print .m-shot { max-width: 100%; }
  #start-overview .m-shot img, #jobs-print .m-shot img { max-height: 420px; }
  .m-steps li, .m-callout, .m-table tr, .role-card { break-inside: avoid; }
  .m-sub h3 { break-after: avoid; }
  .role-card { box-shadow: none; border: 1px solid #d0d5dd; }
  .m-cover { display: flex !important; flex-direction: column; justify-content: center; min-height: 92vh; break-after: page; }
}
.m-cover { display: none; }
.m-cover .brand-logo { width: 72px; height: 72px; font-size: 36px; border-radius: 22px; margin-bottom: 22px; box-shadow: none; }
.m-cover h1 { font-size: 34px; margin-bottom: 6px; }
.m-cover p { margin: 0 0 4px; color: var(--muted); font-size: 16px; }
.m-cover ol { margin-top: 26px; font-size: 15px; line-height: 2; }

/* ---------- Install as app ---------- */
.install-banner {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 12px 12px 12px 14px;
  border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); border: 1.5px solid #fde3b8;
}
.install-banner img { width: 44px; height: 44px; border-radius: 12px; }
.install-banner b { display: block; font-size: 15px; }
.install-banner small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.install-head { display: flex; align-items: center; gap: 14px; padding: 12px; margin-bottom: 14px; border-radius: 16px; background: var(--surface-2); }
.install-head img { width: 56px; height: 56px; border-radius: 15px; }
.install-head b { display: block; font-size: 17px; }
.install-head small { color: var(--muted); }
/* เปิดจากไอคอนบนหน้าจอโฮม: ไม่มีแถบเบราว์เซอร์ จึงใช้พื้นที่ notch ด้านบน */
html.standalone .topbar { background: rgba(243, 245, 250, .95); }
