/* ORDERFLOW common-workspace adaptation (not the conditional UI-v2 theme).
 * Load AFTER every page's extra_head stylesheet; opt in on the admin body.
 * This layer owns visual tokens, not layouts, visibility, scrolling or actions.
 * Reference: app.css, workspace-common.css, Button and PageHeader components.
 */

/* 1. Neutral workspace / local fonts only: no CDN or reference-app assets. */
body.wb.wb-admin[data-ui-theme="orderflow"] {
  --wb-canvas: #f9fafb;
  --wb-paper: #fff;
  --wb-panel: #fff;
  --wb-rail: #fff;
  --wb-ink: #111827;
  --wb-muted: #6b7280;
  --wb-line: #e5e7eb;
  --wb-control-line: #d1d5db;
  --wb-hover: #f3f4f6;
  --wb-accent: #2563eb;
  --wb-selected: #eff6ff;
  --wb-aloe: #dbeafe;
  --wb-warning: #fffbeb;
  --wb-warning-line: #fcd34d;
  --wb-warning-ink: #92400e;
  --wb-error: #fef2f2;
  --wb-error-ink: #b91c1c;
  --wb-radius: 10px;
  --wb-pill: 10px;
  /* Older feature fallback names share the same palette. */
  --border: #e5e7eb;
  --surface: #fff;
  --muted: #6b7280;
  font-family: 'Pretendard', 'Noto Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--wb-ink);
  background: var(--wb-canvas);
}

/* 2. Page hierarchy: keep each workflow's existing header composition. */
body.wb.wb-admin[data-ui-theme="orderflow"] h1 {
  /* The shipping-plan mobile stylesheet has a fixed !important title size. */
  font-size: 30px !important;
  line-height: 1.25;
  letter-spacing: -.025em;
  font-weight: 700;
}
body.wb.wb-admin[data-ui-theme="orderflow"] h2 { font-size: 20px; line-height: 1.4; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  .oq-page-heading, .or-page-heading, .pl-heading, .gift-heading, .sg-heading,
  .pk-heading, .dm-heading, .sp-heading, .ce-heading, .wr-heading, .se-heading,
  .intake-entry-heading, .intake-heading, .wb-release-heading, .mo-heading
) { margin-block-end: 24px; gap: 12px 16px; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  .oq-page-heading, .or-page-heading, .pl-heading, .gift-heading, .sg-heading,
  .pk-heading, .dm-heading, .sp-heading, .ce-heading, .wr-heading, .se-heading,
  .intake-entry-heading, .intake-heading, .wb-release-heading, .mo-heading
) h1 { margin-block: 0 8px; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  .helptext, .pl-hint, .pk-hint, .pk-meta, .sg-note, .sg-meta, .dm-hint,
  .ce-boundary, .se-help, .sp-help, .oq-eyebrow, .sp-eyebrow, .mo-eyebrow,
  .oq-message-flag, .dm-badge, .sp-cell-meta, .sp-draft, .sp-kind,
  .sp-matrix header p, .sp-matrix header small, .sp-summary small,
  .sp-summary > div > span:first-child, .dm-detail code,
  small, label, legend, summary, table, th, td, caption
) { font-size: 14px; }
/* Explicit metadata rules prevent old 11–13px desktop type from leaking in. */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  .oq-cell-meta, .oq-item-option, .oq-status, .oq-summary span, .oq-summary p,
  .oq-vendor-rail p, .oq-vendor-rail span, .oq-vendor-rail strong, .oq-data-boundary p,
  .sp-basis, .sp-basis strong, .sp-next-date span, .sp-matrix footer,
  .sp-matrix footer span, .sp-matrix footer strong, .sp-editor p
) { font-size: 14px; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  .gift-heading p, .wr-heading p, .dm-hint, .dm-day-status small,
  .oq-eyebrow, .sp-eyebrow, .mo-eyebrow
) { color: var(--wb-muted); }

