:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #17191f;
  --panel-2: #20232b;
  --line: #30343d;
  --text: #f4f5f7;
  --muted: #a8b0bd;
  --primary: #39a7ff;
  --primary-2: #166bb8;
  --danger: #ff5a6b;
  --danger-2: #a5122a;
  --success: #28c284;
  --warning: #f2b84b;
  --purple: #ba74ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --z-overlay: 20;
  --z-login: 30;
  --z-toast: 40;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.topbar h1,
.panel h2,
.modal h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 24px;
  font-weight: 750;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.eyebrow.danger {
  color: var(--danger);
}

.balance-warning {
  margin: 6px 0 0;
  color: var(--warning);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.wallet-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.wallet-chip {
  min-width: 148px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.wallet-chip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.wallet-chip strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  font-weight: 700;
}

.wallet-chip.muted strong {
  color: #d7dce4;
}

.user-chip {
  min-width: 180px;
  border-radius: 999px;
  background: var(--panel-2);
}

.user-chip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.last-updated {
  flex-basis: 100%;
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.tabbar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 16px;
  font-weight: 800;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease;
}

.tab-btn:hover {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.tab-btn.active {
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--primary);
}

.tab-panel {
  min-width: 0;
}

.tab-panel[hidden] {
  display: none;
}

.main-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
}

.create-panel {
  padding: 18px;
  position: sticky;
  top: 18px;
}

.table-panel {
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.table-heading {
  padding: 18px 18px 0;
}

.panel-heading h2 {
  font-size: 18px;
}

.panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}

form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111318;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

::placeholder {
  color: #a8b0bd;
  opacity: 1;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
tr:focus-visible {
  border-color: var(--primary);
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  background: var(--panel-2);
  font-weight: 700;
  white-space: nowrap;
  transition:
    background-color 0.14s ease,
    border-color 0.14s ease,
    color 0.14s ease,
    filter 0.14s ease,
    transform 0.12s ease;
}

.btn.primary {
  background: var(--primary-2);
  border-color: #2788d8;
}

.btn.secondary {
  border-color: var(--line);
  background: #1d2631;
}

.btn.busy {
  filter: saturate(0.8);
}

.btn.ghost {
  border-color: var(--line);
  background: transparent;
}

.btn.danger {
  background: var(--danger-2);
  border-color: #d93b50;
}

.btn.danger-outline {
  border-color: rgba(255, 90, 107, 0.65);
  background: rgba(255, 90, 107, 0.08);
  color: #ff9aa5;
}

.btn.wide {
  width: 100%;
}

.btn.mini {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12px;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn:active:not(:disabled) {
  filter: brightness(0.94);
  transform: translateY(1px);
}

.btn.secondary:hover:not(:disabled),
.btn.ghost:hover:not(:disabled) {
  background: #27313d;
}

.btn.danger-outline:hover:not(:disabled) {
  background: rgba(255, 90, 107, 0.16);
}

.inline-warning,
.form-error {
  border: 1px solid rgba(242, 184, 75, 0.4);
  border-radius: 8px;
  background: rgba(242, 184, 75, 0.09);
  color: #ffd38a;
  padding: 9px 10px;
}

.form-error {
  border-color: rgba(255, 90, 107, 0.5);
  background: rgba(255, 90, 107, 0.1);
  color: #ffb5bd;
}

.field-error {
  color: #ffb5bd;
  font-size: 12px;
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: #15171c;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 34px 12px;
}

.recipient {
  display: grid;
  gap: 2px;
}

.recipient span,
.muted-text {
  color: var(--muted);
}

td strong {
  font-weight: 700;
}

.num,
.mono {
  font-variant-numeric: tabular-nums;
}

.status-cell {
  display: grid;
  gap: 5px;
  min-width: 130px;
}

.status-cell small {
  color: var(--muted);
  max-width: 240px;
}

.status-chip {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 700;
  font-size: 12px;
}

.status-chip.draft {
  color: #ffd27c;
  background: rgba(242, 184, 75, 0.16);
}

.status-chip.sending {
  color: #ffb36d;
  background: rgba(255, 138, 61, 0.17);
}

.status-chip.sent {
  color: #8fd2ff;
  background: rgba(57, 167, 255, 0.16);
}

.status-chip.completed {
  color: #72e2ae;
  background: rgba(40, 194, 132, 0.16);
}

.status-chip.failed {
  color: #ff9aa5;
  background: rgba(255, 90, 107, 0.17);
}

.status-chip.cancelled {
  color: #c5cad3;
  background: rgba(168, 176, 189, 0.14);
}

.status-chip.review {
  color: #f5b0ff;
  background: rgba(186, 116, 255, 0.17);
  box-shadow: inset 0 0 0 1px rgba(255, 90, 107, 0.35);
}

.role-badge {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  color: #c9e8ff;
  background: rgba(57, 167, 255, 0.15);
}

.role-badge.admin {
  color: #f5b0ff;
  background: rgba(186, 116, 255, 0.17);
}

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 170px;
}

.copy-ref {
  max-width: 160px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111318;
  color: #c9e8ff;
  padding: 4px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.66);
}

