/*
 * PlusERP Version 1.0 — full ERP English UI stabilization.
 *
 * Presentation only. This layer does not change routes, permissions, data,
 * validation, calculations, posting, tenant scope, or workflow behaviour.
 */

:root {
  --ui-table-action-width: 184px;
  --ui-table-date-width: 116px;
  --ui-table-id-width: 118px;
  --ui-dialog-gutter: clamp(12px, 3vw, 32px);
}

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

.page,
.panel,
.table-wrap,
.inline-workspace-form,
.reports-workspace,
.settings-workspace {
  min-width: 0;
  max-width: 100%;
}

/* Shared table system */
.table-wrap,
.statement-table-wrap,
.snapshot-table-wrap,
.customer-table-wrap,
.mini-table-wrap {
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-inline: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.table-wrap > table,
.statement-table-wrap > table,
.snapshot-table-wrap > table,
.customer-table-wrap > table,
.mini-table-wrap > table {
  width: 100%;
  min-width: max-content;
  table-layout: auto;
  border-collapse: separate;
  border-spacing: 0;
}

.table-wrap :is(th, td),
.statement-table-wrap :is(th, td),
.snapshot-table-wrap :is(th, td),
.customer-table-wrap :is(th, td) {
  min-width: 0;
  vertical-align: middle;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.table-wrap th,
.statement-table-wrap th,
.snapshot-table-wrap th,
.customer-table-wrap th {
  white-space: nowrap;
  line-height: 1.25;
}

.table-wrap tbody td,
.statement-table-wrap tbody td,
.customer-table-wrap tbody td {
  padding-block: 10px;
  line-height: 1.35;
}

.ui-id-column {
  min-width: var(--ui-table-id-width);
  white-space: nowrap;
}

.ui-id-column :is(a, button, strong, code, span) {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}

.ui-date-column {
  min-width: var(--ui-table-date-width);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ui-number-column,
.ui-amount-column,
.amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ui-status-column {
  min-width: 88px;
  text-align: center;
  white-space: nowrap;
}

.ui-actions-column,
.ui-actions-cell {
  width: 1%;
  min-width: var(--ui-table-action-width);
  white-space: nowrap;
  text-align: right;
}

.ui-actions-cell :is(.row-actions, .row-actions-single, .inline-actions, .approval-actions, .customer-actions, .branch-actions) {
  display: inline-flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: max-content;
  min-width: max-content;
}

.ui-actions-cell :is(.btn, button, a),
.row-actions :is(.btn, button, a),
.row-actions-single :is(.btn, button, a) {
  flex: 0 0 auto;
  min-width: max-content;
  max-width: none;
  white-space: nowrap !important;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
}

.table-wrap .badge {
  display: inline-flex;
  max-width: none;
  white-space: nowrap;
}

.table-wrap .empty,
.table-wrap .empty-state {
  min-width: min(520px, calc(100vw - 80px));
  white-space: normal;
  text-align: center;
}

/* Owner-observed Inventory, Journal, HR/Payroll and Purchases patterns */
.inventory-table-wrap table {
  min-width: 1220px;
}

.inventory-table-wrap tbody tr {
  height: auto;
}

.inventory-table-wrap tbody td {
  min-height: 46px;
}

.inventory-table-wrap :is(th:first-child, td:first-child) {
  min-width: 138px;
  white-space: nowrap;
}

.journal-register-wrap,
.content:has(.journal-lines-mini) .table-wrap {
  overflow-x: auto;
}

.journal-register-table,
.content:has(.journal-lines-mini) > .page > .table-wrap > table {
  min-width: 1320px;
}

.journal-lines-mini {
  width: 100%;
  min-width: 560px;
  table-layout: auto;
}

.journal-lines-mini :is(th, td) {
  min-width: 104px;
  padding: 7px 10px;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}

.journal-lines-mini :is(th:nth-child(1), td:nth-child(1)) {
  min-width: 170px;
}

.journal-lines-mini :is(th:nth-child(2), td:nth-child(2)) {
  min-width: 210px;
  white-space: normal;
}

.journal-lines-mini :is(th:nth-child(3), td:nth-child(3), th:nth-child(4), td:nth-child(4)) {
  min-width: 104px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hr-register-grid {
  align-items: start;
}

.hr-register-grid > .panel {
  align-self: start;
  height: auto;
  min-height: 0;
}

.hr-table-wrap table {
  min-width: 760px;
}

.hr-register-table tbody tr {
  height: auto;
}

.hr-register-table .ui-actions-cell {
  min-width: 150px;
}

.report-center.sales-center {
  align-items: start;
  grid-auto-rows: max-content;
}

.report-center.sales-center > .report-block {
  align-self: start;
  height: auto;
  min-height: 0;
}

@media screen and (min-width: 1180px) {
  .content:has(.report-center.sales-center) .report-center.sales-center {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .content:has(.report-center.sales-center) .report-center.sales-center > .report-block:last-child {
    grid-column: span 2;
  }
}

/* Shared cards, forms, filters, toolbars, and dialogs */
.grid-2,
.grid-3,
.metrics,
.dashboard-metrics,
.reports-metric-grid,
.report-center,
.settings-grid,
.migration-layout {
  align-items: start;
  grid-auto-rows: max-content;
}

:is(.grid-2, .grid-3, .metrics, .dashboard-metrics, .reports-metric-grid, .report-center, .settings-grid, .migration-layout) > :is(.panel, .metric, .report-block, .settings-card, .migration-card) {
  align-self: start;
  height: auto;
  min-height: 0;
}

:is(.toolbar, .panel-head, .workspace-return-bar, .report-filters, .reports-filter-bar, .statement-filters, .approval-filter-bar) {
  min-width: 0;
  max-width: 100%;
}

:is(.toolbar, .panel-head, .workspace-return-bar) > * {
  min-width: 0;
}

:is(.topbar-actions, .panel-head-actions, .form-actions, .workspace-return-actions, .reports-filter-actions, .statement-filter-actions, .migration-actions) {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  gap: 8px;
}

:is(.topbar-actions, .panel-head-actions, .form-actions, .workspace-return-actions, .reports-filter-actions, .statement-filter-actions, .migration-actions) :is(.btn, button) {
  flex: 0 0 auto;
  min-width: max-content;
  white-space: nowrap;
}

:is(.form-grid, .modal-grid, .erp-form-grid, .customer-section-grid, .company-settings-fields) > * {
  min-width: 0;
}

:is(.form-grid, .modal-grid, .erp-form-grid, .customer-section-grid, .company-settings-fields) :is(input, select, textarea) {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.modal-backdrop {
  padding: var(--ui-dialog-gutter);
  overflow: hidden;
}

.modal,
.app-alert-dialog {
  max-width: min(1040px, calc(100vw - (2 * var(--ui-dialog-gutter))));
  max-height: calc(100dvh - (2 * var(--ui-dialog-gutter)));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-wide {
  width: min(1180px, calc(100vw - (2 * var(--ui-dialog-gutter))));
  max-width: calc(100vw - (2 * var(--ui-dialog-gutter)));
}

.modal-compact {
  width: min(560px, calc(100vw - (2 * var(--ui-dialog-gutter))));
}

.modal :is(.panel-head, .modal-head),
.app-alert-dialog > :first-child {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface, #fff);
}

.modal .form-actions,
.app-alert-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--surface, #fff);
}

.field-help,
.hint,
.validation-message,
.error-message {
  overflow-wrap: anywhere;
  word-break: normal;
}

:is(button, a, input, select, textarea, summary):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--action-primary, #2563eb) 45%, transparent);
  outline-offset: 2px;
}

button:disabled,
.btn:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.62;
}

@media screen and (max-width: 1024px) {
  :root {
    --ui-table-action-width: 172px;
  }

  .report-center.sales-center {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content:has(.report-center.sales-center) .report-center.sales-center > .report-block:last-child {
    grid-column: auto;
  }

  :is(.report-filters, .reports-filter-bar, .statement-filters, .approval-filter-bar) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media screen and (max-width: 760px) {
  html,
  body {
    overflow-x: hidden;
  }

  .page {
    padding-inline: 12px;
  }

  .report-center.sales-center,
  :is(.report-filters, .reports-filter-bar, .statement-filters, .approval-filter-bar) {
    grid-template-columns: minmax(0, 1fr);
  }

  :is(.toolbar, .panel-head, .workspace-return-bar) {
    align-items: stretch;
  }

  :is(.topbar-actions, .panel-head-actions, .form-actions, .workspace-return-actions, .reports-filter-actions, .statement-filter-actions, .migration-actions) {
    width: 100%;
  }

  :is(.topbar-actions, .panel-head-actions, .form-actions, .workspace-return-actions, .reports-filter-actions, .statement-filter-actions, .migration-actions) :is(.btn, button) {
    min-height: 44px;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .modal,
  .modal-wide,
  .modal-compact,
  .app-alert-dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }
}

@media screen and (max-width: 420px) {
  .page {
    padding-inline: 8px;
  }

  :is(.form-grid, .modal-grid, .erp-form-grid, .customer-section-grid, .company-settings-fields) {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  .sidebar,
  .topbar,
  .top-menu,
  .workspace-return-bar,
  .reports-command,
  .report-filters,
  .reports-filter-bar,
  .statement-filters,
  .form-actions,
  .row-actions,
  .ui-actions-column,
  .ui-actions-cell,
  button,
  [role="button"] {
    display: none !important;
  }

  html,
  body,
  .content,
  .page,
  .panel,
  .table-wrap,
  .statement-table-wrap {
    width: 100% !important;
    max-width: none !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  table {
    width: 100% !important;
    min-width: 0 !important;
    font-size: 9pt;
  }

  thead {
    display: table-header-group;
  }

  tfoot {
    display: table-footer-group;
  }

  tr,
  .totals-box,
  .report-summary,
  .metric {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .company-logo,
  .print-logo,
  .report-logo {
    max-width: 48mm;
    height: auto;
    object-fit: contain;
  }
}
