/* Shared workspace layouts. Patient display and calibrated optotypes use their
   own documents and retain their existing dimensions. */
.main-pad,
.main-pad > *,
:where(.row, .actions, .action-row, .form, .form-two, .filter-grid,
       .sales-filters, .sales-status-form, .staff-calendar-toolbar,
       .schedule-layout, .selected-calendar-day, .pattern-overview,
       .vacation-overview, .location-grid, .location-facts,
       .optometry-search, .optometry-fields) > * {
  min-width: 0;
}

.main-pad > *,
.main-pad :where(fieldset, input, select, textarea, .btn, .link-btn) {
  max-width: 100%;
}

.main-pad fieldset { min-width: 0; }
.main-pad :where(input, select, textarea) { min-width: 0; }
.main-pad :where(p, h1, h2, h3, legend, .flash) { overflow-wrap: anywhere; }
.main-pad .btn,
.main-pad .link-btn {
  min-height: 44px;
  padding-block: 10px;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
}

.form-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sales-filters { grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); }
.sales-summary { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.sales-due-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.sale-detail-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }

.schedule-head,
.history-head {
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
}
.schedule-head > div:first-child,
.history-head > div:first-child { flex: 1 1 360px; min-width: 0; }
.schedule-head > :where(.actions, .action-row, .staff-calendar-actions) {
  flex: 0 1 auto;
  justify-content: flex-end;
  max-width: 100%;
}
.schedule-head h1,
.history-head h1 { font-size: clamp(28px, 3.2vw, 42px); line-height: 1.12; }
.schedule-head p,
.history-head p { margin-bottom: 0; line-height: 1.55; }

