/* Connected workflow layouts */
#nav-customers,
#standaloneInvoiceBtn,
#fromWonQuoteBtn {
  display: none;
}

#page-purchasing.vendor-detail-open > #purchBody > .module-toolbar,
.page-hdr .module-actions.is-empty {
  display: none;
}

#customerDetailPanel.has-customer,
#vendorDetailPane {
  width: 100%;
  max-width: none;
  min-width: 0;
}

.vendor-detail-surface {
  background: var(--panel);
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
}

.erp-summary-grid,
.module-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 12px;
  margin: 0 0 12px;
  padding: 0;
}

#accountingModuleSummary {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.erp-summary-grid > .stat-card,
.module-summary-strip > .stat-card {
  height: 100%;
  min-height: 92px;
  margin: 0;
  padding: 14px;
  border: 2px solid var(--table-frame);
  border-radius: var(--table-radius);
}

/* Summary surfaces use the same physical frame as record tables everywhere,
   including report subviews that render outside the module summary strips. */
.stat-card,
.dash-stat-card,
.purch-stat,
.rpt-stat {
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
}

/* Status may change summary content, but not the shared physical frame. */
.stat-card.accent-top,
.stat-card.green-top,
.dash-stat-card.dash-good,
.dash-stat-card.dash-warn,
.dash-stat-card.dash-bad,
.purch-stat.ok,
.purch-stat.warn,
.rpt-stat.good,
.rpt-stat.warn,
.rpt-stat.bad,
.detail-summary-strip > .info-cell {
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
}

.summary-action-card {
  cursor: pointer;
  text-align: left;
}

.summary-card-link {
  margin-top: 4px;
  color: var(--accent);
  font-size: var(--font-size-button);
  font-weight: var(--font-weight-action);
  line-height: 1.3;
}

/* Shared application surfaces use one physical frame. Tables, summary cards,
   content cards, tab strips, and toolbars should read as parts of one ERP. */
.app-layout .card,
.app-layout .module-toolbar,
.app-layout .quote-tabs,
.app-layout .page-hdr .module-actions,
.app-layout .health-item {
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
}

.app-layout .card > .card-hdr {
  border-bottom: var(--table-grid-width) solid var(--table-grid);
  border-radius: 0;
}

/* Search/filter toolbars and record grids are separate shared surfaces. This
   keeps every visible box on the same complete 2px frame and 8px radius. */
.app-layout .module-toolbar.is-attached:has(+ :is(.erp-table-frame, .card.has-table-frame, .purch-master-list-shell)) {
  margin-bottom: 12px;
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
}

.app-layout .module-toolbar.is-attached + :is(.erp-table-frame, .card.has-table-frame),
.app-layout .module-toolbar.is-attached + .purch-master-list-shell > #vendorTablePane {
  border-radius: var(--table-radius);
}

/* Settings is another module, not a separately themed application. */
#settingsBody {
  padding: 0;
  background: #FFFFFF;
}

#settingsBody .stpane.active {
  padding: 0;
}

.purch-master-list-shell {
  display: flex;
  min-width: 0;
  gap: 14px;
}

#purchasingModuleSummary,
#inventoryModuleSummary {
  width: auto;
  margin: 16px 18px 12px;
}

#purchTabs,
#inventoryTabs {
  width: auto;
  margin: 0 18px;
}

#purchBody,
#inventoryBody {
  padding: 12px 18px 16px;
}

.module-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  color: var(--text-muted);
  font-weight: 700;
}

.is-loading {
  position: relative;
}

.is-loading > * {
  visibility: hidden;
}

.is-loading::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: visible;
  content: 'Loading…';
  color: var(--text-muted);
  font-weight: 700;
  background: var(--bg);
}

/* Full-page purchase-order workspace */
.po-workspace-page {
  overflow: hidden;
  background: var(--bg);
}

.po-page-shell {
  display: none;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.po-page-shell.show {
  display: flex;
}

.po-page-content {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--bg);
}

.po-page-content > .modal-hdr {
  min-height: 80px;
  padding: 18px 24px;
  color: var(--navy);
  background: var(--panel);
  border: 0;
  border-bottom: 1px solid var(--surface-border);
  border-radius: 0;
  flex: 0 0 auto;
}

.erp-document-heading {
  min-width: 220px;
}

.po-page-content > .modal-hdr .modal-title {
  color: var(--text);
  font-size: var(--font-size-page-title);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0;
  text-transform: none;
}

.po-page-content > .modal-hdr .page-hdr-sub {
  color: var(--text-muted);
  font-size: var(--font-size-meta);
  font-weight: 600;
}

.erp-document-close {
  display: none;
}

.erp-document-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 0;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.erp-document-actions .mr-auto {
  margin-right: 0;
}

.po-page-content > .modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px 24px 24px;
  background: var(--bg);
}

.po-document-card {
  width: 100%;
  margin: 0 0 14px;
}

.po-document-card > .card-body {
  padding: 16px;
}

.po-document-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: 14px;
}

.po-document-grid > .card {
  margin: 0;
}

.po-totals-card .inv-total-row {
  min-height: 44px;
}

