:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-border: rgba(17, 24, 39, 0.08);
  --ink: #171d2d;
  --muted: #5f687a;
  --accent: #f05d2f;
  --accent-dark: #c1461c;
  --accent-soft: rgba(240, 93, 47, 0.12);
  --success: #127a5a;
  --success-soft: rgba(18, 122, 90, 0.12);
  --error: #b63b3b;
  --shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  --input-bg: #f8fafc;
  --dark-surface: #111827;
  --dark-surface-soft: #1f2937;
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
  display: grid;
  gap: 14px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: none;
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: none;
}

.hero {
  display: grid;
  gap: 12px;
  padding: 24px;
  background: #ffffff;
}

.live-balance-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(28, 124, 84, 0.2);
  background: #f4fbf8;
  color: var(--ink);
}

.live-balance-stack {
  display: grid;
  gap: 6px;
}

.live-balance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-status-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.portal-status-indicator {
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.portal-status-indicator.unknown {
  color: var(--muted);
  background: rgba(95, 104, 122, 0.12);
  border-color: rgba(95, 104, 122, 0.2);
}

.portal-status-indicator.up {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(18, 122, 90, 0.24);
}

.portal-status-indicator.down {
  color: var(--error);
  background: rgba(182, 59, 59, 0.12);
  border-color: rgba(182, 59, 59, 0.24);
}

.balance-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.balance-connect-button {
  flex-shrink: 0;
  white-space: nowrap;
}

.live-balance-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.live-balance-label {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#live-balance-value {
  font-size: clamp(1.1rem, 2vw, 1.8rem);
  color: var(--success);
}

.last-balance-checked {
  font-size: 0.8rem;
  color: var(--muted);
}

.balance-refresh-indicator {
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.balance-refresh-indicator.idle {
  color: var(--muted);
  background: rgba(95, 104, 122, 0.12);
  border-color: rgba(95, 104, 122, 0.2);
}

.balance-refresh-indicator.refreshing {
  color: #8a4f00;
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.35);
}

.balance-refresh-indicator.success {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(18, 122, 90, 0.24);
}

.balance-refresh-indicator.error {
  color: var(--error);
  background: rgba(182, 59, 59, 0.12);
  border-color: rgba(182, 59, 59, 0.24);
}

.balance-refresh-button {
  border: 1px solid rgba(17, 24, 39, 0.16);
  background: #ffffff;
  color: var(--muted);
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: none;
  font-size: 0.95rem;
}

.balance-refresh-button:hover {
  background: #f8fafc;
  color: var(--ink);
  box-shadow: none;
}

.balance-refresh-button.spinning span {
  display: inline-block;
  animation: spin 0.9s linear infinite;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  color: var(--accent-dark);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 2.8vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

h2 {
  font-size: clamp(1.3rem, 2vw, 1.8rem);
  letter-spacing: -0.04em;
}

.intro {
  max-width: 720px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.45;
}

.form-panel,
.output-panel,
.history-panel {
  padding: 20px;
}

.transfer-tabs {
  display: inline-flex;
  gap: 8px;
  background: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px;
  width: fit-content;
}

.transfer-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  box-shadow: none;
}

.transfer-tab:hover {
  box-shadow: none;
  background: rgba(95, 104, 122, 0.08);
  color: var(--ink);
}

.transfer-tab.active {
  background: #ffffff;
  border-color: rgba(17, 24, 39, 0.14);
  color: var(--ink);
}

.form {
  display: grid;
  gap: 14px;
}

.login-line-picker {
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.9);
  display: grid;
  gap: 10px;
}

.login-line-picker legend {
  padding: 0 4px;
  font-weight: 700;
  color: var(--ink);
}

.login-line-option {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  cursor: pointer;
}

.login-line-option input {
  width: auto;
}

.settings-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.settings-label {
  display: grid;
  gap: 8px;
}

.settings-note {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.9rem;
}

.history-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.groups-grid-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 12px;
  background: #ffffff;
}

.groups-grid {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.groups-grid th,
.groups-grid td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(17, 24, 39, 0.08);
  white-space: nowrap;
  font-size: 0.9rem;
}

.groups-grid th {
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fafc;
}

.groups-grid tbody tr:hover {
  background: rgba(240, 93, 47, 0.06);
}

.batch-upload-grid td:nth-child(3) {
  white-space: normal;
  min-width: 280px;
}

.batch-upload-grid td:nth-child(4) {
  font-weight: 700;
}

.batch-upload-main-row {
  cursor: pointer;
}

.batch-upload-detail-row > td {
  background: #fbfcff;
  white-space: normal;
}

.batch-upload-detail-wrap {
  display: grid;
  gap: 8px;
  padding: 4px 0;
}

.batch-upload-sub-grid {
  min-width: 1100px;
}

.batch-upload-sub-grid td,
.batch-upload-sub-grid th {
  white-space: nowrap;
}

.batch-action-cell {
  position: relative;
}

.batch-action-menu {
  position: fixed;
  z-index: 5000;
  min-width: 170px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 14px 24px rgba(17, 24, 39, 0.2);
}

.batch-action-menu[hidden] {
  display: none !important;
}

.groups-manage-btn {
  padding: 6px 10px;
  min-height: 32px;
  border-radius: 8px;
}

