/* ========== Design Tokens ========== */

:root {
  /* Spacing */
  --spacing-xxs: 2px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-xxl: 48px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Fragment Mono", "Courier New", monospace;
}

/* ========== Dark Mode (default) ========== */

.dark {
  --color-primary: #ffffff;
  --color-background: #000000;
  --color-card: #171717;
  --color-text: #ffffff;
  --color-text-secondary: #a3a3a3;
  --color-text-tertiary: #737373;
  --color-border: #262626;
  --color-success: #10b981;
  --color-error: #ef4444;
  --color-warning: #ffef5d;
  --color-info: #3b82f6;
  --color-icon: #3b82f6;
  --color-modal-background: #0f0f0f;
  --color-modal-border: #3a3a3a;
  --color-modal-blur: rgba(0, 0, 0, 0.4);
  --color-input-bg: var(--color-background);
  --color-input-border: var(--color-border);
  --color-warning-bg: #3a2410;
  --color-error-bg: #3a1418;
  --color-bg-muted: #262626;
  /* Gray scale (inverted: gray-50 ≈ page bg, gray-900 ≈ strongest contrast) */
  --gray-50: #171717;
  --gray-100: #262626;
  --gray-200: #404040;
  --gray-300: #525252;
  --gray-400: #737373;
  --gray-500: #a3a3a3;
  --gray-600: #d4d4d4;
  --gray-700: #e5e5e5;
  --gray-800: #f5f5f5;
  --gray-900: #fafafa;
}

/* ========== Light Mode ========== */

.light {
  --color-primary: #000000;
  --color-background: #fafafa;
  --color-card: #ededed;
  --color-text: #181818;
  --color-text-secondary: #808080;
  --color-text-tertiary: #a0a0a0;
  --color-border: #cecece;
  --color-success: #10b981;
  --color-error: #ef4444;
  --color-warning: #c26700;
  --color-info: #3b82f6;
  --color-icon: #3b82f6;
  --color-modal-background: #ffffff;
  --color-modal-border: #cecece;
  --color-modal-blur: rgba(255, 255, 255, 0.6);
  --color-input-bg: var(--color-background);
  --color-input-border: var(--color-border);
  --color-warning-bg: #fff6eb;
  --color-error-bg: #ffeaea;
  --color-bg-muted: #ededed;
  /* Gray scale (gray-50 ≈ page bg, gray-900 ≈ strongest contrast) */
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #e5e5e5;
  --gray-300: #d4d4d4;
  --gray-400: #a3a3a3;
  --gray-500: #737373;
  --gray-600: #525252;
  --gray-700: #404040;
  --gray-800: #262626;
  --gray-900: #171717;
}

/* ========== Base Styles ========== */

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

/* React Native compatibility: Views default to flex column */
div {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* Inline elements should not inherit flex layout */
span,
a,
strong,
em,
code,
label {
  display: inline;
}

/* Text elements should not inherit flex */
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  display: block;
}

html,
body,
#root {
  font-family: var(--font-sans);
  color: var(--color-text);
  background-color: var(--color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== Typography ========== */

.h1 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 28px;
  line-height: 36px;
  letter-spacing: -0.21px;
  color: var(--color-text);
}

.h2 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 30px;
  line-height: 32px;
  color: var(--color-text);
}

.h3 {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 20px;
  line-height: 28px;
  color: var(--color-text);
}

.body {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
  color: var(--color-text);
}

.body-small {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
  color: var(--color-text);
}

.body-large {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 20px;
  line-height: 26px;
  color: var(--color-text);
}

.body-md-medium {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 16px;
  line-height: 24px;
  color: var(--color-text);
}

.label-caps {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.body-secondary {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
  color: var(--color-text-secondary);
}

.body-tertiary {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
  color: var(--color-text-tertiary);
}

.caption {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 12px;
  line-height: 16px;
  color: var(--color-text-secondary);
}

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

.italic {
  font-style: italic;
}
.bold {
  font-weight: 700;
}
.underline {
  text-decoration: underline;
}
.centered-text {
  text-align: center;
}
.left-text {
  text-align: left;
}

/* ========== Layout ========== */

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100dvh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: none;
  background-color: var(--color-background);
}

.container {
  display: flex;
  flex-direction: column;
  flex: 1;
  background-color: var(--color-background);
}

.container-spaced {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-between;
  background-color: var(--color-background);
}

.app-header {
  height: calc(44px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0 16px;
}

.centered-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  max-width: 600px;
}

