/* ============================================================
   Order action buttons (Oct 2026) — loaded LAST.
   - Buttons never spill their text: every button sizes to its label.
   - Actions are grouped: main actions on top, "Move to" status row below.
   - Quick press feedback, a busy spinner while the server answers,
     bigger touch targets on phones.
   ============================================================ */

/* Wide tables scroll inside their box instead of pushing the whole page
   (and the top-right buttons) off the right edge of the screen. */
.app > .workspace, .workspace > .main { min-width: 0; }

/* The table cell stays a table cell; the flex layout lives inside it. */
td.order-actions-cell { display: table-cell; min-width: 0; width: 1%; vertical-align: middle; }
td.order-actions-cell .oa { width: 210px; max-width: 210px; }
td.order-actions-cell .oa-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
td.order-actions-cell .oa .oa-seg .order-status-btn { padding: 0.25rem 0.35rem; white-space: normal; text-align: center; font-size: 0.72rem; }
td.order-actions-cell .oa-main > * { flex: 1 1 auto; }
/* List view: the Options column stays pinned on the right while the table scrolls. */
#orders-content table th:last-child,
#orders-content td.order-actions-cell { position: sticky; right: 0; z-index: 1; background: var(--surface); box-shadow: -10px 0 10px -10px rgba(15, 20, 30, 0.25); }
.spo-actions.order-actions-cell { display: block; min-width: 0; }

.oa { display: flex; flex-direction: column; gap: 0.45rem; width: 100%; }
.oa-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; min-width: 0; }
.oa-label { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin-right: 0.1rem; }

/* One button shape for every order action. */
.oa .kw-order-btn,
.oa .order-cart-btn,
.oa .oa-btn,
.oa .oa-chip,
.oa .link-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
  width: auto; min-width: 0; max-width: 100%; height: auto; min-height: 32px;
  margin: 0; padding: 0.3rem 0.65rem;
  border-radius: 8px; font: inherit; font-size: 0.76rem; font-weight: 700; line-height: 1.15;
  white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.oa .order-cart-btn { border: 1px solid var(--border); background: var(--surface); color: var(--gold-dark); flex-shrink: 0; }
.oa .order-cart-btn .order-cart-label { margin-left: 0; font-size: inherit; }
.oa .order-cart-btn .order-cart-icon { width: 15px; height: 15px; flex-shrink: 0; }
.oa .oa-btn { border: 1px solid rgba(5, 150, 105, 0.5); background: rgba(5, 150, 105, 0.1); color: #047857; }
.oa .oa-btn:hover { background: rgba(5, 150, 105, 0.18); }
.oa .oa-btn.is-quiet { border-color: var(--border); background: var(--surface); color: inherit; font-weight: 600; }
.oa .oa-btn.is-quiet:hover { background: rgba(212, 175, 55, 0.12); }

/* Status chips: in stock / sold / deleted — text, not a button. */
.oa .oa-chip { cursor: default; border: 1px solid transparent; font-weight: 700; }
.oa .oa-chip.is-stock { background: rgba(5, 150, 105, 0.12); color: #047857; border-color: rgba(5, 150, 105, 0.3); }
.oa .oa-chip.is-sold { background: rgba(37, 99, 235, 0.1); color: #1d4ed8; border-color: rgba(37, 99, 235, 0.28); }
.oa .oa-chip.is-gone { background: rgba(120, 120, 120, 0.12); color: var(--muted); border-color: var(--border); }
.oa .oa-chip .oa-chip-sub { font-family: var(--mono, ui-monospace, Menlo, monospace); font-weight: 600; opacity: 0.85; }
.oa .oa-chip .oa-tag { margin-left: 0.15rem; padding: 0.05rem 0.4rem; min-height: 0; border-radius: 6px; border: 1px solid currentColor; background: transparent; color: inherit; font: inherit; font-size: 0.7rem; cursor: pointer; }

/* "Move to" status row: a compact segmented control + Cancel at the end. */
.oa-status { padding-top: 0.4rem; border-top: 1px dashed var(--border); }
.oa-seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); max-width: 100%; }
.oa .oa-seg .order-status-btn {
  border: 0; border-right: 1px solid var(--border); border-radius: 0; background: transparent;
  color: inherit; font-weight: 600; min-height: 30px; padding: 0.25rem 0.6rem;
}
.oa .oa-seg .order-status-btn:last-child { border-right: 0; }
.oa .oa-seg .order-status-btn:hover:not([disabled]) { background: rgba(212, 175, 55, 0.14); }
.oa .oa-seg .order-status-btn.is-current { background: var(--gold-dark); color: #fff; opacity: 1; font-weight: 700; cursor: default; }
.oa .oa-status .link-btn.danger { margin-left: auto; min-height: 30px; padding: 0.25rem 0.6rem; font-weight: 600; }

/* Press + busy feedback (all order / karigar action buttons). */
.oa button:active:not([disabled]),
.ks-btns button:active:not([disabled]),
.kw-actions button:active:not([disabled]),
.kw-next button:active:not([disabled]),
.row-actions button:active:not([disabled]) { transform: scale(0.96); }
button.is-pressed { box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.35); }
button.is-busy { position: relative; pointer-events: none; opacity: 0.75; color: transparent !important; }
button.is-busy > * { visibility: hidden; }
button.is-busy::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border: 2px solid var(--gold-dark, #92400e); border-right-color: transparent; border-radius: 50%;
  animation: oa-spin 0.7s linear infinite;
}
@keyframes oa-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  button.is-busy::after { animation-duration: 2s; }
  .oa button:active:not([disabled]) { transform: none; }
}

