/*
 * UsynAI mobile layout repair.
 * Loaded last so desktop styles and feature modules cannot collapse mobile grids.
 */

@media (max-width: 760px) {
  html,
  body.usynai-brand {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body.usynai-brand {
    overflow-wrap: normal;
  }

  body.usynai-brand :is(
    .app-shell,
    .app-main,
    .topbar,
    .topbar-copy,
    .dashboard,
    .dashboard-head,
    .dashboard-head > *,
    .dashboard-period-area,
    .overview-period-control,
    .store-row,
    .store-row > div,
    .metrics-grid,
    .analytics-grid,
    .panel,
    .nav-list
  ) {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Compact, stable mobile header. */
  body.usynai-brand .sidebar {
    height: 66px;
    min-height: 66px;
    padding: 10px 14px;
  }

  body.usynai-brand .brand {
    min-width: 0;
    min-height: 44px;
    gap: 10px;
  }

  body.usynai-brand .brand-mark {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 13px;
  }

  body.usynai-brand .brand strong {
    color: #fff;
    font-size: 17px;
    line-height: 1.1;
    white-space: nowrap;
  }

  body.usynai-brand .brand small {
    display: none;
  }

  body.usynai-brand .app-main {
    width: 100%;
    padding: 20px 14px calc(38px + var(--mobile-nav-height) + env(safe-area-inset-bottom));
  }

  /* Page title and connection status must never compete for one narrow row. */
  body.usynai-brand .topbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  body.usynai-brand .topbar-copy {
    width: 100%;
  }

  body.usynai-brand .topbar .eyebrow {
    margin-bottom: 6px;
    font-size: 11px;
    letter-spacing: .12em;
  }

  body.usynai-brand .topbar h1 {
    width: 100%;
    margin: 0;
    font-size: clamp(29px, 8.2vw, 36px);
    line-height: 1.06;
    overflow-wrap: normal;
    word-break: normal;
  }

  body.usynai-brand .page-subtitle {
    max-width: none;
    margin-top: 7px;
    font-size: 13px;
  }

  body.usynai-brand .connection-badge {
    align-self: flex-start;
    width: auto;
    max-width: 100%;
    min-height: 40px;
    padding: 9px 13px;
    overflow: visible;
    border-radius: 14px;
    font-size: 12px;
    line-height: 1.35;
    text-overflow: clip;
    white-space: normal;
  }

  /* Dashboard header is a vertical flow. The old two-column grid squeezed the store to one letter. */
  body.usynai-brand .dashboard {
    margin-top: 20px;
  }

  body.usynai-brand .dashboard-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    width: 100%;
    margin-bottom: 16px;
  }

  body.usynai-brand .dashboard-head > div:first-child {
    order: 1;
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow-sm);
  }

  body.usynai-brand .dashboard-period-area {
    order: 0;
    width: 100%;
  }

  body.usynai-brand #disconnect {
    order: 2;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    height: auto;
    padding: 11px 14px;
    font-size: 13px;
  }

  body.usynai-brand .store-row {
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
  }

  body.usynai-brand .store-logo {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 13px;
  }

  body.usynai-brand .store-row .eyebrow {
    margin: 0 0 3px;
    font-size: 11px;
    letter-spacing: .08em;
    overflow-wrap: normal;
    word-break: normal;
  }

  body.usynai-brand .store-row h2,
  body.usynai-brand #storeName {
    width: 100%;
    margin: 0;
    color: var(--ink);
    font-size: 20px;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
  }

  body.usynai-brand .dashboard-subline {
    width: 100%;
    margin: 10px 0 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px 8px;
    color: var(--ink-soft);
    font-size: 11px;
    line-height: 1.45;
    overflow-wrap: normal;
    word-break: normal;
  }

  /* Period picker: four clear presets plus a full-width custom period action. */
  body.usynai-brand .overview-period-control {
    width: 100%;
    padding: 14px;
    display: grid;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-sm);
  }

  body.usynai-brand .overview-period-label {
    display: block;
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 750;
    line-height: 1.3;
  }

  body.usynai-brand .overview-period-presets {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  body.usynai-brand .overview-period-presets button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 7px 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    color: var(--ink-soft);
    background: #f7f8fc;
    box-shadow: none;
    font-size: 12px;
    font-weight: 750;
    line-height: 1.2;
    white-space: nowrap;
  }

  body.usynai-brand .overview-period-presets button.active,
  body.usynai-brand .overview-period-presets button[aria-pressed="true"] {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    box-shadow: 0 8px 20px rgba(91, 61, 255, .24);
  }

  body.usynai-brand .overview-period-presets [data-period-custom] {
    grid-column: 1 / -1;
    min-height: 42px;
  }

  body.usynai-brand .overview-period-custom {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    padding-top: 2px;
  }

  body.usynai-brand .overview-period-custom[hidden] {
    display: none !important;
  }

  body.usynai-brand .overview-period-custom label {
    min-width: 0;
    display: grid;
    gap: 5px;
    color: var(--ink-soft);
    font-size: 11px;
    font-weight: 700;
  }

  body.usynai-brand .overview-period-custom input {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 0 10px;
    font-size: 16px;
  }

  body.usynai-brand .overview-period-apply {
    grid-column: 1 / -1;
    min-height: 46px;
    border: 0;
    border-radius: 11px;
    color: #fff;
    background: var(--primary);
    font-size: 13px;
    font-weight: 750;
  }

  body.usynai-brand .overview-period-cancel {
    position: absolute;
    width: 38px;
    height: 38px;
    min-height: 38px;
    right: 20px;
    margin-top: -49px;
    border: 0;
    border-radius: 10px;
    color: var(--ink-soft);
    background: #eef0f6;
  }

  body.usynai-brand .overview-period-message {
    min-height: 0;
    color: var(--ink-muted);
    font-size: 11px;
    line-height: 1.4;
  }

  /* Cards remain readable without forcing the whole page wider than the viewport. */
  body.usynai-brand .metrics-grid,
  body.usynai-brand .product-metrics,
  body.usynai-brand .profitability-metrics {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.usynai-brand .metric-card,
  body.usynai-brand .product-metric,
  body.usynai-brand .profitability-metric {
    min-width: 0;
  }

  body.usynai-brand .metric-card strong,
  body.usynai-brand .product-metric strong,
  body.usynai-brand .profitability-metric strong {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Bottom navigation is scrollable by design; items never shrink into unreadable labels. */
  body.usynai-brand .nav-list {
    justify-content: flex-start;
    gap: 4px;
    padding-inline: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
  }

  body.usynai-brand .nav-item {
    flex: 0 0 70px;
    width: 70px;
    min-width: 70px;
    max-width: 70px;
    min-height: 58px;
    scroll-snap-align: start;
  }

  body.usynai-brand .nav-item::after {
    width: 100%;
    font-size: 10px;
    line-height: 13px;
  }

  body.usynai-brand .nav-item em {
    max-width: 30px;
    font-size: 9px;
  }
}

@media (max-width: 380px) {
  body.usynai-brand .overview-period-presets {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.usynai-brand .metrics-grid,
  body.usynai-brand .product-metrics,
  body.usynai-brand .profitability-metrics {
    grid-template-columns: 1fr;
  }
}
