:root {
  --ink: #14201a;
  --muted: #5c6b63;
  --paper: #f3efe6;
  --panel: rgba(255, 252, 246, 0.88);
  --line: rgba(20, 32, 26, 0.12);
  --accent: #1f6b4a;
  --accent-2: #c45c26;
  --danger: #9b2c2c;
  --ok: #1f6b4a;
  --shadow: 0 18px 50px rgba(20, 32, 26, 0.08);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(31, 107, 74, 0.18), transparent 60%),
    radial-gradient(700px 420px at 90% 0%, rgba(196, 92, 38, 0.14), transparent 55%),
    linear-gradient(180deg, #efe8da 0%, #f3efe6 40%, #e7eee8 100%);
  z-index: -1;
}

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.top-brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.admin-switcher {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.admin-switcher label {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.admin-switcher select {
  width: min(260px, 58vw);
  border: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.95);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
}

.account-menu {
  position: relative;
}

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: min(240px, 70vw);
  height: 2.35rem;
  border: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.95);
  border-radius: 999px;
  padding: 0 0.75rem 0 0.9rem;
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  box-sizing: border-box;
}

.account-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  flex-shrink: 0;
}

.account-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 11rem;
  padding: 0.4rem;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(20, 32, 26, 0.12);
  z-index: 30;
}

.account-role {
  margin: 0;
  padding: 0.4rem 0.55rem 0.55rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
  border-bottom: 1px solid var(--line);
}

.account-item {
  width: 100%;
  margin-top: 0.25rem;
  border: 0;
  background: transparent;
  text-align: left;
  justify-content: flex-start;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

.account-item:hover {
  background: rgba(31, 107, 74, 0.08);
}

a.account-item {
  display: flex;
  text-decoration: none;
  box-sizing: border-box;
  color: var(--ink);
}

#signOutBtn.account-item,
.account-item.sign-out {
  color: var(--danger);
}

#signOutBtn.account-item:hover,
.account-item.sign-out:hover {
  background: rgba(155, 44, 44, 0.08);
  color: var(--danger);
}

.customer-pick label,
form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.row {
  display: flex;
  gap: 0.5rem;
}

input,
select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  color: var(--ink);
  min-width: 0;
}

button,
a.primary,
a.secondary,
a.ghost {
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

button.primary,
a.primary {
  background: var(--accent);
  color: #fff;
}

button.secondary,
a.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost,
a.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

a.primary:visited,
a.secondary:visited,
a.ghost:visited,
a.top-link:visited,
a.account-item:visited {
  color: inherit;
}

a.secondary:visited {
  color: var(--ink);
}

a.ghost:visited {
  color: var(--muted);
}

a.primary:visited {
  color: #fff;
}

.hero-balance {
  padding: 1.75rem 1.5rem;
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(31, 107, 74, 0.95), rgba(20, 60, 42, 0.98));
  color: #f7f4ec;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.hero-balance .label {
  margin: 0;
  opacity: 0.8;
  font-size: 0.85rem;
}

.hero-balance .amount {
  margin: 0.2rem 0;
  font-family: var(--display);
  font-size: clamp(2.8rem, 6vw, 4rem);
  line-height: 1;
}

.hero-balance .meta {
  margin: 0.5rem 0 0;
  opacity: 0.85;
  font-size: 0.9rem;
}

.credit-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem 0.65rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(247, 244, 236, 0.2);
}

.credit-form label {
  color: rgba(247, 244, 236, 0.85);
  font-size: 0.75rem;
}

.credit-form input {
  width: 7rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
}

.credit-form .hint {
  flex-basis: 100%;
  margin: 0;
  color: rgba(247, 244, 236, 0.75);
}

