/* Fulfilment dashboard: a single data table (tablecn-style) on the shop's design tokens.
   No inline styles anywhere; the page ships a strict CSP. */
main { max-width: min(2200px, 100%); padding-bottom: 7rem; }
.login { max-width: 420px; margin: 3rem auto; }
.login h1, .focus h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
.login form { display: grid; gap: .6rem; }
.login label { font-weight: 600; font-size: .9rem; }
input[type=password], input[type=text], input[type=search], textarea {
  font: inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink); width: 100%;
}
textarea { resize: vertical; min-height: 4.5rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code { background: var(--soft); padding: .05rem .3rem; border-radius: var(--radius); }

.focus { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: .75rem 1.5rem; margin-bottom: 1rem; }
.focus .empty { margin: 0; }

/* Segmented control (order type). 44px targets: this runs on a tablet at the packing table. */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.seg button { min-height: 44px; background: var(--card); color: var(--ink); border-radius: 0; border-right: 1px solid var(--line); font-weight: 600; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); }
.seg small { display: block; font-weight: 400; font-size: .7rem; opacity: .85; }

/* ---- Toolbar: search, faceted filters, refresh -------------------------------------------------- */
.dt-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem 1rem; margin-bottom: .6rem; }
.dt-filters { display: flex; flex-wrap: nowrap; min-width: 0; max-width: 100%; align-items: center; gap: .5rem; }
.dt-right { display: flex; align-items: center; gap: .6rem; }
.dt-right .fine { margin: 0; }
.search { position: relative; display: block; flex: 0 1 20rem; min-width: 8rem; }
.dt-filters > :not(.search) { flex: none; }
.search svg { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input { padding-left: 2rem; min-height: 38px; }
.facet { position: relative; }
.facet summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; min-height: 38px; padding: 0 .75rem;
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--card); font-size: .88rem; font-weight: 600; user-select: none;
}
.facet summary::-webkit-details-marker { display: none; }
.facet summary::before { content: "+"; color: var(--muted); font-weight: 400; }
.facet[open] summary, .facet summary:hover { border-color: var(--accent); }
.facet-values { display: inline-flex; gap: .3rem; }
.facet-values:not(:empty)::before { content: ""; width: 1px; align-self: stretch; background: var(--line); margin-right: .2rem; }
.facet-values span { background: var(--soft); border-radius: var(--radius); padding: .05rem .45rem; font-weight: 500; font-size: .8rem; }
.facet-menu {
  position: absolute; z-index: 25; top: calc(100% + .35rem); left: 0; min-width: 13rem; padding: .35rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgb(43 29 20 / .18);
}
.facet-menu label { display: flex; align-items: center; gap: .55rem; padding: .45rem .6rem; border-radius: var(--radius); font-size: .9rem; cursor: pointer; }
.facet-menu label:hover { background: var(--soft); }
.facet-menu label .n { margin-left: auto; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.facet-menu input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); }
.facet-menu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; }
.facet-menu .menu-btn { width: 100%; background: none; color: var(--ink); font-weight: 500; text-align: left; padding: .45rem .6rem; }
.facet-menu .menu-btn:hover { background: var(--soft); }
button.reset { min-height: 38px; }
.warn { background: #fef3c7; border: 1px solid #f59e0b; color: #78350f; border-radius: var(--radius); padding: .6rem .8rem; font-size: .9rem; }

/* ---- Table ------------------------------------------------------------------------------------- */
.dt-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 14rem); }
.dt { width: 100%; min-width: 980px; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
.dt th, .dt td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.dt thead th {
  position: sticky; top: 0; z-index: 2; background: var(--soft); color: var(--muted); font-size: .76rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
.dt th.check, .dt td.check { width: 2.6rem; padding-right: 0; text-align: center; }
.dt th.exp, .dt td.exp { width: 2.6rem; padding-left: 0; text-align: center; }
.dt th.num, .dt td.num { text-align: right; font-variant-numeric: tabular-nums; }
.dt input[type=checkbox] { width: 1.05rem; height: 1.05rem; margin: 0; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.dt thead button.sort { background: none; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; padding: 0; display: inline-flex; align-items: center; gap: .3rem; }
.dt thead button.sort::after { content: "↕"; opacity: .4; font-size: .85em; }
.dt thead button.sort[aria-sort=ascending]::after { content: "↑"; opacity: 1; color: var(--accent); }
.dt thead button.sort[aria-sort=descending]::after { content: "↓"; opacity: 1; color: var(--accent); }
.dt tbody tr.order-row:hover { background: #fbf8f4; }
.dt tbody tr.order-row[aria-selected=true] { background: #f6ebdf; }
.dt tbody tr.order-row[data-pending] { opacity: .55; pointer-events: none; }
.dt tbody tr.order-row.just-saved { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #e3f2e7; } }
.dt td.who { max-width: 16rem; }
.dt .name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt .sub { display: block; color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt td.items-cell { min-width: 16rem; max-width: 30rem; }
.item-lines { list-style: none; margin: 0; padding: 0; }
.item-lines li { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; padding: .1rem 0; }
.item-lines li + li { border-top: 1px dashed var(--line); }
.item-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item-qty { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.dt td.ship-cell { white-space: nowrap; line-height: 1.35; }
.dt .ship-cell .name { font-weight: 500; }
.dt .ship-cell .line { display: block; font-size: .84rem; }
.dt .noaddr { color: var(--warn); }
.dt td.date-cell, .dt td.type-cell { white-space: nowrap; }
.dt td.ref-cell { white-space: nowrap; }
.dt .ref { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.dt .track a { font-variant-numeric: tabular-nums; }
.dt .track .muted { color: var(--muted); }
.badge { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: .15rem .5rem; border-radius: var(--radius); background: var(--soft); color: var(--accent); white-space: nowrap; }
.badge.gift { background: #fce7f3; color: #9d174d; margin-left: .3rem; }
.badge.oneoff { background: #e0e7ff; color: #3730a3; }
.badge.linked { background: #ecfdf5; color: #065f46; margin-left: .3rem; text-transform: none; letter-spacing: 0; font-weight: 600; }

/* Linked orders (same address): a bracket down the left edge ties the rows into one box. */
.dt tr.grouped td.check { position: relative; }
.dt tr.grouped td.check::before { content: ""; position: absolute; left: .45rem; top: 0; bottom: 0; width: 3px; background: #34d399; }
.dt tr.group-first td.check::before { top: .5rem; border-radius: var(--radius) 0 0; }
.dt tr.group-last td.check::before { bottom: .5rem; border-radius: var(--radius); }
.dt tr.grouped:not(.group-last) td { border-bottom-style: dashed; }
.packref { margin: .7rem 0 .2rem; font-size: .78rem; font-weight: 700; color: #065f46; }
.packref:first-of-type { margin-top: 0; }
.fields label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .85rem; }
.fields label.check input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); }

/* Status: a native select dressed as a coloured pill, so one tap changes it inline. */
select.status { appearance: none; -webkit-appearance: none; font: inherit; font-size: .82rem; font-weight: 700; min-height: 32px;
  padding: .2rem 1.6rem .2rem .7rem; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
  background: var(--soft) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5'><path d='m6 9 6 6 6-6'/></svg>") no-repeat right .5rem center / .8rem; }
select.status[data-value=new] { background-color: #fdf0e3; color: #9a3412; border-color: #f0c9a3; }
select.status[data-value=fulfilled] { background-color: #e3f2e7; color: #14532d; border-color: #b3dcbe; }

.dt button.chev { background: none; color: var(--muted); padding: .25rem .4rem; font-size: 1rem; line-height: 1; border-radius: var(--radius); transition: transform .15s; }
.dt button.chev:hover { background: var(--soft); color: var(--ink); }
.dt tr.order-row[aria-expanded=true] button.chev { transform: rotate(90deg); }
.dt tr.order-row[aria-expanded=true] td { border-bottom-color: transparent; }

/* Expanded detail row */
.dt tr.detail td { background: #fbf8f4; padding: .9rem 1rem 1.1rem 3.3rem; border-bottom: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: minmax(14rem, 1.1fr) minmax(12rem, .9fr) minmax(18rem, 1.4fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }
.detail h3 { margin: 0 0 .4rem; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.detail ul.items { list-style: none; margin: 0; padding: 0; font-size: .95rem; }
.detail ul.items li { padding: .25rem 0; border-bottom: 1px dashed var(--line); }
.detail ul.items .qty { display: inline-block; min-width: 2.2rem; font-weight: 700; }
.giftnote { margin: .6rem 0 0; padding: .5rem .7rem; background: #fdf2f8; border-radius: var(--radius); font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail address { font-style: normal; font-size: .95rem; line-height: 1.45; overflow-wrap: anywhere; }
.detail .noaddr { color: var(--warn); font-size: .9rem; }
.detail .addr-actions { margin-top: .5rem; display: flex; gap: .5rem; }
.detail .addr-actions button { padding: .35rem .7rem; font-size: .85rem; }
.fields { display: grid; gap: .6rem; }
.fields label { display: grid; gap: .25rem; font-size: .85rem; font-weight: 600; }
.fields .pair { display: grid; grid-template-columns: 9rem 1fr; gap: .6rem; }
@media (max-width: 420px) { .fields .pair { grid-template-columns: 1fr; } }
.fields select { width: 100%; min-height: 40px; }
.fields .actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.fields .saved { color: #15803d; font-size: .85rem; }
.inline-error { margin: .4rem 0 0; }
.dt td.empty-cell { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* ---- Footer: count + pager ----------------------------------------------------------------------- */
.dt-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-top: .6rem; }
.dt-footer .fine { margin: 0; text-align: left; }
.pager { display: flex; align-items: center; gap: .75rem; }
.pager label { display: inline-flex; align-items: center; gap: .4rem; }
.pager select { min-height: 34px; padding: .25rem .4rem; }
button.icon { min-width: 34px; min-height: 34px; padding: 0 .5rem; font-size: 1.1rem; line-height: 1; }

/* ---- Floating action bar (appears when rows are selected) ---------------------------------------- */
.action-bar {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 40; max-width: calc(100vw - 2rem);
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; padding: .6rem .8rem;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgb(43 29 20 / .22);
}
.action-bar .sel { display: flex; align-items: center; gap: .5rem; padding-right: .8rem; border-right: 1px solid var(--line); }
.action-bar .sel strong { white-space: nowrap; }
.action-bar .group { display: flex; align-items: center; gap: .45rem; }
.action-bar .fine { margin: 0; }
.action-bar button.clear { background: none; color: var(--muted); min-width: 28px; min-height: 28px; font-size: .9rem; }
.action-bar button.clear:hover { background: var(--soft); color: var(--ink); }
.bulk-status { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.bulk-status button { background: var(--card); color: var(--ink); border-radius: 0; border-right: 1px solid var(--line); min-height: 36px; padding: .3rem .8rem; font-size: .88rem; }
.bulk-status button:last-child { border-right: 0; }
.bulk-status button[data-value=new]:hover { background: #fdf0e3; color: #9a3412; }
.bulk-status button[data-value=fulfilled]:hover { background: #e3f2e7; color: #14532d; }
.action-bar select { min-height: 36px; padding: .25rem .4rem; }
.action-bar button.secondary { min-height: 36px; padding: .3rem .8rem; font-size: .88rem; }
.action-bar[data-busy] > * { opacity: .6; pointer-events: none; }

.toast {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 50; max-width: min(28rem, calc(100vw - 2rem));
  display: flex; gap: 1rem; align-items: center; background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / .25);
}
@media (max-width: 900px) { .action-bar:not([hidden]) ~ .toast { bottom: 6rem; } }
.toast button.link { color: #fdd9b5; min-height: 32px; }
@media (prefers-reduced-motion: reduce) { .dt tbody tr.order-row.just-saved { animation: none; } .dt button.chev { transition: none; } }

/* Gift / same-box markers sit under the customer's name. */
.dt .flags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .25rem; }
.dt .method-cell { white-space: nowrap; }
.badge.note { background: #fef3c7; color: #78350f; }
.giftnote.custnote { background: #fffbeb; }

.paid-note { margin: 0 0 .75rem; padding: .5rem .75rem; border-radius: var(--radius); background: #ecfdf3; color: #14532d; border: 1px solid #bbf7d0; font-size: .875rem; }
.export-menu .facet-menu { display: flex; flex-direction: column; gap: .35rem; min-width: 11rem; }
.export-menu .facet-menu button { text-align: left; }
.dt td.gift-cell { white-space: nowrap; }