/* Karigar screens: "✓ In inventory · SKU …  [Print tag]" wraps cleanly. */
.kw-next-done { flex-wrap: wrap; row-gap: 0.25rem; }
.kw-next .kw-list li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.ks-btns > * { min-width: 0; }
.ks-btns .btn { white-space: nowrap; }

/* Karigar card header: name on the left, its small buttons in one tidy row. */
.ks-head { flex-wrap: wrap; }
.ks-head > div { min-width: 0; flex: 1 1 8rem; }
.ks-head > span { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.3rem; }
.ks-head > span .link-btn { display: inline-flex; align-items: center; white-space: nowrap; min-height: 30px; padding: 0.2rem 0.55rem; font-size: 0.74rem; }

/* Order history dialog */
#oi-history { width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 720px); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); }
#oi-history::backdrop { background: rgba(15, 20, 30, 0.45); }
#oi-history .oi-h-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; padding: 1rem 1.1rem 0.6rem; border-bottom: 1px solid var(--border); }
#oi-history .oi-h-head h2 { margin: 0; font-size: 1.05rem; }
#oi-history .oi-h-head p { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--muted); }
#oi-history .oi-h-body { padding: 0.4rem 1.1rem 1rem; overflow: auto; max-height: calc(min(80vh, 720px) - 80px); }
#oi-history ol { list-style: none; margin: 0; padding: 0; }
#oi-history li { display: grid; grid-template-columns: 1.6rem 1fr; gap: 0.15rem 0.5rem; padding: 0.55rem 0; border-bottom: 1px dashed var(--border); }
#oi-history li:last-child { border-bottom: 0; }
#oi-history .oi-ico { grid-row: span 2; font-size: 1rem; line-height: 1.3; text-align: center; }
#oi-history .oi-note { font-size: 0.86rem; font-weight: 600; overflow-wrap: anywhere; }
#oi-history .oi-when { font-size: 0.72rem; color: var(--muted); font-family: var(--mono, ui-monospace, Menlo, monospace); }
#oi-history .oi-src { display: inline-block; margin-left: 0.35rem; padding: 0 0.35rem; border-radius: 999px; font-size: 0.64rem; font-weight: 700; background: rgba(184, 134, 11, 0.14); color: #92400e; font-family: inherit; }
#oi-history li.is-inv .oi-note { color: #047857; }
#oi-history li.is-out .oi-note { color: #1d4ed8; }
[data-theme="dark"] #oi-history li.is-inv .oi-note,
[data-theme="dark"] .oa .oa-btn:not(.is-quiet),
[data-theme="dark"] .oa .oa-chip.is-stock { color: #34d399; }
[data-theme="dark"] #oi-history li.is-out .oi-note,
[data-theme="dark"] .oa .oa-chip.is-sold { color: #93c5fd; }
[data-theme="dark"] #oi-history .oi-src { color: #fbbf24; }
[data-theme="dark"] .oa .oa-seg .order-status-btn.is-current { color: #111827; }

/* Phones: full-width rows, 40px+ touch targets. */
@media (max-width: 760px) {
  .oa .kw-order-btn,
  .oa .order-cart-btn,
  .oa .oa-btn,
  .oa .link-btn { min-height: 40px; font-size: 0.8rem; padding: 0.4rem 0.75rem; }
  .oa .oa-chip { min-height: 36px; }
  .oa-main > * { flex: 1 1 auto; }
  .oa-status { gap: 0.4rem; }
  .oa-seg { display: flex; width: 100%; }
  .oa .oa-seg .order-status-btn { flex: 1 1 0; min-height: 40px; white-space: normal; text-align: center; }
  .oa .oa-status .link-btn.danger { margin-left: 0; flex: 1 1 100%; }
  .oa-label { flex-basis: 100%; }
  .ks-btns .btn { flex: 1 1 auto; }
}

/* Per-order Delete (Oct 2026): sits after Cancel in the "Move to" row. */
.oa .oa-status .link-btn.danger.oa-del { margin-left: 0; }
.oa .oa-status .oa-seg + .link-btn.danger.oa-del { margin-left: auto; }
@media (max-width: 760px) { .oa .oa-status .link-btn.danger { flex: 1 1 0; } }
