/* Dark theme + microanimations */
:root {
  --bg: #0e1117;
  --surface: #141926;
  --surface-2: #182032;
  --text: #e6e8ee;
  --muted: #9aa4b2;
  --primary: #6aa2ff;
  --border: #2a3243;
  --danger: #ef4444;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 16px rgba(0,0,0,.35);
  --shadow-2: 0 2px 4px rgba(0,0,0,.35), 0 12px 30px rgba(0,0,0,.45);
  --z-portal: 10000;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: radial-gradient(1200px 600px at 20% -20%, rgba(106,162,255,.08), transparent),
              radial-gradient(900px 500px at 100% 0%, rgba(99,102,241,.06), transparent),
              var(--bg);
  color: var(--text);
}
.elevation-1 { box-shadow: var(--shadow); }
.elevation-2 { box-shadow: var(--shadow-2); }
.fade-in { animation: fadeIn .24s ease both; }
@keyframes fadeIn { from {opacity:0; transform: translateY(8px);} to {opacity:1; transform:none;} }
@keyframes shimmer { 0% { background-position: -468px 0 } 100% { background-position: 468px 0 } }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); background: rgba(14,17,23,.8); backdrop-filter: blur(10px); }
.brand { display: flex; gap: .6rem; align-items: center; font-weight: 700; letter-spacing:.2px; }
.top-actions { display: flex; gap: .5rem; align-items: center; }

/* Bulk actions (visible only when there is a selection) */
.bulk-actions { display: inline-flex; gap: .5rem; align-items: center; }
.bulk-actions .muted { font-size: .9rem; }

.container { max-width: 1200px; margin: 1rem auto; padding: 0 1rem; }

/* Status chips bar */
.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .7rem;
  padding: .5rem;

  justify-content: center;
}
.status-chips .chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: .35rem .7rem;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-weight: 800;
  letter-spacing: .2px;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.status-chips .chip:hover { transform: translateY(-1px); }
.status-chips .chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.status-chips .chip[aria-selected="true"] {
  background: rgba(106,162,255,.15);
  border-color: var(--primary);
}
.status-chips .chip .count {
  font-variant-numeric: tabular-nums;
  min-width: 1.25rem;
  text-align: center;
  border-radius: 999px;
  padding: .05rem .4rem;
  background: rgba(106,162,255,.18);
}

