*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  scroll-padding-top: calc(var(--topbar-height) + 12px);
  scroll-padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 12px);
}

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font: 400 14px/1.5 var(--font-sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

[hidden],
.is-search-hidden {
  display: none !important;
}

a {
  color: var(--accent-ink);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3, p {
  margin: 0;
}

.mono {
  font-family: var(--font-mono);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:is(a, button, summary, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 3px;
}

.muted {
  color: var(--ink-muted);
  font-size: 13px;
}

.hash {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.skip-link {
  position: fixed;
  inset: 12px auto auto 12px;
  clip-path: inset(50%);
  background: var(--cta-dark);
  color: var(--bg-card);
  padding: 8px 14px;
  z-index: 30;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  clip-path: none;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.brand-mark {
  color: var(--accent-blue);
  flex: none;
}

/* Portal navigation and header */
.portal {
  min-height: 100vh;
  display: grid;
  grid-template: auto 1fr / minmax(0, 1fr);
  grid-template-areas: "topbar" "content";
}

.sidebar {
  display: contents;
  grid-area: sidebar;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand:hover {
  text-decoration: none;
}

.sidebar .brand {
  display: none;
}

.portal-nav {
  position: fixed;
  z-index: 15;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding: 4px max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
  border-top: 1px solid var(--hairline);
  background: rgb(255 255 255 / 90%);
  backdrop-filter: blur(16px);
}

.portal-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
  transition: background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.portal-nav a:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  text-decoration: none;
}

.portal-nav a[aria-current="page"] {
  color: var(--accent-ink);
}

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: var(--topbar-height);
  padding-inline: var(--page-gutter);
  background: var(--bg-card);
  border-bottom: 1px solid var(--hairline);
}

.topbar-user,
.topbar-actions {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar-user {
  gap: 12px;
}

.topbar-actions {
  justify-content: flex-end;
  gap: 4px;
}

.user-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cta-dark);
  color: var(--bg-card);
  font-size: 12px;
  font-weight: 700;
}

.topbar-action-label {
  display: none;
}

.user-name {
  position: absolute;
  width: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.portal-search {
  position: relative;
  min-width: 0;
  color: var(--ink-muted);
}

.portal-search .icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  pointer-events: none;
}

.portal-search input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px 8px 36px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font: inherit;
  font-size: 16px;
}

.portal-search input::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

.topbar :is(.mobile-link, .button-quiet) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  border-radius: var(--radius-pill);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.topbar :is(.mobile-link, .button-quiet):hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  text-decoration: none;
}

.portal-content {
  grid-area: content;
  justify-self: center;
  width: 100%;
  max-width: var(--content-width);
  min-width: 0;
  padding: 24px var(--page-gutter) calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 24px);
}

.page-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-heading h1 {
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.split-layout,
.section-stack {
  display: grid;
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.4vw, 24px);
  min-width: 0;
  box-shadow: var(--shadow-card);
}

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

.panel-header h2 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

/* Dashboard */
.dashboard {
  gap: 20px;
}

.dashboard-hero {
  padding: clamp(18px, 3.5vw, 40px);
}

.hero-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.hero-heading h2 {
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 600;
}

.balance-value {
  margin-top: 10px;
  font-size: clamp(38px, 8.5vw, 72px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.06;
  overflow-wrap: anywhere;
}

.balance-fraction,
.balance-currency {
  color: var(--text-secondary);
  font-weight: 600;
}

.balance-fraction {
  font-size: 0.60em;
}

.balance-currency {
  color: var(--ink-muted);
  font-size: 0.38em;
  letter-spacing: 0;
}

.currency-switcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--text-primary);
  transition: transform 150ms ease;
}

.currency-switcher .icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.currency-switcher .icon:last-child {
  right: 12px;
  left: auto;
}

.currency-switcher select {
  min-height: 44px;
  max-width: 100%;
  padding: 6px 36px;
  appearance: none;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  max-width: 410px;
  margin-top: clamp(18px, 3vw, 30px);
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: clamp(11px, 2.75vw, 13px);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  transition: transform 150ms ease;
}

