/* ============================================================
   COMPONENTS — reusable UI pieces: cards, buttons, badges,
                forms, modal, toast, spinner, empty state
   ============================================================ */

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-sm { padding: var(--space-4); border-radius: var(--radius-md); }

/* Stat card — big number for dashboard */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: border-color var(--transition-fast);
}
.stat-card:hover { border-color: var(--border-strong); }
.stat-card__label { font-size: var(--text-xs); color: var(--text-muted); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: 0.07em; }
.stat-card__value { font-size: var(--text-3xl); font-weight: var(--fw-extrabold); line-height: 1; color: var(--text-primary); }
.stat-card__sub   { font-size: var(--text-sm); color: var(--text-muted); }
.stat-card--green  { border-top: 3px solid var(--green); }
.stat-card--red    { border-top: 3px solid var(--red); }
.stat-card--accent { border-top: 3px solid var(--accent); }
.stat-card--amber  { border-top: 3px solid var(--amber); }

/* Section header row */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.section-title  { font-size: var(--text-lg); font-weight: var(--fw-bold); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
  transition: background var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-hover); box-shadow: var(--shadow-accent); }

.btn-secondary { background: var(--surface-2); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }

.btn-ghost     { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--accent-light); color: var(--accent); }

.btn-danger    { background: var(--red-light); color: var(--red); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; }

.btn-sm   { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-lg   { padding: var(--space-4) var(--space-8); font-size: var(--text-base); }
.btn-icon { padding: var(--space-2); border-radius: var(--radius-sm); }
.btn-full { width: 100%; }

/* Google sign-in button */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.btn-google:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn-google img, .btn-google svg { width: 18px; height: 18px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.4;
  white-space: nowrap;
}
.badge-default { background: var(--surface-2); color: var(--text-secondary); }
.badge-accent  { background: var(--accent-light); color: var(--accent); }
.badge-green   { background: var(--green-light); color: var(--green); }
.badge-red     { background: var(--red-light); color: var(--red); }
.badge-amber   { background: var(--amber-light); color: var(--amber); }

/* ── Progress Bar ────────────────────────────────────────── */
.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--accent);
  transition: width var(--transition-slow);
}
.progress__fill--green { background: var(--green); }
.progress__fill--amber { background: var(--amber); }
.progress__fill--red   { background: var(--red); }

/* ── Divider ─────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); border: none; margin: var(--space-4) 0; }
.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  margin: var(--space-4) 0;
}
.divider-label::before, .divider-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img  { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm   { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg   { width: 48px; height: 48px; font-size: var(--text-lg); }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); }

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-input--error, .form-select--error { border-color: var(--red); }
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.form-help  { font-size: var(--text-xs); color: var(--text-muted); }
.form-error { font-size: var(--text-xs); color: var(--red); }

/* Currency prefix input */
.input-prefix-wrap         { position: relative; }
.input-prefix              { position: absolute; left: var(--space-4); top: 50%; transform: translateY(-50%); color: var(--text-muted); font-weight: var(--fw-semibold); pointer-events: none; }
.input-prefix-wrap .form-input { padding-left: var(--space-8); }

/* Custom select arrow */
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236060c0' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  padding-right: var(--space-10);
  cursor: pointer;
}

/* Checkbox / radio */
.form-check { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: var(--text-sm); }
.form-check input[type="checkbox"],
.form-check input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: backdrop-in var(--transition) ease both;
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  width: 100%;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  animation: sheet-up var(--transition) ease both;
  overflow: hidden;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal__handle { width: 36px; height: 4px; background: var(--border-strong); border-radius: var(--radius-full); margin: var(--space-3) auto; flex-shrink: 0; }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal__title { font-size: var(--text-lg); font-weight: var(--fw-bold); }
.modal__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}
.modal__close:hover { background: var(--surface-3); color: var(--text-primary); }

.modal__body   { flex: 1; overflow-y: auto; padding: var(--space-6); overscroll-behavior: contain; }
.modal__footer { display: flex; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); flex-shrink: 0; }

/* ── Toast ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--space-4));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  white-space: nowrap;
  animation: toast-in var(--transition) ease both;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.toast--success { border-color: var(--green); }
.toast--error   { border-color: var(--red); }

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-16) var(--space-8);
  gap: var(--space-3);
}
.empty-state__icon  { font-size: 3rem; opacity: 0.4; margin-bottom: var(--space-1); }
.empty-state__title { font-size: var(--text-lg); font-weight: var(--fw-bold); }
.empty-state__text  { font-size: var(--text-sm); color: var(--text-muted); max-width: 260px; line-height: 1.6; }

/* ── User Menu (header avatar + dropdown, mobile only) ───── */
.user-menu          { position: relative; }
.user-menu summary  { list-style: none; cursor: pointer; border-radius: var(--radius-full); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::marker { display: none; }
.user-menu .avatar  { transition: box-shadow var(--transition-fast); }
.user-menu[open] .avatar { box-shadow: 0 0 0 3px var(--accent); }

.user-menu__dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  overflow: hidden;
  z-index: var(--z-dropdown);
}
.user-menu__label {
  padding: var(--space-3) var(--space-4) var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-menu__item {
  display: block;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  text-align: left;
  color: var(--red);
  transition: background var(--transition-fast);
}
.user-menu__item:hover { background: var(--red-light); }

/* Desktop: sidebar already shows user info, hide header avatar */
@media (min-width: 769px) { .user-menu { display: none; } }

/* ── Grid Layouts ────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

/* ── Stack / Row spacing helpers ─────────────────────────── */
.stack    { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-6); }
.row      { display: flex; align-items: center; gap: var(--space-4); }
.row-sm   { display: flex; align-items: center; gap: var(--space-2); }

/* ── Split selector / presets / display ──────────────────── */
.split-selector { display: flex; background: var(--surface-2); border-radius: var(--radius-md); padding: 3px; gap: 2px; }
.split-selector__btn { flex: 1; padding: var(--space-2) var(--space-3); border-radius: calc(var(--radius-md) - 2px); font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-muted); cursor: pointer; transition: all var(--transition-fast); text-align: center; }
.split-selector__btn.active { background: var(--accent); color: #fff; }
.split-selector__btn:hover:not(.active) { background: var(--surface-3); color: var(--text-primary); }
.split-presets { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.split-preset { padding: var(--space-1) var(--space-3); border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--fw-semibold); background: var(--surface-2); color: var(--text-secondary); cursor: pointer; transition: all var(--transition-fast); border: 1px solid var(--border); }
.split-preset.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.split-preset:hover:not(.active) { background: var(--surface-3); color: var(--text-primary); }
.split-display { display: flex; gap: var(--space-3); margin: var(--space-3) 0; }
.split-person { flex: 1; display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); }
.split-person__name { font-size: var(--text-sm); color: var(--text-secondary); }
.split-person__amount { font-size: var(--text-base); font-weight: var(--fw-bold); }