/* Dropdown portal */
.dropdown-portal { position: fixed; z-index: var(--z-portal); background: #0f1420; border: 1px solid var(--border); border-radius: .6rem; box-shadow: var(--shadow-2); overflow: hidden; width: 260px; opacity: 0; transform: translateY(-4px); transition: opacity .15s ease, transform .15s ease; }
.dropdown-portal.open { opacity: 1; transform: translateY(0); }
.dropdown-portal ul { list-style: none; margin: 0; padding: .4rem; max-height: 320px; overflow: auto; }
.dropdown-portal li { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: .5rem; cursor: pointer; color: var(--text); }
.dropdown-portal li:hover { background: rgba(106,162,255,.15); }
.dropdown-portal li[aria-selected="true"] { background: rgba(106,162,255,.18); }
.dropdown-portal li[aria-selected="true"] .dot { transform: scale(1.15); }
.dropdown-portal li.primary { font-weight: 800; }
.dot { width: .6rem; height: .6rem; border-radius: 999px; display: inline-block; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: .7rem; overflow: auto; max-height: calc(100vh - 320px); position: relative; }
.table-wrap.loading::after { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,.08); pointer-events: none; border-radius: .7rem; }
.table { width: 100%; border-collapse: collapse; }
.table thead th { position: sticky; top: 0; z-index: 5; background: #121723; color: #b7c0cd; font-size: .82rem; letter-spacing: .02em; text-transform: uppercase; box-shadow: 0 1px 0 var(--border) inset, 0 2px 6px rgba(0,0,0,.2); }
.table th, .table td { border-bottom: 1px solid var(--border); padding: .7rem .8rem; text-align: left; vertical-align: middle; }
.table td.num { text-align: right; }
.table tbody tr { transition: background-color .18s ease, transform .12s ease; cursor: pointer; }
.table tbody tr:hover { background: rgba(106,162,255,.06); transform: translateY(-1px); }
.actions-col { width: 1%; white-space: nowrap; }

/* Buttons */
.btn { appearance: none; cursor: pointer; border: 1px solid transparent; border-radius: .55rem; padding: .55rem .85rem; font-weight: 700; letter-spacing:.2px; position: relative; overflow: hidden; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-sm { padding: .4rem .6rem; font-size: .875rem; }
.btn-primary { background: linear-gradient(180deg, rgba(106,162,255,.85), rgba(106,162,255,.7)); color: #091225; border-color: rgba(106,162,255,.3); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: white; }

/* Form & dialog */
.modal { border: none; border-radius: .7rem; padding: 0; background: transparent; }
.modal::backdrop { background: rgba(0,0,0,.5); }
.modal .modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: .8rem; width: min(1100px, 95vw); max-height: 90vh; overflow: auto; }
.modal-header, .modal-footer { padding: .95rem 1rem; border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); border-bottom: 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 1rem; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .8rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field.full { grid-column: 1 / -1; }
label { color: #c5ced9; font-size: .9rem; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], textarea, select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: .5rem; padding: .6rem .7rem;
}
.items { margin-top: 1rem; border-top: 1px dashed var(--border); padding-top: 1rem; }
.items-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.items-row { display: grid; grid-template-columns: 1.4fr 1.6fr .8fr .8fr .8fr .8fr .9fr 1.2fr 1.1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.items-row input, .items-row select { width: 100%; }
.items-row .remove { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: .4rem; padding: .3rem .4rem; }

/* Pagination & utility */
.pagination { display: flex; justify-content: center; align-items: center; gap: .6rem; margin: 1rem 0; }
#toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; display: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: .6rem; padding: .65rem .9rem; box-shadow: var(--shadow); }
#toast.show { display: block; }

.muted { color: var(--muted); }
.sr-only { position: absolute; clip: rect(0 0 0 0); padding: 0; border: 0; height: 1px; width: 1px; overflow: hidden; white-space: nowrap; }

/* Utility */
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* Selection column + checkbox micro-animation */
.sel-col { width: 34px; }
.table td.sel, .table th.sel-col { text-align: center; }
.row-check { width: 18px; height: 18px; transform-origin: center; accent-color: var(--primary); }
.master-check { width: 18px; height: 18px; }
.row-check:checked { animation: tickpop .16s ease-out; }
 60% { transform: scale(1.18); } 100% { transform: scale(1); }

}
/* Spinner */
.spinner { display:inline-block; width:14px; height:14px; border-radius:50%; border:2px solid var(--border); border-top-color: var(--primary); animation: spin .6s linear infinite; margin-right:.45rem; vertical-align:-2px; }


@keyframes spin { to { transform: rotate(360deg); } }


/* Toolbar layout */
.toolbar{display:flex;gap:.6rem;align-items:center;background:var(--surface);border:1px solid var(--border);border-radius:.7rem;padding:.5rem;margin-bottom:.9rem;}
.search-group{flex:1;}
.search-group input[type=search], #searchInput{width:100%;background:var(--surface-2);color:var(--text);border:1px solid var(--border);border-radius:.6rem;padding:.6rem .8rem;}
.filter-group{display:inline-flex;gap:.5rem;align-items:center;}
/* Status pill dot spacing */
.status-control .btn{display:inline-flex;align-items:center;gap:.5rem;}
.status-control .dot{width:.6rem;height:.6rem;border-radius:999px;}
/* Dialog meta */
.modal-header{display:flex;justify-content:space-between;align-items:center;}
.modal-header .meta{font-size:.9rem;color:var(--muted);}


/* --- Micro-animation enhancements (motion-gated) --- */
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes chipBump { 0% { transform: translateY(-1px) scale(.98); } 60% { transform: translateY(-2px) scale(1.02); } 100% { transform: translateY(-1px) scale(1); } }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Improve tickpop overshoot a touch (used for checkboxes) */
@keyframes tickpop { 0% { transform: scale(0.82); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: no-preference) {
  .status-chips .chip { transition: transform .15s ease, background .15s ease, border-color .15s ease, box-shadow .2s ease; }
  .status-chips .chip:active { transform: translateY(0) scale(.98); }
  .status-chips .chip[aria-selected="true"] { animation: chipBump .22s ease-out; }

  .btn { transition: transform .12s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease; }
  .btn:hover { transform: translateY(-1px); }
  .btn:active { transform: translateY(0) scale(.98); }

  .copyable { transition: transform .1s ease; }
  .copyable:active { transform: scale(.98); }

  dialog[open] .modal-content { animation: modalIn .24s cubic-bezier(.2,.8,.2,1) both; }

  #toast.show { animation: toastIn .22s ease both; }

  .row-check.pop { animation: tickpop .18s ease-out; }

  .dropdown-portal li { transition: background .12s ease, transform .12s ease; }
  .dropdown-portal li:hover { transform: translateX(2px); }
}

.items-row + .items-row{border-top:1px dashed var(--border);padding-top:.5rem;margin-top:.5rem;}

.affix{position:relative;display:inline-flex;width:100%;align-items:center;}
.affix .prefix{position:absolute;left:.6rem;top:50%;transform:translateY(-50%);pointer-events:none;opacity:.85}
.affix input{width:100%;padding-left:1.4rem;}


/* Affix label for L/W/Qty with right-aligned value */
.affix-label input{ text-align: right; padding-left: calc(var(--affix-w, 3.4ch) + 1rem); }
.affix-label .prefix{ font-size: .92em; opacity:.9; }


/* History timeline */
.timeline{display:flex;flex-direction:column;gap:.6rem}
.timeline .event{display:grid;grid-template-columns:auto 1fr;gap:.6rem;align-items:flex-start}
.timeline .dot{width:.55rem;height:.55rem;border-radius:999px;background:var(--primary);margin-top:.4rem}
.timeline .content{background:var(--surface-2);border:1px solid var(--border);border-radius:.6rem;padding:.6rem .7rem}
.timeline .time{font-size:.9rem;color:var(--muted);margin-bottom:.2rem}
.timeline .title{font-weight:800}
.timeline .reason{color:var(--muted);margin-top:.2rem;white-space:pre-wrap}
.timeline .dot.red{background: var(--danger);}


/* Floating action button (Report Bug) */
.fab { position: fixed; left: 1rem; bottom: 1rem; z-index: 60; border-radius: 999px; }

/* --- Prevent status label wrapping & give room --- */
.table td[data-status]{white-space:nowrap; width:1%; min-width: 190px;}
.status-control .btn{white-space:nowrap !important; min-width:190px;}
.status-control .label{white-space:nowrap !important;}