.po-line-card > .card-body {
  padding: 14px;
}

.po-page-shell.po-view-mode .modal-body > :not(#poFullDetail),
.po-page-shell.po-view-mode .erp-document-actions {
  display: none;
}

.po-page-shell.is-loading::after {
  background: var(--bg);
}

@media (max-width: 900px) {
  .po-document-grid {
    grid-template-columns: 1fr;
  }

  .po-page-content > .modal-hdr {
    align-items: flex-start;
    flex-direction: column;
  }

  .erp-document-actions {
    justify-content: flex-start;
    margin-left: 0;
  }
}

/* Shared record detail hierarchy */
.erp-detail-page {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

.erp-detail-page > [data-detail-tabs],
[data-detail-tabs] {
  margin-top: 12px;
}

.erp-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--border);
}

.erp-detail-title {
  color: var(--navy);
  font-size: 24px;
  font-weight: 800;
}

.erp-detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 5px;
  color: var(--text-muted);
}

.erp-detail-actions,
.detail-tab-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
}

.erp-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 12px;
  margin-bottom: 12px;
}

.vendor-account-grid {
  grid-template-columns: 1fr;
}

.erp-info-card {
  height: 100%;
  margin: 0;
  border: 1px solid var(--border);
}

.erp-info-card > .card-hdr {
  min-height: 42px;
  padding: 10px 14px;
}

.erp-info-card > .card-body {
  height: calc(100% - 42px);
  padding: 14px;
}

.detail-field {
  display: grid;
  grid-template-columns: minmax(110px, 34%) minmax(0, 1fr);
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.detail-field:last-child {
  border-bottom: 0;
}

.detail-field > span {
  color: var(--text-muted);
  font-size: 12px;
}

.detail-field > strong {
  overflow-wrap: anywhere;
}

.detail-summary-strip {
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
}

.workflow-action-card {
  box-shadow: 0 2px 8px rgba(27, 39, 51, .05);
}

.workflow-dashboard-card {
  display: flex;
  min-width: 0;
  min-height: 170px;
  padding: 12px;
  flex-direction: column;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}

.workflow-dashboard-card .workflow-card-number {
  margin-top: 4px;
  color: var(--navy);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 800;
}

.workflow-dashboard-card .workflow-card-party {
  margin-top: 3px;
  font-weight: 700;
}

.workflow-dashboard-card .workflow-card-value {
  margin-top: 10px;
  font-size: 13px;
}

.workflow-dashboard-card .workflow-card-date {
  margin: 3px 0 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.workflow-dashboard-card .btn {
  margin-top: auto;
}

.workflow-attention-title {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  padding: 12px;
}

#page-dashboard .page-body {
  padding: 16px;
}

.dashboard-command-bar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
  box-shadow: var(--shadow-sm);
}

.dashboard-command-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.dashboard-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-priority-card,
.dashboard-cash-card,
.dashboard-module-card,
.dashboard-recent-card {
  min-width: 0;
  margin: 0;
  overflow: hidden;
}

.dashboard-main-grid > .card,
.dashboard-module-grid > .card {
  height: 100%;
  margin: 0;
}

.dashboard-priority-card > .card-hdr,
.dashboard-cash-card > .card-hdr,
.dashboard-recent-card > .card-hdr {
  min-height: 58px;
}

/* Module cards remain four-up through desktop widths. Reserve two subtitle
   lines so a wrapped label cannot make one header taller than its peers. */
.dashboard-module-card > .card-hdr {
  height: 74px;
  min-height: 74px;
}

.dashboard-count-badge {
  display: inline-flex;
  min-width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  color: var(--navy);
  font-family: var(--font-mono);
  font-size: var(--font-size-meta);
  font-weight: 800;
  background: var(--panel);
  border: 1px solid var(--table-grid);
  border-radius: var(--radius-badge);
}

.dashboard-queue-list,
.dashboard-activity-list {
  min-width: 0;
  background: var(--panel);
}

.dashboard-queue-row,
.dashboard-activity-row {
  width: 100%;
  min-width: 0;
  min-height: 58px;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--font-size-table);
  text-align: left;
  cursor: pointer;
  background: var(--panel);
  border: 0;
  border-bottom: var(--table-grid-width) solid var(--table-grid);
}

.dashboard-queue-row {
  display: grid;
  grid-template-columns: 112px minmax(180px, 1fr) minmax(90px, auto) 64px;
}

.dashboard-activity-row {
  display: grid;
  grid-template-columns: 132px minmax(180px, 1fr) 120px minmax(90px, auto) 64px;
}

.dashboard-queue-row:last-child,
.dashboard-activity-row:last-child {
  border-bottom: 0;
}

.dashboard-queue-row:hover,
.dashboard-activity-row:hover,
.dashboard-module-metric:hover,
.dashboard-cash-summary button:hover {
  background: var(--table-hover);
}

