/* SIXTY SIP — UX refresh layer (Phase 0–4)
   Loaded after every existing stylesheet. Keeps the current information architecture,
   normalises the visual system, and adds accessibility/mobile safeguards. */

:root {
  --ux-primary: #c8102e;
  --ux-primary-hover: #a80f1f;
  --ux-primary-soft: rgba(200, 16, 46, 0.09);
  --ux-primary-border: rgba(200, 16, 46, 0.38);
  --ux-radius: 12px;
  --ux-control: 40px;
  --ux-touch: 44px;
  --ux-font: "Noto Sans Thai", "Sixty Thai", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --ux-primary: #e11d33;
  --ux-primary-hover: #f13a4e;
  --ux-primary-soft: rgba(225, 29, 51, 0.2);
  --ux-primary-border: rgba(241, 58, 78, 0.45);
}

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

html body,
html body button,
html body input,
html body select,
html body textarea,
html body .brand,
html body .nav,
html body .topbar {
  font-family: var(--ux-font) !important;
}

html body {
  font-size: 14px !important;
  line-height: 1.65 !important;
}

/* ---------- accessibility helpers ---------- */

.ux-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.ux-skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10000;
  transform: translateY(-220%);
  padding: 10px 14px;
  border: 1px solid var(--border-strong, #c5ccd6);
  border-radius: 8px;
  background: var(--bg-surface, #fff);
  color: var(--text, #14181f);
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
  text-decoration: none;
}
.ux-skip-link:focus { transform: translateY(0); }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus-ring, rgba(37, 99, 235, 0.45)) !important;
  outline-offset: 2px !important;
}

