:root {
  --primary: #0f766e;
  --primary-dark: #0f5f59;
  --accent: #b45309;
  --page: #f5f7f8;
  --panel: #ffffff;
  --soft: #e6f5f3;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page);
  color: #152026;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
}

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

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
}

button:disabled {
  background: #9aa5ad;
  cursor: not-allowed;
}

.app-shell {
  margin: 0 auto;
  max-width: 1120px;
  min-height: 100vh;
  padding: 18px;
}

.login-panel {
  margin-left: auto;
  margin-right: auto;
  max-width: 520px;
}

.topbar,
.token-row,
.panel-header,
.total-row,
.summary-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.topbar {
  margin-bottom: 16px;
}

.brand-block {
  position: relative;
}

.app-label {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 0;
  color: #fff;
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  margin-top: 4px;
  padding: 4px 9px;
}

.eyebrow {
  color: #65737c;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.icon-button {
  align-items: center;
  aspect-ratio: 1;
  border-radius: 50%;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  padding: 0;
  width: 44px;
}

.login-panel,
.session-panel,
.panel,
.status {
  background: var(--panel);
  border: 1px solid #dce4e8;
  border-radius: 8px;
}

.login-panel,
.session-panel,
.panel {
  padding: 14px;
}

.login-panel,
.session-panel,
.status {
  margin-bottom: 12px;
}

.session-panel {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.hidden {
  display: none !important;
}

.collection-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(320px, 430px) 1fr;
}

label,
.section-title {
  color: #31414b;
  display: block;
  font-size: 13px;
  font-weight: 800;
  margin: 0 0 8px;
}

.section-title {
  background: linear-gradient(135deg, var(--soft), rgba(255, 255, 255, 0));
  border-left: 4px solid var(--primary);
  border-radius: 0;
  border-top: 1px solid #e6ecef;
  margin-top: 16px;
  padding: 10px 12px;
}

.section-title:first-child {
  border-top: 0;
  margin-top: 0;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cbd6dc;
  border-radius: 8px;
  color: #152026;
  margin-top: 7px;
  min-height: 42px;
  min-width: 0;
  padding: 10px 12px;
  width: 100%;
}

.previous-user-select {
  margin-top: 0;
}

.previous-user-select select {
  margin-top: 7px;
  width: 100%;
}

.password-field {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  margin-top: 7px;
}

.password-field input {
  margin-top: 0;
  min-width: 0;
  width: 100%;
}

.password-toggle {
  background: var(--soft);
  color: var(--primary-dark);
  min-height: 42px;
  min-width: 72px;
  padding: 0 12px;
}

.secondary-button {
  background: var(--soft);
  color: var(--primary-dark);
  margin-bottom: 8px;
  width: 100%;
}

.view-only-banner {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
  display: block;
}

.view-only-row {
  grid-template-columns: 1fr auto;
}

textarea {
  resize: vertical;
}

