:root {
  --bg: #0f1115;
  --bg-sidebar: #14171d;
  --card: #191d24;
  --card-soft: #1f242c;
  --line: #2a303a;
  --text: #e7eaf0;
  --text-dim: #99a1b0;
  --text-faint: #6b7483;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --good: #3ecf8e;
  --danger: #ff6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ── Layout ──────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100%;
}

/* No flash of the app before auth is confirmed: the shell stays hidden
   until init() marks the body as authed. */
body:not(.authed) .layout { display: none; }

.sidebar {
  width: 218px;
  flex: none;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 22px;
}

.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  appearance: none;
  border: 0;
  background: none;
  color: var(--text-dim);
  font: inherit;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--card-soft);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

.save-status {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.save-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  transition: background 0.15s;
}

.save-status[data-state="saving"] .dot { background: var(--accent); }
.save-status[data-state="error"] .dot { background: var(--danger); }
.save-status[data-state="error"] { color: var(--danger); }

/* In normal flow at the very end of the page: pushed to the viewport bottom
   when content is short, after all content when the page scrolls. */
.credit {
  margin-top: auto;
  padding-top: 48px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-faint);
}

.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 30px 34px 24px;
  display: flex;
  flex-direction: column;
}

.page { display: none; }
.page.is-active { display: block; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
}

h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.2px;
}

.subtitle {
  margin: 5px 0 0;
  color: var(--text-faint);
  font-size: 13.5px;
}

/* ── Price list pills ────────────────────────────────────────── */
.tier-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tier-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  margin-right: 2px;
}

.pills {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.pill {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  padding: 6px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.pill:hover {
  border-color: #3a424f;
  color: var(--text);
}

.pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.pill-add {
  width: 30px;
  padding: 0;
  height: 30px;
  font-size: 17px;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--text-dim);
}

#editTiers { font-size: 13px; }

#editTiers.is-confirm {
  border-color: var(--good);
  color: var(--good);
  font-size: 15px;
}

/* ── Pill edit mode ──────────────────────────────────────────── */
.pills.is-editing .pill {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
}

.pills.is-editing .pill.is-active {
  background: rgba(255, 107, 107, 0.22);
  font-weight: 600;
}

.pill-edit {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: text;
}

.pill-text {
  outline: none;
  min-width: 14px;
  white-space: nowrap;
}

.pill-x {
  appearance: none;
  flex: none;
  border: 0;
  background: none;
  padding: 0;
  margin-right: -5px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--danger);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.pill-x:hover {
  background: var(--danger);
  color: #fff;
}

.pill-handle {
  flex: none;
  margin-left: -5px;
  font-size: 11px;
  opacity: 0.65;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.pill-handle:active { cursor: grabbing; }

.pill.dragging { opacity: 0.4; }

.pill-lock {
  flex: none;
  margin-right: -5px;
  font-size: 10px;
  opacity: 0.8;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Table tools (fee + reset) ───────────────────────────────── */
.table-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 840px;
  margin-bottom: 14px;
}

.search-input {
  flex: 1;
  max-width: 300px;
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}

.search-input::placeholder { color: var(--text-faint); }

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.fee-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-dim);
}

