#app .brand-home {
  display: flex; align-items: center; gap: inherit; color: inherit;
  font: inherit; text-decoration: none; border-radius: 9px;
}
#app .brand-home:focus-visible { outline: 2px solid #214e44; outline-offset: 3px; }
.mobile-navigation-toggle { display: none; }
/* Mobile layouts reflow their content instead of clipping horizontal overflow. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* Invisible, absolutely positioned tooltips still enlarge WebKit's scroll area. */
.context-help > span { display: none; }
.context-help:is(:hover, :focus, :focus-visible) > span { display: block; }
@media (max-width: 1000px) {
  #app, #app > .workspace, #app > header, #app > nav { width: 100%; min-width: 0; }
  #app > .primary-nav { flex-wrap: wrap; overflow: visible; }
  #app > .primary-nav button { min-width: 0; white-space: normal; }
  #app .context-help > span { position: fixed; left: 12px; right: 12px; bottom: 20px; width: auto; max-width: none; transform: none; }
}

@media (max-width: 900px) {
  .login-shell { grid-template-columns: minmax(0, 1fr); width: 100%; }
  .login-shell > *, .login-card label { min-width: 0; }
  .login-story { padding: 1.25rem; }
  .login-story h1 { font-size: 2rem; overflow-wrap: anywhere; }
  .login-card { max-width: calc(100% - 2rem); }
  .login-card input { width: 100%; min-width: 0; font-size: 16px; }
}

