/* Picking V3 — tokens no padrão Sonder (Orchestrator), marca operacional. */

@layer tokens, base, components, pages;

@layer tokens {
  :root {
    --sonder-cream: #f2e8d5;
    --sonder-paper: #fffdf8;
    --sonder-navy: #0e2a47;
    --sonder-terra: #c25a3c;
    --sonder-terra-deep: #a8492f;
    --sonder-blue: #1e4d7b;
    --sonder-ink: #1b1b1b;

    --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

    --text-2xs: 0.75rem;
    --text-xs: 0.8125rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.25rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;

    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-pill: 999px;

    --sidebar-width: 220px;
    --sidebar-rail: 72px;
    --topbar-height: 56px;
    --control-sm: 2rem;
    --control-md: 2.375rem;
    --control-lg: 2.75rem;
    --content-max: 68rem;

    --dur-1: 120ms;
    --dur-2: 200ms;
    --dur-3: 320ms;
    --dur-4: 560ms;
    --ease-standard: cubic-bezier(0.2, 0, 0, 1);
    --ease-emphasized: cubic-bezier(0.3, 0, 0, 1);
    --ease-exit: cubic-bezier(0.4, 0, 1, 1);
    --stagger: 40ms;

    /* Sombras em camadas (Orchestrator / guia Sonder) — elevação real, sem glow. */
    --shadow-xs: 0 1px 2px rgb(14 42 71 / 5%);
    --shadow-sm: 0 1px 3px rgb(14 42 71 / 8%), 0 1px 2px rgb(14 42 71 / 4%);
    --shadow-md: 0 8px 24px rgb(14 42 71 / 8%);
    --shadow-lg: 0 12px 32px rgb(27 27 27 / 12%);
    --shadow-xl: 0 18px 50px rgb(14 42 71 / 22%);
    --shadow-card: 0 16px 40px rgb(27 27 27 / 7%);
    --shadow-lift: 0 6px 14px -6px rgb(14 42 71 / 40%), 0 1px 2px rgb(0 0 0 / 6%);
  }

  :root,
  [data-theme="light"] {
    color-scheme: light;
    --bg: #f4eee3;
    --surface: #fffdf9;
    --surface-2: #f9f5ee;
    --raised: #ffffff;
    --fg: var(--sonder-ink);
    --fg-2: #3e3830;
    --fg-muted: #635a4d;
    --heading: var(--sonder-navy);
    --line: #e3dacb;
    --line-strong: #c9beac;
    --field-border: #8a7f70;
    --primary: var(--sonder-navy);
    --primary-hover: var(--sonder-blue);
    --on-primary: #fffdf9;
    --accent: var(--sonder-terra-deep);
    --accent-soft: rgb(194 90 60 / 12%);
    --focus: var(--sonder-blue);
    --success: #2f6b4f;
    --success-bg: #e5efe8;
    --warning: #8a6116;
    --warning-bg: #f6ecd6;
    --danger: #a3341f;
    --danger-bg: #f8e3dd;
    --danger-hover: #852916;
    --on-danger: #fffdf9;
    --scrim: rgb(14 42 71 / 45%);
    --sidebar-bg: var(--sonder-navy);
    --sidebar-edge: transparent;
    --sidebar-fg: var(--sonder-cream);
    --sidebar-muted: #b4b2a8;
    --sidebar-hover: rgb(242 232 213 / 7%);
    --sidebar-active: rgb(242 232 213 / 10%);
    --sidebar-border: rgb(242 232 213 / 12%);
    --sidebar-accent: #d4694a;
    --sidebar-focus: #f0a58c;
  }

  [data-theme="dark"] {
    color-scheme: dark;
    /* Navy em degraus (guia §11.2) — nunca quase-preto. */
    --bg: #0e1a26;
    --surface: #142231;
    --surface-2: #192a3b;
    --raised: #1d3044;
    --fg: #f2e8d5;
    --fg-2: #dcd2c0;
    --fg-muted: #bcb19e;
    --heading: #f7efe2;
    --line: #24384c;
    --line-strong: #3a5068;
    --field-border: #7d8896;
    --primary: #e8dcc6;
    --primary-hover: #f2e8d5;
    --on-primary: #0e1a26;
    --accent: #e07b5c;
    --accent-soft: rgb(236 154 127 / 14%);
    --focus: #f0a58c;
    --success: #7dba98;
    --success-bg: #1c3228;
    --warning: #e0b35a;
    --warning-bg: #3a3018;
    --danger: #e07a66;
    --danger-bg: #3a221c;
    --danger-hover: #c25a3c;
    --on-danger: #fff8ec;
    --scrim: rgb(0 0 0 / 55%);
    --sidebar-bg: #0a1520;
    --sidebar-edge: #142231;
    --sidebar-fg: #ede6d8;
    --sidebar-muted: #9aa3ab;
    --sidebar-hover: rgb(237 230 216 / 6%);
    --sidebar-active: rgb(237 230 216 / 10%);
    --sidebar-border: rgb(237 230 216 / 12%);
    --sidebar-accent: #d4694a;
    --sidebar-focus: #f0a58c;
    --shadow-xs: 0 1px 2px rgb(0 0 0 / 28%);
    --shadow-sm: 0 1px 3px rgb(0 0 0 / 32%), 0 1px 2px rgb(0 0 0 / 18%);
    --shadow-md: 0 10px 28px rgb(0 0 0 / 38%);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 45%);
    --shadow-xl: 0 22px 56px rgb(0 0 0 / 50%);
    --shadow-card: 0 18px 44px rgb(0 0 0 / 35%);
    --shadow-lift: 0 8px 18px -6px rgb(0 0 0 / 55%), 0 1px 2px rgb(0 0 0 / 25%);
  }
}