.fee-input {
  width: 62px;
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  text-align: right;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fee-input::placeholder { color: var(--text-faint); }

.fee-input:focus {
  outline: none;
  border-color: var(--accent);
}

.fee-suffix { color: var(--text-faint); }

/* ── Sheet ───────────────────────────────────────────────────── */
.card {
  /* Fixed clamp: item column ≈ 2× "Feathers Shimmering Red" plus the
     fixed price/qty/total/actions columns. Same width even when empty. */
  max-width: 840px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.card.placeholder {
  padding: 22px;
  color: var(--text-dim);
  font-size: 14px;
}

.card.placeholder code {
  background: var(--card-soft);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text);
}

.sheet {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.sheet th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: #161a20;
}

.sheet td {
  padding: 6px 14px;
  border-bottom: 1px solid #22272f;
  vertical-align: middle;
}

.sheet tbody tr:last-child td { border-bottom: 0; }
.sheet tbody tr:hover { background: #1c2028; }

.col-price { width: 132px; }
.col-qty { width: 168px; }
.col-total { width: 132px; }
.col-actions { width: 52px; }

.sheet th.col-total, .sheet td.col-total { text-align: right; }
.sheet th.col-qty { text-align: center; }

/* Base sheet mode: Item | Payout | Fee | Post-fee payout.
   Same columns, different labels; qty controls swap for a fee amount. */
.sheet .th-base, .sheet .fee-amount { display: none; }

.sheet.is-base .th-normal { display: none; }
.sheet.is-base .th-base { display: inline; }
.sheet.is-base .qty-wrap { display: none; }
.sheet.is-base .fee-amount { display: inline; }

.sheet.is-base th.col-qty, .sheet.is-base td.col-qty { text-align: right; }

.fee-amount {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  padding-right: 8px;
}

/* Inputs */
.cell {
  width: 100%;
  min-width: 0;
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 7px 8px;
  border-radius: 7px;
}

.cell::placeholder { color: var(--text-faint); }

.cell:hover { border-color: #2f3642; }

.cell:focus {
  outline: none;
  border-color: var(--accent);
  background: #12151b;
}

.price-wrap {
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  padding-left: 8px;
}

.price-wrap:hover { border-color: #2f3642; }

.price-wrap:focus-within {
  border-color: var(--accent);
  background: #12151b;
}

.price-wrap .currency {
  color: var(--text-faint);
  font-size: 13.5px;
}

.price-wrap .cell {
  border: 0;
  background: transparent;
  padding-left: 3px;
}

.price-wrap .cell:hover,
.price-wrap .cell:focus { border: 0; background: transparent; }

.qty-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.step {
  appearance: none;
  flex: none;
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.step:hover {
  background: #2a313b;
  color: var(--text);
  border-color: #3a424f;
}

.step:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.cell-qty {
  width: 56px;
  flex: none;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.line-total {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  padding-right: 8px;
}

.remove {
  appearance: none;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-faint);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.remove:hover {
  background: rgba(255, 107, 107, 0.14);
  color: var(--danger);
}

.empty {
  padding: 26px 14px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}

/* ── Footer ──────────────────────────────────────────────────── */
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  background: #161a20;
  border-top: 1px solid var(--line);
}

.btn {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--text-dim);
  cursor: pointer;
}

.btn:hover { background: #2a313b; color: var(--text); }

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn:disabled:hover {
  background: var(--card-soft);
  color: var(--text-dim);
}

.btn-plus { font-size: 15px; line-height: 1; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: #3d7bf0; color: #fff; }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
}

.btn-danger:hover { background: #ff5252; color: #fff; }

.grand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.grand-meta {
  font-size: 12.5px;
  color: var(--text-faint);
}

.grand-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
}

.grand-value {
  font-size: 21px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
  min-width: 108px;
  text-align: right;
}

/* ── Floating widgets (cart + payout) ────────────────────────── */
.float-stack {
  position: fixed;
  top: 128px;
  right: 56px;
  width: 262px;
  max-height: calc(100vh - 170px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 30;
}

.float-stack[hidden] { display: none; }

.cart {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
}

.cart-title {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.cart-lines {
  overflow-y: auto;
  min-height: 0;
}

.cart-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 3px 0;
  font-size: 13.5px;
}

.cart-name {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cart-price {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.cart-empty {
  font-size: 13px;
  color: var(--text-faint);
  padding: 2px 0;
}

.cart-empty[hidden] { display: none; }

.cart-grand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.cart-grand-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
}

.cart-grand-value {
  font-size: 19px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}

/* ── Payout confirmation box ─────────────────────────────────── */
.pay {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
}

.pay-title {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
}

.pay-input {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
}

.pay-input::placeholder { color: var(--text-faint); }

.pay-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Tab-completed ghost text shows as a selection; tint it subtly. */
.pay-input::selection {
  background: rgba(79, 140, 255, 0.3);
}

.pay-confirm {
  appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  margin-top: 3px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--good);
  background: var(--good);
  color: #08251a;
  cursor: pointer;
}

.pay-confirm:hover { background: #34c284; }

.pay-confirm:disabled {
  opacity: 0.45;
  cursor: default;
}

.pay-confirm:disabled:hover { background: var(--good); }

/* ── Contacts ────────────────────────────────────────────────── */
.contacts .col-avatar { width: 52px; }
.contacts .col-stateid { width: 125px; }
.contacts .col-bankid { width: 135px; }
.contacts .col-txcount { width: 112px; }
.contacts .col-paytotal { width: 116px; }

.contacts th.col-txcount, .contacts td.col-txcount,
.contacts th.col-paytotal, .contacts td.col-paytotal { text-align: right; }

.contacts .stat {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  padding-right: 8px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Transactions ────────────────────────────────────────────── */
.tx-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid #22272f;
  font-size: 14px;
}

.tx-row:last-child { border-bottom: 0; }

.tx-n {
  flex: none;
  width: 46px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.tx-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-by {
  flex: none;
  width: 120px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-amount {
  flex: none;
  min-width: 84px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tx-row .remove {
  flex: none;
  align-self: center;
  margin-right: -6px;
}

.tx-head {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  background: #161a20;
  border-bottom: 1px solid var(--line);
}

.tx-head[hidden] { display: none; }

.tx-head .tx-name, .tx-head .tx-by { color: var(--text-faint); }

.tx-head .tx-x {
  flex: none;
  width: 20px;
}

/* ── Login ───────────────────────────────────────────────────── */
.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login[hidden] { display: none; }

.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 300px;
  padding: 28px 26px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
}

.login-title {
  margin: 2px 0 10px;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.2px;
}

.login-input {
  width: 100%;
  appearance: none;
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
}

.login-input::placeholder { color: var(--text-faint); }

.login-input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  font-size: 12.5px;
  color: var(--danger);
}

.login-submit {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
  padding: 10px 12px;
  font-weight: 650;
}

/* ── Modal ───────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 13, 0.6);
  display: grid;
  place-items: center;
  z-index: 50;
}

.overlay[hidden] { display: none; }

.modal {
  width: 340px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.modal-hint {
  margin: 6px 0 14px;
  font-size: 13px;
  color: var(--text-faint);
}

.modal-input {
  width: 100%;
  appearance: none;
  font: inherit;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
