/* เรือเจริญ Mobile UX refinement v189
   Presentation only: no formulas, permissions, or Firebase data paths. */

.mux-mobile-only { display: none; }
.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;
}
.mux-cost-tools {
  display: grid;
  grid-template-columns: minmax(220px,1fr) minmax(170px,auto);
  gap: 10px;
  margin: 0 0 14px;
}
.mux-cost-tools input,
.mux-cost-tools select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--ci-border);
  border-radius: 11px;
  background: var(--ci-surface-strong);
  color: var(--ci-dark);
  font: inherit;
}
.cost-card.mux-filtered { display: none !important; }

/* One permission list, with one comparison column per user. */
.uix-perm-matrix-wrap { min-width: 0; margin-top: 6px; }
.uix-perm-matrix-wrap.perm-saving { opacity: .55; pointer-events: none; }
.uix-perm-scroll-hint { display: none; }
.uix-perm-matrix-scroll {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--ci-border);
  border-radius: 14px;
  background: var(--ci-surface-strong);
  scrollbar-width: thin;
  scrollbar-color: var(--ci-border) transparent;
}
.uix-perm-matrix-scroll:focus-visible { outline: 3px solid color-mix(in srgb, var(--ci-gold) 45%, transparent); outline-offset: 2px; }
.uix-perm-matrix {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ci-dark);
}
.uix-perm-matrix th,
.uix-perm-matrix td {
  box-sizing: border-box;
  border: 0;
  border-right: 1px solid color-mix(in srgb, var(--ci-border) 65%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--ci-border) 65%, transparent);
}
.uix-perm-matrix tr > *:last-child { border-right: 0; }
.uix-perm-matrix tbody tr:last-child > * { border-bottom: 0; }
.uix-perm-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  min-width: 124px;
  height: 72px;
  padding: 10px;
  background: var(--ci-surface-accent);
  text-align: center;
  vertical-align: middle;
}
.uix-perm-matrix .uix-perm-name-head {
  left: 0;
  z-index: 4;
  width: 210px;
  min-width: 210px;
  padding-left: 14px;
  text-align: left;
}
.uix-perm-user-head .u-avatar {
  display: inline-flex;
  width: 32px;
  height: 32px;
  margin-right: 7px;
  vertical-align: middle;
}
.uix-perm-user-copy { display: inline-block; max-width: 100px; text-align: left; vertical-align: middle; }
.uix-perm-user-copy strong,
.uix-perm-user-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uix-perm-user-copy strong { font-size: 13px; }
.uix-perm-user-copy small { margin-top: 2px; color: color-mix(in srgb, var(--ci-dark) 55%, transparent); font-size: 10px; font-weight: 500; }
.uix-perm-matrix tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 210px;
  min-width: 210px;
  padding: 11px 14px;
  background: var(--ci-surface-strong);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
  text-align: left;
}
.uix-perm-matrix tbody tr:nth-child(even) th,
.uix-perm-matrix tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--ci-surface-accent) 45%, var(--ci-surface-strong)); }
.uix-perm-matrix td { min-width: 124px; height: 64px; padding: 6px 10px; text-align: center; vertical-align: middle; }
.uix-perm-matrix .uix-perm-control { justify-content: center; flex-direction: column-reverse; gap: 0; }
.uix-perm-matrix .uix-perm-control strong { width: auto; min-height: 14px; font-size: 10px; text-align: center; }
.uix-perm-matrix button.uix-perm-toggle { flex: 0 0 auto; }

