/* A viewport-sized workspace. Long content scrolls inside its own panel. */
@media (min-width: 701px) {
  body.app-page {
    --rail-width: 92px;
    height: 100vh;
    height: var(--workspace-height, 100dvh);
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app-page .sidebar {
    width: var(--rail-width);
    height: inherit;
    padding: 20px 8px 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .app-page .sidebar .brand {
    width: 100%;
    flex-shrink: 0;
  }

  .app-page .nav-caption,
  .app-page .nav-dot,
  .app-page .sidebar-note,
  .app-page .sidebar-account > .account-avatar,
  .app-page .sidebar-account > div {
    display: none;
  }

  .app-page .sidebar nav {
    margin-top: 26px;
    gap: 8px;
  }

  .app-page .nav-link {
    flex-direction: column;
    justify-content: center;
    gap: 7px;
    min-height: 68px;
    padding: 10px 3px;
    font-size: 11px;
    white-space: nowrap;
  }

  .app-page .sidebar-account {
    margin-top: auto;
    padding-top: 12px;
    justify-content: center;
  }

  .app-page .sidebar-account form {
    margin: 0;
  }

  .app-page .workspace {
    height: 100%;
    margin-left: var(--rail-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .app-page .topbar {
    height: 42px;
    min-height: 42px;
    padding: 0 20px;
    flex: 0 0 auto;
  }

  .app-page .main-content {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 16px 20px 20px;
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: contain;
  }

  .app-page .page-heading {
    flex: 0 0 auto;
    margin: 0;
    min-height: 48px;
  }

  .app-page .page-heading .eyebrow,
  .app-page .page-footer,
  .app-page .tip-card {
    display: none;
  }

  .app-page h1 { font-size: 24px; }
  .app-page h2 { font-size: 16px; }
  .app-page .subtitle { margin-top: 2px; font-size: 12px; }
  .app-page .today { display: inline; }

  .app-page .search-panel {
    position: relative;
    z-index: 5;
    flex: 0 0 auto;
    grid-template-columns: minmax(200px, .8fr) minmax(0, 1.2fr);
    padding: 12px 18px;
    gap: 18px;
    margin: 0;
  }

  .app-page .search-intro { gap: 10px; }
  .app-page .search-intro p { max-width: none; font-size: 11px; }
  .app-page .search-intro .soft-icon { width: 36px; height: 36px; }
  .app-page .search-input input { min-height: 44px; padding-top: 9px; padding-bottom: 9px; }
  .app-page #search-help { margin-top: 4px; font-size: 10px; }
  .app-page .search-results { top: 46px; max-height: min(330px, 45dvh); overscroll-behavior: contain; }
  .app-page .search-option { min-height: 48px; }

  .app-page .sales-layout,
  .app-page .users-layout {
    flex: 1 1 0;
    min-height: 0;
    gap: 14px;
    align-items: stretch;
  }

  .app-page .sales-layout {
    grid-template-columns: minmax(185px, .65fr) minmax(0, 2fr);
  }

  .app-page .sales-layout > div:first-child {
    display: block;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .app-page .payment-panels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    gap: 14px;
    min-height: 0;
    align-items: stretch;
  }

  .app-page .panel { padding: 18px; }
  .app-page .section-heading { margin-bottom: 14px; }
  .app-page .section-heading .soft-icon { width: 34px; height: 34px; }
  .app-page .section-heading .eyebrow { font-size: 8px; }
  .app-page .payment-panels > .panel {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .app-page .balance-block {
    padding: 13px 14px;
    gap: 2px;
    margin-bottom: 16px;
  }

  .app-page .balance-block strong { font-size: 29px; }
  .app-page .payment-panels > .panel { padding: 14px; }
  .app-page .payment-panels .section-heading { margin-bottom: 10px; }
  .app-page .payment-panels .balance-block { margin-bottom: 12px; }
  .app-page .balance-block { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .app-page .balance-block > span { grid-column: 1 / -1; }
  .app-page .balance-block > .text-link { position: static; margin: 0; min-height: 44px; align-self: end; }
  .app-page .balance-form label { margin-top: 13px; margin-bottom: 6px; }
  .app-page .balance-form legend { font-size: 12px; margin-bottom: 10px; }
  .app-page .package-options { gap: 6px; }
  .app-page .package-option { padding: 14px 6px 10px; gap: 5px; min-height: 62px; }
  .app-page .balance-form .package-option { margin: 0; }
  .app-page .package-option strong { font-size: 12px; }
  .app-page .package-option small { font-size: 9px; }
  .app-page .package-option input { width: 14px; height: 14px; flex-shrink: 0; }
  .app-page .button-row { margin-top: 14px; gap: 8px; }
  .app-page .button { min-height: 44px; padding: 10px 12px; }
  .app-page .icon-button { min-width: 44px; min-height: 44px; }
  .app-page input:not([type="radio"]):not([type="hidden"]) { min-height: 44px; font-size: 16px; }
  .app-page .customer-identity { gap: 10px; padding: 6px 0 16px; }
  .app-page .large-avatar { width: 44px; height: 44px; flex-shrink: 0; font-size: 19px; }
  .app-page .customer-identity h3 { font-size: 18px; overflow-wrap: anywhere; }
  .app-page .customer-details { padding-top: 16px; margin-bottom: 14px; gap: 12px; }
  .app-page .customer-details > div { flex-wrap: wrap; gap: 2px 8px; }
  .app-page .customer-details dd { overflow-wrap: anywhere; }
  .app-page .customer-card > .text-link { min-height: 44px; padding-top: 10px; }
  .app-page .customer-card .empty-state { padding: 18px 0; }
  .app-page .customer-card .empty-state p { font-size: 11px; }

  .app-page .users-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .app-page .profile-field { min-width: 0; }
  .app-page .profile-field label { margin-top: 12px; margin-bottom: 6px; }
  .app-page .form-link { min-height: 36px; margin-top: 10px; }

  .app-page .table-panel {
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  .app-page .main-content > .table-panel { flex: 1 1 0; }
  .app-page .table-panel > .section-heading { flex-shrink: 0; padding: 14px 18px 0; margin-bottom: 4px; }
  .app-page .table-description { flex-shrink: 0; padding: 0 18px 10px; }
  .app-page .table-scroll {
    min-height: 0;
    flex: 1 1 0;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }

  .app-page table { border-collapse: separate; border-spacing: 0; }
  .app-page th { position: sticky; top: 0; z-index: 1; padding: 10px; }
  .app-page td { padding: 8px 10px; height: 52px; }
  .app-page .table-person { min-height: 44px; gap: 7px; }
  .app-page .row-action { min-width: 44px; min-height: 44px; justify-content: center; }
  .app-page .table-bottom { flex-shrink: 0; padding: 8px 18px; }
  .app-page .table-panel > .empty-state { flex: 1 1 auto; overflow: auto; padding: 18px; }
  .app-page .table-panel:has(> .empty-state) .table-scroll { flex: 0 0 auto; }

  .app-page .history-layout {
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 14px;
    margin: 0;
  }

  .app-page .history-layout .panel { padding: 14px 18px; }
  .app-page .history-layout .customer-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 16px; }
  .app-page .history-layout .customer-card .section-heading { grid-column: 1 / -1; margin: 0; }
  .app-page .history-layout .customer-identity { padding: 0; }
  .app-page .history-layout .customer-details { padding: 0; margin: 0; border: 0; align-content: center; gap: 6px; }
  .app-page .history-layout .customer-card > .text-link { grid-column: 1 / -1; min-height: 30px; padding-top: 4px; }
  .app-page .history-layout .customer-card .eyebrow { display: none; }
  .app-page .history-layout .customer-card .empty-state { grid-column: 1 / -1; padding: 0; text-align: left; }
  .app-page .history-layout .empty-state .empty-icon { display: none; }
  .app-page .history-layout .empty-state p { margin-top: 3px; }
  .app-page .history-layout .empty-state br { display: none; }
  .app-page .history-summary { justify-content: center; }
  .app-page .history-summary > .eyebrow { margin-bottom: 3px; }
  .app-page .summary-number { font-size: 30px; margin: 2px 0; line-height: 1.3; }
  .app-page .history-summary > span { font-size: 11px; }
  .app-page .history-summary .text-link { min-height: 30px; margin-top: 3px; }

  .app-page .notice { flex: 0 0 auto; margin: 0; padding: 9px 14px; max-height: 80px; overflow: auto; }
  .app-page dialog {
    top: calc(var(--workspace-height, 100dvh) / 2);
    bottom: auto;
    margin: 0 auto;
    transform: translateY(-50%);
    max-height: calc(var(--workspace-height, 100dvh) - 32px);
    overflow: auto;
    overscroll-behavior: contain;
  }

  /* A software keyboard reduces the visual viewport, not always the CSS viewport. */
  .app-page.keyboard-open .page-heading { display: none; }
  .app-page.keyboard-open .main-content { overflow: auto; }
  .app-page.keyboard-open .sales-layout { flex: 0 0 470px; }
  .app-page.keyboard-open .users-layout { flex: 0 0 470px; }
  .app-page.keyboard-open .main-content > .table-panel { flex: 0 0 260px; }
}

/* Portrait iPad: customer summary on top, both balances visible side by side. */
@media (min-width: 701px) and (max-width: 999px) {
  body.app-page { --rail-width: 80px; }
  .app-page .main-content { padding: 14px; gap: 12px; }
  .app-page .sidebar { padding-inline: 5px; }
  .app-page .nav-link { font-size: 10px; }
  .app-page .today { display: none; }
  .app-page .search-panel { padding: 10px 14px; grid-template-columns: 190px minmax(0, 1fr); gap: 10px; }
  .app-page .search-intro > .soft-icon { display: none; }
  .app-page .search-intro p { font-size: 10px; }
  .app-page #search-help { font-size: 9px; }

  .app-page .sales-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
  .app-page .sales-layout > div:first-child { overflow: visible; }
  .app-page .sales-layout .customer-card { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; padding: 12px 16px; }
  .app-page .sales-layout .customer-card .section-heading { grid-column: 1 / -1; margin: 0; }
  .app-page .sales-layout .customer-card .eyebrow { display: none; }
  .app-page .sales-layout .customer-identity { padding: 0; }
  .app-page .sales-layout .customer-details { margin: 0; padding: 0; border: 0; gap: 3px; align-content: center; }
  .app-page .sales-layout .customer-card > .text-link { grid-column: 1 / -1; padding-top: 4px; min-height: 30px; }
  .app-page .sales-layout .customer-card .empty-state { grid-column: 1 / -1; padding: 2px 0; text-align: left; }
  .app-page .sales-layout .customer-card .empty-icon { display: none; }
  .app-page .sales-layout .customer-card .empty-state p { margin-top: 1px; }
  .app-page .sales-layout .customer-card .empty-state br { display: none; }
  .app-page .payment-panels { gap: 12px; }

  .app-page .users-layout .table-person .small-avatar { display: none; }
  .app-page .users-layout td,
  .app-page .users-layout th { padding-inline: 8px; }

  .app-page .history-layout { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .app-page .history-layout .customer-card { grid-template-columns: 1fr; gap: 5px; }
  .app-page .history-layout .customer-card .section-heading { display: none; }
  .app-page .history-layout .customer-details > div { flex-wrap: nowrap; }
  .app-page .history-layout .customer-card .large-avatar { width: 34px; height: 34px; }
}

/* Short windows (browser chrome, Split View, or zoom) retain reachable controls. */
@media (min-width: 701px) and (max-height: 620px) {
  .app-page .main-content { overflow: auto; }
  .app-page .page-heading { display: none; }
  .app-page .sales-layout { flex: 0 0 470px; }
  .app-page .users-layout { flex: 0 0 470px; }
  .app-page .main-content > .table-panel { flex: 0 0 260px; }
}

@media (pointer: coarse) {
  input:not([type="radio"]):not([type="hidden"]) { font-size: 16px; }
  .button, .icon-button, .row-action, .search-option { min-height: 44px; }
  .row-action, .icon-button { min-width: 44px; }
}

.transaction-date { white-space: nowrap; }
.transaction-date small { font-size: inherit; color: inherit; }
@media (min-width: 701px) and (max-width: 1100px) {
  .app-page .transaction-date time { display: flex; flex-direction: column; gap: 1px; }
  .app-page .transaction-date small { color: var(--muted); font-size: 10px; }
}


/* Keep navigation context and customer search in one compact toolbar. */
.app-page .workspace-toolbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 44px;
}

.app-page .workspace-toolbar h1 {
  font-size: 22px;
  white-space: nowrap;
  letter-spacing: -.8px;
  flex-shrink: 0;
}

.app-page .workspace-toolbar .customer-search {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 520px;
  margin-left: auto;
}

.app-page .workspace-toolbar .search-input input {
  min-height: 44px;
  padding: 10px 14px 10px 42px;
  background: #fff;
}

.app-page .workspace-toolbar .search-results {
  top: calc(100% + 6px);
}

.app-page .workspace-toolbar > .button {
  white-space: nowrap;
  flex-shrink: 0;
}

button.table-person {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

button.table-person:hover strong { color: var(--green); text-decoration: underline; }

#customer-dialog { width: min(440px, calc(100% - 32px)); }
#customer-form { display: block; }
#customer-form .profile-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
#customer-dialog .section-heading { margin-bottom: 8px; }
#customer-dialog-title:focus { outline: none; }

@media (min-width: 701px) {
  .app-page .main-content { padding-top: 14px; }
  .app-page .workspace-toolbar .search-results { max-height: min(400px, 60dvh); }
  .app-page .users-layout .table-panel { min-height: 0; }
}

@media (max-width: 700px) {
  .app-page .workspace-toolbar {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
  }
  .app-page .workspace-toolbar h1 { flex: 1 1 auto; font-size: 22px; }
  .app-page .workspace-toolbar .customer-search { order: 2; flex-basis: 100%; max-width: none; }
  .app-page .workspace-toolbar .mobile-signout { display: block; }
  .app-page .workspace-toolbar .button { min-height: 44px; }
  .app-page .users-layout { grid-template-columns: minmax(0, 1fr); }
}

/* Care counters stay with the selected customer; editing happens in a dialog. */
.care-panel { margin-top: 14px; }
.care-balance-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.care-balance-row strong { margin-left: auto; font-size: 22px; color: var(--green); font-variant-numeric: tabular-nums; }
.care-balance-row small { font-size: 11px; font-weight: 400; margin-left: 4px; }
.care-panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.care-panel .section-heading { margin-bottom: 8px; }
.care-panel .soft-icon { width: 30px; height: 30px; }
.care-panel .button { min-height: 44px; }
.care-overview { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.care-overview .care-panel { margin: 0; }
.care-reason { overflow-wrap: anywhere; max-width: 280px; }
.manual-points-link { background: none; border: 0; padding: 4px 0; min-height: 36px; margin-top: 8px; }
.mileage-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #faf2e5; padding: 4px; border-radius: 10px; }
.mileage-modes button { min-height: 44px; padding: 6px; border: 0; border-radius: 7px; background: transparent; color: #805518; font: inherit; font-size: 13px; font-weight: 700; }
.mileage-modes button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 4px #80551820; }
.mileage-input-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mileage-input-heading .text-link { border: 0; background: transparent; min-height: 44px; padding: 0; font-size: 12px; }
.mileage-preview { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; border-radius: 10px; background: #faf6ee; font-size: 12px; }
.mileage-preview strong { color: #956018; text-align: right; font-variant-numeric: tabular-nums; }
.mileage-history-note { max-width: 160px; white-space: normal; overflow-wrap: anywhere; }
.mileage-history-note small { display: block; color: var(--muted); font-size: 11px; }
#package-benefits { min-height: 38px; font-size: 11px; }
select { width: 100%; min-height: 44px; border: 1px solid #dfe5dd; border-radius: 9px; padding: 10px; color: var(--ink); background: white; font: inherit; }
@media (min-width: 701px) {
  .app-page .care-panel { padding: 14px; }
  .app-page .care-overview { flex: 0 0 auto; }
  .app-page .care-overview .customer-card { padding: 14px; }
  .app-page .care-overview .customer-details { margin-bottom: 8px; padding-top: 8px; }
  .app-page .care-overview .customer-identity { padding-bottom: 8px; }
  .app-page .sales-layout > div:first-child { overflow: auto; }
  .app-page .package-option input { width: 12px; height: 12px; }
  .app-page .package-option small { font-size: 9px; letter-spacing: -.4px; }
}
@media (min-width: 701px) and (max-width: 999px) {
  .app-page .sales-layout { grid-template-rows: auto minmax(0, 1fr); }
  .app-page .sales-layout > div:first-child { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; overflow: auto; max-height: 275px; }
  .app-page .sales-layout .care-panel { margin: 0; }
  .app-page .sales-layout .care-balance-row { padding-block: 2px; }
  .app-page .sales-layout .care-panel-actions { margin-top: 8px; }
  .app-page .sales-layout .customer-card { grid-template-columns: minmax(0, 1fr); }
  .app-page .sales-layout .customer-details { align-content: start; }
  .app-page .care-overview { max-height: 300px; overflow: auto; }
}
@media (max-width: 700px) {
  .sidebar nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .nav-link { font-size: 10px; }
  .care-overview { grid-template-columns: minmax(0, 1fr); margin-bottom: 16px; }
}

/* Membership tiers retain their own palette in every selection state. */
.app-page .package-option[data-package-tier] {
  --tier-ink: #414e60;
  --tier-muted: #59677a;
  --tier-border: #c5ced9;
  --tier-accent: #66768c;
  --tier-bg: linear-gradient(135deg, #fafbfc, #e8edf3);
  --tier-badge: #dce3ec;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 5px 6px;
  min-height: 82px;
  padding: 14px 9px 10px;
  border: 1px solid var(--tier-border);
  border-radius: 13px;
  background: var(--tier-bg);
  color: var(--tier-ink);
  box-shadow: 0 2px 4px #1f293706;
  transition: border-color .15s, box-shadow .15s;
}
.app-page .package-option[data-package-tier="gold"] {
  --tier-ink: #795010;
  --tier-muted: #886629;
  --tier-border: #dfc68f;
  --tier-accent: #a87520;
  --tier-bg: linear-gradient(135deg, #fffbef, #f5e5bb);
  --tier-badge: #efdaa6;
}
.app-page .package-option[data-package-tier="black"] {
  --tier-ink: #ffffff;
  --tier-muted: #d2d8e1;
  --tier-border: #424b59;
  --tier-accent: #a5b5ce;
  --tier-bg: linear-gradient(135deg, #3a4351, #1b222d);
  --tier-badge: #4a5669;
}
.app-page .package-option[data-package-tier] input { width: 14px; height: 14px; accent-color: var(--tier-accent); }
.app-page .package-option[data-package-tier] strong { font-size: 13px; color: var(--tier-ink); line-height: 1.3; }
.app-page .package-option[data-package-tier] small { grid-column: 1 / -1; font-size: 10px; color: var(--tier-muted); letter-spacing: -.2px; line-height: 1.5; }
.app-page .package-option[data-package-tier] small span,
.app-page .package-option[data-package-tier] small b { display: block; }
.app-page .package-option[data-package-tier] small b { color: var(--tier-ink); font-weight: 700; }
.app-page .package-option[data-package-tier] em { top: -8px; right: 8px; padding: 1px 7px; border: 1px solid var(--tier-border); border-radius: 20px; color: var(--tier-ink); background: var(--tier-badge); font-size: 9px; line-height: 1.5; }
.app-page .package-option[data-package-tier]:has(input:checked) { border-color: var(--tier-accent); box-shadow: 0 0 0 2px var(--tier-accent), 0 4px 8px #1f293714; }
.app-page .package-option[data-package-tier]:has(input:focus-visible) { outline: 3px solid #427db7; outline-offset: 4px; }
@media (hover: hover) {
  .app-page .package-option[data-package-tier]:not(:has(input:disabled)):hover { border-color: var(--tier-accent); box-shadow: 0 2px 8px #1f29371c; }
  .app-page .package-option[data-package-tier]:has(input:checked):hover { box-shadow: 0 0 0 2px var(--tier-accent), 0 4px 8px #1f293714; }
}
.app-page .package-option[data-package-tier]:has(input:disabled) { cursor: default; opacity: .6; }