.dashboard-queue-row:focus-visible,
.dashboard-activity-row:focus-visible,
.dashboard-module-metric:focus-visible,
.dashboard-cash-summary button:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.dashboard-queue-flag,
.dashboard-activity-kind {
  overflow: hidden;
  color: var(--text-muted);
  font-size: var(--font-size-label);
  font-weight: 800;
  letter-spacing: .35px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.dashboard-queue-flag {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 4px 7px;
  background: var(--surface-header);
  border-radius: var(--radius-control);
}

.dashboard-queue-flag.urgent {
  color: var(--red);
  background: var(--red-bg);
}

.dashboard-queue-flag.watch {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.dashboard-queue-record,
.dashboard-activity-record {
  min-width: 0;
}

.dashboard-queue-record strong,
.dashboard-activity-record strong {
  display: block;
  overflow: hidden;
  color: var(--navy);
  font-size: var(--font-size-body);
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-queue-record small,
.dashboard-activity-record small {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: var(--font-size-meta);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-queue-value,
.dashboard-activity-value {
  color: var(--navy);
  font-family: var(--font-mono);
  font-weight: 750;
  text-align: right;
  white-space: nowrap;
}

.dashboard-activity-date {
  color: var(--text-muted);
  font-size: var(--font-size-meta);
  white-space: nowrap;
}

.dashboard-row-open {
  color: var(--accent-dark);
  font-size: var(--font-size-button);
  font-weight: var(--font-weight-action);
  text-align: right;
  white-space: nowrap;
}

.dashboard-cash-summary {
  display: grid;
  grid-template-columns: 1fr;
}

.dashboard-cash-net {
  display: flex;
  min-height: 82px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 14px;
  background: var(--surface-header);
  border-bottom: var(--table-grid-width) solid var(--table-grid);
}

.dashboard-cash-net span,
.dashboard-cash-summary button span {
  color: var(--text-muted);
  font-size: var(--font-size-meta);
  font-weight: 650;
}

.dashboard-cash-net strong {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 23px;
}

.dashboard-cash-net.negative strong {
  color: var(--red);
}

.dashboard-cash-summary button {
  display: flex;
  min-height: 51px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font-body);
  cursor: pointer;
  background: var(--panel);
  border: 0;
  border-bottom: var(--table-grid-width) solid var(--table-grid);
}

.dashboard-cash-summary button:last-child {
  border-bottom: 0;
}

.dashboard-cash-summary button strong {
  color: var(--navy);
  font-family: var(--font-mono);
  font-size: var(--font-size-body);
}

.dashboard-module-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-module-metrics {
  display: grid;
  grid-template-columns: 1fr;
}

.dashboard-module-metric {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--font-size-meta);
  text-align: left;
  cursor: pointer;
  background: var(--panel);
  border: 0;
  border-bottom: var(--table-grid-width) solid var(--table-grid);
}

.dashboard-module-metric:last-child {
  border-bottom: 0;
}

.dashboard-module-metric span {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-module-metric strong {
  color: var(--navy);
  font-family: var(--font-mono);
  font-size: var(--font-size-body);
  white-space: nowrap;
}

.dashboard-recent-card {
  margin-bottom: 0;
}

.app-layout .card-title {
  font-size: 13px;
  line-height: 1.25;
}

.card-subtitle {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

[data-detail-panels] > .card,
[data-detail-panels] > [data-panel] > .card {
  margin-bottom: 0;
}

.vendor-contacts-wrap {
  margin-top: 12px;
}

.vendor-contacts-wrap > .card {
  margin: 0;
}

.summary-action {
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.summary-action:hover,
.stat-card[data-kbm-action]:hover,
.stat-card[onclick]:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(232, 97, 26, .12);
  transform: translateY(-1px);
}

.computed-display {
  display: flex;
  min-height: 36px;
  align-items: center;
  padding: 8px 10px;
  color: var(--navy);
  font-weight: 700;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
}

@media (max-width: 1100px) {
  #accountingModuleSummary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-main-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-module-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .erp-summary-grid,
  .module-summary-strip,
  #accountingModuleSummary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .erp-info-grid {
    grid-template-columns: 1fr;
  }

  .erp-detail-header,
  .workflow-action-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .erp-detail-actions {
    justify-content: flex-start;
  }

  .dashboard-action-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-command-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .dashboard-command-actions {
    justify-content: flex-start;
  }

  .dashboard-queue-row {
    grid-template-columns: 100px minmax(150px, 1fr) minmax(80px, auto);
  }

  .dashboard-activity-row {
    grid-template-columns: 115px minmax(150px, 1fr) minmax(80px, auto);
  }

  .dashboard-queue-row .dashboard-row-open,
  .dashboard-activity-row .dashboard-row-open,
  .dashboard-activity-date {
    display: none;
  }

  .detail-tab-actions {
    display: none;
  }
}

@media (max-width: 620px) {
  .erp-summary-grid,
  .module-summary-strip,
  #accountingModuleSummary {
    grid-template-columns: 1fr;
  }

  .dashboard-module-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-queue-row,
  .dashboard-activity-row {
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
  }

  .dashboard-queue-flag,
  .dashboard-activity-kind {
    grid-column: 1 / -1;
  }

  .dashboard-queue-value,
  .dashboard-activity-value {
    grid-column: 2;
    grid-row: 2;
  }
}
