/* Shared narrow-screen safeguards for every application module. */
@media (max-width: 899px) {
  /* Leave a dedicated right-side slot for the global theme control. */
  .topbar .avatar { flex:0 0 44px; margin-right:52px; }
  .quotation-form { grid-template-columns:1fr !important; }
  .quotation-form > * { grid-column:1 / -1 !important; min-width:0; }
  .quotation-form > .customer-details { display:grid !important; grid-template-columns:1fr !important; gap:13px; }
  .customer-details .customer-name, .customer-document-fields, .customer-document-fields h3 { grid-column:1 / -1 !important; }
  .customer-document-fields { grid-template-columns:1fr !important; }
  .customer-document-fields label:has(textarea) { grid-column:auto !important; }
  .sales-type-panel { display:grid; gap:14px; }
  .tax-choice { width:100%; }
  .tax-mode-button { flex:1; }
  .line-items .pricing-panel { grid-template-columns:1fr !important; gap:16px; padding:17px; }
  .pricing-panel .field-label { max-width:none; }
  .sales-hero { min-height:auto; padding:26px 24px; align-items:flex-start; }
  .sales-hero-cta { position:static; width:100%; margin-top:22px; }
  .sales-document-grid { grid-template-columns:1fr; }
}

@media (max-width: 620px) {
  html, body { max-width:100%; overflow-x:hidden; }
  .app-shell { width:100%; padding:18px 14px 102px; }
  .topbar, .page-header, .section-head { align-items:flex-start; }
  .topbar { flex-wrap:wrap; }
  .topbar > *, .page-header > *, .section-head > *, .transaction > *, .sales-card > *, .sales-document-card > *, .labour-card > *, .company-hero > * { min-width:0; }
  input, select, textarea, button { max-width:100%; }
  .primary-btn, .secondary-btn, .danger-btn { min-width:0; }
  .filter-card div, .accounting-actions { flex-wrap:wrap; }
  .form-actions, .detail-grid { grid-template-columns:1fr; }
  .form-actions .primary-btn, .form-actions .secondary-btn { width:100%; }
  .company-hero { align-items:flex-start; }
  .company-hero > a { margin-left:0; }
  .sales-card-total, .sales-document-card > b { flex:0 0 auto; }
  .sales-card-content, .sales-document-card > div { min-width:0; }
  .sales-card strong, .sales-document-card strong, .transaction p { overflow-wrap:anywhere; }
  /* The bell sits at the left of the bottom navigation, so its menu must not
     inherit the desktop right-aligned popover position on a phone. */
  .notifications > div {
    position:fixed;
    right:14px;
    bottom:94px;
    left:14px;
    z-index:40;
    width:auto;
    max-height:calc(100dvh - 126px);
    overflow-y:auto;
  }
}

/* Keep every footer action in an equal-width, vertically centered slot. */
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  justify-content: initial;
}

.bottom-nav > .notifications,
.bottom-nav > a,
.bottom-nav > form {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  height: 100%;
}

.bottom-nav > form > button,
.bottom-nav > .notifications > summary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.bottom-nav > .notifications > summary { gap: 4px; }
.bottom-nav .nav-add { align-self: center; justify-self: center; margin-top: 0; }

@media (max-width: 620px) {
  .bottom-nav { height: 78px; border-radius: 22px 22px 0 0; }
}

/* Final narrow-screen containment rules shared by every page. */
@media (max-width: 620px) {
  *, *::before, *::after { box-sizing: border-box; }
  .app-shell, .app-shell > *, main, section, article, form { max-width: 100%; }
  .page-header, .section-head, .topbar, .company-hero, .labour-toolbar,
  .labour-search, .labour-card, .attendance-hero, .accounting-kpi,
  .sales-hero, .sales-card, .sales-document-card { min-width: 0; }
  .page-header h1, .section-head h2, .labour-card strong,
  .sales-card strong, .sales-document-card strong { overflow-wrap: anywhere; }
  .labour-toolbar { gap: 10px; }
  .labour-toolbar .primary-btn { flex: 0 1 auto; white-space: nowrap; }
  .labour-search { width: 100%; }
  .labour-search input { min-width: 0; width: 100%; }
  .labour-card .labour-actions { min-width: 0; gap: 4px; }
  .labour-card .labour-actions { align-items: center; justify-content: center; flex-shrink: 0; }
  .labour-card .labour-open { display: none; }
  .labour-card .labour-actions .secondary-btn,
  .labour-card .labour-actions .danger-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; width: 34px; padding: 0; font-size: 0; overflow: hidden; }
  .labour-card .labour-actions .labour-delete-form { display: contents; }
  .labour-card .labour-actions .secondary-btn svg,
  .labour-card .labour-actions .danger-btn svg { display: block; width: 16px; height: 16px; margin: 0 auto; }
  .labour-card .labour-actions .secondary-btn,
  .labour-card .labour-actions .danger-btn { gap: 0; line-height: 1; text-align: center; }
  .labour-card .labour-actions .danger-btn {
    width: 68px;
    min-width: 68px;
    gap: 4px;
    padding: 0 6px;
    font-size: 10px;
  }
  .labour-card .labour-actions .danger-btn span {
    display: inline;
    font-size: 10px;
    white-space: nowrap;
  }
  .accounts-kpis, .labour-account-summary, .detail-grid,
  .attendance-stat-grid, .sales-document-grid { grid-template-columns: 1fr !important; }
  .sales-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .sales-hero-copy, .sales-card-content, .sales-stat-card > div { min-width: 0; }
  .sales-card-top small, .sales-card-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .filter-card > *, .accounting-actions > *, .attendance-hero-actions > *,
  .sales-hero-actions > * { min-width: 0; max-width: 100%; }
  .ledger-table, .attendance-ledger-header { overflow-x: auto; }
}

@media (min-width: 421px) and (max-width: 620px) {
  .labour-card .labour-actions .secondary-btn {
    min-width: 0;
    width: auto;
    padding: 0 7px;
    font-size: 10px;
  }
}

@media (min-width: 621px) and (max-width: 899px) {
  .labour-card .labour-open { display: none; }
}

@media (max-width: 620px) {
  .sales-hero {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    min-height: 0 !important;
    padding: 24px 20px 22px !important;
  }
  .sales-hero-copy {
    width: 100%;
    max-width: none !important;
    min-width: 0;
  }
  .sales-hero h2, .sales-hero p { max-width: 100%; }
  .sales-hero h2 { font-size: 28px; }
  .sales-hero-art { display: none !important; }
  .sales-hero-cta {
    position: static !important;
    inset: auto !important;
    width: 100% !important;
    margin: 18px 0 0 !important;
  }
  .sales-timeline, .conversion-actions, .conversion-card,
  .quotation-preview-section, .quotation-preview-frame {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .sales-timeline { padding: 14px 10px; }
  .timeline-heading { flex-direction: column; align-items: flex-start; gap: 8px; }
  .timeline-track { width: 100%; }
  .timeline-step { min-width: 0; }
  .timeline-label { overflow-wrap: anywhere; }
  .conversion-card { align-items: flex-start; }
  .quotation-preview-heading { width: 100%; min-width: 0; }
  .quotation-preview-heading h2 { font-size: 18px; overflow-wrap: anywhere; }
  .quotation-preview-frame { overflow: hidden; }
  .quotation-preview-frame iframe { width: 100%; max-width: 100%; }
}