.credit-form button.credit-admin {
  background: transparent;
  color: rgba(247, 244, 236, 0.85);
  border: 1px solid rgba(247, 244, 236, 0.35);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.25rem;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel.create {
  margin-top: 1.25rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

form {
  display: grid;
  gap: 0.85rem;
}

.create-form {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

.hint {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.method-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  position: relative;
}

.pm-menu {
  position: relative;
  flex-shrink: 0;
}

.pm-menu-btn {
  width: 2rem;
  height: 2rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pm-menu-icon {
  display: block;
}

.pm-menu-btn:hover,
.pm-menu-btn[aria-expanded="true"] {
  background: rgba(20, 32, 26, 0.08);
  color: var(--ink);
}

.pm-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 10rem;
  padding: 0.25rem;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(20, 32, 26, 0.14);
  z-index: 20;
  flex-direction: column;
  gap: 0.1rem;
}

.pm-menu-dropdown.is-open {
  display: flex;
}

.pm-menu-dropdown button {
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
}

.pm-menu-dropdown button:hover {
  background: rgba(31, 107, 74, 0.08);
}

.pm-menu-dropdown .pm-remove {
  color: var(--danger);
}

.pm-menu-dropdown .pm-remove:hover {
  background: rgba(155, 44, 44, 0.08);
}

.shipment-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
}

.shipment-form label {
  flex: 1 1 140px;
}

.test-tools {
  border-style: dashed;
  margin-top: 1.25rem;
}

.list li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

.stripe-box {
  margin-top: 1rem;
  padding: 1rem 0 0.25rem;
  border-top: 1px solid var(--line);
}

.stripe-box #confirmSetupBtn {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.stripe-box .hint {
  margin-top: 0.35rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e7eee8;
}

.badge.processing {
  background: #f3e0d2;
  color: var(--accent-2);
}

.badge.succeeded {
  background: #d9ebe2;
  color: var(--ok);
}

.badge.failed,
.badge.returned {
  background: #f3d9d9;
  color: var(--danger);
}

.frozen {
  color: #fecaca;
}

.masquerade-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  padding: 0.65rem 1.25rem;
  background: #1a3328;
  color: #f4f1ea;
  border-bottom: 1px solid rgba(244, 241, 234, 0.15);
}

.masquerade-banner[hidden] {
  display: none !important;
}

.masquerade-banner p {
  margin: 0;
  font-size: 0.9rem;
}

.masquerade-banner strong {
  font-weight: 600;
}

.masquerade-banner .ghost {
  color: #f4f1ea;
  border-color: rgba(244, 241, 234, 0.35);
  background: transparent;
}

.masquerade-banner .ghost:hover {
  background: rgba(244, 241, 234, 0.1);
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}

.auth-gate[hidden],
.shell[hidden],
[hidden] {
  display: none !important;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 2.2rem;
}

.auth-lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.auth-form {
  display: grid;
  gap: 0.85rem;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.auth-error {
  color: var(--danger);
}

.auth-links {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
}

.auth-links a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.auth-links a:hover {
  text-decoration: underline;
}

.password-rules {
  list-style: none;
  margin: -0.35rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.password-rules .rule-ok {
  color: var(--ok);
}

.password-rules .rule-bad {
  color: var(--muted);
}

.password-rules .rule-ok::before {
  content: "✓ ";
}

.password-rules .rule-bad::before {
  content: "○ ";
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.pager-size {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.pager-size select {
  width: auto;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  font-size: 0.8rem;
}

.pager-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1 1 auto;
  text-align: center;
}

.pager-nav {
  display: flex;
  gap: 0.35rem;
}

.pager-btn {
  min-width: 2.25rem;
  padding: 0.4rem 0.65rem;
}

.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

a.ghost.top-link,
.top-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  height: 2.35rem;
  padding: 0 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  background: rgba(255, 252, 246, 0.95);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-sizing: border-box;
}

a.ghost.top-link:hover,
.top-link:hover {
  background: #fff;
  color: var(--ink);
}

.user-search {
  min-width: min(240px, 50vw);
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

.click-row {
  cursor: pointer;
}

.click-row:hover {
  background: rgba(31, 107, 74, 0.06);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 26, 0.45);
  display: grid;
  place-items: center;
  padding: 1.25rem;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: min(520px, 100%);
  max-height: min(85vh, 720px);
  overflow: auto;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem 1.35rem;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 400;
  word-break: break-all;
}

.detail-grid {
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.detail-grid > div {
  display: grid;
  gap: 0.15rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

.detail-grid dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.detail-grid dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink);
  word-break: break-word;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-card-wide {
  width: min(640px, 100%);
}

.modal-section {
  margin-top: 1.15rem;
}

.modal-section h3 {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.assigned-users {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.assigned-users li {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 252, 246, 0.8);
  font-size: 0.9rem;
}

.modal-actions a.primary {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

.modal-actions a.secondary {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.modal-actions a.secondary:visited {
  color: var(--ink);
}

.check-row {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

.check-row input {
  width: auto;
  min-width: 0;
}

@media (max-width: 800px) {
  .grid {
    grid-template-columns: 1fr;
  }
}
