/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f5f5;
  --surface:   #ffffff;
  --surface2:  #f9f9f9;
  --surface3:  #f0f0f0;
  --border:    #e8e8e8;
  --border2:   #d4d4d4;
  --primary:   #e8372a;
  --primary-h: #c82d22;
  --primary-dim: rgba(232,55,42,.08);
  --success:   #1a9c4e;
  --danger:    #e8372a;
  --warning:   #d97706;
  --text:      #141414;
  --text-sub:  #3d3d3d;
  --text-muted:#888888;
  --radius:    4px;
  --radius-sm: 3px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --font: 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

/* ── Dark / Lunar mode ────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #080f1d;
  --surface:     #0c1628;
  --surface2:    #101e35;
  --surface3:    #152440;
  --border:      #1a2f4e;
  --border2:     #203860;
  --primary:     #e8372a;
  --primary-h:   #c82d22;
  --primary-dim: rgba(232,55,42,.14);
  --success:     #2ab065;
  --danger:      #e8372a;
  --warning:     #c8a030;
  --text:        #e8d49a;
  --text-sub:    #c4a050;
  --text-muted:  #5c80a8;
  --shadow:      0 1px 4px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-md:   0 4px 20px rgba(0,0,0,.6), 0 2px 8px rgba(0,0,0,.4);
}

/* Subtle moon glow on surfaces in dark mode */
[data-theme="dark"] .card:hover {
  border-color: rgba(200,160,80,.25);
  box-shadow: 0 4px 20px rgba(0,0,0,.6), 0 0 0 1px rgba(200,160,80,.1);
}
[data-theme="dark"] .modal-sheet {
  box-shadow: 0 -8px 40px rgba(0,0,0,.7), 0 0 60px rgba(10,25,60,.8);
}
[data-theme="dark"] .topbar,
[data-theme="dark"] .bottom-nav {
  background: #0a1424;
}
[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus {
  border-color: var(--text-sub);
  box-shadow: 0 0 0 3px rgba(196,160,80,.12);
}
[data-theme="dark"] .service-trigger.open {
  border-color: var(--text-sub);
  box-shadow: 0 0 0 3px rgba(196,160,80,.12);
}
[data-theme="dark"] .form-group input::placeholder,
[data-theme="dark"] .service-trigger-name.placeholder,
[data-theme="dark"] .service-dropdown-search input::placeholder { color: #2e4a6a; }
[data-theme="dark"] .btn-primary { background: var(--text-sub); color: #080f1d; }
[data-theme="dark"] .btn-primary:hover { background: #b08840; }
[data-theme="dark"] .btn-ghost { color: var(--text-muted); }
[data-theme="dark"] .btn-ghost:hover { background: var(--surface3); color: var(--text); }
[data-theme="dark"] .user-avatar { background: var(--text-sub); color: #080f1d; }
[data-theme="dark"] .toast { background: var(--text-sub); color: #080f1d; }
/* Simple Icons SVGs: most are colored, but if a service icon is black, bump it slightly */
[data-theme="dark"] .card-icon img,
[data-theme="dark"] .service-trigger-logo img,
[data-theme="dark"] .service-dropdown-item-logo img { filter: brightness(1.15); }

/* Theme toggle button */
.btn-theme {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: .38rem .55rem;
  cursor: pointer;
  display: flex; align-items: center;
  transition: color .15s, border-color .15s, background .15s;
  line-height: 1;
}
.btn-theme:hover { color: var(--text); border-color: var(--border2); background: var(--surface3); }

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Brand wordmark ───────────────────────────────────────────────────────── */
.brand {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1;
}
.brand .dot { color: var(--primary); }

/* ── Auth page ────────────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem 1rem;
  background: var(--bg);
}

.auth-wordmark {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
  margin-bottom: 2.5rem;
}
.auth-wordmark .dot { color: var(--primary); }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.auth-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  margin-bottom: .3rem;
}
.auth-card > div > p {
  color: var(--text-muted);
  font-size: .875rem;
  margin-bottom: 1.5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1.25rem;
  font-size: .875rem;
  color: var(--text-muted);
}
.auth-switch a { color: var(--text); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
}
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

/* All topbar action buttons: uniform 34×34 square */
.topbar-actions .btn-icon,
.topbar-actions .btn-theme,
.topbar-actions .user-avatar {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar {
  width: 34px; height: 34px;
  background: var(--text);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .75rem;
  cursor: pointer;
  color: var(--surface);
  letter-spacing: .5px;
  overflow: hidden;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 1.5rem 1.25rem 5.5rem;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: .3rem;
  padding: .7rem .5rem .6rem;
  font-size: .65rem;
  font-weight: 700;
  font-family: var(--font);
  letter-spacing: .05em;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s;
  border: none; background: none;
  position: relative;
}
.nav-item svg.nav-icon {
  width: 22px; height: 22px;
  transition: stroke .15s;
}
.nav-item.active { color: var(--text); }
/* Punto rojo activo — mismo motivo que el wordmark */
.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 5px;
  width: 4px; height: 4px;
  background: var(--primary);
  border-radius: 50%;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
  letter-spacing: .3px;
}
.form-group input,
.form-group select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  padding: .65rem .85rem;
  font-size: .95rem;
  font-family: var(--font);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(20,20,20,.06);
}
.form-group input::placeholder { color: #c0c0c0; }
.form-group input[readonly] {
  background: var(--surface3);
  color: var(--text-sub);
  cursor: default;
  border-style: dashed;
}

.form-row { display: flex; gap: .75rem; }
.form-row .form-group { flex: 1; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .68rem 1.25rem;
  border-radius: var(--radius);
  font-size: .9rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; border: none; transition: background .15s, opacity .15s;
  text-decoration: none;
  letter-spacing: -.01em;
}
.btn:active { opacity: .85; }
.btn-primary { background: var(--text); color: var(--surface); }
.btn-primary:hover { background: #2a2a2a; text-decoration: none; }
.btn-red { background: var(--primary); color: #fff; }
.btn-red:hover { background: var(--primary-h); }
.btn-ghost {
  background: transparent;
  color: var(--text-sub);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { background: var(--surface3); text-decoration: none; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-full { width: 100%; }
.btn-sm { padding: .4rem .85rem; font-size: .82rem; }
.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text-muted);
  padding: .4rem .65rem;
  font-size: .95rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  display: flex; align-items: center;
}
.btn-icon:hover { color: var(--text); border-color: var(--border2); background: var(--surface3); }
.btn-icon.active { color: var(--primary); border-color: var(--primary); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: .6rem;
  cursor: pointer;
  transition: border-color .18s, box-shadow .18s;
  box-shadow: var(--shadow);
}
.card:hover { border-color: var(--border2); box-shadow: var(--shadow-md); }
.card-static { cursor: default; margin-bottom: 1rem; }
.card-static:hover { border-color: var(--border); box-shadow: var(--shadow); }

.card-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: .75rem; margin-bottom: .9rem;
}
.card-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  /* fondo transparente — el SVG de Simple Icons se ve sobre el color de la card */
  background: transparent;
  border: none;
}
.card-icon img { width: 100%; height: 100%; object-fit: contain; }

.card-title { font-weight: 700; font-size: .975rem; letter-spacing: -.01em; color: var(--text); }
.card-subtitle { font-size: .8rem; color: var(--text-muted); margin-top: .1rem; }

/* Tags */
.tag {
  display: inline-flex; align-items: center;
  padding: .18rem .55rem;
  border-radius: 99px;
  font-size: .7rem; font-weight: 600;
  letter-spacing: .2px;
  background: var(--surface3);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.tag-red   { background: var(--primary-dim); color: var(--primary); border-color: rgba(232,55,42,.2); }
.tag-green { background: rgba(26,156,78,.08); color: var(--success); border-color: rgba(26,156,78,.2); }
.tag-warn  { background: rgba(217,119,6,.08); color: var(--warning); border-color: rgba(217,119,6,.2); }
.tag-dark  { background: var(--text); color: var(--surface); border-color: transparent; }

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* Amount */
.amount-big {
  font-size: 1.85rem; font-weight: 800;
  color: var(--text);
  letter-spacing: -.04em;
  line-height: 1;
}
.amount-big.red { color: var(--primary); }
.amount-label {
  font-size: .7rem; font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .3px;
  margin-bottom: .2rem;
}

/* ── Members list ─────────────────────────────────────────────────────────── */
.member-list { display: flex; flex-direction: column; gap: .4rem; }
.member-item {
  display: flex; align-items: center; gap: .85rem;
  padding: .75rem .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.member-avatar {
  width: 34px; height: 34px;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .78rem; flex-shrink: 0;
  color: var(--text-sub);
}
.member-info { flex: 1; min-width: 0; }
.member-name { font-size: .9rem; font-weight: 600; display: flex; align-items: center; gap: .4rem; color: var(--text); }
.member-email { font-size: .75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Section headers ──────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .85rem;
}
.section-title {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-sheet {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem 1.25rem 2rem;
  width: 100%; max-width: 640px;
  max-height: 92dvh; overflow-y: auto;
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -4px 24px rgba(0,0,0,.1);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle {
  width: 36px; height: 3px;
  background: var(--border2);
  border-radius: 99px;
  margin: 0 auto 1.25rem;
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 1.25rem;
  color: var(--text);
}

/* ── Service selector ─────────────────────────────────────────────────────── */
.service-selector-row {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  margin-bottom: 1.1rem;
}
.service-selector-row .form-group { flex: 1; margin-bottom: 0; }

.service-trigger {
  width: 100%;
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: .6rem .85rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  min-height: 42px;
}
.service-trigger:hover { border-color: var(--border2); box-shadow: 0 0 0 3px rgba(20,20,20,.05); }
.service-trigger.open { border-color: var(--text); box-shadow: 0 0 0 3px rgba(20,20,20,.06); }

.service-trigger-logo {
  width: 22px; height: 22px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.service-trigger-name {
  flex: 1;
  font-size: .92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.service-trigger-name.placeholder { color: #c0c0c0; }
.service-trigger-chevron {
  font-size: .65rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform .15s;
}
.service-trigger.open .service-trigger-chevron { transform: rotate(180deg); }

/* Dropdown panel */
.service-dropdown {
  position: absolute;
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 300;
  max-height: 260px;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
.service-dropdown-search {
  padding: .55rem .65rem;
  border-bottom: 1px solid var(--border);
}
.service-dropdown-search input {
  width: 100%;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .4rem .7rem;
  font-size: .85rem;
  font-family: var(--font);
}
.service-dropdown-search input:focus { outline: none; border-color: var(--border2); }
.service-dropdown-search input::placeholder { color: #c0c0c0; }

.service-dropdown-list { overflow-y: auto; flex: 1; }
.service-dropdown-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .85rem;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid var(--border);
}
.service-dropdown-item:last-child { border-bottom: none; }
.service-dropdown-item:hover { background: var(--surface3); }
.service-dropdown-item.selected { background: var(--primary-dim); }

.service-dropdown-item-logo {
  width: 26px; height: 26px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.service-dropdown-item-name { font-size: .875rem; font-weight: 600; color: var(--text); }
.service-dropdown-item-company { font-size: .72rem; color: var(--text-muted); }

.service-selector-wrapper { position: relative; flex: 1; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 5.5rem; left: 50%; transform: translateX(-50%);
  z-index: 999; display: flex; flex-direction: column; gap: .4rem;
  pointer-events: none; width: calc(100% - 2rem); max-width: 360px;
}
.toast {
  background: var(--text);
  border-radius: var(--radius);
  padding: .7rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--surface);
  box-shadow: var(--shadow-md);
  animation: slideUp .2s ease forwards;
}
.toast.error   { background: var(--primary); }
.toast.success { background: var(--success); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 4rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { margin-bottom: .75rem; display: flex; justify-content: center; }
.empty-state p { font-size: .9rem; line-height: 1.7; }
.empty-state strong { color: var(--text-sub); }

/* ── Detail stat boxes ────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-bottom: 1rem;
}
.stat-box {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem .9rem;
  text-align: left;
  min-width: 0;
  overflow: hidden;
}
.stat-box .amount-big {
  font-size: clamp(1.15rem, calc(3vw + .5rem), 1.85rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Owner info box ───────────────────────────────────────────────────────── */
.owner-box {
  display: flex; align-items: center; gap: .75rem;
  background: var(--primary-dim);
  border: 1px solid rgba(232,55,42,.15);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-bottom: 1rem;
}
.owner-box-label { font-size: .7rem; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .3px; margin-bottom: .1rem; }
.owner-box-name  { font-size: .95rem; font-weight: 700; color: var(--text); }

/* ── Share link ───────────────────────────────────────────────────────────── */
.share-link-box { display: flex; gap: .5rem; margin-top: .4rem; }
.share-link-box input {
  flex: 1; font-size: .78rem; padding: .5rem .75rem;
  background: var(--surface3); border: 1px solid var(--border2);
  border-radius: var(--radius); color: var(--text-muted);
  font-family: monospace;
}

/* ── Invite page ──────────────────────────────────────────────────────────── */
.invite-page {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100dvh; padding: 1.5rem 1rem;
  background: var(--bg);
}
.invite-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem; width: 100%; max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.invite-icon { font-size: 2.2rem; margin-bottom: 1rem; }
.invite-card h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: .5rem; }
.invite-card > p { color: var(--text-muted); margin-bottom: 1.5rem; font-size: .875rem; }
.invite-detail {
  background: var(--surface3);
  border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1.5rem; text-align: left;
  border: 1px solid var(--border);
}
.invite-detail-row {
  display: flex; justify-content: space-between;
  font-size: .875rem; padding: .3rem 0;
  border-bottom: 1px solid var(--border);
}
.invite-detail-row:last-child { border-bottom: none; }
.invite-detail-row span:first-child { color: var(--text-muted); }
