/* Member home: compact mobile layout using the existing brand and controls.
 * Shell rules are width-scoped; catalogue rules require explicit mobile mode.
 * Desktop mode and business logic stay unchanged.
 */
@media (max-width: 60rem) {
  body.member-authenticated .app-shell-home {
    --mobile-surface: var(--color-paper);
    --mobile-background: var(--color-paper-2);
    --mobile-ink: var(--color-ink);
    --mobile-muted: var(--color-muted);
    --mobile-rule: var(--color-rule);
    --mobile-accent: var(--color-green-deep);
    --mobile-on-accent: var(--color-accent-ink);
    --mobile-danger: var(--color-error);
    min-width: 0;
  }

  body.member-authenticated:not(.light-theme) .app-shell-home {
    --mobile-surface: var(--color-rail-2);
    --mobile-background: var(--color-rail);
    --mobile-ink: var(--color-rail-ink);
    --mobile-muted: var(--color-rule);
    --mobile-rule: var(--color-muted);
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-topbar {
    position: relative !important;
    top: auto !important;
    background: var(--mobile-surface) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-bottom: 1px solid var(--mobile-rule) !important;
    box-shadow: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-topbar__inner {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
    min-height: 0 !important;
    padding: 16px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-topbar__title {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline !important;
    gap: 2px 8px !important;
    width: 100%;
    text-align: start;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-eyebrow {
    grid-column: 1 / -1;
    color: var(--mobile-accent) !important;
    font-size: 10px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-topbar__title h1 {
    min-width: 0;
    margin: 0;
    font-size: 20px !important;
    line-height: 1.4 !important;
    color: var(--mobile-ink) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home #home-time {
    margin: 0 !important;
    font-size: 10px !important;
    color: var(--mobile-muted) !important;
    white-space: nowrap;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-topbar__actions {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    width: 100% !important;
    min-width: 0;
    overflow: visible !important;
    padding: 0 !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-utility-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px 44px;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-credit-card {
    grid-column: 1 / -1;
    display: flex !important;
    justify-content: flex-start;
    align-items: center;
    gap: 8px !important;
    min-width: 0;
    height: 44px;
    margin: 0 !important;
    padding: 0 12px !important;
    border: 1px solid var(--mobile-rule) !important;
    border-radius: 8px !important;
    background: var(--mobile-background) !important;
    box-shadow: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-credit-card__copy {
    display: flex;
    flex: 1;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    white-space: nowrap;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-credit-card__label {
    font-size: 12px !important;
    color: var(--mobile-muted) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home #member-header-credit {
    font-size: 16px !important;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--mobile-ink) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-credit-card__icon {
    display: inline-flex;
    color: var(--mobile-accent) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .layout-toggle-container {
    display: flex !important;
    align-items: center;
    gap: 4px;
    height: 44px;
    min-width: 0;
    padding: 3px !important;
    border: 1px solid var(--mobile-rule) !important;
    border-radius: 8px !important;
    background: var(--mobile-background) !important;
    box-shadow: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .layout-toggle-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    height: 36px;
    min-height: 36px !important;
    padding: 0 6px !important;
    border: 0 !important;
    border-radius: 5px !important;
    background: transparent !important;
    color: var(--mobile-muted) !important;
    font-size: 12px !important;
    white-space: nowrap;
    box-shadow: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .layout-toggle-btn.is-active {
    background: var(--mobile-accent) !important;
    color: var(--mobile-on-accent) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-action-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0 !important;
    border: 1px solid var(--mobile-rule) !important;
    border-radius: 8px !important;
    background: var(--mobile-surface) !important;
    color: var(--mobile-ink) !important;
    box-shadow: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-logout-button {
    color: var(--mobile-danger) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-pending-action {
    width: 100%;
    height: auto;
    min-height: 44px;
    padding: 8px 12px !important;
    background: var(--mobile-accent) !important;
    color: var(--mobile-on-accent) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-utility-group svg {
    width: 18px !important;
    height: 18px !important;
    flex: 0 0 auto;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.layout-toggle-btn, .home-action-button):focus-visible {
    outline: 2px solid var(--mobile-accent) !important;
    outline-offset: 2px;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.layout-toggle-btn, .home-action-button):disabled {
    opacity: 0.5 !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-tools,
  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-grid-wrap {
    width: 100% !important;
    min-width: 0;
    padding: 12px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.home-market-tabs, .home-market-chip-row) {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100%;
    min-width: 0;
    gap: 6px !important;
    margin: 0 !important;
    padding: 4px 0 10px !important;
    scrollbar-width: thin;
    border: 0 !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.home-market-tab, .home-market-chip) {
    flex: 0 0 auto;
    min-height: 40px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-tools__main {
    padding: 12px !important;
    border: 1px solid var(--mobile-rule) !important;
    border-radius: 10px !important;
    background: var(--mobile-surface) !important;
    box-shadow: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-tools__heading {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-tools__heading h2 {
    margin: 0 !important;
    font-size: 14px !important;
    color: var(--mobile-ink) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-tools__actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    background: transparent !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.home-market-search, .home-market-sort) {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 44px !important;
    min-height: 44px !important;
    font-size: 13px !important;
    border-radius: 6px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-search {
    font-size: 16px !important; /* Prevent iOS focus zoom. */
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-chip-row {
    margin-top: 10px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .home-market-summary {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0 !important;
    margin: 0 !important;
    border: 1px solid var(--mobile-rule) !important;
    border-radius: 8px !important;
    overflow: hidden;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .summary-card {
    min-width: 0;
    min-height: 64px !important;
    padding: 8px 12px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: var(--mobile-background) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .summary-card:nth-child(odd) {
    border-right: 1px solid var(--mobile-rule) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .summary-card:nth-child(-n+2) {
    border-bottom: 1px solid var(--mobile-rule) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .summary-card span {
    font-size: 11px !important;
    color: var(--mobile-muted) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .summary-card strong {
    font-size: 20px !important;
    color: var(--mobile-ink) !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-group {
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-group__header {
    padding: 4px 0 10px !important;
    margin: 0 !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-group__title {
    font-size: 16px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .group-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card {
    min-width: 0;
    min-height: 0 !important;
    border-radius: 10px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card__top {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    min-height: 68px !important;
    padding: 12px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.stock-card__flag-wrap, .stock-card__flag) {
    width: 32px !important;
    height: 24px !important;
    flex: 0 0 auto;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card__identity {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 4px 8px;
    width: 100%;
    min-width: 0;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card h3 {
    grid-column: 1;
    font-size: 14px !important;
    line-height: 1.5 !important;
    overflow-wrap: anywhere;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card__draw-date {
    grid-column: 1;
    grid-row: 2;
    font-size: 11px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card__draw-time {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
    font-size: 11px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.stock-card__glow, .stock-card__status-row) {
    display: none !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card__bottom {
    display: grid !important;
    align-items: stretch !important;
    justify-items: stretch !important;
    margin: 0 12px !important;
    padding: 8px 0 10px !important;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home .stock-card__detail-row {
    display: flex !important;
    width: 100%;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
  }

  html body.member-authenticated:is(.light-theme, .mode-mobile, .mode-desktop) .app-shell-home :is(.stock-card__detail-label, .stock-card__detail-value, .stock-card__status-value, .stock-card__timer-value) {
    font-size: 11px !important;
    line-height: 1.7 !important;
    white-space: nowrap;
  }
}

/* The user can select mobile mode even on a wide screen. These overrides must
 * never match mode-desktop. Dates and names wrap instead of losing information. */
html body.member-authenticated.mode-mobile .app-shell-home {
  --mobile-card-surface: #222c35;
  --mobile-card-ink: #f1f5f9;
  --mobile-card-rule: #465360;
}

html body.light-theme.member-authenticated.mode-mobile .app-shell-home {
  --mobile-card-surface: #ffffff;
  --mobile-card-ink: #17212b;
  --mobile-card-rule: #dfe6e3;
}

html body.member-authenticated.mode-mobile .app-shell-home .group-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 8px !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card {
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 9px 8px !important;
  border: 1px solid var(--mobile-card-rule) !important;
  border-radius: 8px !important;
  background: var(--mobile-card-surface) !important;
  color: var(--mobile-card-ink) !important;
  box-shadow: 0 2px 10px rgba(19, 37, 31, 0.06) !important;
  filter: none !important;
  opacity: 1 !important;
  transform: none !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card-open {
  border-color: #159447 !important;
  background: linear-gradient(135deg, #159447 0%, #087637 100%) !important;
  color: #ffffff !important;
}

html body.member-authenticated.mode-mobile .app-shell-home :is(.stock-card__glow, .stock-card__status-row) {
  display: none !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card__top {
  display: grid !important;
  grid-template-columns: 22px minmax(0, 1fr) !important;
  align-items: start !important;
  align-content: start !important;
  gap: 4px !important;
  min-height: 90px !important;
  padding: 0 0 10px !important;
}

html body.member-authenticated.mode-mobile .app-shell-home :is(.stock-card__flag-wrap, .stock-card__flag) {
  width: 22px !important;
  height: 16px !important;
  display: block !important;
  object-fit: cover !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 2px !important;
  background: transparent !important;
  box-shadow: none !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card__identity {
  display: contents !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card h3 {
  grid-column: 2 !important;
  grid-row: 1 !important;
  display: block !important;
  min-width: 0 !important;
  min-height: 36px !important;
  margin: 0 !important;
  color: inherit !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  line-height: 1.5 !important;
  white-space: normal !important;
  overflow-wrap: anywhere;
  -webkit-line-clamp: unset !important;
}

html body.member-authenticated.mode-mobile .app-shell-home :is(.stock-card__draw-date, .stock-card__draw-time) {
  grid-column: 1 / -1 !important;
  grid-row: auto !important;
  color: inherit !important;
  font-family: "Outfit", "Noto Sans Thai", sans-serif !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  line-height: 1.35 !important;
  white-space: nowrap !important;
  text-align: start !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card__bottom {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 6px !important;
  margin: auto 0 0 !important;
  padding: 8px 0 0 !important;
  border-top: 1px solid var(--mobile-card-rule) !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card-open .stock-card__bottom {
  border-top-color: rgba(255, 255, 255, 0.42) !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card__detail-row {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 1px !important;
  min-width: 0 !important;
}

html body.member-authenticated.mode-mobile .app-shell-home :is(.stock-card__detail-label, .stock-card__detail-value, .stock-card__status-value, .stock-card__status-prefix, .stock-card__timer-value) {
  min-width: 0 !important;
  color: inherit !important;
  font-family: "Outfit", "Noto Sans Thai", sans-serif !important;
  font-size: 11px !important;
  line-height: 1.45 !important;
  white-space: normal !important;
  text-align: start !important;
}

html body.member-authenticated.mode-mobile .app-shell-home :is(.stock-card__detail-label, .stock-card__status-prefix) {
  font-weight: 400 !important;
  opacity: 0.85 !important;
}

html body.member-authenticated.mode-mobile .app-shell-home .stock-card__status-value {
  display: flex !important;
  flex-wrap: wrap !important;
  column-gap: 3px !important;
}

/* Tablet / wide mobile mode: horizontal details like the desktop reference. */
@media (min-width: 40rem) {
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card {
    padding: 12px !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card__top {
    grid-template-columns: 28px minmax(0, 1fr) auto !important;
    column-gap: 6px !important;
    min-height: 70px !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home :is(.stock-card__flag-wrap, .stock-card__flag) {
    width: 28px !important;
    height: 20px !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card h3 {
    min-height: 0 !important;
    font-size: 13px !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card__draw-date {
    grid-column: 2 / -1 !important;
    grid-row: 2 !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card__draw-time {
    grid-column: 3 !important;
    grid-row: 1 !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card__detail-row {
    grid-template-columns: auto minmax(0, 1fr) !important;
    gap: 4px !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card__detail-value {
    text-align: end !important;
  }
  html body.member-authenticated.mode-mobile .app-shell-home .stock-card__status-value {
    justify-content: flex-end !important;
  }
}