@media (max-width: 760px) {
  #app :is(section, article, form, fieldset, div, label) { min-width: 0; }
  #app :is(p, li, dd, code, h1, h2, h3), dialog :is(p, li, code) { overflow-wrap: anywhere; }
  #app .table-wrap { max-width: 100%; overflow: visible; }
  #app .order-detail-scroll { max-height: none; min-height: 0; }
  #app .responsive-table { display: block; width: 100%; min-width: 0; table-layout: auto; }
  #app .responsive-table thead { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
  #app .responsive-table :is(tbody, tfoot) { display: block; position: static; }
  #app .responsive-table :is(tbody, tfoot) > tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .35rem .65rem; margin: .65rem 0; padding: .7rem;
    border: 1px solid #d8e5e1; border-radius: 12px; background: #fff;
  }
  #app .responsive-table :is(td, th[scope="row"]) {
    display: block; position: static; min-width: 0; width: auto;
    padding: .25rem 0; white-space: normal; overflow-wrap: anywhere;
    text-align: left; border: 0; font-size: .77rem;
  }
  #app .responsive-table [data-cell-label]::before {
    content: attr(data-cell-label); display: block; margin-bottom: .2rem;
    color: #607570; font-size: .65rem; font-weight: 650;
  }
  #app .responsive-table :is(th[scope="row"], .table-wide-cell) { grid-column: 1 / -1; }
  #app .responsive-table th[scope="row"]::before { display: none; }
  #app .order-detail-table tbody > tr > th[scope="row"] { order: -1; padding-bottom: .5rem; border-bottom: 1px solid #e1eae7; }
  #app .order-detail-table tbody > tr > td:last-child { grid-column: 1 / -1; }
  #app .order-detail-content { width: 100%; font-size: .76rem; }
  #app .order-detail-content dl { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #app .order-detail-table tfoot { box-shadow: none; }
  #app .order-detail-table tfoot > tr { background: #eaf3ef; }
  #app .pl-table tbody > tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #app .pl-table td { text-align: right; }
  #app .pl-table .pl-result-row { background: #eaf3ef; }
  #app .pl-table .pl-fee-family { padding-left: 1rem; }
  #app .pl-table .pl-fee-position { margin-left: .5rem; }
  #app .pl-table .pl-cost-basis { text-align: right; }
  #app .calculation-grid-head { display: none; }
  #app .calculation-row, #app .calculation-fee-group > summary { grid-template-columns: minmax(0, 1fr) auto; }
  #app .calculation-basis { grid-column: 1 / -1; }
  .upload-dialog, .connector-success-dialog, .metric-drill-dialog, dialog.settings-wizard {
    max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px);
  }
  dialog :is(input, select, textarea) { max-width: 100%; min-width: 0; }
  .upload-process-columns, .upload-download-columns { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 650px) {
  #app { font-size: .82rem; }
  #app > header {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto;
    min-height: 60px; gap: .5rem; padding: .6rem .75rem;
    align-items: center;
  }
  #app .mobile-navigation-toggle {
    display: grid; place-items: center; grid-column: 1;
    width: 40px; height: 40px; padding: 9px;
    background: transparent; color: #214e44; border-radius: 9px;
  }
  .mobile-navigation-toggle svg {
    width: 22px; height: 22px; fill: none; stroke: currentColor;
    stroke-width: 1.8; stroke-linecap: round;
  }
  #app > header > div.brand {
    position: absolute; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
    font-size: 0; gap: 0; margin: 0;
  }
  #app > header > .brand span { width: 32px; height: 32px; font-size: 1rem; }
  #app > header > div:has(#tenant-name) { display: none; }
  #app .header-account-actions { grid-column: 3; gap: .25rem; margin: 0 !important; }
  #app .header-account-actions :is(.header-settings, .header-refresh, summary) {
    width: 32px; height: 36px; min-width: 32px; min-height: 36px; padding: 6px !important;
  }
  #app .header-account-actions #refresh-orders { flex: 0 0 32px; width: 32px; order: 0; margin: 0; }
  #app .header-account-actions svg { width: 20px; height: 20px; }
  #notification-count { font-size: .6rem; padding: 2px; min-width: 17px; }
  #app > header:has(#company-logo:not([hidden])) { padding-bottom: 3.3rem; }
  #app > header > .header-company-logo { height: 2.1rem; bottom: .55rem; width: 70%; }
  #app > .primary-nav { display: none; }
  #app > .primary-nav.is-open {
    display: grid; grid-template-columns: minmax(0, 1fr);
    padding: .45rem .75rem; gap: .15rem; border-bottom: 1px solid #d8e5e1;
  }
  #app > .primary-nav button {
    justify-content: flex-start; width: 100%; min-height: 44px;
    padding: .65rem .75rem; font-size: .82rem; border-radius: 7px;
  }
  #app > .primary-nav .tab.active { background: #e4f0eb; border-bottom-color: #6c9d37; }
  #app .workspace { padding: .85rem .75rem; }
  #app .heading { gap: .65rem; margin-bottom: .85rem; }
  #app .heading h1 { font-size: 1.6rem; line-height: 1.15; }
  #app h2 { font-size: 1rem; }
  #app h3 { font-size: .9rem; }
  #app .heading p { font-size: .78rem; line-height: 1.45; }
  #app .heading small, #app .card > small { font-size: .65rem; }
  #app .card { padding: .85rem; border-radius: 13px; }
  #app :is(button, .button-link) { max-width: 100%; font-size: .76rem; padding: .65rem .75rem; white-space: normal; }
  /* 16px controls prevent Safari's focus zoom, which can leave a panned page. */
  #app :is(input, select, textarea), dialog :is(input, select, textarea), #login :is(input, select, textarea) { font-size: 16px; }
  .settings-wizard #tax-onboarding-form :is(select, input:not([type=checkbox])) { font-size: 16px; }
  #app :is(input, select, textarea) { min-width: 0; max-width: 100%; }
  #app select, dialog select { width: 100%; overflow: hidden; text-overflow: ellipsis; }
  #app .period { gap: .55rem; }
  #app .period > label { flex: 1 1 130px; min-width: 0; }
  #profit-view .dashboard-periods { gap: .45rem; margin-bottom: .8rem; }
  #profit-view .dashboard-period-card { min-height: 50px; padding: .5rem .65rem; gap: .15rem; }
  #profit-view .dashboard-period-card b { font-size: .73rem; }
  #profit-view .dashboard-kpi-row, #app .dashboard-chart-grid { gap: .6rem; }
  #profit-view .dashboard-kpi-row article { padding: .8rem; gap: .25rem .4rem; border-radius: 12px; }
  #profit-view .dashboard-kpi-label { min-height: 1.6rem; }
  #profit-view .dashboard-kpi-label small { font-size: .62rem; letter-spacing: .04em; }
  #profit-view .dashboard-kpi-row > article > strong { font-size: 1.3rem; min-height: 1.55rem; }
  #profit-view .dashboard-kpi-row > article > p { font-size: .68rem; }
  #app .comparison { font-size: .6rem; padding: .25rem .4rem; }
  #app .dashboard-shop-breakdown > .dashboard-shop-breakdown-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: .3rem .5rem; padding: .3rem 0;
  }
  #app .dashboard-shop-breakdown-row > span { justify-items: end; text-align: right; }
  #app .dashboard-run-rate { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #app .dashboard-chart-card { padding: .8rem; }
  #app .trend-chart { height: 125px; }
  #app .dashboard-shop-chart .dashboard-bar-row {
    grid-template-columns: minmax(55px, .75fr) minmax(0, 1fr) minmax(80px, 1fr); gap: .45rem;
  }
  #app .dashboard-shop-chart .dashboard-bar-row progress { grid-column: 2; grid-row: auto; width: 100%; }
  #app .dashboard-shop-chart .dashboard-bar-row > b { grid-column: 3; grid-row: auto; font-size: .7rem; }
  #app .profit-section-heading { align-items: flex-start; flex-wrap: wrap; }
  #app .order-table-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); flex-basis: auto; }
  #app .order-search-filter { grid-column: 1 / -1; }
  #app .order-table-filters label { min-width: 0; font-size: .65rem; }
  #app .order-filter-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
  #app .order-table-pagination { font-size: .7rem; gap: .5rem; align-items: stretch; }
  #app .order-table-pagination > div { justify-content: space-between; }
  #app .order-table-pagination > label { justify-content: space-between; }
  #app .order-table-pagination > span { text-align: right; }
  #app :is(.metrics, .snapshot-metrics) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #app .metric { padding: .7rem; }
  #app .metric b { font-size: 1.2rem; }
  #app .profit-channels, #app .guided-shop-cards, #app .customer-connection-list { grid-template-columns: minmax(0, 1fr); }
  #app .connector-setup-state { min-width: 0; }
  #app .settings-nav { gap: .2rem; margin-bottom: .8rem; }
  #app .settings-nav button { flex: 1 1 45%; min-width: 0; font-size: .72rem; padding: .6rem .4rem; }
  #app .notification-panel { top: 65px; max-height: calc(100dvh - 85px); }
  #app .context-help > span { position: fixed; left: 12px; right: 12px; bottom: 20px; width: auto; max-width: none; transform: none; }
  .upload-dialog-shell { padding: .85rem; gap: .85rem; }
  .upload-dialog-heading h2, .connector-success-dialog h2 { font-size: 1.1rem; }
  .upload-dialog-heading p, .upload-dialog p { font-size: .78rem; line-height: 1.5; }
}

