/* Shared finishing layer. Screen-only: exported/printed business documents keep their own layout. */
@media screen {
  :root {
    --muted: #65716b;
    --ui-field: #fffefa;
    --ui-border: #d5d9d1;
    --ui-hover: #f0f4ef;
    --ui-focus: rgba(15,77,60,.13);
    --ui-scroll: #adb8af;
    --ui-ease: cubic-bezier(.2,.7,.3,1);
    --ui-radius: 9px;
    --ui-label: 12px;
  }
  html[data-appearance="glass"] {
    --muted: #53657d;
    --ui-field: #fff;
    --ui-border: #d3deec;
    --ui-hover: #edf3fc;
    --ui-focus: rgba(36,100,200,.14);
    --ui-scroll: #a9bad0;
    --line-soft: rgba(100,126,163,.16);
    --shadow: 0 3px 14px rgba(40,65,110,.035), inset 0 1px 0 rgba(255,255,255,.9);
  }

  /* Comfortable Chinese/Latin text and stable numbers in dense business screens. */
  html body { letter-spacing: 0; line-height: 1.6; }
  html :is(button,input,select,textarea) { letter-spacing: inherit; }
  html :is(input,textarea) { caret-color: var(--brand); }
  html ::selection { background: var(--brand-soft); color: var(--text); }
  html :is(.page-head p,.panel-head p,.dialog-head p,.field-hint,.date-input-hint) { line-height: 1.75; }
  html .page-head h1 { font-weight: 650; letter-spacing: -.025em; line-height: 1.35; }
  html .page-head p { font-size: 13px; margin-top: 7px; }
  html .panel h2 { font-size: 15px; line-height: 1.5; }
  html :is(.dialog-head h2,.drawer-head h2) { letter-spacing: -.02em; line-height: 1.4; }
  html :is(.dialog-head p,.panel-head p,.result-summary) { font-size: 12px; }
  html :is(.metric small,.glass-caption,.glass-empty,.glass-shortcuts small,.glass-due-row small,
    .performance-filters label,.performance-stats small,.performance-foot p,.performance-details summary,
    .metric-label,.glass-stage,.glass-due-row time) { font-size: 12px; color: var(--muted); }
  html :is(.metric-value,.money-value,.money-cell,.due-cell,.performance-stats strong,
    .platform-stats,.badge,.doc-totals strong,input[type="number"],.us-date-input) {
    font-variant-numeric: tabular-nums;
  }
  html :is(.metric-value,.money-value) { letter-spacing: -.025em; }
  html :is(.row-main,.panel-head>div,.dialog-head>div,.drawer-head>div) { min-width: 0; }
  html :is(.row-main strong,.fw-card,.drawer-head h2,.doc-drawer-item,.mail-linked-order) { overflow-wrap: anywhere; }

  /* Quiet, consistent native surfaces, including places outside the form-grid. */
  html :is(input,select,textarea) { accent-color: var(--brand); }
  html :is(.filters,.period-bar,.inline-form,.form-grid,.fw-form,.mail-form,.auth-form,
    .supplier-toolbar,.language-switch,.performance-filters,.supplier-drawer,.order-drawer,.customer-drawer,.inquiry-drawer,dialog)
    :is(input,select,textarea):not(:where([type="checkbox"],[type="radio"],[type="range"],[type="file"],[type="hidden"],[type="color"])) {
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    background-color: var(--ui-field);
    color: var(--text);
    font-size: 13px;
    transition: border-color .16s var(--ui-ease), box-shadow .16s var(--ui-ease), background-color .16s;
  }
  html :is(input,textarea)::placeholder { color: var(--muted); opacity: .92; }
  html :is(.filters,.form-grid,.fw-form,.mail-form,.auth-form,dialog) textarea { line-height: 1.7; resize: vertical; }
  html .form-grid { row-gap: 14px; }
  /* Order fields stay top-aligned even when a neighbour has a validation message. */
  html #orderForm .form-grid { align-items: start; }
  html #orderForm :is(.form-grid > label,.customer-picker,.customer-picker > label) { align-content: start; min-width: 0; }
  html #orderForm .form-grid > [hidden] { display: none !important; }
  html #orderForm :is(.money-field,.input-with-action,.form-grid > label > input,.form-grid > label > select) { height: 38px; }
  html #orderForm .money-field > input { height: 100%; min-height: 0; }
  html #orderForm #fFreightLink { justify-self: start; }
  html :is(.form-grid label,.fw-form label,.mail-form label,.field label) { gap: 6px; font-size: var(--ui-label); line-height: 1.55; }
  html :is(.filters,.period-bar,.supplier-toolbar,.language-switch) select { padding-inline: 10px; }
  html :is(.filters,.supplier-toolbar) :is(input,select) { min-width: 0; max-width: 100%; }
  html .language-switch select { height: 36px; }
  html :is(input,select,textarea):enabled:hover { border-color: color-mix(in srgb,var(--brand) 38%,var(--ui-border)); }
  html :is(input,select,textarea):focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ui-focus);
    outline: 2px solid transparent;
    outline-offset: 2px;
  }
  html :is(button,a,summary,[tabindex]):focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
  html :is(.global-search,.supplier-search) { border-color: var(--ui-border); }
  html :is(.global-search,.supplier-search):focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ui-focus); }
  html :is(.global-search,.supplier-search) input:focus { outline: 0; box-shadow: none; }
  html .supplier-toolbar .supplier-search input { border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  html .money-field { border-color: var(--ui-border); background: var(--ui-field); border-radius: var(--ui-radius); }
  html .money-field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ui-focus); }
  html .form-grid .money-field input { border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  html .form-grid .money-field input:focus { outline: 0; box-shadow: none; }
  html .form-grid input:invalid:not(:user-invalid):not(.date-invalid):not([aria-invalid="true"]) { border-color: var(--ui-border); }
  html :is(input,select,textarea):user-invalid,
  html :is(input,select,textarea)[aria-invalid="true"] { border-color: var(--danger); }
  html :is(input,select,textarea):user-invalid:focus { box-shadow: 0 0 0 3px color-mix(in srgb,var(--danger) 14%,transparent); }
  html :is(input,textarea)[readonly] { background: var(--line-soft); color: var(--muted); }
  html :is(button,input,select,textarea):disabled { cursor: not-allowed; opacity: .58; }
  html button:disabled { transform: none; box-shadow: none; }
  html :is(input[type="checkbox"],input[type="radio"]) { flex-shrink: 0; cursor: pointer; }

  /* Controls keep their existing roles, with less movement and clearer feedback. */
  html :is(.primary,.secondary,.danger,.auth-submit) { min-height: 36px; font-weight: 550; line-height: 1.45; }
  html :is(.primary,.secondary,.danger) { border-radius: var(--ui-radius); }
  html .primary { box-shadow: 0 2px 5px var(--ui-focus); }
  html .primary:hover { transform: none; box-shadow: 0 3px 8px var(--ui-focus); }
  html :is(.primary,.secondary,.danger):active:enabled { transform: translateY(1px); }
  html .secondary { border-color: var(--ui-border); }
  html .secondary:hover { background: var(--ui-hover); border-color: color-mix(in srgb,var(--brand) 35%,var(--ui-border)); }
  html .icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; flex-shrink: 0; line-height: 1; }
  html .icon-btn:hover { background: var(--ui-hover); color: var(--text); }
  html :is(.link,.inline-link,.text-btn) { text-underline-offset: 3px; text-decoration-thickness: 1px; }
  html :is(.inline-link,.text-btn):hover { color: var(--brand-2); }
  html .metric:hover { transform: none; box-shadow: var(--shadow); }
  html .glass-shortcuts button:hover { transform: none; border-color: var(--ui-border); background: var(--ui-hover); }
  html :is(.panel-head-actions,.dialog-head,.drawer-head) { gap: 12px; }
  html :is(.dialog-actions,.drawer-actions,.button-row) { flex-wrap: wrap; row-gap: 10px; }

  /* Navigation icons share a 24px drawing grid in both appearances. */
  html .nav-item .nav-icon { display: inline-grid; place-items: center; width: 22px; flex: 0 0 22px; line-height: 1; }
  html :is(.nav-icon,.search-icon) svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
  html .nav-item { gap: 9px; letter-spacing: 0; }
  html .nav-item.active { font-weight: 600; }
  html .search-icon { display: inline-flex; align-items: center; flex-shrink: 0; }
  html .brand strong { letter-spacing: .01em; }
  html[data-appearance="glass"] .nav-item { color: #506b8b; }
  html[data-appearance="glass"] .nav-item.active { color: var(--brand); }
  html[data-appearance="glass"] .nav-item:hover { color: var(--brand); background: #ffffffa8; }
  html[data-appearance="glass"] :is(.sidebar-user-actions .user-action,.glass-eyebrow) { color: #526b8a; }
  html[data-appearance="glass"] .sidebar-user-actions .danger-text { color: var(--danger); }

  /* Tables retain horizontal scrolling and the original column structure. */
  html th { color: var(--muted); font-size: 12px; letter-spacing: .01em; line-height: 1.5; }
  html :is(th,td) { border-bottom-color: var(--line-soft); }
  html td { line-height: 1.6; }
  html td small { font-size: 12px; line-height: 1.55; }
  html tbody tr:hover { background: var(--ui-hover); }
  html tbody tr:focus-within { background: var(--ui-hover); }
  html :is(.badge,.doc-status,.mail-tag,.todo-tag) { font-size: 12px; line-height: 1.5; }
  html :is(.quick-action,.quick-stage,.quick-payment,.quick-follow-date,.quick-ship-date) { border-color: var(--ui-border); background: var(--ui-field); }
  html :is(.abnormal-toggle,.todo-quick button) { white-space: nowrap; }
  html .row-actions button { white-space: nowrap; }
  html .abnormal-toggle { font-size: 12px; line-height: 1.5; }
  html .platform-groups td:nth-child(3) { white-space: nowrap; }
  html[data-appearance="glass"] :is(.platform-toggle,.scat-item,.mail-item):hover { background: var(--ui-hover); }
  html[data-appearance="glass"] :is(.scat-count,.scat-item.active .scat-count) { background: var(--brand-soft); color: var(--brand); }
  html[data-appearance="glass"] .mail-item.selected { background: var(--brand-soft); }
  html .tab-btn { letter-spacing: 0; line-height: 1.5; }
  html[data-appearance="glass"] .tab-btn.active::before { height: 2px; background: var(--brand); }

  /* Editing surfaces are solid for reading; glass stays in the surrounding chrome. */
  html[data-appearance="glass"] dialog {
    background: #fbfcff; color: var(--text); border-color: #e1e8f3;
    border-radius: 16px; backdrop-filter: none; -webkit-backdrop-filter: none;
    box-shadow: 0 24px 72px rgba(28,49,80,.2);
  }
  html dialog { color: var(--text); overscroll-behavior: contain; }
  html dialog::backdrop { background: rgba(26,43,65,.28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
  html dialog form { scrollbar-gutter: stable; }
  html :is(.order-drawer,.customer-drawer,.inquiry-drawer,.supplier-drawer):not(.open) { box-shadow: none; }
  html[data-appearance="glass"] :is(.order-drawer,.customer-drawer,.inquiry-drawer,.supplier-drawer) {
    background: #f8faff; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  html :is(.order-drawer,.supplier-drawer) { overscroll-behavior: contain; }
  html[data-appearance="glass"] :is(.doc-address-block,.doc-proof,.doc-totals,.fw-checklist,.fw-candidates) {
    background: #f3f6fc; border-color: var(--line-soft);
  }
  html .dialog-head { align-items: flex-start; margin-bottom: 18px; }
  html .dialog-head p { margin-top: 6px; }
  html legend { letter-spacing: 0; line-height: 1.6; }
  html :is(.form-error,.auth-error,.form-warning,.mail-analysis-error) { line-height: 1.7; }
  html .toast { max-width: calc(100vw - 32px); line-height: 1.6; text-align: center; overflow-wrap: anywhere; transition: opacity .18s, transform .18s; }
  html :is(.empty,.glass-empty,.supplier-empty) { color: var(--muted); line-height: 1.8; }
  html :is(.empty p,.glass-empty) { font-size: 12px; }
  html .fw-files a { color: var(--brand); text-underline-offset: 3px; }
  html .fw-card { background: var(--panel); }
  html #financeWorkflow .fw-list>.field-hint { background: var(--ui-hover); border-color: var(--ui-border); }
  html .mail-analysis .mail-action { border-left-width: 2px; }
  html .auth-sub { line-height: 1.7; }
  html .auth-brand small { font-size: 12px; letter-spacing: .03em; }
  html :is(.auth-foot,.pwd-rule) { font-size: 12px; }

  /* Browser-owned details belong to the active palette as well. */
  html * { scrollbar-width: thin; scrollbar-color: var(--ui-scroll) transparent; }
  html ::-webkit-scrollbar { width: 8px; height: 8px; }
  html ::-webkit-scrollbar-thumb { background: var(--ui-scroll); border: 2px solid transparent; background-clip: padding-box; border-radius: 8px; }
  html ::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
  html ::-webkit-scrollbar-corner { background: transparent; }
  html .view { animation: none; }
  @media (pointer: coarse) {
    html :is(.primary,.secondary,.danger,.auth-submit) { min-height: 42px; }
    html :is(.icon-btn,.sidebar-toggle) { min-width: 40px; min-height: 40px; }
  }
  @media (max-width: 800px) {
    html .page-head h1 { font-size: 24px; }
    html .page-head p { font-size: 12px; }
    html :is(.dialog-head p,.panel-head p) { overflow-wrap: anywhere; }
    html :is(.dialog-actions,.drawer-actions) { gap: 8px; }
    html .language-switch select { font-size: 12px; }
  }
  @media (prefers-reduced-motion: reduce) {
    html *,html *::before,html *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  }
  @media (forced-colors: active) {
    html :is(input,select,textarea):focus { outline-color: Highlight; }
    html :is(.nav-item.active,.tab-btn.active) { outline: 1px solid Highlight; outline-offset: -1px; }
  }
}