@media (max-width: 736px) {
  .mux-mobile-only { display: inline-flex; }

  /* Keep the closing warning actionable without letting it take over the screen. */
  #close-reminder-banner {
    min-height: 56px;
    padding: 6px 8px 6px 12px !important;
    gap: 8px !important;
    align-items: center !important;
  }
  #close-reminder-text {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 12px;
    line-height: 1.35;
    cursor: pointer;
  }
  #close-reminder-banner.mux-expanded #close-reminder-text {
    display: block;
    overflow: visible;
    -webkit-line-clamp: initial;
  }
  #close-reminder-banner > div {
    gap: 4px !important;
  }
  #close-reminder-go,
  #close-reminder-dismiss {
    min-height: 44px !important;
    margin: 0 !important;
  }
  #close-reminder-go { padding-inline: 10px !important; white-space: nowrap; }
  #close-reminder-dismiss { width: 44px; padding: 0 !important; }

  /* The global warning already covers the same stale-close condition. */
  body.mux-has-close-reminder #view-stock #stock-carryover-banner { display: none !important; }

  /* The greeting already provides today's context, so avoid a duplicate hero. */
  #view-dashboard > .mapp-page-title { display: none !important; }
  #view-dashboard #dash-widgets-area { gap: 12px; }

  /* Finance: primary balances appear after a compact period selector. */
  #fin-export-bar { padding: 10px !important; gap: 8px !important; }
  #fin-export-bar .fin-bar-left { gap: 8px !important; }
  #fin-export-bar .fin-month-nav { margin-bottom: 0 !important; }
  #fin-mobile-actions-toggle {
    width: 100%;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--ci-border);
    border-radius: 11px;
    background: var(--ci-surface-strong);
    color: var(--ci-red);
    font-weight: 750;
  }
  #fin-mobile-actions-toggle::after { content: "›"; font-size: 19px; transform: rotate(90deg); transition: transform .15s ease; }
  #fin-mobile-actions-toggle[aria-expanded="true"]::after { transform: rotate(-90deg); }
  #fin-export-bar .fin-bar-right {
    display: none !important;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 8px !important;
    padding-top: 2px;
  }
  #fin-export-bar .fin-bar-right.is-open { display: grid !important; }
  #fin-export-bar .fin-bar-right > * { min-width: 0; width: 100%; }
  #fin-export-bar .fin-bar-right #fin-sync-slot { grid-column: 1 / -1; }
  #fin-export-bar .fin-bar-right #fin-sync-slot > * { width: 100%; }

  /* Stock: one clear date route, with only the active quick date retained. */
  #stock-date-nav {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 8px !important;
    justify-content: stretch !important;
    padding: 10px !important;
  }
  #stock-date-nav .sdn-label { grid-column: 1 / -1; }
  #stock-date-nav .sdn-chips { grid-column: 1 / -1; }
  #stock-date-nav .sdn-chip:not(.active):not(.today-chip) { display: none; }
  #stock-date-nav .sdn-chip { min-height: 38px; align-items: center; padding: 8px 12px; }
  #stock-date-nav .sdn-sep { display: none; }
  #stock-date-nav .sdn-date-input { min-width: 0; width: 100%; min-height: 44px; }
  #stock-date-nav .sdn-arrows { align-self: stretch; }
  #stock-date-nav .sdn-arr { width: 44px; height: 44px; }
  #stock-date-nav .sdn-current { grid-column: 1 / -1; margin-left: 0; white-space: normal; text-align: right; }

  /* Insights: reduce alarm fatigue and lead with the work that matters now. */
  .iai-toolbar { grid-template-columns: minmax(0,1fr) auto !important; align-items: end; }
  .iai-toolbar > div { grid-column: 1 / -1 !important; }
  .iai-toolbar label { min-width: 0; }
  .iai-toolbar select { min-width: 0 !important; }
  .iai-toolbar button { width: auto !important; min-width: 44px; padding-inline: 13px; }
  #iai-refresh,
  #fai-refresh { font-size: 0 !important; }
  #iai-refresh::before,
  #fai-refresh::before { content: "↻"; font-size: 21px; line-height: 1; }
  #iai-refresh::after,
  #fai-refresh::after { content: " อัปเดต"; font-size: 13px; }
  #iai-ai-priorities .iai-ai-priority:nth-child(n+4) { display: none; }
  .iai-level-card li:nth-child(n+4) { display: none; }
  #iai-list:not(.mux-show-normal) .iai-item-success,
  #iai-list:not(.mux-show-normal) .iai-item-muted { display: none; }
  #iai-normal-toggle {
    width: 100%;
    min-height: 44px;
    margin: 0 0 12px;
    border: 1px solid var(--ci-border);
    border-radius: 11px;
    background: var(--ci-surface-strong);
    color: var(--ci-red);
    font-weight: 750;
  }

  /* Sales: a skeleton communicates progress instead of a large empty card. */
  .mux-sales-loading {
    position: relative;
    min-height: 126px;
    overflow: hidden;
  }
  .mux-sales-loading::after {
    content: "";
    display: block;
    width: calc(100% - 30px);
    height: 48px;
    margin: 14px auto 0;
    border-radius: 10px;
    background: linear-gradient(90deg,var(--ci-surface-accent) 20%,var(--ci-surface-strong) 45%,var(--ci-surface-accent) 70%);
    background-size: 220% 100%;
    animation: muxShimmer 1.25s linear infinite;
  }

  /* User administration behaves like four focused screens on mobile. */
  .uix-users-nav { position: sticky; top: 0; z-index: 3; padding: 6px; border: 1px solid var(--ci-border); border-radius: 12px; background: var(--ci-surface); }
  .uix-users-nav button[aria-selected="true"] { border-color: var(--ci-red); background: var(--ci-red); color: #fff8ef; }
  #view-users.mux-users-tabs .mux-user-panel:not(.is-active) { display: none !important; }
  .uix-perm-scroll-hint { display: block; margin: 0 0 7px; color: color-mix(in srgb, var(--ci-dark) 58%, transparent); font-size: 12px; }
  .uix-perm-matrix-scroll { border-radius: 12px; scroll-snap-type: x proximity; }
  .uix-perm-matrix .uix-perm-name-head,
  .uix-perm-matrix tbody th { width: 148px; min-width: 148px; }
  .uix-perm-matrix thead th,
  .uix-perm-matrix td { min-width: 108px; scroll-snap-align: start; }
  .uix-perm-matrix thead th { height: 68px; padding: 8px; }
  .uix-perm-matrix tbody th { padding: 10px; font-size: 12px; }
  .uix-perm-matrix td { height: 62px; padding-inline: 6px; }
  .uix-perm-user-head .u-avatar { display: flex; width: 28px; height: 28px; margin: 0 auto 3px; }
  .uix-perm-user-copy { display: block; max-width: 92px; margin: auto; text-align: center; }
  .uix-perm-user-copy strong { font-size: 12px; }
  .uix-perm-user-copy small { font-size: 9px; }

  .mux-cost-tools { grid-template-columns: minmax(0,1fr); margin-top: 2px; }

  /* The reviewed controls should meet a dependable finger target. */
  .iai-filter,
  .log-filter-btn,
  .filter-btn,
  .uix-users-nav button { min-height: 44px; }
}

@media (max-width: 360px) {
  .mux-average-widget .metrics-grid { grid-template-columns: repeat(2,minmax(0,1fr)) !important; }
  .mux-average-widget .metrics-grid > .mc:first-child { grid-column: 1 / -1; }
  .mux-average-widget .mc { min-height: 116px; }
  #close-reminder-go { font-size: 12px !important; }
}

@keyframes muxShimmer { to { background-position: -220% 0; } }
@media (prefers-reduced-motion: reduce) { .mux-sales-loading::after { animation: none; } }