.ux-caps-hint {
  display: none;
  margin-top: 6px;
  color: var(--warning, #b45309);
  font-size: 12px;
  line-height: 1.5;
}
.ux-caps-hint.is-visible { display: block; }

/* ---------- shell: one sidebar / one topbar across departments ---------- */

body[class] .app-shell,
body.wh-ops:has(#app)[data-route][data-route][data-route] .app-shell {
  grid-template-columns: 260px minmax(0, 1fr) !important;
}

body[class] .sidebar,
body.ac-active .sidebar,
body.pd-active .sidebar,
body.aw-runtime .sidebar,
body.aw-superadmin .sidebar,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar {
  width: 260px !important;
  background: #ffffff !important;
  color: var(--text, #14181f) !important;
  border-right: 1px solid var(--border, #dfe3e9) !important;
  box-shadow: none !important;
}

html[data-theme="dark"] body[class] .sidebar,
html[data-theme="dark"] body.ac-active .sidebar,
html[data-theme="dark"] body.pd-active .sidebar,
html[data-theme="dark"] body.aw-runtime .sidebar,
html[data-theme="dark"] body.aw-superadmin .sidebar,
html[data-theme="dark"] body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar {
  background: #1c1613 !important;
  border-right-color: #38302a !important;
}

body[class] .sidebar .brand,
body[class] .sidebar .sidebar-foot,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .brand,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .sidebar-foot {
  border-color: var(--border, #dfe3e9) !important;
  background: transparent !important;
  color: var(--text, #14181f) !important;
}

body[class] .sidebar .brand strong,
body[class] .sidebar .brand span,
body[class] .sidebar .sidebar-foot,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .brand strong,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .brand span {
  color: var(--text, #14181f) !important;
}

body[class] .sidebar .nav-section-toggle,
body[class] .sidebar .nav-item,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .nav-section-toggle,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .nav-item {
  color: var(--text-muted, #5b6472) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  border-radius: 8px !important;
}

body[class] .sidebar .nav-item:hover,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .nav-item:hover {
  background: var(--bg-hover, rgba(15, 23, 42, 0.04)) !important;
  color: var(--text, #14181f) !important;
}

body[class] .sidebar .nav-item.active,
body[class] .sidebar .nav a.active,
body[class] .sidebar .nav a[aria-current="page"],
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .nav-item.active {
  background: var(--ux-primary-soft) !important;
  color: var(--ux-primary) !important;
  font-weight: 750 !important;
  box-shadow: inset 3px 0 0 var(--ux-primary) !important;
}

body[class] .sidebar .nav-item.active .ti,
body[class] .sidebar .nav a.active .ti,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .nav-item.active .ti {
  color: var(--ux-primary) !important;
}

body[class] .sidebar .nav-section-toggle,
body.wh-ops:has(#app)[data-route][data-route][data-route] .sidebar .nav-section-toggle {
  color: var(--text, #14181f) !important;
  font-weight: 750 !important;
}

body[class] .topbar,
body.ac-active .topbar,
body.pd-active .topbar,
body.aw-runtime .topbar,
body.aw-superadmin .topbar,
body.wh-ops:has(#app)[data-route][data-route][data-route] .topbar {
  background: color-mix(in srgb, var(--bg-surface, #fff) 92%, transparent) !important;
  border-bottom: 1px solid var(--border, #dfe3e9) !important;
  color: var(--text, #14181f) !important;
}

/* ---------- buttons / controls ---------- */

body[class] :is(button, a).primary-button:not(.success-button),
body.ac-active :is(button, a).primary-button:not(.success-button),
body.pd-active :is(button, a).primary-button:not(.success-button),
body.aw-runtime :is(button, a).primary-button:not(.success-button),
body.wh-ops:has(#app)[data-route][data-route][data-route] :is(button, a).primary-button:not(.success-button) {
  background: var(--ux-primary) !important;
  border-color: var(--ux-primary) !important;
  color: #fff !important;
}
body[class] :is(button, a).primary-button:not(.success-button):hover,
body.wh-ops:has(#app)[data-route][data-route][data-route] :is(button, a).primary-button:not(.success-button):hover {
  background: var(--ux-primary-hover) !important;
  border-color: var(--ux-primary-hover) !important;
}

body[class] :is(.primary-button, .ghost-button, .danger-button, .text-button, .row-action, .compact-button),
body.ac-active :is(.primary-button, .ghost-button, .danger-button, .row-action),
body.pd-active :is(.primary-button, .ghost-button, .danger-button),
body.aw-runtime :is(.primary-button, .ghost-button, .danger-button),
body.wh-ops:has(#app)[data-route][data-route][data-route] :is(.primary-button, .ghost-button, .danger-button, .row-action, .compact-button) {
  min-height: var(--ux-control);
  height: auto;
  border-radius: 8px !important;
  font-size: 14px !important;
  font-weight: 650 !important;
}

body[class] input,
body[class] select,
body[class] textarea,
body.ac-active input,
body.ac-active select,
body.ac-active textarea,
body.pd-active input,
body.pd-active select,
body.pd-active textarea,
body.wh-ops:has(#app)[data-route][data-route][data-route] input,
body.wh-ops:has(#app)[data-route][data-route][data-route] select,
body.wh-ops:has(#app)[data-route][data-route][data-route] textarea {
  min-height: var(--ux-touch);
  border-radius: 8px;
  font-size: 14px;
}

/* ---------- typography floor ---------- */

#app small,
#app .small,
#app .sub,
#app .meta,
#app .hint,
#app .caption,
#app .eyebrow,
#app .kpi-label,
#app .wh-kpi-label,
#app .ac-note,
#app .aw-updated,
#app .pd-block,
#app .ops-block-head p,
#app .panel-header p,
#app .content-heading p,
#app .card-head p {
  font-size: 12px !important;
  line-height: 1.55 !important;
}

#app :is(.badge, .ac-tag, .aw-tag, .flow-badge, .pd-badge, .ss-warehouse-status) {
  font-size: 12px !important;
}

#app :is(th, .ac-page th) {
  font-size: 12px !important;
}

#app :is(.num, .money, .amount, .code, [data-ux-num]) {
  font-variant-numeric: tabular-nums;
}

/* ---------- page headings / cards / KPI ---------- */

body[class] :is(.content-heading h2, .ops-page-head h2, .ac-heading h2, .aw-heading h2, .flow-heading h2, .pp-heading h2, .ri-heading h2, .pd-page .ac-heading h2) {
  font-size: clamp(24px, 2.2vw, 28px) !important;
  line-height: 1.35 !important;
  font-weight: 750 !important;
  letter-spacing: -0.01em;
}

body[class] :is(.panel, .card, .ops-table-card, .ac-panel, .aw-panel, .pd-panel, .pd-stat, .metric-card, .wh-kpi-card, .dashboard-live-kpi) {
  border: 1px solid var(--border, #dfe3e9) !important;
  border-radius: var(--ux-radius) !important;
  box-shadow: none !important;
  background: var(--bg-surface, #fff) !important;
}

body[class] :is(.metric-card strong, .wh-kpi-value, .ac-kpis strong, .aw-kpis strong, .pd-stat strong) {
  font-size: clamp(22px, 2vw, 26px) !important;
  font-variant-numeric: tabular-nums;
}

body[class] :is(.ac-kpis, .aw-kpis) {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) !important;
}

#app > .status-state-panel,
#app > .guidance-strip,
#app > .workflow-status-panel {
  margin-bottom: 16px;
}

/* quick in-page navigation for long workflow pages */
.ux-section-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 8px 10px;
  border: 1px solid var(--border, #dfe3e9);
  border-radius: 10px;
  background: var(--bg-surface, #fff);
  overflow-x: auto;
}
.ux-section-nav > span {
  color: var(--text-faint, #667085);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.ux-section-nav > div { display: flex; gap: 6px; flex-wrap: nowrap; }
.ux-section-nav button {
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--border, #dfe3e9);
  border-radius: 7px;
  background: var(--bg-elevated, #f7f8fa);
  color: var(--text-muted, #5b6472);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.ux-section-nav button:hover {
  border-color: var(--ux-primary-border);
  color: var(--ux-primary);
  background: var(--ux-primary-soft);
}

/* accounting purchase tabs */
.ux-purchase-tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--border, #dfe3e9);
  overflow-x: auto;
}
.ux-purchase-tabs button {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted, #5b6472);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.ux-purchase-tabs button[aria-selected="true"] {
  color: var(--ux-primary);
  border-bottom-color: var(--ux-primary);
}
.ux-purchase-tabs ~ .aw-panel[hidden] { display: none !important; }
@media (max-width: 760px) {
  .ux-purchase-tabs button { min-height: 44px; }
}

/* ---------- tables (the JS layer adds .ux-data-table + data-label) ---------- */

table.ux-data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

table.ux-data-table caption {
  text-align: left;
}

table.ux-data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 14px;
  background: var(--bg-elevated-2, #eef1f4) !important;
  color: var(--text-muted, #5b6472) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border, #dfe3e9) !important;
}

table.ux-data-table td {
  padding: 12px 14px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border, #dfe3e9) !important;
}

table.ux-data-table tbody tr:last-child td { border-bottom: 0 !important; }
table.ux-data-table tbody tr:hover td { background: var(--bg-hover, rgba(15, 23, 42, 0.03)); }

table.ux-data-table .ux-num,
table.ux-data-table .num,
table.ux-data-table .money {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

table.ux-data-table .ux-code,
table.ux-data-table .code,
table.ux-data-table [data-label="รหัส"],
table.ux-data-table [data-label="LOT"],
table.ux-data-table [data-label="วันที่"],
table.ux-data-table [data-label="หมดอายุ"],
table.ux-data-table [data-label="กำหนด"],
table.ux-data-table [data-label="ต้องใช้"],
table.ux-data-table [data-label="นัดรับ"] {
  white-space: nowrap;
}

/* ---------- banners / toast spacing ---------- */

#toast { right: 28px; bottom: 28px; }

/* ---------- login ---------- */

.login-card .login-copy h1 {
  margin: 0 0 6px;
  font-size: 26px;
  line-height: 1.3;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.login-card .login-help {
  margin: 16px 0 0;
  color: var(--text-muted, #5b6472);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}
.login-card .login-help a { color: var(--ux-primary); font-weight: 650; }
.login-form input { min-height: 44px !important; font-size: 14px; }
.login-form button[type="submit"] { min-height: 48px; font-size: 14px; }

.password-input-wrap { position: relative; display: flex; align-items: center; }
.password-input-wrap input { padding-right: 54px; width: 100%; }
.password-input-wrap .password-visibility-toggle {
  position: absolute;
  right: 4px;
  min-width: 46px;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted, #5b6472);
  font-size: 12px;
  font-weight: 650;
}

/* ---------- command palette ---------- */

.ux-palette {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  align-items: start;
  justify-items: center;
  padding: 12vh 20px 20px;
  background: rgba(10, 15, 23, 0.55);
  backdrop-filter: blur(3px);
}
.ux-palette[hidden] { display: none; }
.ux-palette-card {
  width: min(680px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border, #dfe3e9);
  border-radius: 14px;
  background: var(--bg-surface, #fff);
  box-shadow: 0 24px 70px rgba(16, 24, 40, 0.28);
}
.ux-palette-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #dfe3e9);
}
.ux-palette-input input {
  flex: 1;
  min-height: 36px !important;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 16px;
}
.ux-palette-input input:focus { outline: none; }
.ux-palette-results { overflow: auto; padding: 6px; }
.ux-palette-group {
  padding: 8px 10px 4px;
  color: var(--text-faint, #667085);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.ux-palette-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text, #14181f);
  text-align: left;
  cursor: pointer;
}
.ux-palette-item .ti { color: var(--text-muted, #5b6472); font-size: 18px; }
.ux-palette-item strong { display: block; font-size: 13px; font-weight: 650; }
.ux-palette-item small { display: block; color: var(--text-faint, #667085); font-size: 12px; }
.ux-palette-item[aria-selected="true"] { background: var(--ux-primary-soft); }
.ux-palette-item[aria-selected="true"] .ti { color: var(--ux-primary); }
.ux-palette-empty { padding: 28px 18px; text-align: center; color: var(--text-faint, #667085); font-size: 13px; }
.ux-palette-empty strong { display: block; color: var(--text, #14181f); font-size: 14px; margin-bottom: 4px; }
.ux-palette-foot {
  display: flex;
  gap: 14px;
  padding: 8px 14px;
  border-top: 1px solid var(--border, #dfe3e9);
  color: var(--text-faint, #667085);
  font-size: 11px;
}

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  html body { font-size: 14px !important; }
  #app :is(input, select, textarea) { font-size: 16px !important; }

  .content,
  #app {
    padding-left: 14px;
    padding-right: 14px;
  }

  body[class] .primary-button,
  body[class] .ghost-button,
  body[class] .danger-button,
  body[class] .row-action,
  body[class] .text-button,
  body[class] .nav-item,
  body[class] .nav-section-toggle,
  body[class] .icon-button,
  body[class] .avatar-button {
    min-height: var(--ux-touch) !important;
  }

  /* table -> card */
  table.ux-data-table,
  table.ux-data-table tbody,
  table.ux-data-table tr,
  table.ux-data-table td {
    display: block !important;
    width: 100% !important;
  }
  table.ux-data-table thead { display: none !important; }
  table.ux-data-table tr {
    margin: 10px 12px;
    padding: 12px;
    border: 1px solid var(--border, #dfe3e9);
    border-radius: 10px;
    background: var(--bg-surface, #fff);
  }
  table.ux-data-table td {
    display: grid !important;
    grid-template-columns: 108px minmax(0, 1fr);
    gap: 10px;
    padding: 5px 0 !important;
    border: 0 !important;
    font-size: 13px;
  }
  table.ux-data-table td::before {
    content: attr(data-label);
    color: var(--text-muted, #5b6472);
    font-size: 12px;
    font-weight: 650;
    line-height: 1.5;
  }
  table.ux-data-table td[data-label=""]::before,
  table.ux-data-table td:not([data-label])::before { display: none; }
  table.ux-data-table td.ux-actions,
  table.ux-data-table td:last-child:has(button),
  table.ux-data-table td:last-child:has(a.row-action) {
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 10px !important;
  }
  table.ux-data-table td.ux-actions::before,
  table.ux-data-table td:last-child:has(button)::before,
  table.ux-data-table td:last-child:has(a.row-action)::before { display: none; }
  table.ux-data-table td.ux-num,
  table.ux-data-table td.num { text-align: left; }

  .ux-palette { padding: 8vh 14px 14px; }
  #toast { right: 24px; bottom: 24px; }
}

@media (pointer: coarse) {
  body[class] :is(.primary-button, .ghost-button, .danger-button, .icon-button, .nav-item, .nav-section-toggle, .row-action, .text-button) {
    min-height: var(--ux-touch) !important;
  }
}

@media print {
  .ux-skip-link, .ux-palette, .ux-palette * { display: none !important; }
  table.ux-data-table,
  table.ux-data-table thead,
  table.ux-data-table tbody,
  table.ux-data-table tr,
  table.ux-data-table th,
  table.ux-data-table td { display: revert !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Critical shell overrides must live in the same cascade layer as the shared
   screen contract, otherwise layered !important rules win over unlayered ones. */
@layer ss-workspace {
  .app-shell > .sidebar {
    background: #ffffff !important;
    border-right: 1px solid #dfe3e9 !important;
    color: #14181f !important;
    box-shadow: none !important;
  }
  html[data-theme="dark"] .app-shell > .sidebar {
    background: #1c1613 !important;
    border-right-color: #38302a !important;
    color: #f3ede6 !important;
  }
  .app-shell > .sidebar .brand strong,
  .app-shell > .sidebar .brand span,
  .app-shell > .sidebar .sidebar-foot,
  .app-shell > .sidebar .nav-section-toggle,
  .app-shell > .sidebar .nav-item {
    color: #4a5563 !important;
  }
  html[data-theme="dark"] .app-shell > .sidebar .brand strong,
  html[data-theme="dark"] .app-shell > .sidebar .brand span,
  html[data-theme="dark"] .app-shell > .sidebar .sidebar-foot,
  html[data-theme="dark"] .app-shell > .sidebar .nav-section-toggle,
  html[data-theme="dark"] .app-shell > .sidebar .nav-item {
    color: #b7c0cb !important;
  }
  .app-shell > .sidebar .nav-item {
    transition: none !important;
  }
  .app-shell > .sidebar .nav-item.active,
  .app-shell > .sidebar .nav a.active,
  .app-shell > .sidebar .nav a[aria-current="page"] {
    background: rgba(200, 16, 46, 0.10) !important;
    color: #c8102e !important;
    box-shadow: inset 3px 0 0 #c8102e !important;
  }
  html[data-theme="dark"] .app-shell > .sidebar .nav-item.active,
  html[data-theme="dark"] .app-shell > .sidebar .nav a.active,
  html[data-theme="dark"] .app-shell > .sidebar .nav a[aria-current="page"] {
    background: rgba(225, 29, 51, 0.20) !important;
    color: #ff7a84 !important;
    box-shadow: inset 3px 0 0 #e11d33 !important;
  }
  .main > .topbar {
    background: #fffdfb !important;
    border-bottom: 1px solid #ece5dd !important;
  }
  html[data-theme="dark"] .main > .topbar {
    background: #211a15 !important;
    border-bottom-color: #38302a !important;
  }
  .primary-button:not(.success-button) {
    background: #c8102e !important;
    border-color: #c8102e !important;
    color: #ffffff !important;
    transition: none !important;
  }
  html[data-theme="dark"] .primary-button:not(.success-button) {
    background: #e11d33 !important;
    border-color: #e11d33 !important;
  }
}

@layer ss-workspace {
  body[class] .primary-button:not(.success-button),
  body[class] .ss-work-action.primary-button,
  body[class] .ac-page .primary-button:not(.success-button),
  body[class] .aw-page .primary-button:not(.success-button),
  body[class] .pd-page .primary-button:not(.success-button),
  body[class] .flow-page .primary-button:not(.success-button) {
    background: #c8102e !important;
    border-color: #c8102e !important;
    color: #ffffff !important;
    transition: none !important;
  }
  html[data-theme="dark"] body[class] .primary-button:not(.success-button),
  html[data-theme="dark"] body[class] .ss-work-action.primary-button,
  html[data-theme="dark"] body[class] .ac-page .primary-button:not(.success-button),
  html[data-theme="dark"] body[class] .aw-page .primary-button:not(.success-button),
  html[data-theme="dark"] body[class] .pd-page .primary-button:not(.success-button),
  html[data-theme="dark"] body[class] .flow-page .primary-button:not(.success-button) {
    background: #e11d33 !important;
    border-color: #e11d33 !important;
  }
}

@layer ss-workspace {
  #app .primary-button:not(.success-button),
  #app .ss-work-action.primary-button,
  dialog .primary-button:not(.success-button),
  .modal-backdrop .primary-button:not(.success-button) {
    background: #c8102e !important;
    border-color: #c8102e !important;
    color: #ffffff !important;
    transition: none !important;
  }
  html[data-theme="dark"] #app .primary-button:not(.success-button),
  html[data-theme="dark"] #app .ss-work-action.primary-button,
  html[data-theme="dark"] dialog .primary-button:not(.success-button),
  html[data-theme="dark"] .modal-backdrop .primary-button:not(.success-button) {
    background: #e11d33 !important;
    border-color: #e11d33 !important;
  }
}

@layer ss-workspace {
  #app #login-form input {
    min-height: 44px !important;
  }
}

/* custom confirmation dialog (CSP-safe: no inline styles) */
body.ux-confirm-open { overflow: hidden; }
.ux-confirm {
  position: fixed;
  inset: 0;
  z-index: 9600;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 15, 23, 0.55);
  backdrop-filter: blur(3px);
}
.ux-confirm-card {
  width: min(480px, 100%);
  overflow: hidden;
  border: 1px solid var(--border, #dfe3e9);
  border-radius: 14px;
  background: var(--bg-surface, #fff);
  color: var(--text, #14181f);
  box-shadow: 0 24px 70px rgba(16, 24, 40, 0.28);
}
.ux-confirm-card header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border, #dfe3e9);
}
.ux-confirm-card header h2 {
  margin: 0 0 4px;
  font-size: 18px;
  line-height: 1.4;
}
.ux-confirm-card header p {
  margin: 0;
  color: var(--text-muted, #5b6472);
  font-size: 12px;
}
.ux-confirm-card .ux-confirm-body {
  padding: 18px;
  font-size: 14px;
  line-height: 1.65;
}
.ux-confirm-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border, #dfe3e9);
  background: var(--bg-elevated, #f7f8fa);
}
@media (max-width: 760px) {
  .ux-confirm { padding: 16px; }
  .ux-confirm-card footer { flex-wrap: wrap; }
  .ux-confirm-card footer button { flex: 1 1 auto; }
}

/* generic bulk selection + CSV export for data tables */
.ux-bulk-check {
  width: 42px !important;
  min-width: 42px;
  padding-left: 10px !important;
  padding-right: 6px !important;
  text-align: center;
}
.ux-bulk-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: #c8102e;
}
.ux-bulkbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border, #dfe3e9);
  background: rgba(200, 16, 46, 0.07);
  color: var(--text, #14181f);
  font-size: 13px;
  flex-wrap: wrap;
}
.ux-bulkbar[hidden] { display: none; }
.ux-bulkbar strong { color: #a80f1f; font-weight: 700; }
.ux-bulkbar .spacer { flex: 1; }
.ux-bulkbar .compact-button { min-height: 32px; padding: 4px 10px; font-size: 12px; }
html[data-theme="dark"] .ux-bulkbar { background: rgba(225, 29, 51, 0.14); }
html[data-theme="dark"] .ux-bulkbar strong { color: #ff7a84; }
@media (max-width: 760px) {
  table.ux-data-table td.ux-bulk-check {
    display: flex !important;
    justify-content: flex-start;
    padding: 4px 0 8px !important;
  }
  table.ux-data-table td.ux-bulk-check::before { display: none; }
  .ux-bulkbar .compact-button { min-height: 44px; }
}

/* keep inline text links identifiable without relying on color alone */
#app a[href^="mailto:"] {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Mobile shell: the unified layout keeps a sidebar grid column even when the
   sidebar is off-canvas, which squeezed every page into a narrow strip. */
@media (max-width: 1180px) {
  html body:has(#app) .app-shell {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  html body:has(#app) .app-shell > .main {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  html body:has(#app) .app-shell > .main > .content,
  html body:has(#app) #app {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
}

@media (max-width: 600px) {
  .topbar {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }
  .topbar .topbar-actions {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    justify-content: flex-end !important;
    overflow: hidden !important;
  }
  #live-data-status {
    flex: 0 0 auto !important;
    max-width: 82px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Warehouse pages use a stronger legacy selector for the sidebar column. */
@media (max-width: 1180px) {
  html body.wh-ops:has(#app)[data-route][data-route][data-route] .app-shell {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  html body.wh-ops:has(#app)[data-route][data-route][data-route] .app-shell > .main {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
}

/* Legacy workspace tab strips duplicate the purchase tab bar and shrink into
   unreadable 44px buttons on phones. Keep the clear purchase tabs only. */
@media (max-width: 760px) {
  body[data-route="accounting-purchase"] .ws-panel-tabs {
    display: none !important;
  }

  /* Legacy tables force 620–660px min-widths inside scroll containers, which
     defeats the card layout and clips the right side on a 360–390px phone. */
  :is(#app, dialog) :is(.aw-table-scroll, .ac-table-scroll, .table-wrap, .ops-table-wrap) table.ux-data-table {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    display: block !important;
  }
  :is(#app, dialog) :is(.aw-table-scroll, .ac-table-scroll, .table-wrap, .ops-table-wrap):has(table.ux-data-table) {
    overflow: visible !important;
  }
}

/* CSP-safe utilities replacing inline style attributes */
.ux-flex-wrap{display:flex;flex-wrap:wrap;gap:16px}
.ux-ow-anywhere{overflow-wrap:anywhere}
.ux-display-contents{display:contents}
.ux-flex-between{display:flex;align-items:center;justify-content:space-between;gap:16px}
.aw-evidence-figure{margin:0;max-width:240px}
.aw-evidence-img{display:block;max-width:100%;height:140px;object-fit:contain}
.ac-avatar-row{display:flex;align-items:center;gap:16px;margin-bottom:16px}
.ac-avatar-img{width:96px;height:96px;object-fit:cover;border-radius:50%}
.ws-purchase-picker label.ux-span2{grid-column:1 / 3}
.map-pin.siam{left:62%;top:38%}
.map-pin.asok{left:48%;top:56%}
.map-pin.ari{left:35%;top:44%}
.map-pin.silom{left:68%;top:68%}
.bar-fill{display:block;width:0}

/* CSP-safe utilities replacing inline style attributes */
.ux-w70{width:70px}
.ux-w72{width:72px}
.ux-w80{width:80px}
.ux-w82{width:82px}
.ux-w105{width:105px}
.ux-w150{width:150px}
.ux-mb16{margin-bottom:16px}
.dash-bar-slot i{opacity:.85}
.dash-bar-slot i.is-hi{opacity:1}
[data-dash-color="safe"]{color:var(--safe)}
[data-dash-color="warning"]{color:var(--warning)}
[data-dash-color="danger"]{color:var(--danger)}
[data-dash-color="info"]{color:var(--info)}
[data-dash-color="accent"]{color:var(--accent)}
[data-dash-color="neutral"]{color:var(--text-faint)}
[data-dash-bg="safe"]{background:var(--safe)}
[data-dash-bg="warning"]{background:var(--warning)}
[data-dash-bg="danger"]{background:var(--danger)}
[data-dash-bg="info"]{background:var(--info)}
[data-dash-bg="accent"]{background:var(--accent)}
[data-dash-bg="neutral"]{background:var(--text-faint)}
[data-whkpi-border="safe"]{border-left-color:var(--safe)}
[data-whkpi-border="warning"]{border-left-color:var(--warning)}
[data-whkpi-border="danger"]{border-left-color:var(--danger)}
[data-whkpi-border="neutral"]{border-left-color:var(--text-faint)}
[data-whkpi-bg="safe"]{background:var(--safe-soft)}
[data-whkpi-bg="warning"]{background:var(--warning-soft)}
[data-whkpi-bg="danger"]{background:var(--danger-soft)}
[data-whkpi-bg="neutral"]{background:var(--bg-elevated-2)}
[data-whkpi-color="safe"]{color:var(--safe)}
[data-whkpi-color="warning"]{color:var(--warning)}
[data-whkpi-color="danger"]{color:var(--danger)}
[data-whkpi-color="neutral"]{color:var(--text-faint)}

/* Production label print sheet (moved from inline <style>; page size stays on
   the dedicated label print flow so other A4 prints are unaffected). */
#production-label-print-sheet{display:none}
@media print{
  body.production-label-print-active *{visibility:hidden!important}
  body.production-label-print-active #production-label-print-sheet,
  body.production-label-print-active #production-label-print-sheet *{visibility:visible!important}
  body.production-label-print-active #production-label-print-sheet{display:block!important;position:fixed;inset:0 auto auto 0;width:40mm}
  #production-label-print-sheet .production-label-copy{box-sizing:border-box;width:40mm;height:30mm;padding:2mm;overflow:hidden;display:flex;flex-direction:column;justify-content:space-between;break-after:page;page-break-after:always;font:8pt Arial,sans-serif;color:#000}
  #production-label-print-sheet .production-label-copy:last-child{break-after:auto;page-break-after:auto}
  #production-label-print-sheet strong{font-size:10pt}
  #production-label-print-sheet .production-label-code{font:bold 12pt monospace;letter-spacing:.4mm}
}
/* Phase 2.2 bulk action bars */
.seller-bulk-bar,.aw-bulk-bar{display:flex;flex-wrap:wrap;gap:12px;align-items:center;padding:10px 12px;border:1px solid var(--border-color,#e5e8ed);border-radius:10px;margin:0 0 12px;background:var(--surface-color,#fff)}
.seller-bulk-bar label,.aw-bulk-bar label{display:inline-flex;gap:8px;align-items:center;font-size:13px}
.seller-bulk-bar [data-bulk-seller-count],.aw-bulk-bar [data-bulk-approval-count]{font-size:13px;color:var(--text-muted,#667085)}
#seller-list-table th:first-child,#seller-list-table td:first-child{width:44px;text-align:center}
#seller-list-table td:first-child input{width:18px;height:18px}
.ux-check-target{display:inline-flex;align-items:center;justify-content:center;min-width:44px;min-height:44px;cursor:pointer}

/* Phase 0 closure: typography floor (no body text below 12px) */
#app small,
dialog small,
.modal-backdrop small { font-size: 12px !important; line-height: 1.5; }

/* Phase 1 — F3: module loading skeleton */
.module-loading-skeleton { display: grid; gap: 14px; padding: 18px 0 8px; }
.module-loading-bar,
.module-loading-line,
.module-loading-grid span {
  background: linear-gradient(90deg, var(--bg-elevated-2), var(--bg-elevated), var(--bg-elevated-2));
  background-size: 200% 100%;
  border-radius: 10px;
  animation: p0-skeleton 1.3s ease-in-out infinite;
}
.module-loading-bar { width: 220px; height: 18px; }
.module-loading-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.module-loading-grid span { height: 88px; border-radius: 14px; }
.module-loading-line { height: 12px; width: 100%; }
.module-loading-line.short { width: 62%; }
@keyframes p0-skeleton { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }
@media (prefers-reduced-motion: reduce) { .module-loading-bar, .module-loading-line, .module-loading-grid span { animation: none; } }
@media (max-width: 720px) { .module-loading-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Phase 1 — F3: dim stale content while the next route renders */
#app.is-route-loading > *:not(.module-loading-skeleton) { opacity: .45; filter: saturate(.7); }

/* Phase 1 — F4: per-page last-updated status (not a page-wide badge) */
.page-data-status { margin: 6px 0 0; color: var(--text-muted); font-size: 12px; font-weight: 600; }
.page-data-status[data-fresh="false"] { color: var(--warning); }

/* Phase 2 — F10: section tabs hide only their own panels */
.ux-workflow-tabs ~ [hidden] { display: none !important; }

/* CSP-safe toast cursor */
#toast.is-dismissible { cursor: pointer; }

/* CSP-safe live-data badge */
#live-data-status { padding: 6px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; }
#live-data-status[data-current="true"] { background: var(--success-soft); color: var(--success); }
#live-data-status[data-current="false"] { background: var(--warning-soft); color: var(--warning); }