.field-grid,
.allocation-list {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.allocation-list {
  grid-template-columns: repeat(3, 1fr);
}

.status {
  color: #31414b;
  display: none;
  padding: 10px 12px;
}

.status.visible {
  display: block;
}

.status.error,
.warning {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #be123c;
}

.loan-summary,
.loan-list {
  background: #f8fafb;
  border: 1px solid #e0e7eb;
  border-radius: 8px;
  margin: 10px 0 0;
  padding: 12px;
}

.loan-option {
  align-items: center;
  background: #fff;
  border: 1px solid #dfe7eb;
  border-radius: 8px;
  color: #152026;
  display: grid;
  gap: 10px;
  grid-template-columns: auto 1fr auto;
  margin: 8px 0 0;
  padding: 10px;
}

.loan-option input {
  margin: 0;
  min-height: 20px;
  width: 20px;
}

.loan-option small,
.allocation-head small {
  color: #65737c;
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-top: 3px;
}

.selected-list {
  display: grid;
  gap: 10px;
}

.allocation-card {
  background: #fff;
  border: 1px solid #dfe7eb;
  border-radius: 8px;
  padding: 12px;
}

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

.allocation-head b,
.loan-option b {
  color: var(--primary-dark);
  white-space: nowrap;
}

.balance-button {
  background: linear-gradient(135deg, var(--soft), #fff);
  border: 1px solid #bde4df;
  border-radius: 0;
  color: var(--primary-dark);
  font-weight: 800;
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.other-entry {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr 130px auto;
}

.ledger-drawer {
  background: rgba(21, 32, 38, 0.28);
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 0;
  transition: opacity 180ms ease;
  width: 100%;
  z-index: 20;
}

.ledger-drawer.open {
  opacity: 1;
  pointer-events: auto;
}

.ledger-panel {
  background: var(--panel);
  border-left: 1px solid #dce4e8;
  box-shadow: -12px 0 34px rgba(15, 23, 42, 0.18);
  height: 100%;
  max-width: 780px;
  overflow: auto;
  padding: 16px;
  transform: translateX(100%);
  transition: transform 180ms ease;
  width: min(92vw, 780px);
}

.ledger-drawer.open .ledger-panel {
  transform: translateX(0);
}

.ledger-table-wrap {
  min-height: 180px;
  position: relative;
}

.loading-overlay {
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  inset: 0;
  justify-content: center;
  position: absolute;
  z-index: 6;
}

.loading-overlay.hidden {
  display: none;
}

#appLoading {
  background: rgba(245, 247, 248, 0.82);
  position: fixed;
  z-index: 40;
}

.loading-panel {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.loading-spinner {
  animation: loading-spin 0.8s linear infinite;
  border: 3px solid var(--soft);
  border-radius: 50%;
  border-top-color: var(--primary);
  height: 40px;
  width: 40px;
}

.loading-text {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
  margin: 0;
  text-align: center;
}

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

.summary-row {
  border-bottom: 1px solid #e7edf0;
  padding: 8px 0;
}

.summary-row:last-child {
  border-bottom: 0;
}

.summary-row span,
.account-map span {
  color: #65737c;
  font-size: 12px;
}

.summary-row strong,
.account-map strong {
  color: #152026;
  font-size: 13px;
  text-align: right;
}

.account-map {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.account-map div {
  display: grid;
  gap: 4px;
}

.warning {
  border: 1px solid #fecdd3;
  border-radius: 8px;
  margin-top: 10px;
  padding: 8px;
}

.total-row {
  background: linear-gradient(135deg, var(--soft), #ffffff);
  border: 1px solid #bde4df;
  border-radius: 0;
  color: var(--primary-dark);
  font-size: 18px;
  margin: 12px 0;
  padding: 12px;
}

.submit-button {
  margin-top: 8px;
  width: 100%;
}

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

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

th,
td {
  border-bottom: 1px solid #e5ebef;
  font-size: 13px;
  max-width: 280px;
  padding: 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: #f8fafb;
  color: #31414b;
  font-weight: 800;
  position: sticky;
  top: 0;
}

#ledgerTable th,
#ledgerTable td {
  line-height: 0.75;
  padding: 7.5px 10px;
}

#ledgerTable th.numeric,
#ledgerTable td.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#ledgerTable tbody tr:nth-child(odd) {
  background: var(--soft);
  color: #152026;
}

#ledgerTable tbody tr:nth-child(even) {
  background: var(--panel);
  color: #152026;
}

.empty {
  color: #65737c;
  margin: 0;
  padding: 10px 0;
}

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

  .collection-grid,
  .field-grid,
  .other-entry,
  .allocation-list {
    grid-template-columns: 1fr;
  }

  .token-row {
    align-items: stretch;
    flex-direction: column;
  }

  .token-row button {
    width: 100%;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }

  .login-panel,
  .session-panel,
  .panel {
    padding: 12px;
  }

}
