/* Final ledger and typography authority.
 * The left navigation keeps its existing visual system.
 */

@font-face {
  font-family: "Source Han Sans SC";
  src: url("./assets/fonts/SourceHanSansCN-VF.otf.woff2") format("woff2");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

:root {
  --erp-ui-font: "Source Han Sans SC", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-color-scheme="light"] {
  --ui-ink: #000000;
  --ui-ink-950: #000000;
  --ui-ink-800: #111111;
  --ui-ink-650: #333333;
  --ui-ink-500: #555555;
  --mac-v3-label: #000000;
  --mac-v3-label-secondary: #333333;
  --mac-v3-label-tertiary: #555555;
  --macos-label: #000000;
  --macos-label-secondary: #333333;
  --macos-label-tertiary: #555555;
  --enterprise-text: #000000;
  --enterprise-text-secondary: #333333;
  --enterprise-text-tertiary: #555555;
  --reference-text: #000000;
  --reference-text-secondary: #333333;
  --reference-text-tertiary: #555555;
}

body[data-ui-theme="macos-workspace-v3"] :where(
  .login-gate,
  .app-header,
  .erp-main,
  .module-subnav,
  .user-menu-dropdown,
  .global-overlay-root,
  .system-notice,
  #erp-flow-launch-dialog,
  dialog
) {
  font-family: var(--erp-ui-font);
  letter-spacing: 0;
}

body[data-ui-theme="macos-workspace-v3"] :where(
  .login-gate,
  .app-header,
  .erp-main,
  .module-subnav,
  .user-menu-dropdown,
  .global-overlay-root,
  .system-notice,
  #erp-flow-launch-dialog,
  dialog
) :is(button, input, select, textarea, table, optgroup, option) {
  font-family: inherit;
}

:root[data-color-scheme="light"] body[data-ui-theme="macos-workspace-v3"] :where(
  .app-header,
  .erp-main,
  .module-subnav,
  .user-menu-dropdown,
  .global-overlay-root,
  .system-notice,
  #erp-flow-launch-dialog,
  dialog
) {
  color: #000000;
}

:root[data-color-scheme="light"] body[data-ui-theme="macos-workspace-v3"] :where(
  .app-header,
  .erp-main,
  .module-subnav,
  .user-menu-dropdown,
  .global-overlay-root,
  .system-notice,
  #erp-flow-launch-dialog,
  dialog
) :is(
  h1,
  h2,
  h3,
  h4,
  th,
  td,
  label,
  legend,
  summary,
  p,
  strong
) {
  color: inherit;
}

:root[data-color-scheme="light"] body[data-ui-theme="macos-workspace-v3"] :is(
  .table-missing-value,
  .ledger-record-number,
  .ledger-record-cell small,
  .ledger-static-metric span,
  .ledger-static-metric small,
  .panel-title span,
  .context-card small,
  .context-card span,
  .flow-field-hint,
  input[readonly],
  input:disabled,
  textarea:disabled,
  select:disabled
) {
  color: #4b4b4b;
}

:root[data-color-scheme="light"] body[data-ui-theme="macos-workspace-v3"] :is(input, textarea)::placeholder {
  color: #666666;
  opacity: 1;
}

body[data-ui-theme="macos-workspace-v3"] :is(
  .data-table,
  .workbench-project-table,
  .payroll-table,
  .money,
  .amount,
  .is-money
) {
  font-variant-numeric: tabular-nums;
}

@media (min-width: 761px) {
  body[data-ui-theme="macos-workspace-v3"] .view-root:is(
    [data-view="projects"],
    [data-view="contracts"],
    [data-view="parties"],
    [data-view="receivables"],
    [data-view="payments"],
    [data-view="invoices"],
    [data-view="finance"]
  ) {
    width: 100%;
    max-width: none;
    min-height: 100%;
    margin: 0;
    padding: 8px 8px 16px;
  }

  body[data-ui-theme="macos-workspace-v3"] .view-root:is(
    [data-view="projects"],
    [data-view="contracts"],
    [data-view="parties"],
    [data-view="receivables"],
    [data-view="payments"],
    [data-view="invoices"],
    [data-view="finance"]
  ) > :is(.panel, .tabs, .finance-subnav, .party-import-toolbar) {
    width: 100%;
    max-width: none;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table-shell {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 220px);
    overflow-x: auto;
    overflow-y: auto;
    border-radius: 2px 2px 0 0;
    scrollbar-gutter: stable;
    overscroll-behavior-inline: contain;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table {
    width: max-content;
    min-width: 0;
    table-layout: fixed;
    font-size: 12px;
    line-height: 1.35;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table thead th {
    height: 30px;
    min-width: 0;
    min-height: 30px;
    padding: 0 8px;
    overflow: visible;
    font-size: 12px;
    line-height: 1.25;
    white-space: nowrap;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table tbody td {
    height: 34px;
    min-width: 0;
    min-height: 34px;
    max-width: 320px;
    padding: 4px 8px;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table :is(th, td):first-child {
    min-width: 0;
    text-align: center;
  }

  body[data-ui-theme="macos-workspace-v3"] .data-table[data-ledger-table="true"] {
    min-width: 0 !important;
    table-layout: fixed !important;
  }

  body[data-ui-theme="macos-workspace-v3"] .data-table[data-ledger-table="true"] :is(th, td) {
    min-width: 0 !important;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table td.is-action {
    min-width: 104px;
    overflow: visible;
    white-space: nowrap;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table td.is-action .table-action {
    height: 26px;
    min-height: 26px;
    margin: 0 3px 0 0;
    padding: 0 7px;
    font-size: 12px;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table-shell + .data-table-pagination {
    min-height: 32px;
    padding: 4px 8px;
  }
}

@media (max-width: 760px) {
  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table-shell {
    max-width: 100%;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table {
    width: 100% !important;
    min-width: 0 !important;
  }

  body[data-ui-theme="macos-workspace-v3"] .module-ledger-table :is(tbody, tr, td) {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none;
  }
}

/* Final interaction authority: compact search and clean workflow labels. */
body[data-ui-theme="macos-workspace-v3"] .global-search::before,
body[data-ui-theme="macos-workspace-v3"] .global-search::after {
  content: none !important;
  display: none !important;
}

body[data-ui-theme="macos-workspace-v3"] .app-header .topbar.is-compact {
  width: 100%;
  max-width: none !important;
  margin: 0 !important;
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
}

body[data-ui-theme="macos-workspace-v3"] .topbar > .topbar-actions {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  grid-column: 1 / -1 !important;
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search {
  order: 0;
  flex: 0 0 auto;
  width: 40px !important;
  max-width: min(620px, calc(100vw - 160px)) !important;
  height: 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: center;
  gap: 0;
  margin-left: auto;
  margin-right: 4px;
  overflow: visible;
  transition: width 180ms ease;
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .cloud-sync-status {
  order: 1;
  flex: 0 0 auto;
  margin: 0 2px 0 0;
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .user-menu-anchor {
  order: 2;
  flex: 0 0 auto;
}

/* Final shell authority: opened-flow tabs share the ledger content width. */
body[data-ui-theme="macos-workspace-v3"] .erp-main > .workspace-tabs {
  width: calc(100% - 16px);
  max-width: calc(100% - 16px);
  min-width: 0;
  margin: 0 8px;
  padding-inline: 0;
  box-sizing: border-box;
}

body[data-ui-theme="macos-workspace-v3"] .workspace-tabs-close-all {
  position: sticky;
  right: 0;
  z-index: 2;
  flex: 0 0 auto;
  min-width: 72px;
  min-height: 34px;
  margin-left: auto;
  padding: 0 12px;
  color: var(--mac-v3-label-secondary, #333333);
  background: var(--mac-v3-surface, #ffffff);
  border: 0;
  border-left: 1px solid var(--mac-v3-separator, #d8dee8);
  border-radius: 0;
  box-shadow: -8px 0 12px var(--mac-v3-surface, #ffffff);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

body[data-ui-theme="macos-workspace-v3"] .workspace-tabs-close-all:is(:hover, :focus-visible) {
  color: var(--mac-v3-accent, #1677ff);
  background: var(--mac-v3-control, #f4f7fa);
}

/* Centered, keyboard-safe replacement for the browser's native leave prompt. */
body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: min(420px, calc(100vw - 32px));
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: var(--mac-v3-label, #111827);
  background: var(--mac-v3-surface, #ffffff);
  border: 1px solid var(--mac-v3-separator, #d8dee8);
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(15, 31, 55, 0.24), 0 4px 16px rgba(15, 31, 55, 0.12);
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-dialog::backdrop {
  background: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(3px);
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-card {
  display: grid;
  gap: 0;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-content {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 24px;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-icon {
  width: 40px;
  height: 40px;
  display: block;
  background: #fff5df;
  border: 1px solid #f0c36a;
  border-radius: 50%;
  position: relative;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-icon::before {
  content: "!";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8a5700;
  font-size: 20px;
  font-weight: 750;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-content h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.4;
  font-weight: 750;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-content p {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.55;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-content small {
  display: block;
  margin-top: 6px;
  color: var(--mac-v3-label-secondary, #4b5563);
  font-size: 12px;
  line-height: 1.5;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--mac-v3-control, #f4f7fa);
  border-top: 1px solid var(--mac-v3-separator, #d8dee8);
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-card footer button {
  min-width: 88px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--mac-v3-separator, #d8dee8);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 650;
}

body[data-ui-theme="macos-workspace-v3"] .unsaved-navigation-card footer button.primary {
  color: #ffffff;
  background: var(--mac-v3-accent, #1677ff);
  border-color: var(--mac-v3-accent, #1677ff);
}

:root[data-color-scheme="dark"] body[data-ui-theme="macos-workspace-v3"] .workspace-tabs-close-all {
  box-shadow: -8px 0 12px var(--mac-v3-surface, #20242c);
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search.is-expanded {
  width: min(620px, calc(100vw - 160px)) !important;
  gap: 8px;
}

body[data-ui-theme="macos-workspace-v3"] .global-search-toggle {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--mac-v3-label-secondary, #333333);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  box-shadow: none;
  cursor: pointer;
}

body[data-ui-theme="macos-workspace-v3"] .global-search-toggle:hover,
body[data-ui-theme="macos-workspace-v3"] .global-search-toggle:focus-visible,
body[data-ui-theme="macos-workspace-v3"] .global-search.is-expanded .global-search-toggle {
  color: var(--mac-v3-accent, #1677ff);
  background: var(--mac-v3-control, #f4f7fa);
  border-color: var(--mac-v3-separator, #d8dee8);
}

body[data-ui-theme="macos-workspace-v3"] .global-search-toggle > span {
  width: 18px;
  height: 18px;
  display: block;
  background-color: currentColor;
  -webkit-mask: url("./assets/vendor/lucide-icons/search.svg") center / contain no-repeat;
  mask: url("./assets/vendor/lucide-icons/search.svg") center / contain no-repeat;
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search > input {
  width: 0 !important;
  min-width: 0 !important;
  padding-inline: 0 !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease;
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search.is-expanded > input {
  width: 100% !important;
  padding-inline: 12px !important;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search.is-expanded > .global-search-panel {
  right: 48px;
  left: 0;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form.flow-form-streamlined .form-grid > label,
body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form.flow-form-streamlined .form-grid > label > span {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
}

body[data-ui-theme="macos-workspace-v3"] #flow-form .form-section-label {
  background: var(--mac-v3-control, #f4f7fa);
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form [data-flow-field="party"] > .expense-payee-type-control {
  grid-column: 1 !important;
  grid-row: 1 !important;
  width: 100% !important;
  min-width: 0 !important;
  height: var(--flow-reference-row-height) !important;
  min-height: var(--flow-reference-row-height) !important;
  padding: 0 !important;
  display: flex !important;
  align-items: stretch !important;
  background: var(--flow-reference-surface) !important;
  border-right: 1px solid var(--operational-form-line) !important;
  overflow: hidden !important;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form [data-flow-field="party"] > .expense-payee-type-control[hidden] {
  display: none !important;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form [data-flow-field="party"] > #party-field-label[hidden] {
  display: none !important;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form .expense-payee-type-control > select {
  grid-column: auto !important;
  grid-row: auto !important;
  width: 100% !important;
  min-width: 0 !important;
  height: var(--flow-reference-row-height) !important;
  min-height: var(--flow-reference-row-height) !important;
  margin: 0 !important;
  padding: 2px 22px 2px 7px !important;
  color: var(--flow-reference-text) !important;
  background-color: var(--flow-reference-surface) !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  font-family: var(--flow-reference-font) !important;
  font-size: 12px !important;
  font-weight: 400 !important;
  line-height: 1.2 !important;
  text-align: right !important;
  text-align-last: right !important;
}

:root[data-color-scheme="dark"] body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #flow-form .expense-payee-type-control > select {
  color: var(--flow-reference-text) !important;
}

body[data-ui-theme="macos-workspace-v3"] #contract-line-items .data-table-column-resizer {
  display: block;
}

/* Project expense detail: dense ledger rhythm with adjustable columns and rows. */
body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .weekly-expense-workbook-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .weekly-expense-workbook-actions[hidden] {
  display: none !important;
}

body[data-ui-theme="macos-workspace-v3"] #expense-line-items .project-expense-line-table {
  table-layout: fixed;
  min-width: 1040px;
}

body[data-ui-theme="macos-workspace-v3"] #expense-line-items .line-item-table thead th {
  position: relative;
  height: 32px;
  padding: 5px 7px;
  line-height: 1.25;
}

body[data-ui-theme="macos-workspace-v3"] #expense-line-items .line-item-table tbody td {
  min-height: 34px;
  padding: 4px 6px;
  line-height: 1.3;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #expense-line-items .line-item-table :is(input, select) {
  height: 30px !important;
  min-height: 30px !important;
  padding: 3px 6px !important;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #expense-line-items .expense-item-textarea {
  width: 100%;
  min-width: 0;
  height: 34px !important;
  min-height: 34px !important;
  max-height: 240px;
  padding: 5px 7px !important;
  line-height: 1.35 !important;
  resize: vertical;
}

body[data-ui-theme="macos-workspace-v3"] #expense-line-items .data-table-column-resizer {
  display: block;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .flow-recovery-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .flow-recovery-dismiss {
  width: 28px;
  min-width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  color: #6f4a00;
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .flow-recovery-dismiss:is(:hover, :focus-visible) {
  background: rgba(111, 74, 0, 0.1);
}

/* Flow window title remains visually centered after secondary tools were removed. */
body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .erp-flow-launch-dialog-head {
  position: relative;
  justify-content: center;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .erp-flow-launch-dialog-head > div:first-child {
  width: 100%;
  min-width: 0;
  padding-inline: 132px;
  text-align: center;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .erp-flow-launch-dialog-head h2 {
  width: 100%;
  margin: 0;
  text-align: center;
}

body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .erp-flow-launch-dialog-actions {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
}

@media (max-width: 760px) {
  body[data-ui-theme="macos-workspace-v3"] .erp-main > .workspace-tabs {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search {
    width: 40px !important;
  }

  body[data-ui-theme="macos-workspace-v3"] .topbar-actions > .global-search.is-expanded {
    width: clamp(120px, calc(100vw - 200px), 190px) !important;
  }

  body[data-ui-theme="macos-workspace-v3"] #expense-line-items .project-expense-line-table {
    min-width: 0;
  }

  body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) #expense-line-items .expense-item-textarea {
    height: 34px !important;
    min-height: 34px !important;
  }

  body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .flow-recovery-actions {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .flow-recovery-dismiss {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  body[data-ui-theme="macos-workspace-v3"] #erp-flow-launch-dialog:not(.is-picker) .erp-flow-launch-dialog-head > div:first-child {
    padding-inline: 56px;
  }
}