@layer base {
  * { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body {
    margin: 0;
    min-height: 100vh;
    background:
      radial-gradient(900px 380px at 100% -8%, rgb(194 90 60 / 7%), transparent 50%),
      radial-gradient(700px 320px at -5% 20%, rgb(30 77 123 / 6%), transparent 45%),
      var(--bg);
    color: var(--fg);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: var(--weight-regular);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  [data-theme="dark"] body {
    background:
      radial-gradient(800px 360px at 100% 0%, rgb(208 105 74 / 8%), transparent 48%),
      var(--bg);
  }
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns var(--dur-3) var(--ease-emphasized);
  }
  .app-shell.sidebar-collapsed {
    grid-template-columns: var(--sidebar-rail) minmax(0, 1fr);
  }
  body.locked .app-shell { display: none; }
  body:not(.locked) #loginPage { display: none; }
  .sidebar-scrim {
    display: none;
  }

  .login-page {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
      radial-gradient(900px 420px at 12% -10%, rgb(194 90 60 / 12%), transparent 55%),
      linear-gradient(165deg, var(--bg), var(--surface-2));
  }
  .login-card {
    width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); padding: 32px 28px 22px;
    animation: rise var(--dur-3) var(--ease-emphasized);
  }
  .setup-card { width: min(460px, 100%); }
  .login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
  .login-brand strong { display: block; color: var(--heading); font-size: var(--text-base); }
  .login-brand span { display: block; color: var(--fg-muted); font-size: var(--text-2xs); }
  .login-card h1 { font-size: var(--text-xl); margin-bottom: 4px; }
  .login-lead { margin-bottom: 18px; font-size: var(--text-xs); }
  .login-submit { width: 100%; margin-top: 18px; }
  .credit {
    margin-top: 18px; text-align: center; color: var(--fg-muted);
    font-size: var(--text-2xs); letter-spacing: 0.02em;
  }
  .sidebar-credit { margin: 4px 2px 0; text-align: left; color: var(--sidebar-muted); }

  .qr-large img { width: 100%; height: 100%; object-fit: contain; display: block; }
  .qr-large {
    width: min(240px, 70vw); aspect-ratio: 1; margin: 12px auto; padding: 10px;
    background: #fff; border-radius: var(--radius-md); border: 1px solid var(--line);
  }
  .qr-url { word-break: break-all; text-align: center; font-size: 11px; }
  .qr-help {
    margin: 0;
    padding-left: 1.15rem;
    font-size: 12px;
    line-height: 1.45;
    text-align: left;
  }
  .qr-help li + li { margin-top: 0.35rem; }
  .qr-modal-body .modal-actions { flex-wrap: wrap; }

  .toolbar {
    display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: var(--space-4); align-items: center;
  }
  .search-field {
    flex: 1 1 220px; min-width: 180px;
    display: flex; align-items: center; gap: 10px;
    min-height: var(--control-md); padding: 0 12px;
    border: 1px solid var(--field-border); border-radius: var(--radius-sm);
    background: var(--raised);
  }
  .search-field:focus-within { border-color: var(--focus); }
  .search-field input {
    flex: 1; min-width: 0; width: auto; min-height: calc(var(--control-md) - 2px);
    padding: 8px 0; border: 0 !important; background: transparent !important;
    box-shadow: none !important; outline: none;
  }
  .search-ico {
    flex: 0 0 18px; width: 18px; height: 18px; color: var(--fg-muted);
    display: grid; place-items: center; pointer-events: none;
  }
  .search-ico .icon { width: 18px; height: 18px; display: block; }
  .toolbar select {
    min-height: var(--control-md); min-width: 180px; padding: 8px 12px;
    border: 1px solid var(--field-border); border-radius: var(--radius-sm); background: var(--raised);
  }

  .choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .choice-card {
    display: grid; gap: 6px; text-align: left; padding: 16px; border-radius: var(--radius-md);
    border: 1px solid var(--line); background: var(--raised); cursor: pointer; color: inherit;
    transition: border-color var(--dur-1), transform var(--dur-1), box-shadow var(--dur-1);
  }
  .choice-card:hover { border-color: var(--focus); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
  .choice-card strong { color: var(--heading); }
  .choice-card span { color: var(--fg-muted); font-size: var(--text-xs); }
  .items-title { margin: 16px 0 8px; font-size: var(--text-sm); }
  .items-head { margin-top: 8px; }
  .line-row {
    display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.4fr) 72px 64px auto;
    gap: 8px; align-items: end; padding: 8px 0; border-top: 1px solid var(--line);
  }
  .line-row .field { margin-top: 0; }

  @media (max-width: 860px) {
    .choice-grid { grid-template-columns: 1fr; }
    .line-row { grid-template-columns: 1fr 1fr; }
  }
  h1, h2, h3, h4 { color: var(--heading); font-weight: var(--weight-semibold); letter-spacing: -0.02em; margin: 0; }
  h1 { font-size: clamp(1.5rem, 2.4vw, 2rem); line-height: 1.15; font-weight: var(--weight-bold); }
  h2 { font-size: var(--text-lg); }
  h3 { font-size: var(--text-base); }
  p { margin: 0; }
  a { color: var(--focus); }
  button, input, select, textarea { font: inherit; color: inherit; }
  :focus-visible {
    outline: 2px solid var(--bg);
    outline-offset: 0;
    box-shadow: 0 0 0 4px var(--focus);
  }
  .tabular { font-variant-numeric: tabular-nums; }
  .mono { font-family: var(--font-mono); font-size: var(--text-xs); }
  .muted { color: var(--fg-muted); }
  .hidden, [hidden] { display: none !important; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); border: 0;
  }
}