/* Large data views scroll within their panel, never the whole workspace. */
.table-scroll,
.sales-table-wrap,
.users-table-wrap,
.staff-month-card,
.doctor-tabs,
.optometry-tabs {
  min-width: 0;
  max-width: 100%;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table-scroll,
.sales-table-wrap,
.users-table-wrap { scrollbar-width: thin; }
.card:has(> .table) { max-width: 100%; overflow-x: auto; }
.card > .table { min-width: 560px; }
.table :where(th, td) { overflow-wrap: normal; word-break: normal; }
.sales-table-wrap > .table { width: max-content; min-width: 100%; table-layout: auto; }
.sales-table-wrap > .table > thead th,
.sales-table-wrap > .table > thead button,
.sales-table-wrap > .table > tbody > tr:not(.sale-detail-row) > td { white-space: nowrap; }
.staff-month-card { overflow-x: auto; }
.staff-month-card .staff-calendar { min-width: 820px; }
.staff-calendar-filter,
.staff-calendar-filter label,
.month-switcher { min-width: 0; max-width: 100%; }
.month-switcher { grid-template-columns: 44px minmax(0, 1fr) 44px; }
.month-arrow { width: 44px; height: 44px; }
.employee-color-tag { max-width: 100%; overflow-wrap: anywhere; }
.selected-shift-list article :where(strong, span),
.vacation-list article :where(strong, span) { overflow-wrap: anywhere; }

/* Editors stay inside the visible screen, including short laptop windows. */
.main-pad .action-popover[open] { z-index: 100; }
.main-pad .action-popover > .popover-form {
  position: fixed;
  inset: 84px 16px auto;
  width: min(420px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
  margin: 0 auto;
  overflow: auto;
  overscroll-behavior: contain;
  z-index: 101;
}

/* Keep the complete section list available at laptop and tablet widths. */
.topbar .container { min-width: 0; }
.topbar .nav { min-width: 0; max-width: 100%; flex-wrap: wrap; }
.nav-user { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-settings-menu { max-height: min(70vh, 650px); overflow-y: auto; }
@media (min-width: 1440px) {
  .topbar .container { width: min(1480px, calc(100% - 48px)); }
  .topbar .nav { flex-wrap: wrap; justify-content: flex-end; }
}
@media (max-width: 1439px) {
  .topbar .brand { flex: 1; min-width: 0; font-size: 17px; }
  .nav-ready .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid #d9dde4;
    border-radius: 10px;
    background: #f5f6f8;
    color: #333d49;
    font: 600 13px/1.3 Inter, Arial, sans-serif;
    cursor: pointer;
  }
  .nav-ready .topbar .nav { display: none; width: 100%; margin: 4px 0 0; }
  .nav-ready .topbar .nav.nav-open {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    max-height: calc(100dvh - 92px);
    overflow-y: auto;
  }
  .nav-ready .topbar .nav > a,
  .nav-ready .nav-settings summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 9px;
    background: #f5f6f8;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 13px;
    line-height: 1.4;
  }
  .nav-ready .topbar .nav-user { display: none; }
  .nav-ready .nav-settings { min-width: 0; }
  .nav-ready .nav-settings[open] { grid-column: 1 / -1; }
  .nav-ready .nav-settings-menu {
    position: static;
    width: 100%;
    max-height: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 6px 0 0;
    border: 0;
    background: none;
    box-shadow: none;
  }
  .nav-ready .nav-settings-menu a {
    min-height: 44px;
    display: flex;
    align-items: center;
    border: 1px solid #e2e5ea;
    white-space: normal;
  }
}

@media (max-width: 1100px) {
  .sales-status-form { grid-template-columns: minmax(0, 2fr) minmax(70px, 1fr) minmax(80px, 1fr); }
  .staff-calendar-actions { flex-wrap: wrap; }
  .staff-calendar-actions > * { min-width: 0; }
}

@media (max-width: 760px) {
  .container { width: calc(100% - 24px); }
  .main-pad { padding: 20px 0 32px; }
  .card { padding: 18px; border-radius: 16px; margin-bottom: 14px; }
  .card :where(h1, h2, h3) { line-height: 1.2; }
  .card h1 { font-size: 28px; }
  .card h2 { font-size: 22px; }
  .main-pad .muted { line-height: 1.55; }
  .schedule-head,
  .history-head { margin: 4px 0 20px; gap: 14px; }
  .schedule-head > div:first-child,
  .history-head > div:first-child { flex: none; }
  .schedule-head > :where(.actions, .action-row, .staff-calendar-actions) {
    width: 100%;
    justify-content: flex-start;
  }
  .actions,
  .action-row { max-width: 100%; gap: 8px; }
  .actions > :where(.btn, .link-btn),
  .action-row > :where(.btn, .link-btn) { flex: 1 1 140px; }
  .staff-calendar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .staff-calendar-actions .action-popover:last-child { grid-column: 1 / -1; }
  .staff-calendar-toolbar { gap: 14px; padding: 16px; }
  .staff-month-card { padding: 0; }
  .month-switcher { width: min(100%, 310px); }
  .month-switcher strong { font-size: 16px; }
  .calendar-legend { gap: 8px 12px; line-height: 1.5; }
  .location-access { padding: 14px; }
  .main-pad :where(input, select, textarea) { font-size: 16px; }
  .main-pad :where(input[type="checkbox"], input[type="radio"]) { flex-shrink: 0; }
  .sales-status-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sales-status-form > label:first-of-type { grid-column: 1 / -1; }
  .sales-status-form > button { grid-column: 1 / -1; }
  /* Reports and payment forms have no alternate card view: keep them visible. */
  .sales-table-wrap:not(:has(+ .sales-mobile-list)) { display: block; }
  .sales-table-wrap:not(:has(+ .sales-mobile-list)) .table { min-width: 640px; }
  .calibration-badge { white-space: normal; line-height: 1.4; }
  .popover-form,
  .staff-calendar-actions .popover-form,
  .pattern-edit-form { max-height: calc(100dvh - 28px); }
}

@media (max-width: 600px) {
  .nav-ready .topbar .nav.nav-open { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-ready .nav-settings-menu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-two { grid-template-columns: 1fr; }
  .schedule-kicker { font-size: 11px; letter-spacing: .1em; }
  .sales-filters { grid-template-columns: 1fr; }
  .sale-ledger-tabs { gap: 4px; }
  .sale-ledger-tabs a { gap: 5px; padding: 8px; font-size: 13px; line-height: 1.35; text-align: center; }
  .sale-ledger-tabs span { flex: 0 0 auto; }
}

@media (max-width: 360px) {
  .container { width: calc(100% - 20px); }
  .card { padding: 14px; }
  .topbar .brand { font-size: 15px; }
  .nav-ready .nav-settings-menu { grid-template-columns: 1fr; }
  .sales-summary { grid-template-columns: 1fr; }
}