.quick-action-icon,
.currency-badge,
.transaction-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.quick-action-icon {
  width: 44px;
  height: 44px;
  transition: background-color 150ms ease, color 150ms ease;
}

.quick-action-icon-primary {
  background: var(--cta-dark);
  color: var(--bg-card);
}

.quick-action:hover {
  text-decoration: none;
}

.quick-action:hover .quick-action-icon {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.dashboard-bento {
  display: grid;
  align-items: start;
  gap: 20px;
}

.dashboard-accounts,
.dashboard-activity {
  min-width: 0;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr));
  gap: 12px;
}

.account-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  overflow-wrap: anywhere;
}

.account-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-meta {
  min-width: 0;
}

.currency-badge {
  font-size: 18px;
  font-weight: 600;
}

.account-card h3 {
  font-size: 14px;
  font-weight: 650;
}

.account-number {
  color: var(--ink-muted);
  font-size: 11px;
}

.account-balance {
  font-size: clamp(20px, 3vw, 24px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

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

.transaction-list li + li {
  border-top: 1px solid var(--hairline);
}

.transaction-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) fit-content(44%);
  align-items: center;
  gap: clamp(6px, 1.5vw, 12px);
  width: 100%;
  padding: 11px 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms ease, transform 150ms ease;
}

.transaction-row:hover {
  background: var(--bg-canvas);
}

.transaction-copy,
.transaction-values {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.transaction-values {
  justify-items: end;
  text-align: right;
}

.transaction-title,
.transaction-amount {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.transaction-time {
  color: var(--ink-muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.transaction-values .badge {
  justify-content: flex-end;
  font-size: 11px;
  line-height: 1.3;
}

/* Forms & Inputs */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.field small {
  font-size: 12px;
  color: var(--ink-muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field .mono {
  font-family: var(--font-mono);
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 1px solid var(--accent-blue);
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline-strong);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.button:hover {
  background: var(--bg-subtle);
  text-decoration: none;
}

.button:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 3px;
}

.button-primary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--bg-card);
}

.button-primary:hover {
  background: color-mix(in srgb, var(--accent-blue) 84%, var(--text-primary));
  border-color: var(--accent-blue);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-muted);
  padding: 6px 10px;
}

.button-quiet:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.button-block {
  width: 100%;
}

/* Badges & Alerts */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  width: fit-content;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.badge-good {
  background: var(--good-soft);
  color: var(--good-ink);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn-ink);
}

.badge-bad {
  background: var(--bad-soft);
  color: var(--bad-ink);
}

.badge-muted {
  background: var(--bg-subtle);
  color: var(--ink-muted);
}

.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
}

.alert-success {
  background: var(--good-soft);
  border-color: #BBF7D0;
  color: var(--good-ink);
}

.alert-warning {
  background: var(--warn-soft);
  border-color: #FDE68A;
  color: var(--warn-ink);
}

.alert-error {
  background: var(--bad-soft);
  border-color: #FECACA;
  color: var(--bad-ink);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}

.data-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table th.numeric,
.data-table td.numeric {
  text-align: right;
}

.data-table tbody tr:hover {
  background: var(--bg-canvas);
}

.empty-state {
  padding: 18px;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Exchange Preview & Verification */
.rate-box {
  padding: 16px;
  min-height: 88px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--hairline);
  overflow-wrap: anywhere;
}

.rate-box.htmx-request {
  opacity: .7;
}

.rate-amount {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 4px 0;
}

.verification-result {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.signature-details summary {
  cursor: pointer;
  color: var(--accent-blue);
}

.signature-details .hash {
  display: block;
  margin-top: 6px;
}

/* Auth Pages */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-canvas);
}