@layer components {
  .icon {
    width: 18px; height: 18px; stroke: currentColor; fill: none;
    stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto;
  }
  .icon.sm { width: 16px; height: 16px; }
  .icon.lg { width: 20px; height: 20px; }

  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--control-md); padding: 0 14px; border-radius: var(--radius-sm);
    border: 1px solid transparent; background: var(--primary); color: var(--on-primary);
    font-family: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold);
    letter-spacing: -0.01em; cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: transform var(--dur-1) var(--ease-standard), box-shadow var(--dur-1) var(--ease-standard),
      background var(--dur-1) var(--ease-standard), border-color var(--dur-1) var(--ease-standard);
  }
  .btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
  .btn:active { transform: scale(0.95); box-shadow: none; }
  .btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
  .btn.secondary {
    background: var(--raised); color: var(--fg); border-color: var(--line-strong);
    box-shadow: none;
  }
  .btn.secondary:hover { background: var(--surface-2); box-shadow: var(--shadow-sm); }
  .btn.ghost {
    background: transparent; color: var(--sidebar-fg);
    border-color: transparent; box-shadow: none;
  }
  .btn.ghost:hover { background: var(--sidebar-hover); box-shadow: none; transform: none; }
  .btn.danger { background: var(--danger); color: var(--on-danger); }
  .btn.danger:hover { background: var(--danger-hover); }
  .btn.accent { background: var(--accent); color: #fffdf9; }
  .btn.accent:hover { filter: brightness(1.04); }
  .btn.sm { min-height: var(--control-sm); padding: 0 10px; font-size: var(--text-xs); }
  .btn.lg { min-height: var(--control-lg); padding: 0 18px; }
  .btn.icon-only { width: var(--control-md); padding: 0; }

  .field { display: grid; gap: 6px; margin-top: var(--space-3); }
  .field > span, .field-label {
    font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--fg-muted);
    letter-spacing: 0.02em;
  }
  .field input, .field select, .field textarea,
  input[type="text"], input[type="password"], input[type="search"], input[type="number"],
  input[type="date"], input[type="file"], select, textarea {
    width: 100%; min-height: var(--control-md); padding: 8px 12px;
    border: 1px solid var(--field-border); border-radius: var(--radius-sm);
    background: var(--raised); color: var(--fg);
    transition: border-color var(--dur-1) var(--ease-standard), box-shadow var(--dur-1) var(--ease-standard);
  }
  .field input:focus, .field select:focus, .field textarea:focus,
  input:focus, select:focus, textarea:focus { border-color: var(--focus); }
  .field-error { color: var(--danger); font-size: var(--text-xs); }
  .field[aria-invalid="true"] input { border-color: var(--danger); }
  .password-wrap { position: relative; }
  .password-wrap input { padding-right: 44px; }
  .password-wrap .btn.icon-only {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    background: transparent; color: var(--fg-muted); border: 0; box-shadow: none;
  }
  .check-row {
    display: flex; align-items: center; gap: 8px; margin-top: var(--space-3);
    font-size: var(--text-sm); color: var(--fg-2);
  }
  .check-row input { width: auto; min-height: auto; }

  .badge {
    display: inline-flex; align-items: center; gap: 6px; min-height: 24px;
    padding: 0 10px; border-radius: var(--radius-pill); background: var(--surface-2);
    color: var(--fg-2); font-size: var(--text-2xs); font-weight: var(--weight-semibold);
    letter-spacing: 0.04em; text-transform: uppercase;
  }
  .badge.ok { background: var(--success-bg); color: var(--success); }
  .badge.warn { background: var(--warning-bg); color: var(--warning); }
  .badge.danger { background: var(--danger-bg); color: var(--danger); }

  .panel {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card); padding: var(--space-5) var(--space-6);
  }
  .panel + .panel { margin-top: var(--space-4); }
  .section-head {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    margin-bottom: var(--space-4);
  }
  .section-head h2 {
    margin: 0; font-size: var(--text-lg); font-weight: var(--weight-semibold);
    letter-spacing: -0.02em; color: var(--heading);
  }
  .metrics {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: var(--space-3);
    margin-bottom: var(--space-5);
  }
  .metric {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
    box-shadow: var(--shadow-card);
    position: relative; overflow: hidden;
    animation: rise var(--dur-3) var(--ease-emphasized) both;
    transition: transform var(--dur-1) var(--ease-standard), box-shadow var(--dur-1) var(--ease-standard);
  }
  .metric:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
  .metric::before {
    content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px;
    border-radius: 0 2px 2px 0; background: var(--accent);
  }
  .metric:nth-child(2) { animation-delay: var(--stagger); }
  .metric:nth-child(3) { animation-delay: calc(var(--stagger) * 2); }
  .metric:nth-child(4) { animation-delay: calc(var(--stagger) * 3); }
  .metric:nth-child(5) { animation-delay: calc(var(--stagger) * 4); }
  .metric .label {
    font-size: 11px; font-weight: var(--weight-semibold); color: var(--fg-muted);
    letter-spacing: 0.06em; text-transform: uppercase;
  }
  .metric .value {
    margin-top: 6px; font-size: var(--text-xl); font-weight: var(--weight-bold);
    letter-spacing: -0.03em; font-variant-numeric: tabular-nums; color: var(--heading);
  }

  .data-table { width: 100%; border-collapse: collapse; }
  .data-table th, .data-table td {
    padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle;
  }
  .data-table th {
    background: var(--surface-2); font-size: var(--text-2xs); font-weight: var(--weight-semibold);
    color: var(--fg-muted); letter-spacing: 0.06em; text-transform: uppercase;
  }
  .data-table tbody tr { transition: background var(--dur-1) var(--ease-standard); }
  .data-table tbody tr:hover { background: var(--surface-2); }
  .data-table .actions-cell { opacity: 0.55; transition: opacity var(--dur-1); }
  .data-table tr:hover .actions-cell { opacity: 1; }
  .row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

  .empty {
    display: grid; place-items: center; gap: 10px; text-align: center;
    padding: 48px 20px; color: var(--fg-muted);
  }
  .empty strong { color: var(--heading); font-size: var(--text-base); }

  .skeleton {
    background: linear-gradient(90deg, var(--surface-2), var(--raised), var(--surface-2));
    background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
    border-radius: var(--radius-sm); height: 14px;
  }

  /* dialog modeless fica na top-layer (acima dos modais) */
  .toast-host {
    position: fixed; inset: auto 16px 16px auto; margin: 0; padding: 0;
    border: 0; background: transparent; max-width: none;
    width: min(380px, calc(100vw - 24px));
    display: grid; gap: 8px; z-index: 2147483647;
    pointer-events: none;
  }
  .toast-host[open] { display: grid; }
  .toast-host::backdrop { display: none; }
  .toast {
    pointer-events: auto;
    display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start;
    padding: 12px 14px; border-radius: var(--radius-md); background: var(--raised);
    border: 1px solid var(--line); box-shadow: var(--shadow-lg);
    animation: toast-in var(--dur-2) var(--ease-emphasized);
  }
  .toast.ok { border-color: var(--success); background: var(--success-bg); color: var(--success); }
  .toast.danger {
    border-color: var(--danger); background: var(--danger-bg); color: var(--danger);
    font-weight: var(--weight-semibold);
  }
  .toast.warn { border-color: var(--warning); background: var(--warning-bg); color: var(--warning); }

  .modal {
    border: 0; padding: 0; border-radius: var(--radius-lg); background: transparent;
    width: min(520px, calc(100vw - 24px)); box-shadow: var(--shadow-lg);
  }
  .modal.wide { width: min(780px, calc(100vw - 24px)); }
  .modal::backdrop {
    background: var(--scrim); animation: fade var(--dur-2) var(--ease-standard);
  }
  .modal[open] { animation: modal-in var(--dur-3) var(--ease-emphasized); }
  .modal-body {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
    padding: var(--space-5) var(--space-6); position: relative;
    box-shadow: var(--shadow-xl);
  }
  .modal-body header { margin-bottom: var(--space-4); padding-right: 40px; }
  .modal-body header p { margin-top: 4px; color: var(--fg-muted); font-size: var(--text-xs); }
  .modal-close {
    position: absolute; top: 12px; right: 12px; z-index: 2;
  }
  .field-code-bad input {
    border-color: var(--danger) !important; background: var(--danger-bg);
  }
  .check-warn {
    margin-top: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
    background: var(--danger-bg); color: var(--danger);
    border: 2px solid var(--danger);
    font-size: var(--text-sm); font-weight: var(--weight-bold);
    line-height: 1.35;
  }
  .check-warn-flash { animation: warn-pulse 0.9s var(--ease-emphasized) 2; }
  @keyframes warn-pulse {
    0%, 100% { transform: scale(1); box-shadow: none; }
    50% { transform: scale(1.02); box-shadow: 0 0 0 4px rgb(163 52 31 / 25%); }
  }
  .modal-inline-toast {
    position: sticky; top: 0; z-index: 5; margin: 0 0 12px;
    pointer-events: auto;
  }
  #checkSubmit:disabled {
    opacity: 0.45; cursor: not-allowed; filter: grayscale(0.35);
  }
  .divergence-panel { margin-top: var(--space-3); }
  .modal-actions {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: var(--space-5);
  }
  .view-grid {
    display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; margin: var(--space-3) 0;
  }
  .view-grid dt { color: var(--fg-muted); font-size: var(--text-xs); font-weight: var(--weight-semibold); }
  .view-grid dd { margin: 0; color: var(--fg); }
  .dirty-bar {
    position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center;
    gap: 12px; margin-top: var(--space-4); padding: 10px 12px; border-radius: var(--radius-sm);
    background: var(--warning-bg); color: var(--warning); border: 1px solid var(--line);
  }

  .picking-view {
    width: min(100%, 42rem);
    margin: 0 auto;
  }
  .picking-toolbar {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
    margin-bottom: var(--space-4);
  }
  .picking-order-field { flex: 1 1 220px; margin: 0; }
  .pick-area { display: grid; gap: 0; }
  .item-card {
    border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px;
    margin-top: 10px; background: var(--raised);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--dur-1), background var(--dur-1), transform var(--dur-1), box-shadow var(--dur-1);
    display: grid;
    grid-template-columns: minmax(100px, 118px) minmax(0, 1fr) auto;
    gap: 14px; align-items: center;
  }
  .item-card:hover {
    transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: var(--line-strong);
  }
  .item-card.done { background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 35%, var(--line)); }
  .item-card .item-body { min-width: 0; display: grid; gap: 2px; }
  .item-card .code {
    font-family: var(--font-mono); font-size: var(--text-xs); font-weight: var(--weight-semibold);
    letter-spacing: -0.02em; color: var(--fg-muted);
  }
  .item-card .item-location {
    display: flex; flex-direction: column; gap: 2px; min-width: 0;
    padding: 10px 12px; border-radius: var(--radius-sm);
    background: linear-gradient(145deg, var(--sonder-navy), #164062);
    color: var(--sonder-cream);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 10%), var(--shadow-xs);
  }
  .item-card .item-location .loc-kicker {
    font-size: 10px; font-weight: var(--weight-semibold); letter-spacing: 0.08em;
    text-transform: uppercase; opacity: 0.75;
  }
  .item-card .item-location .loc-value {
    font-family: var(--font-mono); font-size: 1rem; font-weight: var(--weight-bold);
    letter-spacing: 0.02em; line-height: 1.15; word-break: break-word;
  }
  .item-card .item-location.missing {
    background: var(--warning-bg); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 35%, var(--line));
  }
  .item-card .item-desc { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--heading); margin: 0; }
  .item-card .item-qty { margin: 0; color: var(--fg-2); font-size: var(--text-xs); }
  .item-card .pick-item-actions {
    display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center;
  }
  .pick-progress {
    display: grid; gap: 6px; margin: 0 0 var(--space-4);
    padding: 12px 14px; border-radius: var(--radius-md);
    background: var(--surface); border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
  }
  .pick-progress-meta {
    display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
    font-size: var(--text-xs); color: var(--fg-muted);
  }
  .pick-progress-meta strong { color: var(--heading); font-size: var(--text-sm); }
  .pick-progress-bar {
    height: 8px; border-radius: 999px; background: var(--line); overflow: hidden;
  }
  .pick-progress-bar > span {
    display: block; height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--sonder-terra-deep), #d4694a);
    transition: width var(--dur-3) var(--ease-emphasized);
  }
  .pick-head h3 {
    margin: 0; font-size: clamp(1.25rem, 2.5vw, 1.6rem);
    letter-spacing: -0.03em; color: var(--heading);
  }
  .pick-head .meta { margin: 4px 0 0; }

  .check-order-ref { margin: 4px 0 0; color: var(--fg-muted); font-size: var(--text-xs); }
  .check-context {
    display: grid; gap: 10px; margin-bottom: var(--space-4);
  }
  .check-context.compact { margin-bottom: var(--space-3); }
  .check-location {
    display: grid; gap: 4px; padding: 16px 18px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--sonder-navy) 0%, #164062 100%);
    color: var(--sonder-cream);
    border: 1px solid transparent;
    grid-template-columns: auto 1fr;
    align-items: start;
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 10%), var(--shadow-md);
  }
  .check-location-label { grid-row: 1 / span 2; margin-top: 2px; opacity: 0.85; }
  .check-location .check-location-kicker,
  .check-location .check-location-value { grid-column: 2; }
  .check-location.missing {
    background: var(--warning-bg); color: var(--warning);
    border-color: color-mix(in srgb, var(--warning) 40%, var(--line));
  }
  .check-location-kicker {
    font-size: 11px; font-weight: var(--weight-semibold);
    letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8;
  }
  .check-location-value {
    font-family: var(--font-mono); font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: var(--weight-bold); letter-spacing: 0.03em; line-height: 1.1;
  }
  .check-product { display: grid; gap: 8px; }
  .check-desc {
    margin: 0; font-size: var(--text-sm); font-weight: var(--weight-semibold);
    color: var(--heading); line-height: 1.35;
  }
  .check-facts {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
    margin: 0;
  }
  .check-facts > div {
    padding: 8px 10px; border-radius: var(--radius-sm);
    background: var(--surface-2); border: 1px solid var(--line);
  }
  .check-facts dt {
    margin: 0; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--fg-muted); font-weight: var(--weight-semibold);
  }
  .check-facts dd {
    margin: 2px 0 0; font-family: var(--font-mono); font-size: var(--text-sm);
    font-weight: var(--weight-bold); color: var(--heading);
  }
  .check-sku-line {
    margin: 0; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-muted);
  }
  .field-hint {
    display: block; margin-top: 6px; font-size: var(--text-2xs); color: var(--fg-muted);
  }
  .settings-lead { margin-top: 4px; font-size: 13px; }
  .settings-form { display: grid; gap: 10px; margin-top: var(--space-2); max-width: 40rem; }
  .settings-acc {
    margin: 0; border: 1px solid var(--line); border-radius: var(--radius-md);
    background: var(--raised); overflow: hidden;
  }
  .settings-acc > summary {
    list-style: none; cursor: pointer; display: flex; justify-content: space-between;
    align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface-2);
    font-weight: var(--weight-semibold); color: var(--heading); font-size: var(--text-sm);
  }
  .settings-acc > summary::-webkit-details-marker { display: none; }
  .settings-acc-hint {
    display: block; margin-top: 2px; font-weight: var(--weight-regular);
    font-size: var(--text-2xs); color: var(--fg-muted);
  }
  .settings-acc-chev { color: var(--fg-muted); transition: transform var(--dur-2) var(--ease-standard); }
  .settings-acc[open] > summary .settings-acc-chev { transform: rotate(180deg); }
  .settings-acc-body { padding: 4px 16px 14px; }
  .settings-row {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
    padding: 12px 0; border-top: 1px solid var(--line);
  }
  .settings-row span { display: grid; gap: 2px; min-width: 0; }
  .settings-row strong { font-size: var(--text-sm); color: var(--heading); }
  .settings-row small { color: var(--fg-muted); font-size: var(--text-2xs); line-height: 1.4; }
  .settings-row input[type="checkbox"] {
    width: 1.15rem; height: 1.15rem; margin-top: 2px; flex: 0 0 auto; accent-color: var(--accent);
  }
  .settings-row-action { align-items: center; }
  .settings-facts {
    display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px;
    margin: 12px 0; font-size: var(--text-xs);
  }
  .settings-facts dt { color: var(--fg-muted); }
  .settings-facts dd { margin: 0; font-family: var(--font-mono); color: var(--heading); }
  .settings-saved { margin: 0; font-size: var(--text-xs); }
  body.density-compact .item-card { padding: 10px; margin-top: 8px; gap: 10px; }
  body.density-compact .item-card .item-location .loc-value { font-size: 0.95rem; }
  body.density-compact .metrics { margin-bottom: var(--space-3); }
  @media (max-width: 720px) {
    .item-card {
      grid-template-columns: 1fr;
      align-items: stretch;
    }
    .item-card .pick-item-actions { justify-content: stretch; }
    .item-card .pick-item-actions .btn { flex: 1; }
  }
  .tabular { font-variant-numeric: tabular-nums; }
}