/* 3. Controls: explicit button hooks only; ordinary links remain links.
 * No display/width/white-space declarations: preserve native hidden fallbacks,
 * compact numeric columns and all existing responsive control arrangements.
 */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  button, .wb-button, input[type="submit"], input[type="reset"], input[type="button"]
) {
  min-height: 44px !important;
  padding: 8px 16px;
  border: 1px solid var(--wb-control-line);
  border-radius: 10px;
  background: var(--wb-paper);
  color: var(--wb-ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 1px 2px rgb(15 23 42 / .04);
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  button, .wb-button, input[type="submit"], input[type="reset"], input[type="button"]
):not(:disabled):not([aria-disabled="true"]):hover {
  background: var(--wb-hover);
  border-color: #9ca3af;
  color: var(--wb-ink);
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-secondary, .wb-button-secondary) {
  background: #f3f4f6;
  border-color: #e5e7eb;
  color: #374151;
}
/* Canonical primary aliases. Only visual colors need !important to supersede
 * the feature-local dm-primary colors; never override validation/visibility.
 * Query actions must lose their primary class in markup, not via CSS guessing.
 */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-primary, .wb-button-primary, .dm-primary) {
  background: #2563eb !important;
  border-color: #2563eb !important;
  color: #fff !important;
  box-shadow: 0 1px 2px rgb(15 23 42 / .08), 0 4px 12px rgb(37 99 235 / .14);
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-primary, .wb-button-primary, .dm-primary):not(:disabled):not([aria-disabled="true"]):hover {
  background: #1d4ed8 !important;
  border-color: #1d4ed8 !important;
  color: #fff !important;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-primary, .wb-button-primary, .dm-primary):not(:disabled):not([aria-disabled="true"]):active {
  background: #1e40af !important;
  border-color: #1e40af !important;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-danger, .wb-button-danger, [data-ui-variant="destructive"]) {
  background: #b91c1c !important;
  border-color: #b91c1c !important;
  color: #fff !important;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-danger, .wb-button-danger, [data-ui-variant="destructive"]):not(:disabled):not([aria-disabled="true"]):hover {
  background: #991b1b !important;
  border-color: #991b1b !important;
}