.auth-shell {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-heading h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-footer {
  text-align: center;
  color: var(--ink-muted);
  font-size: 13px;
}


/* Modal bottom sheets */
html:has(.bottom-sheet[open]) {
  overflow: hidden;
}

.bottom-sheet {
  --sheet-bottom: 0px;

  position: fixed;
  inset: auto 0 var(--sheet-bottom);
  width: min(100%, 520px);
  max-width: none;
  max-height: min(85dvh, 680px);
  margin: 0 auto;
  padding: 14px clamp(18px, 5vw, 32px) calc(24px + env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  transform: translateY(calc(100% + var(--sheet-bottom)));
  transition: transform 230ms cubic-bezier(0.2, 0.7, 0.2, 1);
  transition: transform 230ms cubic-bezier(0.2, 0.7, 0.2, 1), display 230ms allow-discrete, overlay 230ms allow-discrete;
}

.bottom-sheet[open] {
  transform: translateY(0);
}

.bottom-sheet::backdrop {
  background: transparent;
  transition: background-color 200ms ease, display 230ms allow-discrete, overlay 230ms allow-discrete;
}

.bottom-sheet[open]::backdrop {
  background: var(--sheet-scrim);
}

@starting-style {
  .bottom-sheet[open] {
    transform: translateY(calc(100% + var(--sheet-bottom)));
  }

  .bottom-sheet[open]::backdrop {
    background: transparent;
  }
}

.bottom-sheet .button-primary {
  border-color: transparent;
  border-radius: var(--radius-pill);
  background: var(--cta-dark);
}

.bottom-sheet .button-primary:hover {
  background: color-mix(in srgb, var(--cta-dark) 84%, var(--bg-card));
}

.currency-switcher select:disabled {
  color: var(--ink-muted);
  cursor: default;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.sheet-header h2 {
  font-size: clamp(20px, 4vw, 26px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.sheet-close {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 150ms ease, transform 150ms ease;
}

.sheet-close:hover {
  background: var(--hairline);
}

.sheet-details {
  display: grid;
  gap: 12px;
  margin: 0;
}

.sheet-details dt {
  color: var(--ink-muted);
  font-size: 13px;
}

.sheet-details dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

:is(.quick-action, .currency-switcher, .transaction-row, .button, .sheet-close, .portal-nav a, .mobile-link):active {
  transform: scale(0.97);
}

@media (max-width: 560px) {
  .account-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: min(230px, 85%);
    margin-inline: -4px;
    padding: 4px 4px 8px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-padding-inline: 4px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    scrollbar-color: var(--hairline-strong) transparent;
  }

  .account-card {
    scroll-snap-align: start;
  }
}

@media (width > 768px) {
  :root {
    scroll-padding-bottom: 16px;
  }

  .portal {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "sidebar content";
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) minmax(0, 420px) minmax(0, 1fr);
    gap: 16px;
  }

  .portal-search input {
    font-size: 14px;
  }

  .user-name {
    position: static;
    width: auto;
    clip-path: none;
  }

  .sidebar {
    position: sticky;
    top: var(--topbar-height);
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: calc(100dvh - var(--topbar-height));
    overflow: auto;
    padding: 28px 16px;
    border-right: 1px solid var(--hairline);
    background: var(--bg-card);
  }

  .sidebar .brand {
    display: flex;
    padding-inline: 12px;
  }

  .portal-nav {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    padding: 0;
    border: 0;
    background: var(--bg-card);
    backdrop-filter: none;
  }

  .portal-nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
    font-size: 14px;
  }

  .portal-nav a[aria-current="page"] {
    background: var(--accent-soft);
  }

  .portal-content {
    padding-block: 34px 48px;
  }

  .bottom-sheet {
    --sheet-bottom: 12px;
    border-radius: var(--radius-lg);
  }
}

@media (min-width: 1024px) {
  .topbar-action-label {
    display: inline;
  }

  .topbar :is(.mobile-link, .button-quiet) {
    padding-inline: 12px;
  }

  .dashboard-bento {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  }

  .split-layout {
    grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
  }

  :is(.quick-action, .currency-switcher, .transaction-row, .button, .sheet-close, .portal-nav a, .mobile-link):active {
    transform: none;
  }
}