@layer pages {
  .sidebar {
    --color-focus: var(--sidebar-focus);
    position: sticky; top: 0; height: 100vh; z-index: 20;
    display: flex; flex-direction: column; gap: var(--space-6);
    background:
      linear-gradient(180deg, rgb(242 232 213 / 4%) 0%, transparent 28%),
      var(--sidebar-bg);
    color: var(--sidebar-fg);
    padding: var(--space-6) 0.875rem 1rem;
    border-right: 1px solid var(--sidebar-edge);
    box-shadow: 8px 0 28px rgb(14 42 71 / 10%);
    transition: width var(--dur-3) var(--ease-emphasized), padding var(--dur-2) var(--ease-standard);
    overflow-x: hidden;
    overflow-y: auto;
  }
  [data-theme="dark"] .sidebar {
    box-shadow: 10px 0 32px rgb(0 0 0 / 35%);
  }
  .sidebar-top {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
    padding: 0 0.35rem;
  }
  .brand { display: flex; gap: 12px; align-items: center; min-width: 0; flex: 1; }
  .brand-mark {
    width: 2.25rem; height: 2.25rem; border-radius: 10px; display: grid; place-items: center;
    background: var(--sonder-cream); color: var(--sonder-navy);
    font-weight: var(--weight-bold); font-size: 14px; letter-spacing: -0.02em;
    flex: 0 0 auto;
    box-shadow: inset 0 0 0 1px rgb(242 232 213 / 25%), 0 6px 14px rgb(0 0 0 / 18%);
  }
  .login-brand .brand-mark {
    background: var(--accent); color: #fffdf9;
    box-shadow: var(--shadow-sm);
  }
  .brand-copy { min-width: 0; }
  .brand strong {
    display: block; font-size: var(--text-base); font-weight: var(--weight-semibold);
    letter-spacing: -0.02em; color: var(--sidebar-fg);
  }
  .brand span {
    display: block; color: var(--sidebar-muted); font-size: 11px; margin-top: 3px;
    letter-spacing: 0.08em; text-transform: uppercase; font-weight: var(--weight-medium);
  }
  .sidebar-toggle {
    color: var(--sidebar-muted); flex: 0 0 auto;
    opacity: 0.85;
  }
  .sidebar-toggle:hover { color: var(--sidebar-fg); opacity: 1; }
  .nav { display: grid; gap: 2px; margin-top: 2px; }
  .nav-item {
    display: flex; align-items: center; gap: 0.625rem; width: 100%; text-align: left;
    min-height: 2.25rem; padding: 0.4rem 0.7rem; border: 0; border-radius: 8px;
    background: transparent; color: var(--sidebar-muted); cursor: pointer;
    font-family: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium);
    position: relative;
    transition: background var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
  }
  .nav-item .icon { opacity: 0.85; }
  .nav-item:hover {
    background: var(--sidebar-hover); color: var(--sidebar-fg);
  }
  .nav-item:hover .icon { opacity: 1; }
  .nav-item.active {
    background: var(--sidebar-active); color: var(--sidebar-fg);
  }
  .nav-item.active .icon { opacity: 1; }
  .nav-item.active::before {
    content: ""; position: absolute; left: 0; top: 0.45rem; bottom: 0.45rem; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--sidebar-accent);
  }
  .nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar-foot {
    margin-top: auto; display: grid; gap: 12px; padding: 14px 0.35rem 0;
    border-top: 1px solid var(--sidebar-border);
  }
  .sidebar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .conn { display: flex; align-items: center; gap: 8px; color: var(--sidebar-muted); font-size: var(--text-2xs); }
  .conn .dot {
    width: 7px; height: 7px; border-radius: 50%; background: #5fbf8d;
    flex: 0 0 auto; box-shadow: 0 0 0 3px rgb(95 191 141 / 18%);
  }

  /* Trilho recolhido no PC — ícones só; botão da topbar recupera o menu */
  .app-shell.sidebar-collapsed .brand-copy,
  .app-shell.sidebar-collapsed .nav-item span,
  .app-shell.sidebar-collapsed .conn-label,
  .app-shell.sidebar-collapsed .logout-label,
  .app-shell.sidebar-collapsed .sidebar-credit {
    display: none;
  }
  .app-shell.sidebar-collapsed .sidebar {
    padding-left: 0.55rem; padding-right: 0.55rem; align-items: center; gap: var(--space-4);
  }
  .app-shell.sidebar-collapsed .sidebar-top {
    flex-direction: column; align-items: center; padding-bottom: 4px; width: 100%;
  }
  .app-shell.sidebar-collapsed .brand { justify-content: center; padding: 0; }
  .app-shell.sidebar-collapsed .nav { width: 100%; }
  .app-shell.sidebar-collapsed .nav-item {
    justify-content: center; padding: 0.45rem; width: 2.75rem; margin: 0 auto;
  }
  .app-shell.sidebar-collapsed .nav-item.active::before {
    left: 0; top: 0.55rem; bottom: 0.55rem;
  }
  .app-shell.sidebar-collapsed .sidebar-foot {
    width: 100%; justify-items: center; text-align: center;
  }
  .app-shell.sidebar-collapsed .sidebar-tools { justify-content: center; }
  .logout-ico { display: none; }
  .app-shell.sidebar-collapsed .logout-ico { display: inline-flex; }
  .app-shell.sidebar-collapsed #logoutBtn {
    width: var(--control-md); padding: 0; min-height: var(--control-md);
  }

  .main {
    min-width: 0; min-height: 100vh; display: flex; flex-direction: column;
    background: transparent;
  }
  .topbar {
    position: sticky; top: 0; z-index: 15;
    height: auto; min-height: var(--topbar-height); display: flex; align-items: center;
    justify-content: space-between; gap: 12px; padding: 8px 12px 8px clamp(16px, 3vw, 24px);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-xs);
  }
  .topbar-lead { display: flex; align-items: center; gap: 12px; min-width: 0; }
  .topbar h1 {
    margin: 0; font-size: var(--text-lg); font-weight: var(--weight-semibold);
    letter-spacing: -0.025em; color: var(--heading); line-height: 1.2;
  }
  .sidebar-open { display: none; }
  .app-shell.sidebar-collapsed .sidebar-open { display: inline-flex; }
  .topbar .eyebrow {
    margin: 0 0 2px; font-size: 11px; color: var(--fg-muted);
    letter-spacing: 0.08em; text-transform: uppercase; font-weight: var(--weight-semibold);
  }
  .topbar-actions {
    display: flex; align-items: center; justify-content: flex-end; gap: 2px; flex: 0 0 auto;
  }
  .topbar-actions .btn.icon-only {
    width: 38px; min-height: 38px; border-radius: 8px;
  }
  .topbar-divider {
    width: 1px; height: 20px; margin: 0 8px; background: var(--line); flex: none;
  }
  .avatar-btn {
    width: 30px; height: 30px; margin-left: 2px; padding: 0; border: 0; border-radius: 50%;
    display: grid; place-items: center; cursor: default;
    background: var(--sonder-navy); color: var(--sonder-cream);
    font-size: 11px; font-weight: var(--weight-bold); letter-spacing: 0.02em;
    box-shadow: var(--shadow-xs);
    transition: transform var(--dur-1) var(--ease-standard);
  }
  .avatar-btn:hover { transform: scale(1.06); }
  [data-theme="dark"] .avatar-btn {
    background: var(--sonder-cream); color: var(--sonder-navy);
  }
  .notify-wrap { position: relative; }
  .notify-wrap #notifyBtn { position: relative; }
  .notify-badge {
    position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px;
    padding: 0 5px; border-radius: 9px; background: var(--sidebar-accent, #d4694a);
    color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  }
  .notify-panel {
    position: absolute; right: 0; top: calc(100% + 8px); width: min(360px, calc(100vw - 24px));
    max-height: min(420px, 70vh); overflow: auto; z-index: 40;
    background: var(--raised); color: var(--fg);
    border: 1px solid var(--line); border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    animation: modal-in var(--dur-2) var(--ease-emphasized);
  }
  .notify-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 12px 14px; border-bottom: 1px solid var(--border, rgb(0 0 0 / 10%));
    position: sticky; top: 0; background: inherit; z-index: 1;
  }
  .notify-enable {
    padding: 12px 14px; border-bottom: 1px solid var(--border, rgb(0 0 0 / 8%));
    background: var(--warning-bg, #fff6e8); font-size: var(--text-xs, 13px);
  }
  .notify-enable p { margin: 0 0 8px; }
  .notify-list { display: grid; gap: 0; }
  .notify-item {
    display: grid; gap: 4px; padding: 12px 14px; text-align: left; width: 100%;
    border: 0; border-bottom: 1px solid var(--border, rgb(0 0 0 / 8%));
    background: transparent; color: inherit; cursor: pointer; font: inherit;
  }
  .notify-item:hover { background: var(--sidebar-hover, rgb(0 0 0 / 4%)); }
  .notify-item.unread { background: rgb(212 105 74 / 8%); }
  .notify-item strong { font-size: 13px; }
  .notify-item p { margin: 0; font-size: 12px; color: var(--fg-muted, #666); }
  .notify-item time { font-size: 11px; color: var(--fg-muted, #888); }
  .content {
    width: min(100%, var(--content-max)); margin: 0 auto;
    padding: 22px clamp(16px, 3vw, 32px) 48px; flex: 1;
  }
  .content > section {
    animation: rise var(--dur-3) var(--ease-emphasized);
  }
  .filters {
    display: grid; grid-template-columns: minmax(0, 2fr) minmax(140px, 1fr); gap: 12px;
    margin-bottom: var(--space-4);
  }
  .pick-head { margin-bottom: var(--space-3); }
  .pick-head .meta { color: var(--fg-muted); margin-top: 4px; }
  .login-hero {
    display: grid; gap: 8px; margin-bottom: var(--space-4); padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--line);
  }
  .login-hero .mark {
    width: 42px; height: 42px; border-radius: var(--radius-sm); display: grid; place-items: center;
    background: var(--accent); color: #fff; font-weight: var(--weight-bold);
  }
  .sonder-sign {
    margin-top: 18px; font-size: var(--text-2xs); color: var(--fg-muted); text-align: center;
  }
  .sonder-sign button {
    border: 0; background: none; color: var(--focus); cursor: pointer; font: inherit;
    text-decoration: underline; text-underline-offset: 2px;
  }
  #scanner video,
  .qr-reader {
    width: 100%; max-height: 56vh; object-fit: cover; border-radius: var(--radius-md); background: #111;
    overflow: hidden;
  }
  .qr-reader video { width: 100% !important; border-radius: var(--radius-md); }
  .qr-reader img { display: none !important; }
  .scan-state { margin-top: 10px; text-align: center; }
  .scanner-modal { width: min(560px, calc(100vw - 16px)); }
  .scan-primary {
    width: 100%; margin-top: 4px; min-height: 3rem; gap: 10px;
  }
  .qty-stepper {
    display: grid; grid-template-columns: var(--control-lg) 1fr var(--control-lg); gap: 8px; align-items: center;
  }
  .qty-stepper input { text-align: center; font-size: var(--text-lg); font-weight: var(--weight-semibold); }
  .check-actions { width: 100%; }
  .check-actions .btn.lg { flex: 1; }
  .pick-item-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
  .report-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
  .item-card .badge.warn { margin-top: 6px; display: inline-flex; }

  @keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
  @keyframes modal-in {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: none; }
  }
  @keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      transition-duration: 0.01ms !important;
    }
  }

  @media (max-width: 860px) {
    .check-modal { width: calc(100vw - 12px); max-width: none; margin: auto 6px; }
    .check-modal .modal-body { padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); }
    .scan-primary { min-height: 3.25rem; font-size: var(--text-base); }
    .item-card { padding: 14px; }
    .item-card .code { font-size: 1.05rem; }
    .pick-item-actions .btn { min-height: 2.75rem; flex: 1 1 auto; }
    .modal-actions .btn.lg,
    .modal-actions .btn.accent { min-height: 2.85rem; }
    .toast-host {
      inset: auto 12px calc(12px + env(safe-area-inset-bottom)) 12px;
      width: auto; right: 12px; left: 12px;
    }
    .app-shell,
    .app-shell.sidebar-collapsed {
      grid-template-columns: 1fr;
    }
    .sidebar-scrim {
      display: block; position: fixed; inset: 0; z-index: 40;
      background: var(--scrim); border: 0; padding: 0; margin: 0; cursor: pointer;
    }
    .sidebar-scrim[hidden] { display: none !important; }
    .sidebar {
      position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
      width: min(280px, 86vw); height: 100vh; height: 100dvh;
      transform: translateX(-105%);
      transition: transform var(--dur-3) var(--ease-emphasized);
      box-shadow: var(--shadow-lg);
      padding: 18px 14px 16px;
      align-items: stretch !important;
    }
    .app-shell.sidebar-open .sidebar { transform: translateX(0); }
    .app-shell.sidebar-collapsed .brand-copy,
    .app-shell.sidebar-collapsed .nav-item span,
    .app-shell.sidebar-collapsed .conn-label,
    .app-shell.sidebar-collapsed .logout-label,
    .app-shell.sidebar-collapsed .sidebar-credit {
      display: revert;
    }
    .app-shell.sidebar-collapsed .nav-item {
      justify-content: flex-start; padding: 0 12px; width: 100%; margin: 0;
    }
    .app-shell.sidebar-collapsed #logoutBtn { width: auto; padding: 0 14px; }
    .sidebar-open { display: inline-flex !important; }
    .sidebar-top { align-items: center; }
    .metrics, .filters, .view-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
  }
}