/* 4. Native inputs: do not touch type=hidden, radios, checkbox dimensions,
 * original widths, textarea resizing, invalid state or HTML form semantics. */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  input:not([type]), input[type="text"], input[type="search"], input[type="email"],
  input[type="password"], input[type="url"], input[type="tel"], input[type="number"],
  input[type="date"], input[type="time"], input[type="datetime-local"],
  input[type="file"], select, textarea
) {
  min-height: 44px !important;
  padding: 8px 12px;
  border: 1px solid var(--wb-control-line);
  border-radius: 10px;
  background: var(--wb-paper);
  color: var(--wb-ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}
body.wb.wb-admin[data-ui-theme="orderflow"] textarea { min-height: 96px !important; }
body.wb.wb-admin[data-ui-theme="orderflow"] input:is([type="checkbox"], [type="radio"]) { accent-color: #2563eb; }
body.wb.wb-admin[data-ui-theme="orderflow"] :focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-main, .wb-scroll, tr):focus-visible { outline-offset: -3px; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(input, select, textarea)[aria-invalid="true"] {
  border-color: var(--wb-error-ink);
  box-shadow: 0 0 0 1px var(--wb-error-ink);
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(input, textarea)[readonly] { background: #f9fafb; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(button, input, select, textarea, .wb-button):is(:disabled, [aria-disabled="true"]) {
  background: #f3f4f6 !important;
  border-color: #d1d5db !important;
  color: #6b7280 !important;
  border-style: dashed;
  box-shadow: none;
  opacity: 1;
  cursor: not-allowed;
}

/* 5. Work tabs / sidebar: selection has a persistent non-color cue. */
body.wb.wb-admin[data-ui-theme="orderflow"] > .wb-header { background: var(--wb-rail); border-color: var(--wb-line); }
body.wb.wb-admin[data-ui-theme="orderflow"] .wb-task-nav a { color: var(--wb-ink); border-radius: 10px; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-task-nav, .wb-nav, .oq-tabs, .gift-tabs, .dm-tabs, .intake-actions) a {
  border-radius: 10px;
  font-size: 14px;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-task-nav, .wb-nav, .oq-tabs, .gift-tabs, .dm-tabs, .intake-actions) a:not([aria-current]):hover { background: var(--wb-hover); }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-task-nav, .wb-nav, .oq-tabs, .gift-tabs, .dm-tabs, .intake-actions, .sg-filter-bar) :is([aria-current="page"], [aria-current="true"], [aria-selected="true"], [aria-pressed="true"]) {
  background: #eff6ff;
  border-color: #2563eb;
  color: #1d4ed8;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .3em;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.dm-selected, .pk-selected, .gift-table tr.is-selected) {
  background: #eff6ff;
  border-color: #2563eb;
  box-shadow: inset 3px 0 #2563eb;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.dm-original, .gift-table th) { background: var(--wb-canvas); border-color: var(--wb-line); }
body.wb.wb-admin[data-ui-theme="orderflow"] .dm-detail summary { color: var(--wb-ink); }

/* 6. Table rhythm: block padding only. Preserve inline padding (especially
 * narrow numeric cells), widths, alignment, nowrap, sticky and scroll wrappers.
 * Do not paint every tbody cell: held/error/selected row colors must survive.
 */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(th, td) {
  padding-block: 10px;
  border-bottom-color: var(--wb-line);
  line-height: 1.5;
}
body.wb.wb-admin[data-ui-theme="orderflow"] thead th {
  background-color: #f9fafb;
  color: #374151;
  font-weight: 600;
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.oq-table, .gift-table, .wb-table) tr:is([data-selected], [aria-selected="true"], .is-selected) {
  background: #eff6ff;
  box-shadow: inset 3px 0 #2563eb;
}

/* 7. Panel and filter spacing, without imposing a page/grid composition. */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-panel, .dm-list, .dm-detail, .pl-toolbar, .se-group) {
  border-color: var(--wb-line);
  border-radius: 10px;
  background: var(--wb-paper);
}
body.wb.wb-admin[data-ui-theme="orderflow"] :is(
  .oq-filters, .pl-filters, .gift-filters, .pk-filters, .dm-search, .ce-filters,
  .wr-batch-form, .se-controls, .sg-date-form
) { gap: 12px; }
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-actions, .dm-actions, .sg-heading-actions) { gap: 8px; }
/* Success is not selection. Existing warning/error classes retain their rules. */
body.wb.wb-admin[data-ui-theme="orderflow"] :is(.wb-state-pass, .wb-notice[data-level="success"], .oq-status-complete, .or-status-complete) {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #166534;
}

/* 8. Mobile and system accessibility: keep existing screen breakpoints/layout. */
@media (max-width: 48rem) {
  body.wb.wb-admin[data-ui-theme="orderflow"] h1 { font-size: 24px !important; }
  body.wb.wb-admin[data-ui-theme="orderflow"] :is(
    input:not([type]), input[type="text"], input[type="search"], input[type="email"],
    input[type="password"], input[type="url"], input[type="tel"], input[type="number"],
    input[type="date"], input[type="time"], input[type="datetime-local"],
    input[type="file"], select, textarea
  ) { font-size: 16px; }
}
@media (forced-colors: active) {
  body.wb.wb-admin[data-ui-theme="orderflow"] :focus-visible { outline-color: Highlight; }
  body.wb.wb-admin[data-ui-theme="orderflow"] :is([aria-current="page"], [aria-selected="true"], .dm-selected, .pk-selected) { outline: 2px solid Highlight; outline-offset: -2px; }
  body.wb.wb-admin[data-ui-theme="orderflow"] :is(button, input, select, textarea, .wb-button):is(:disabled, [aria-disabled="true"]) { color: GrayText !important; border-color: GrayText !important; }
}