#loginOverlay {
  z-index: var(--z-login);
}

.overlay[hidden] {
  display: none;
}

.modal {
  width: min(680px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal.small {
  width: min(390px, 100%);
}

.modal.small p {
  margin: 6px 0 18px;
  color: var(--muted);
}

.modal-message {
  margin: 0 0 4px;
  color: var(--muted);
}

#actionFields {
  display: grid;
  gap: 10px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  transition:
    background-color 0.14s ease,
    border-color 0.14s ease,
    filter 0.14s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: #48505d;
}

.icon-btn:active:not(:disabled) {
  filter: brightness(0.9);
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.detail-list div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #12141a;
}

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
}

.detail-list dd {
  margin: 3px 0 0;
  font-weight: 700;
}

.danger-note {
  margin: 16px 0;
  border: 1px solid rgba(255, 90, 107, 0.52);
  border-radius: 8px;
  background: rgba(255, 90, 107, 0.11);
  color: #ffc4ca;
  padding: 11px 12px;
  font-weight: 700;
}

.modal-error {
  margin: 0 0 16px;
}

.password-display {
  margin: 12px 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1116;
  padding: 11px 12px;
  overflow-wrap: anywhere;
}

.password-display code {
  color: #dce7f3;
  font-size: 15px;
  font-weight: 700;
}

.inline-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.breakable {
  overflow-wrap: anywhere;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.logs-modal {
  width: min(980px, 100%);
}

.logs-content {
  display: grid;
  gap: 14px;
}

.log-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
}

.log-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.log-section h3 {
  margin: 0;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  background: #15171c;
  font-size: 14px;
}

details {
  border-top: 1px solid var(--line);
}

details:first-of-type {
  border-top: 0;
}

summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  background: #0c0d10;
  color: #dce7f3;
  font-size: 12px;
}

.empty-log {
  margin: 0;
  padding: 12px;
  color: var(--muted);
}

.valid-badge {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}

.valid-badge.ok {
  color: #72e2ae;
  background: rgba(40, 194, 132, 0.16);
}

.valid-badge.bad {
  color: #ff9aa5;
  background: rgba(255, 90, 107, 0.17);
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: var(--z-toast);
  display: grid;
  gap: 10px;
  width: min(390px, calc(100vw - 36px));
}

.toast {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255, 90, 107, 0.42);
  border-radius: 8px;
  background: #2a1218;
  color: #ffd9dd;
  padding: 11px 12px;
  box-shadow: var(--shadow);
}

.toast.success {
  border-color: rgba(40, 194, 132, 0.42);
  background: #10251d;
  color: #c5f5df;
}

.toast.warn {
  border-color: rgba(242, 184, 75, 0.42);
  background: #2a2110;
  color: #ffe0a3;
}

.toast-close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  line-height: 1;
}

.toast-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 980px) {
  .topbar,
  .main-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .tabbar {
    overflow-x: auto;
  }

  .create-panel {
    position: static;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 14px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .wallet-chip {
    min-width: 0;
    flex: 1 1 140px;
  }

  .detail-list {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    display: grid;
  }
}