@media (max-width: 380px) {
  #app .header-account-actions { gap: 2px; }
  #app .header-account-actions :is(.header-settings, .header-refresh, summary) {
    width: 30px; min-width: 30px;
  }
  #app .header-account-actions #refresh-orders { flex-basis: 30px; width: 30px; }
  #app .header-account-actions svg { width: 18px; height: 18px; }
}

/* Keep the header and the device's top inset in the same brand color. */
html:has(#app:not([hidden])), body:has(#app:not([hidden])) { background: #123b37; }
#app { background: #f3f7f5; min-height: 100dvh; }
#app > header {
  --header-top-padding: .7rem;
  position: sticky; top: 0; z-index: 100;
  background: #123b37; color: #f4faf7; border-bottom-color: #3d6258;
}
#app > header:not(:has(#company-logo:not([hidden]))),
#app > header:has(#company-logo:not([hidden])) {
  padding-top: calc(var(--header-top-padding) + env(safe-area-inset-top, 0px));
}
#app > header small { color: #c9dfd8; }
#app .header-account-actions > button,
#app .header-account-actions > details > summary {
  background: #204a43 !important; color: #f4faf7 !important;
  border: 1px solid #63837a !important; border-radius: 11px;
}
#app .header-account-actions > button:hover,
#app .header-account-actions > details > summary:hover { background: #2c5a50 !important; }
#app .header-account-actions svg { stroke: #f4faf7; }
#app .mobile-navigation-toggle { color: #f4faf7; }
#app .brand-home:focus-visible,
#app .mobile-navigation-toggle:focus-visible,
#app .header-account-actions > button:focus-visible,
#app .header-account-actions > details > summary:focus-visible {
  outline: 2px solid #d4f36b; outline-offset: 3px;
}
#app .notification-panel, #app .user-menu-panel { color: #17233a; }
@media (max-width: 650px) {
  #app > header { --header-top-padding: .6rem; }
}

@media (max-width: 650px) {
  #app > .primary-nav.is-open {
    position: fixed; top: var(--header-height, 61px); left: 0; right: 0; z-index: 90;
    max-height: calc(100dvh - var(--header-height, 61px)); overflow-y: auto;
    overscroll-behavior: contain; box-shadow: 0 8px 18px #123b3720;
  }
  #app .notification-panel {
    top: calc(var(--header-height, 61px) + 8px);
    max-height: calc(100dvh - var(--header-height, 61px) - 28px);
  }
}