/* ── Wizard / flow screen layout ─────────────────────────────────────────── */
/* Content area: fills remaining space, scrolls if needed */
.screen-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Sticky footer: hugs the bottom, never scrolls */
.screen-footer {
  flex-shrink: 0;
  padding: 16px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* No-divider variant: same structure without the top border */
.screen-footer--no-divider {
  flex-shrink: 0;
  padding: 16px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

/* Screen heading block (wizard / fund flow) */
.screen-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* ─────────────────────────────────────────────────────────────────────────── */

/* Member-list grid: 2 columns on narrow viewports, 3 at >= 480px. */
@media (min-width: 480px) {
  .member-chip-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

.row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.row-between {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.spacer {
  flex: 1;
}

.bottom {
  justify-content: flex-end;
  gap: 8px;
  padding: 20px;
}

.invite-contents {
  flex: 1;
  gap: 32px;
  padding-top: 74px;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 32px;
  align-items: center;
}

.submit-button {
  margin-bottom: 24px;
}

.bottom-buttons {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-bottom: 20px;
  padding-left: 20px;
  padding-right: 20px;
}

.bottom-actions {
  width: 100%;
  align-items: center;
  gap: 24px;
  min-height: 82px;
  justify-content: center;
}

.header {
  position: relative;
  justify-content: space-between;
  align-items: center;
  padding-top: max(var(--spacing-lg), env(safe-area-inset-top));
  padding-left: var(--spacing-lg);
  padding-right: var(--spacing-lg);
}

.bordered {
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.text-container {
  row-gap: 4px;
}

.text-button {
  width: 100%;
  align-items: center;
  text-align: center;
  padding: 16px;
}

.icon-container {
  padding: 8px;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.card {
  background-color: var(--color-card);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
}

.list-item {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

/* ========== Buttons ========== */

.btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  min-height: 48px;
  padding: 0 16px;
  cursor: pointer;
  background: transparent;
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 20px;
  line-height: 1.3;
  color: var(--color-text-secondary);
  transition:
    background-color 0.12s,
    opacity 0.12s;
}

.btn:hover:not(:disabled) {
  background-color: var(--color-bg-muted);
}

.btn:active:not(:disabled) {
  background-color: var(--color-bg-muted);
  opacity: 0.7;
}

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

.btn-salient {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 16px;
  cursor: pointer;
  background-color: var(--color-primary);
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 20px;
  line-height: 1.3;
  color: var(--color-background);
  transition: opacity 0.12s;
}

.btn-salient:hover:not(:disabled) {
  opacity: 0.88;
}

.btn-salient:active:not(:disabled) {
  opacity: 0.72;
}

.btn-salient:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-cancel {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-error);
  border-radius: 8px;
  min-height: 48px;
  padding: 0 16px;
  cursor: pointer;
  background-color: var(--color-error-bg);
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 20px;
  line-height: 1.3;
  color: var(--color-error);
  transition: opacity 0.12s;
}

.btn-cancel:hover:not(:disabled) {
  opacity: 0.88;
}

.btn-cancel:active:not(:disabled) {
  opacity: 0.72;
}

.btn-cancel:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== Inputs ========== */

.input {
  width: 100%;
  height: 48px;
  padding: 8px 16px;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 21px;
  color: var(--color-text);
  background: var(--color-input-bg);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.12s;
}

.input::placeholder {
  color: var(--color-text-tertiary);
}

.amount-input::placeholder {
  color: var(--color-text-tertiary);
}

.input:focus {
  border-color: var(--color-text);
}

.input.is-error {
  border-color: var(--color-error);
  background: var(--color-error-bg);
}

.input.is-error::placeholder {
  color: var(--color-text-tertiary);
}

/* Modifier: Fragment Mono for ticket / @p / address fields */
.input--mono {
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 22px;
}

/* Modifier: tall textarea */
.input--lg {
  height: 96px;
  resize: vertical;
}

/* Labelled input group */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.input-label {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 21px;
  color: var(--color-text-secondary);
}

.input-label.is-error {
  color: var(--color-error);
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(128, 128, 128, 0.35);
  border-radius: var(--radius-sm);
  background-color: var(--color-border);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

input[type="checkbox"]:checked {
  background-color: var(--color-text);
  border-color: var(--color-text);
}

input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 45%;
  width: 25%;
  height: 55%;
  border: solid var(--color-background);
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}

/* ========== Status ========== */

.success-text {
  color: var(--color-success);
}
.error-text {
  color: var(--color-error);
}
.warning-text {
  color: var(--color-warning);
}
.info-text {
  color: var(--color-info);
}

/* ========== Spacing Utilities ========== */

.mt-xs {
  margin-top: var(--spacing-xs);
}
.mt-sm {
  margin-top: var(--spacing-sm);
}
.mt-md {
  margin-top: var(--spacing-md);
}
.mt-lg {
  margin-top: var(--spacing-lg);
}
.mt-xl {
  margin-top: var(--spacing-xl);
}

.mb-xs {
  margin-bottom: var(--spacing-xs);
}
.mb-sm {
  margin-bottom: var(--spacing-sm);
}
.mb-md {
  margin-bottom: var(--spacing-md);
}
.mb-lg {
  margin-bottom: var(--spacing-lg);
}
.mb-xl {
  margin-bottom: var(--spacing-xl);
}

.p-xs {
  padding: var(--spacing-xs);
}
.p-sm {
  padding: var(--spacing-sm);
}
.p-md {
  padding: var(--spacing-md);
}
.p-lg {
  padding: var(--spacing-lg);
}
.p-xl {
  padding: var(--spacing-xl);
}

/* ========== Components ========== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-modal-blur);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background-color: var(--color-modal-background);
  border: 1px solid var(--color-modal-border);
  border-radius: 0;
  padding: var(--spacing-lg); /* 24px — matches Figma canonical */
  margin: var(--spacing-xl);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.08);
}

/* Sheet modal — multi-step flows (Send, Receive, wizard steps).
 *
 * Mobile (default): fills the full viewport — `flex: 1` expands inside
 * `.modal-overlay → .centered-content`, both of which are `flex: 1`.
 * `overflow: hidden` lets `.screen-content` / `.screen-footer` handle
 * internal scrolling without a double scroll-container.
 *
 * Tablet / desktop (≥ 640 px): reverts to a floating centered card.
 * Height is capped at 90dvh; internal content still scrolls via
 * `.screen-content { overflow-y: auto }`.
 *
 * Usage: className="modal modal--sheet"
 * Never add margin, width, maxWidth, or minHeight as inline styles.
 */
.modal--sheet {
  width: 100%;
  max-width: 480px;
  margin: 0;
  flex: 1;
  max-height: calc(100dvh - 48px);
  overflow: hidden;
}

@media (min-width: 640px) {
  .modal--sheet {
    flex: none;
    min-height: 480px;
    max-height: calc(100dvh - 48px);
  }
}

.divider {
  height: 1px;
  background-color: var(--color-border);
  margin: var(--spacing-md) 0;
}

.scroll-container {
  overflow-y: auto;
  flex: 1;
}

/* ========== Misc ========== */

.reversed-color {
  color: var(--color-background);
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
}

/* ========== Tab Bar ========== */

.tab-bar {
  display: flex;
  flex-direction: row;
  height: 42px;
  background-color: var(--color-background);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: relative;
}

/* sliding indicator — position driven by --tab-ix / --tab-iw set via JS */
.tab-bar::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: var(--tab-ix, 0px);
  width: var(--tab-iw, 0px);
  height: 2px;
  background: var(--color-text);
  transition:
    left 0.22s cubic-bezier(0.4, 0, 0.2, 1),
    width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* suppress animation on first render */
.tab-bar.tab-bar--init::after {
  transition: none;
}
@media (prefers-reduced-motion: reduce) {
  .tab-bar::after {
    transition: none;
  }
}

/* ========== Alert ========== */

.alert {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
}

.alert--block {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
}

.alert--block .alert__header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.alert__icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: flex;
}

.alert__title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}

.alert__body {
  font-size: 14px;
  line-height: 18px;
  flex: 1;
}

.alert--block .alert__body {
  flex: none;
  font-size: 16px;
  line-height: 1.3;
  width: 100%;
}

.alert--warning {
  background: var(--color-warning-bg);
  border-color: var(--color-warning);
  color: var(--color-warning);
}

.alert--error {
  background: var(--color-error-bg);
  border-color: var(--color-error);
  color: var(--color-error);
}

.alert--info {
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
}

.alert--neutral {
  background: var(--color-modal-background);
  border-color: var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  color: var(--color-text);
  align-items: center;
  padding: 16px;
  gap: 12px;
}

/* ========== Animations ========== */

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

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