.manage-group-menu {
  position: fixed;
  z-index: 1100;
  min-width: 210px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  background: #ffffff;
  box-shadow: 0 18px 35px rgba(17, 24, 39, 0.2);
}

.manage-group-menu[hidden] {
  display: none !important;
}

.manage-group-menu-item {
  width: 100%;
  text-align: left;
  border-radius: 8px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  background: #ffffff;
  color: var(--ink);
  box-shadow: none;
  padding: 8px 10px;
  font-weight: 600;
}

.manage-group-menu-item:hover {
  background: rgba(240, 93, 47, 0.1);
  color: var(--accent-dark);
  box-shadow: none;
  transform: none;
}

.manage-group-menu-item.danger {
  color: var(--error);
  border-color: rgba(182, 59, 59, 0.2);
}

.groups-grid-loading-cell {
  text-align: center;
  color: var(--muted);
}

.groups-grid-loading-cell span {
  vertical-align: middle;
}

.groups-grid-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border: 2px solid rgba(95, 104, 122, 0.28);
  border-top-color: var(--accent-dark);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.create-group-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 16, 27, 0.45);
}

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

.create-group-wrap {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid rgba(17, 24, 39, 0.1);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 20px 45px rgba(17, 24, 39, 0.24);
}

.create-group-wrap h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.create-group-head {
  margin-bottom: 12px;
}

.create-group-close {
  white-space: nowrap;
}

#create-group-output {
  margin-top: 12px;
  min-height: 120px;
}

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

label,
.locked-fields > div {
  min-width: 0;
  display: grid;
  gap: 8px;
}

span,
.locked-label {
  font-size: 0.92rem;
  color: var(--muted);
}

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

textarea,
input,
select {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.38);
  background: var(--input-bg);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: rgba(240, 93, 47, 0.5);
  box-shadow: 0 0 0 4px rgba(240, 93, 47, 0.08);
  background: rgba(255, 255, 255, 0.98);
}

.locked-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.locked-fields > div {
  padding: 16px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 18px;
  border: 1px dashed rgba(102, 61, 22, 0.18);
}

button {
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent) 0%, #e67346 100%);
  color: white;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
  box-shadow: 0 8px 18px rgba(240, 93, 47, 0.16);
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow: 0 16px 32px rgba(240, 93, 47, 0.2);
}

button:active {
  transform: translateY(0);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  box-shadow: none;
}

.secondary-button {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent-dark);
  border: 1px solid rgba(17, 24, 39, 0.08);
  box-shadow: none;
}

.secondary-button:hover {
  box-shadow: none;
  background: rgba(255, 255, 255, 0.9);
}

.output-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.connection-head {
  flex-wrap: nowrap;
}

.history-actions {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.status-pill {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.status-pill.idle {
  background: rgba(148, 163, 184, 0.14);
  color: var(--muted);
}

.status-pill.sending {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-pill.success {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.error {
  background: rgba(182, 59, 59, 0.10);
  color: var(--error);
}

pre {
  min-width: 0;
  max-width: 100%;
  margin: 0;
  min-height: 160px;
  padding: 14px;
  border-radius: 12px;
  background: #172133;
  color: #edf6ff;
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

summary::-webkit-details-marker {
  display: none;
}

.settings-note,
.history-summary,
.output-head h2,
.output-head h3,
.history-row,
.status-pill {
  overflow-wrap: anywhere;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-summary {
  margin-bottom: 10px;
  color: var(--muted);
  line-height: 1.35;
}

.history-card {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(102, 61, 22, 0.12);
}

.history-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.history-row span,
.history-card p,
.history-empty {
  color: var(--muted);
}

.history-card p,
.history-empty {
  margin: 0;
  word-break: break-all;
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.page-indicator {
  color: var(--muted);
  font-weight: 500;
}

.column-filter-wrap {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  gap: 8px;
}

.column-filter-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.column-filter-toggle {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-icon {
  display: block;
}

.column-filter-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 3200;
  min-width: 280px;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.16);
}

.column-filter-popover input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: #fff;
}

.column-filter-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.column-filter-actions .secondary-button {
  padding: 7px 10px;
}

.batch-upload-page-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.batch-upload-page-buttons .secondary-button {
  min-width: 40px;
}

.batch-upload-page-buttons .secondary-button.active-page {
  background: linear-gradient(135deg, var(--accent) 0%, #e67346 100%);
  color: #ffffff;
  border-color: transparent;
}

.groups-page-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.groups-page-buttons .secondary-button {
  min-width: 40px;
}

.groups-page-buttons .secondary-button.active-page {
  background: linear-gradient(135deg, var(--accent) 0%, #e67346 100%);
  color: #ffffff;
  border-color: transparent;
}

@media (max-width: 980px) {
  .shell {
    width: min(calc(100% - 24px), 1100px);
    padding-top: 24px;
  }

  .grid,
  .history-filters,
  .settings-form,
  .locked-fields {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(calc(100% - 18px), 1100px);
    padding: 18px 0 28px;
  }

  .hero,
  .form-panel,
  .output-panel,
  .history-panel {
    padding: 20px;
  }

  .output-head,
  .history-actions,
  .history-row,
  .history-pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .live-balance-banner {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .live-balance-header {
    width: 100%;
    align-items: center;
  }
}
