/* =============================================================
   MailForge WebApp — app.css  (v5 — Emitly CRM Design)
   Design language: Fintech CRM dashboard. Warm cream palette,
   soft-tinted bank cards, stat dashboard, professional spacing.
   Philosophy: every element feels designed, not just coded.
   ============================================================= */

/* -------------------------------------------------------------
   1. CSS RESET (minimal, targeted)
   ------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
}

input, select, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; }
ul, ol { list-style: none; }

/* -------------------------------------------------------------
   2. DESIGN TOKENS — Emitly CRM palette
   ------------------------------------------------------------- */
:root {
  /* --- Core palette --- */
  --bg:             #f5f3ef;   /* warm cream — NOT cold gray */
  --bg-rgb:         245, 243, 239;
  --surface:        #ffffff;
  --surface-raised: #ffffff;
  --border:         rgba(0, 0, 0, 0.06);
  --border-focus:   rgba(0, 0, 0, 0.20);
  --divider:        rgba(0, 0, 0, 0.05);

  /* --- Text --- */
  --text-primary:   #1a1a2e;
  --text-secondary: #6b7280;
  --text-tertiary:  #9ca3af;

  /* --- Semantic --- */
  --accent-green:  #22c55e;
  --accent-red:    #ef4444;
  --accent-amber:  #f59e0b;
  --destructive:   #ef4444;
  --success:       #22c55e;
  --warning:       #f59e0b;

  /* --- Button defaults (dark pill) --- */
  --btn-bg:   #1a1a2e;
  --btn-text: #ffffff;

  /* --- Shadows --- */
  --shadow-xs:    0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md:    0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-card:  0 1px 3px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 -1px 0 rgba(0, 0, 0, 0.05), 0 -8px 24px rgba(0, 0, 0, 0.07);

  /* --- Radius scale --- */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   20px;
  --r-pill: 999px;

  /* --- Typography --- */
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-mono:   "SF Mono", "Fira Code", ui-monospace, monospace;

  /* --- Layout --- */
  --header-h:    56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* --- Transitions --- */
  --t-fast:   120ms ease;
  --t-base:   200ms ease;
  --t-slow:   300ms cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* --- Per-bank brand color (accent only, used for tints) --- */
  --bank-bmo-accent:        #0079c1;
  --bank-rbc-accent:        #005dab;
  --bank-cibc-accent:       #c41f3e;
  --bank-td-accent:         #34b233;
  --bank-scotiabank-accent: #ec1c24;
  --bank-desjardins-accent: #00783c;
  --bank-binance-accent:    #f3ba2f;
  --bank-coinbase-accent:   #0052ff;
  --bank-cryptocom-accent:  #002d74;
  --bank-shakepay-accent:   #6c5ce7;
  --bank-cra-accent:        #334d63;
  --bank-bnc-accent:        #003da5;
}

/* --- Dark theme overrides --- */
.dark-theme {
  --bg:             #111116;
  --bg-rgb:         17, 17, 22;
  --surface:        #1c1c22;
  --surface-raised: #242430;
  --border:         rgba(255, 255, 255, 0.07);
  --border-focus:   rgba(255, 255, 255, 0.22);
  --divider:        rgba(255, 255, 255, 0.05);

  --text-primary:   #f0f0f8;
  --text-secondary: #8e8ea0;
  --text-tertiary:  #5a5a70;

  --btn-bg:   #f0f0f8;
  --btn-text: #111116;

  --shadow-xs:   0 1px 3px rgba(0, 0, 0, 0.30);
  --shadow-sm:   0 2px 8px rgba(0, 0, 0, 0.40);
  --shadow-md:   0 4px 12px rgba(0, 0, 0, 0.50);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.40), 0 0 0 1px rgba(255,255,255,0.04);
  --shadow-sheet:0 -1px 0 rgba(255,255,255,0.05), 0 -8px 24px rgba(0,0,0,0.50);
}

/* -------------------------------------------------------------
   3. BASE / GLOBAL
   ------------------------------------------------------------- */
html, body {
  height: 100%;
  min-height: 100dvh;
}

body {
  font-family:   var(--font-family);
  font-size:     15px;
  line-height:   1.5;
  color:         var(--text-primary);
  background:    var(--bg);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* Visually hidden; kept available to screen readers and focus order where used */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Keyframes ───────────────────────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

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

@keyframes heart-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.45); }
  70%  { transform: scale(0.88); }
  100% { transform: scale(1); }
}

@keyframes sheet-slide-up {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes stat-count-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------
   4. HEADER — clean white surface, subtle border
   ------------------------------------------------------------- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: rgba(var(--bg-rgb, 245, 243, 239), 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.dark-theme .app-header {
  background: rgba(var(--bg-rgb, 17, 17, 22), 0.85);
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.header-back {
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-primary);
  transition: background var(--t-fast), transform var(--t-fast);
  margin-right: 2px;
}
.header-back:active {
  background: rgba(0,0,0,0.07);
  transform: scale(0.88);
}
.dark-theme .header-back:active {
  background: rgba(255,255,255,0.08);
}

/* Logo mark */
.header-logo {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--btn-bg);
  color: var(--btn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.14);
}
.header-back:not(.hidden) ~ .header-logo { display: none; }

.header-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  color: var(--text-primary);
}

.header-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.breadcrumb-segment {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.breadcrumb-sep {
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.header-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.header-icon-btn:active {
  background: rgba(0,0,0,0.07);
  color: var(--text-primary);
  transform: scale(0.88);
}
.dark-theme .header-icon-btn:active {
  background: rgba(255,255,255,0.08);
}

/* -------------------------------------------------------------
   5. VIEW SYSTEM — slide transitions
   ------------------------------------------------------------- */
.view {
  position: fixed;
  inset: 0;
  top: var(--header-h);
  background: var(--bg);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  transform: translate3d(100%, 0, 0);
  opacity: 0;
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 220ms ease;
}

.view.is-transitioning { will-change: transform, opacity; }

.view.active {
  transform: translate3d(0, 0, 0);
  opacity: 1;
}

.view.slide-in {
  transform: translate3d(0, 0, 0);
  opacity: 1;
}

.view.slide-out {
  transform: translate3d(-28%, 0, 0);
  opacity: 0.5;
}

#view-catalog {
  transform: translate3d(0, 0, 0);
  opacity: 1;
}
#view-catalog.hidden {
  transform: translate3d(-28%, 0, 0);
  pointer-events: none;
}

/* -------------------------------------------------------------
   6. STATS DASHBOARD CARD — top of home screen
   ------------------------------------------------------------- */

/* Wrapper: full-width padding zone above the services section */
.stats-dashboard-wrap {
  padding: 16px 16px 0;
}

/* The card itself */
.stats-dashboard-card {
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
  overflow: hidden;
  position: relative;
}

/* Subtle warm-gradient tint across the top portion of the card */
.stats-dashboard-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    145deg,
    rgba(251, 247, 235, 0.60) 0%,
    rgba(245, 243, 239, 0.00) 55%
  );
  pointer-events: none;
  border-radius: inherit;
}

.dark-theme .stats-dashboard-card::before {
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.03) 0%,
    transparent 55%
  );
}

/* Top section: greeting row */
.stats-greeting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  position: relative;
  z-index: 1;
}

.stats-greeting-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

/* Live status dot */
.stats-status-dot {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-green);
  letter-spacing: 0.01em;
}

.stats-status-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18);
}

/* 2x2 stat grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0 0 14px;
  position: relative;
  z-index: 1;
}

/* Vertical + horizontal dividers drawn with pseudo-elements on the cells */
.stat-cell {
  padding: 10px 16px 14px;
  position: relative;
}

/* Right border on left cells */
.stat-cell:nth-child(odd) {
  border-right: 1px solid var(--divider);
}

/* Top border on bottom cells */
.stat-cell:nth-child(3),
.stat-cell:nth-child(4) {
  border-top: 1px solid var(--divider);
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.1;
  animation: stat-count-in 400ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.stat-value.loading {
  display: inline-block;
  width: 48px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--bg) 25%,
    rgba(0,0,0,0.05) 50%,
    var(--bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

.dark-theme .stat-value.loading {
  background: linear-gradient(
    90deg,
    #1c1c22 25%,
    #2a2a33 50%,
    #1c1c22 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

.stat-sub {
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-sub-text {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
}

/* Green / red badge: +12% or -3% */
.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 2px 6px;
  border-radius: var(--r-pill);
}

.stat-badge.up {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
}

.stat-badge.down {
  background: rgba(239, 68, 68, 0.10);
  color: #dc2626;
}

.dark-theme .stat-badge.up {
  background: rgba(34, 197, 94, 0.16);
  color: #4ade80;
}

.dark-theme .stat-badge.down {
  background: rgba(239, 68, 68, 0.16);
  color: #f87171;
}

/* -------------------------------------------------------------
   7. SEARCH BAR
   ------------------------------------------------------------- */
.low-balance-banner {
  margin: 10px 16px 2px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  border: 1px solid color-mix(in srgb, var(--accent-amber) 28%, transparent);
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--accent-amber) 18%, white),
    color-mix(in srgb, var(--accent-amber) 8%, transparent)
  );
  color: color-mix(in srgb, var(--text-primary) 88%, #000);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-xs);
}

.dark-theme .low-balance-banner {
  border-color: rgba(245, 158, 11, 0.25);
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.14),
    rgba(245, 158, 11, 0.06)
  );
}

.low-balance-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #b45309;
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.24);
}

.dark-theme .low-balance-icon {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.22);
}

.low-balance-body {
  flex: 1;
  min-width: 0;
}

.low-balance-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.low-balance-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  min-height: 44px;
  font-size: 11px;
}

.search-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 16px 0;
  background: var(--bg);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  padding: 0 14px;
  height: 42px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  box-shadow: var(--shadow-xs);
}

.search-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
.dark-theme .search-box:focus-within {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.05);
}

.search-icon {
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.search-input {
  flex: 1;
  font-size: 15px;
  color: var(--text-primary);
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: var(--r-pill);
  transition: color var(--t-fast), transform var(--t-fast);
}
.search-clear:active {
  color: var(--text-primary);
  transform: scale(0.85);
}

/* Search result highlight */
mark.search-highlight {
  background: rgba(0,0,0,0.08);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}
.dark-theme mark.search-highlight {
  background: rgba(255,255,255,0.14);
}

/* Count bar */
.catalog-count-bar  { padding: 10px 16px 0; }
.catalog-count-text {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* -------------------------------------------------------------
   8. FILTER PILLS
   ------------------------------------------------------------- */
.filter-pills-wrap {
  padding: 12px 0 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.filter-pills-wrap::-webkit-scrollbar { display: none; }

.filter-pills {
  display: flex;
  gap: 7px;
  padding: 0 16px 12px;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  transition: color var(--t-fast), background var(--t-fast),
              border-color var(--t-fast), transform var(--t-fast),
              box-shadow var(--t-fast);
  flex-shrink: 0;
  user-select: none;
  box-shadow: var(--shadow-xs);
}

.pill:active { transform: scale(0.94); }

.pill.active {
  background: var(--text-primary);
  color: #ffffff;
  border-color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.16);
}

.dark-theme .pill.active {
  background: #f0f0f8;
  color: #111116;
  border-color: #f0f0f8;
}

.pill-emoji {
  font-size: 13px;
  line-height: 1;
}

/* "Your Services" section header below stats card */
.services-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 4px;
}

/* -------------------------------------------------------------
   8b. RECENTS SHELF — horizontal chips above bank grid
   ------------------------------------------------------------- */
.recents-shelf {
  padding: 10px 0 0;
}

.recents-shelf-header {
  padding: 0 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.recents-shelf-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.recents-shelf-scroller {
  display: flex;
  gap: 10px;
  padding: 0 16px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x mandatory;
  scroll-padding: 16px;
}
.recents-shelf-scroller::-webkit-scrollbar { display: none; }

.recent-chip {
  scroll-snap-align: start;
  flex: 0 0 auto;
  width: 168px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
  padding: 10px 10px 10px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.recent-chip:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-xs);
}

.recent-chip-accent {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--bank-accent, #6c757d);
}

.recent-chip-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 6px;
}

.recent-chip-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  padding-left: 6px;
}

.recent-chip-lang {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.05);
  border-radius: var(--r-pill);
  padding: 2px 7px;
}

.dark-theme .recent-chip-lang {
  background: rgba(255,255,255,0.08);
}

.services-section-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.services-section-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-tertiary);
}

/* -------------------------------------------------------------
   9. BANK CARD GRID — soft tinted white cards, 2-column
   Emitly-style: NOT full gradient. White base, bank color
   used only as a 4px left accent bar and very subtle tint.
   ------------------------------------------------------------- */
.bank-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 10px 16px 90px;
}

@media (min-width: 600px) {
  .bank-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 10px 16px 90px; }
}
@media (min-width: 900px) {
  .bank-grid { grid-template-columns: repeat(4, 1fr); }
}

/* The card itself */
.bank-card {
  position: relative;
  height: 130px;
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* White base + very subtle warm tint bottom gradient */
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 180ms ease;
  transform: translateZ(0);
}

/* Soft bottom tint using the bank accent at 8% opacity */
.bank-card::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  background: linear-gradient(
    to top,
    color-mix(in srgb, var(--bank-accent, #6c757d) 6%, transparent),
    transparent
  );
  pointer-events: none;
  z-index: 1;
}

@media (hover: hover) and (pointer: fine) {
  .bank-card:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: var(--shadow-md);
  }
}

.bank-card:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-xs);
  transition: transform 90ms ease, box-shadow 90ms ease;
}

/* 4px colored accent bar — left edge */
.bank-card-accent-bar {
  display: none;
}

/* Bank initial circle — top left, tinted soft background */
.bank-card-icon-wrap {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: visible;
}

.bank-card-initial {
  font-size: 12px;
  font-weight: 700;
  color: var(--bank-accent, #555);
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Bank name — bottom left, dark text */
.bank-card-name {
  position: absolute;
  bottom: 28px;
  left: 16px;
  right: 14px;
  z-index: 3;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Template count — below name */
.bank-card-count {
  position: absolute;
  bottom: 13px;
  left: 16px;
  z-index: 3;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Small chevron — top right */
.bank-card-chevron {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  color: var(--text-tertiary);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}

/* Entrance stagger */
.bank-card.entering {
  animation: fade-up 300ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Legacy elements — kept for JS compat */
.bank-card-count-dot { display: none; }
.bank-card-body      { display: none; }
.bank-card-type-badge{ display: none; }

/* -------------------------------------------------------------
   9b. SKELETON LOADING
   ------------------------------------------------------------- */
.skeleton-bank-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 10px 16px;
}

@media (min-width: 600px) {
  .skeleton-bank-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 10px 16px;
  }
}

.skeleton-bank-card {
  height: 130px;
  border-radius: var(--r-lg);
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    rgba(0,0,0,0.04) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border: 1px solid var(--border);
}

.dark-theme .skeleton-bank-card {
  background: linear-gradient(
    90deg,
    #1c1c22 25%,
    #2a2a33 50%,
    #1c1c22 75%
  );
  background-size: 200% 100%;
  border: none;
}

/* -------------------------------------------------------------
   10. SEARCH RESULTS & FAVORITES GRID
   ------------------------------------------------------------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 16px 90px;
}

@media (max-width: 319px) { .card-grid { grid-template-columns: 1fr; } }
@media (min-width: 600px) { .card-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; } }
@media (min-width: 900px) { .card-grid { grid-template-columns: repeat(4, 1fr); } }

/* Template card in search/favorites */
.tpl-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  min-width: 0;
  /* no border-left accent */
}

@media (hover: hover) and (pointer: fine) {
  .tpl-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
}
.tpl-card:active { transform: scale(0.97); }

/* Legacy hidden */
.card-thumb    { display: none; }
.card-accent   { display: none; }
.card-icon-wrap { display: none; }

.card-fav-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: color var(--t-fast), transform var(--t-fast);
  background: none;
}
.card-fav-btn.is-fav { color: var(--destructive); }
.card-fav-btn.heart-pop { animation: heart-pop 380ms cubic-bezier(0.34, 1.56, 0.64, 1); }

.card-body {
  padding: 11px 30px 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-category-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--bank-accent, var(--text-tertiary));
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  letter-spacing: -0.01em;
}

.card-subject { display: none; }

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}

.card-lang-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: var(--r-pill);
}
.dark-theme .card-lang-badge {
  background: rgba(255,255,255,0.08);
}

.card-cost-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* -------------------------------------------------------------
   11. EMPTY STATE
   ------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--text-tertiary);
  text-align: center;
}
.empty-state svg { opacity: 0.28; }
.empty-state p {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* -------------------------------------------------------------
   12. CATEGORY LIST VIEW
   ------------------------------------------------------------- */
.category-list {
  padding: 10px 16px 90px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Section header */
.category-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 8px;
}

.category-section-bar {
  width: 3px;
  height: 18px;
  border-radius: var(--r-pill);
  background: var(--bank-accent, var(--text-tertiary));
  flex-shrink: 0;
}

.category-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  flex: 1;
}

.category-section-count {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Category card */
.category-row {
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  /* 4px left accent bar */
  overflow: hidden;
}

/* Accent bar inside category rows */
.category-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 3px;
  background: var(--bank-accent, var(--text-tertiary));
  border-radius: var(--r-md) 0 0 var(--r-md);
  flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
  .category-row:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
  }
}
.category-row:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-xs);
}

/* Icon circle */
.category-row-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--bank-accent, #667eea) 12%, transparent);
  color: var(--bank-accent, #667eea);
  border: 1px solid color-mix(in srgb, var(--bank-accent, #667eea) 18%, transparent);
  margin-left: 4px; /* account for the 3px accent bar */
}

.category-row-body {
  flex: 1;
  min-width: 0;
}

.category-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-row-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  flex-wrap: wrap;
}

.category-row-count {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
}

.category-lang-pip {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bank-accent, var(--text-secondary));
  background: color-mix(in srgb, var(--bank-accent, #667eea) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--bank-accent, #667eea) 18%, transparent);
  border-radius: var(--r-pill);
  padding: 1px 7px;
}

.category-row-chevron {
  flex-shrink: 0;
  color: var(--text-tertiary);
  opacity: 0.5;
}

/* Section header in template list (language groups) */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 6px;
}
.section-header-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.section-header-count {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* Category-specific accent colors for new category slugs */
.category-row[data-category="security"] {
  --bank-accent: #e74c3c;
}
.category-row[data-category="transaction"] {
  --bank-accent: #2ecc71;
}
.category-row[data-category="account_manage"] {
  --bank-accent: #3498db;
}

/* Entrance stagger */
.category-row.entering {
  animation: fade-up 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* -------------------------------------------------------------
   13. TEMPLATE LIST VIEW
   ------------------------------------------------------------- */
.tpl-list {
  padding: 10px 16px 90px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tpl-row {
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  cursor: pointer;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
}

@media (hover: hover) and (pointer: fine) {
  .tpl-row:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
  }
}
.tpl-row:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-xs);
}

/* Language flag circle */
.tpl-row-lang-strip {
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

.tpl-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tpl-row-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpl-row-subject {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpl-row-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.tpl-row-lang-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.05);
  padding: 2px 7px;
  border-radius: var(--r-pill);
}
.dark-theme .tpl-row-lang-badge {
  background: rgba(255,255,255,0.08);
}

.tpl-row-cost-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Cost pill — styled like Emitly's small green badges */
.tpl-row-cost-pill {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.05);
  padding: 2px 7px;
  border-radius: var(--r-pill);
}
.dark-theme .tpl-row-cost-pill {
  background: rgba(255,255,255,0.08);
}

.tpl-row-fav-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-pill);
  color: var(--text-tertiary);
  transition: color var(--t-fast), transform var(--t-fast);
}
.tpl-row-fav-btn.is-fav { color: var(--destructive); }
.tpl-row-fav-btn.heart-pop { animation: heart-pop 380ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.tpl-row-fav-btn:active { transform: scale(0.80); }

.tpl-row-chevron {
  flex-shrink: 0;
  color: var(--text-tertiary);
  opacity: 0.45;
}

/* Row entrance stagger */
.tpl-row.entering {
  animation: fade-up 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* -------------------------------------------------------------
   14. PREVIEW VIEW
   ------------------------------------------------------------- */
#view-preview {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.preview-frame-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #f0f0f0;
  overflow: hidden;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #ffffff;
}

.iframe-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity var(--t-base);
}
.iframe-loading-overlay.hidden {
  display: flex;
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Bottom sheet */
.preview-sheet {
  flex-shrink: 0;
  background: var(--surface);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: var(--shadow-sheet);
  height: 220px;
  max-height: 75vh;
  transition: height 280ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  position: relative;
  padding-bottom: calc(72px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

#view-preview.active .preview-sheet {
  animation: sheet-slide-up 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.preview-sheet.expanded { height: 55vh; max-height: 75vh; }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--border);
  margin: 10px auto 2px;
  touch-action: pan-x;
  cursor: grab;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 16px 6px;
  flex-shrink: 0;
}

.sheet-title-wrap {
  flex: 1;
  min-width: 0;
}

.sheet-badges-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  margin-bottom: 4px;
  overflow: hidden;
  max-width: 100%;
}

.sheet-category-badge {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  flex-shrink: 1;
  min-width: 0;
}

.sheet-lang-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.05);
  padding: 2px 7px;
  border-radius: var(--r-pill);
}
.dark-theme .sheet-lang-badge {
  background: rgba(255,255,255,0.08);
}

.sheet-cost-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sheet-subject {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Favorite button */
.fav-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  background: rgba(0,0,0,0.04);
  transition: color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.dark-theme .fav-btn { background: rgba(255,255,255,0.06); }
.fav-btn.is-fav { color: var(--destructive); background: rgba(239,68,68,0.10); }
.fav-btn:active { transform: scale(0.84); }
.fav-btn.heart-pop { animation: heart-pop 380ms cubic-bezier(0.34, 1.56, 0.64, 1); }

/* Sheet tab bar */
.sheet-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  margin-top: 4px;
  flex-shrink: 0;
}

.sheet-tab {
  flex: 1;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.sheet-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

/* Details panel */
.sheet-details {
  padding: 12px 16px 16px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  align-items: start;
}

.detail-list dt {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  padding-top: 1px;
  font-weight: 400;
}

.detail-list dd {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.detail-vars-section {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.detail-vars-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.detail-vars-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.var-chip {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
}
.dark-theme .var-chip { background: rgba(255,255,255,0.06); }

.detail-vars-none {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* Preview action bar */
.preview-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* -------------------------------------------------------------
   15. BUTTONS
   ------------------------------------------------------------- */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 50px;
  border-radius: var(--r-lg);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  background: var(--btn-bg);
  color: var(--btn-text);
  transition: opacity var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  user-select: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.16);
}
.btn-primary:active {
  opacity: 0.85;
  transform: scale(0.96);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.btn-primary:disabled {
  opacity: 0.28;
  pointer-events: none;
}

/* Gradient variant — contextual bank color for "Use This Template" */
.btn-primary.btn-gradient {
  background: linear-gradient(
    135deg,
    var(--preview-btn-start, var(--btn-bg)),
    var(--preview-btn-end, var(--btn-bg))
  );
  color: #ffffff;
  box-shadow: 0 4px 12px var(--preview-btn-shadow, rgba(0,0,0,0.22));
}
.btn-primary.btn-gradient:active {
  box-shadow: 0 2px 6px var(--preview-btn-shadow, rgba(0,0,0,0.18));
}

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  border-radius: var(--r-lg);
  font-size: 15px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  transition: background var(--t-fast), transform var(--t-fast);
  user-select: none;
  box-shadow: var(--shadow-xs);
}
.btn-secondary:active {
  background: var(--bg);
  transform: scale(0.96);
}

.btn-full { width: 100%; }

/* -------------------------------------------------------------
   16. SLOTS FORM
   ------------------------------------------------------------- */
#view-slots {
  padding-bottom: calc(84px + var(--safe-bottom));
}

.slots-intro {
  padding: 16px 16px 10px;
}

.slots-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.4;
}

.slots-form {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slot-field {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  box-shadow: var(--shadow-xs);
}
.slot-field:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
.dark-theme .slot-field:focus-within {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.05);
}
.slot-field:first-child { margin-top: 4px; }

.slot-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 10px 14px 3px;
}

.slot-input {
  display: block;
  width: 100%;
  padding: 4px 14px 12px;
  font-size: 16px;
  color: var(--text-primary);
  background: transparent;
  caret-color: var(--text-primary);
  font-weight: 400;
  min-height: 44px;
}
.slot-input::placeholder { color: var(--text-tertiary); }

.slot-input.is-textarea {
  resize: none;
  min-height: 80px;
  padding-top: 4px;
}

.slot-input.is-textarea.editable-body-textarea {
  min-height: 200px;
  resize: vertical;
}

.body-char-count {
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: right;
  padding: 2px 14px 6px;
}

.slot-field.has-error { border-color: var(--destructive); }
.slot-field.has-error .slot-input { color: var(--destructive); }

.slot-error-msg {
  display: none;
  font-size: 12px;
  color: var(--destructive);
  padding: 0 14px 8px;
  font-weight: 400;
}
.slot-field.has-error .slot-error-msg { display: block; }

.slot-suggestions {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-height: 180px;
  overflow-y: auto;
}

.slot-suggestion-item {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  transition: background var(--t-fast);
  font-weight: 400;
}
.slot-suggestion-item:last-child { border-bottom: none; }
.slot-suggestion-item:active { background: var(--bg); }

/* Slots action bar */
.slots-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  z-index: 50;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.slots-action-bar .btn-secondary { flex: 1; }
.slots-action-bar .btn-primary   { flex: 2; min-height: 50px; font-size: 16px; }

/* -------------------------------------------------------------
   17. SETTINGS VIEW
   ------------------------------------------------------------- */
#view-settings {
  padding-bottom: var(--safe-bottom);
}

.settings-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.settings-section {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 14px 16px 6px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-top: 1px solid var(--divider);
  width: 100%;
  text-align: left;
  color: var(--text-primary);
  background: transparent;
  border-left: none;
  border-right: none;
  border-bottom: none;
  font-size: 14px;
  font-weight: 400;
}
.settings-row:first-of-type { border-top: none; }

.settings-label { flex: 1; }

.settings-value {
  font-size: 13px;
  color: var(--text-tertiary);
}

.settings-action-row {
  cursor: pointer;
  transition: background var(--t-fast);
}
.settings-action-row:active { background: var(--bg); }

.settings-select {
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 5px 28px 5px 10px;
  font-size: 13px;
  color: var(--text-primary);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239ca3af' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.dark-theme .settings-select {
  background-color: rgba(255,255,255,0.06);
}

/* -------------------------------------------------------------
   18. TOAST NOTIFICATIONS
   ------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: calc(76px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-6px) scale(0.95); }
}

.toast {
  padding: 9px 16px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: rgba(26, 26, 46, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.20);
  animation: toast-in 200ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  white-space: nowrap;
  pointer-events: none;
}

.toast.success { background: rgba(21, 128, 61, 0.94); }
.toast.error   { background: rgba(185, 28, 28, 0.94); }

.toast.hiding {
  animation: toast-out 160ms ease forwards;
}

/* -------------------------------------------------------------
   ONBOARDING OVERLAY
   ------------------------------------------------------------- */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 9600;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}
.onboarding-overlay:not(.hidden) { pointer-events: auto; }
.onboarding-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 22, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.onboarding-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 14px 18px 18px;
  padding-bottom: calc(18px + var(--safe-bottom));
  animation: topup-sheet-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.onboarding-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 2px 0 10px;
}
.onboarding-dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--divider);
}
.onboarding-dots .dot.active {
  background: var(--text-primary);
}
.dark-theme .onboarding-dots .dot.active {
  background: #f0f0f8;
}
.onboarding-title {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 8px;
}
.onboarding-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
  text-align: center;
  margin-bottom: 14px;
}
.onboarding-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* -------------------------------------------------------------
   18b. TOP-UP MODAL — credits purchase
   ------------------------------------------------------------- */
.stat-credits-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.stat-credits-header .stat-label {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
}

.btn-topup {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-text);
  box-shadow: var(--shadow-xs);
  transition: transform var(--t-fast), opacity var(--t-fast);
}

.btn-topup:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.topup-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  pointer-events: none;
}

.topup-overlay:not(.hidden) {
  pointer-events: auto;
}

.topup-overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.topup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 22, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.topup-sheet {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: min(88vh, 640px);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 8px 18px 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  z-index: 1;
  animation: topup-sheet-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes topup-sheet-in {
  from { transform: translateY(100%); opacity: 0.6; }
  to   { transform: translateY(0); opacity: 1; }
}

.topup-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--divider);
  margin: 4px auto 12px;
}

.topup-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  color: var(--text-secondary);
  border-radius: var(--r-sm);
}

.topup-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 40px 14px 0;
  color: var(--text-primary);
}

.topup-step {
  position: relative;
}

.topup-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.45;
}

.topup-back-link {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding: 4px 0;
}

.topup-plan-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topup-plan-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast), transform var(--t-fast);
}

.topup-plan-btn:active {
  transform: scale(0.99);
}

.topup-plan-btn:hover,
.topup-plan-btn:focus-visible {
  border-color: var(--border-focus);
}

.topup-plan-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.topup-plan-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.topup-plan-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.topup-coin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.topup-coin-btn {
  padding: 12px 10px;
  border-radius: var(--r-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  transition: border-color var(--t-fast), transform var(--t-fast);
}

.topup-coin-btn:active {
  transform: scale(0.98);
}

.topup-coin-btn:hover,
.topup-coin-btn:focus-visible {
  border-color: var(--border-focus);
}

.topup-qr-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.topup-qr {
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: #fff;
}

.topup-field {
  margin-bottom: 12px;
}

.topup-field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.topup-mono {
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
  color: var(--text-primary);
}

.topup-break {
  line-height: 1.4;
}

.topup-amount-line {
  font-size: 15px;
  font-weight: 600;
}

.btn-topup-copy {
  margin-top: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.topup-memo-warning {
  font-size: 12px;
  color: var(--accent-amber);
  margin-top: 6px;
  line-height: 1.4;
}

.topup-ref {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.topup-ref code {
  font-size: 11px;
}

.topup-countdown {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 10px;
  min-height: 1.4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: color var(--t-base);
}

.topup-countdown:empty {
  display: none;
}

.topup-countdown-expired {
  color: var(--accent-red);
  font-weight: 700;
}

.topup-status {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
  min-height: 1.2em;
}

.topup-step-success {
  text-align: center;
  padding: 12px 0 8px;
}

.topup-success-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
  font-size: 28px;
  font-weight: 700;
}

.topup-success-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  margin-bottom: 18px;
}

.topup-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(2px);
  border-radius: inherit;
  z-index: 5;
}

.dark-theme .topup-loading {
  background: rgba(28, 28, 34, 0.94);
}

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

.topup-loading .spinner {
  width: 32px;
  height: 32px;
}

.topup-loading p {
  font-size: 13px;
  color: var(--text-secondary);
}

/* -------------------------------------------------------------
   19. RESPONSIVE OVERRIDES
   ------------------------------------------------------------- */
@media (min-width: 600px) {
  .preview-sheet { height: 240px; }
  .preview-sheet.expanded { height: 48vh; }

  .preview-action-bar,
  .slots-action-bar {
    max-width: 600px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .preview-sheet { height: 140px; }
  .preview-sheet.expanded { height: 60vh; max-height: 75vh; }
}

/* Small mobile — tighter spacing, larger touch targets */
@media (max-width: 380px) {
  .sheet-header { padding: 8px 12px 4px; gap: 8px; }
  .sheet-title { font-size: 15px; }
  .slot-label { font-size: 10px; padding: 8px 12px 2px; }
  .slot-input { padding: 4px 12px 10px; font-size: 16px; }
  .preview-action-bar,
  .slots-action-bar { padding-left: 12px; padding-right: 12px; }
}

/* -------------------------------------------------------------
   20. FOCUS STYLES
   ------------------------------------------------------------- */
:focus-visible {
  outline: 2.5px solid var(--text-primary);
  outline-offset: 2px;
  border-radius: 3px;
}

:focus:not(:focus-visible) { outline: none; }

/* -------------------------------------------------------------
   23. SEND CONFIRMATION SHEET (Feature 3)
   ------------------------------------------------------------- */
.send-confirm-overlay { position: fixed; inset: 0; z-index: 9500; display: flex; align-items: flex-end; justify-content: center; }
.send-confirm-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.send-confirm-sheet { position: relative; width: 100%; max-width: 600px; background: var(--surface); border-radius: 16px 16px 0 0; padding: 24px 20px calc(24px + var(--safe-bottom)); }
.send-confirm-details { margin: 16px 0; font-size: 14px; line-height: 1.8; }
.send-confirm-actions { display: flex; gap: 10px; }
.send-confirm-actions .btn-primary { flex: 1; }
.send-confirm-actions .btn-secondary { flex: 1; }
.send-confirm-actions button { padding: 12px; border-radius: 10px; font-weight: 600; }

/* -------------------------------------------------------------
   24. SKELETON SHIMMER LOADING (Feature 4)
   ------------------------------------------------------------- */
.skeleton-card { background: var(--skeleton-bg, #e9ecef); border-radius: 12px; height: 80px; position: relative; overflow: hidden; }
.dark-theme .skeleton-card { --skeleton-bg: #2a2a2a; }
.skeleton-card::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent); animation: skeleton-shimmer 1.5s infinite; }
@keyframes skeleton-shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* -------------------------------------------------------------
   25. CUSTOM TEMPLATE BADGE
   ------------------------------------------------------------- */
.tpl-row-custom-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: #e8f5e9;
  color: #2e7d32;
  white-space: nowrap;
}
.dark-theme .tpl-row-custom-badge {
  background: #1b3a1d;
  color: #66bb6a;
}

/* -------------------------------------------------------------
   26. HISTORY VIEW
   ------------------------------------------------------------- */
.history-list {
  padding: 8px 16px 40px;
}
.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface, #fff);
  border-radius: 12px;
  border: 1px solid var(--border, #e9ecef);
  animation: fade-up 0.25s ease both;
}
.dark-theme .history-row {
  background: var(--surface, #1e1e1e);
  border-color: var(--border, #333);
}
.history-row-date {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-secondary, #6c757d);
  width: 60px;
  text-align: center;
  line-height: 1.3;
}
.history-row-body {
  flex: 1;
  min-width: 0;
}
.history-row-recipient {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #212529);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dark-theme .history-row-recipient {
  color: var(--text-primary, #e0e0e0);
}
.history-row-tpl {
  font-size: 12px;
  color: var(--text-secondary, #6c757d);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-status-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.history-status-sent {
  background: #e8f5e9;
  color: #2e7d32;
}
.dark-theme .history-status-sent {
  background: #1b3a1d;
  color: #66bb6a;
}
.history-status-failed {
  background: #ffebee;
  color: #c62828;
}
.dark-theme .history-status-failed {
  background: #3a1b1b;
  color: #ef5350;
}
.history-status-queued {
  background: #fff8e1;
  color: #f57f17;
}
.dark-theme .history-status-queued {
  background: #3a3100;
  color: #ffca28;
}
.history-row-cost {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary, #6c757d);
}
.history-loading {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

/* Make history rows clickable */
.history-row {
  cursor: pointer;
  transition: background var(--t-fast);
}
.history-row:active {
  background: var(--bg, #f5f5f5);
}
.dark-theme .history-row:active {
  background: rgba(255,255,255,0.05);
}

/* -------------------------------------------------------------
   DISPATCH DETAIL OVERLAY
   ------------------------------------------------------------- */
.dispatch-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.dispatch-detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.dispatch-detail-sheet {
  position: relative;
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  animation: topup-sheet-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.dispatch-detail-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 14px;
}
.dispatch-detail-body {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-primary);
}
.dispatch-detail-body .dd-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--divider);
}
.dispatch-detail-body .dd-row:last-child { border-bottom: none; }
.dispatch-detail-body .dd-label {
  color: var(--text-secondary);
  font-weight: 500;
}
.dispatch-detail-body .dd-value {
  font-weight: 600;
  text-align: right;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dispatch-detail-status {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin: 0 0 12px;
  min-height: 18px;
}
.dispatch-detail-actions {
  display: flex;
  gap: 10px;
}
.dispatch-detail-actions button {
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
}

/* Dark-theme overlay borders */
.dark-theme .send-confirm-sheet { border: 1px solid var(--border); }
.dark-theme .dispatch-detail-sheet { border: 1px solid var(--border); }
.dark-theme .preview-frame-wrap { background: var(--surface); }

/* -------------------------------------------------------------
   EMAIL AUTOCOMPLETE DROPDOWN
   ------------------------------------------------------------- */
.email-autocomplete {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-height: 180px;
  overflow-y: auto;
}
.email-autocomplete-item {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  transition: background var(--t-fast);
  font-weight: 400;
}
.email-autocomplete-item:last-child { border-bottom: none; }
.email-autocomplete-item:active { background: var(--bg); }

/* =============================================================
   MOBILE RESPONSIVE — Telegram Mini App (320px-430px)
   All fixes for small-screen touch devices.
   ============================================================= */

/* -------------------------------------------------------------
   M0. GENERAL — prevent horizontal overflow everywhere
   ------------------------------------------------------------- */
body {
  overflow-x: hidden;
}

html {
  overflow-x: hidden;
}

/* Ensure all interactive elements meet 44px touch target minimum */
@media (max-width: 480px) {
  .btn-primary,
  .btn-secondary,
  .btn-topup,
  .btn-topup-copy,
  .topup-plan-btn,
  .topup-coin-btn,
  .send-confirm-actions button,
  .slots-action-bar button,
  .preview-action-bar button,
  .low-balance-btn {
    min-height: 44px;
  }
}

/* -------------------------------------------------------------
   M1. PREVIEW SHEET — bottom sheet that slides up
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .preview-sheet {
    max-height: 85vh;
    overflow-y: auto;
  }

  .preview-sheet.expanded {
    height: 85vh;
    max-height: 85vh;
  }

  .sheet-badges-row {
    flex-wrap: wrap;
    gap: 4px;
  }

  .preview-action-bar {
    flex-direction: column;
    gap: 8px;
  }

  .preview-action-bar .btn-primary,
  .preview-action-bar .btn-secondary,
  .preview-action-bar .btn-gradient {
    width: 100%;
  }

  .sheet-title {
    font-size: 15px;
  }

  .sheet-header {
    padding: 8px 14px 6px;
  }
}

@media (max-width: 380px) {
  .preview-sheet {
    max-height: 80vh;
    height: auto;
    min-height: 180px;
  }

  .sheet-title {
    font-size: 14px;
  }

  .sheet-badges-row {
    gap: 3px;
  }

  .sheet-category-badge,
  .sheet-lang-badge,
  .sheet-cost-badge {
    font-size: 10px;
  }
}

/* -------------------------------------------------------------
   M2. SLOTS FORM — input fields and action bar
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .slot-field {
    max-width: 100%;
  }

  .slot-field input,
  .slot-field select,
  .slot-field textarea,
  .slot-input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .slot-input.is-textarea {
    min-height: 100px;
  }

  /* Custom body textarea — larger for composing content */
  .slot-field:last-of-type .slot-input.is-textarea,
  .slot-field .slot-input.is-textarea[name*="body"],
  .slot-field .slot-input.is-textarea[name*="custom"],
  .slot-field .slot-input.is-textarea[placeholder*="body"],
  .slot-field .slot-input.is-textarea[placeholder*="Body"],
  .slot-field .slot-input.is-textarea[placeholder*="HTML"],
  .slot-field .slot-input.is-textarea[placeholder*="html"] {
    min-height: 150px;
  }

  .slot-input.is-textarea.editable-body-textarea {
    min-height: 200px;
  }

  .slots-form {
    padding: 0 14px;
  }
}

@media (max-width: 400px) {
  .slots-action-bar {
    flex-direction: column;
    gap: 6px;
  }

  .slots-action-bar .btn-secondary,
  .slots-action-bar .btn-primary {
    flex: unset;
    width: 100%;
  }
}

/* -------------------------------------------------------------
   M3. BANK CARD GRID — 1 col below 360px, 2 cols above
   ------------------------------------------------------------- */
@media (max-width: 360px) {
  .bank-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 14px 90px;
  }

  .bank-card {
    height: 120px;
  }

  .skeleton-bank-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 14px;
  }
}

@media (min-width: 361px) and (max-width: 480px) {
  .bank-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 10px 14px 90px;
  }

  .bank-card {
    height: 130px;
  }
}

/* -------------------------------------------------------------
   M4. TEMPLATE LIST — badge wrapping and title truncation
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .tpl-row {
    gap: 10px;
    padding: 11px 12px;
    max-width: 100%;
    overflow: hidden;
  }

  .tpl-row-badges {
    flex-wrap: wrap;
    gap: 4px;
  }

  .tpl-row-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .tpl-row-subject {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tpl-row-body {
    min-width: 0;
    overflow: hidden;
  }
}

@media (max-width: 380px) {
  .tpl-row {
    gap: 8px;
    padding: 10px 10px;
  }

  .tpl-row-lang-strip {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }

  .tpl-row-title {
    font-size: 13px;
  }

  .tpl-row-subject {
    font-size: 11px;
  }

  .tpl-row-badges {
    gap: 3px;
  }

  .tpl-row-lang-badge,
  .tpl-row-cost-pill {
    font-size: 9px;
    padding: 1px 5px;
  }

  .tpl-row-fav-btn {
    width: 28px;
    height: 28px;
  }
}

/* -------------------------------------------------------------
   M5. TOP-UP OVERLAY — credits purchase sheet
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .topup-sheet {
    max-height: 90vh;
    overflow-y: auto;
    padding: 8px 14px 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .topup-plan-list {
    gap: 6px;
  }

  .topup-plan-btn {
    width: 100%;
    padding: 12px 14px;
  }

  .topup-coin-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .topup-qr {
    max-width: 160px;
    height: auto;
  }

  .topup-title {
    font-size: 16px;
    margin-right: 36px;
  }

  .topup-mono {
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .topup-sheet {
    padding: 6px 12px 14px;
    padding-bottom: calc(14px + var(--safe-bottom));
  }

  .topup-plan-name {
    font-size: 14px;
  }

  .topup-plan-price {
    font-size: 13px;
  }

  .topup-coin-btn {
    padding: 10px 8px;
    font-size: 12px;
  }

  .topup-qr {
    max-width: 140px;
  }
}

/* -------------------------------------------------------------
   M6. SEND CONFIRMATION SHEET
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .send-confirm-sheet {
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .send-confirm-details {
    font-size: 13px;
    line-height: 1.7;
    word-break: break-word;
  }
}

@media (max-width: 380px) {
  .send-confirm-actions {
    flex-direction: column;
    gap: 8px;
  }

  .send-confirm-actions button {
    flex: unset;
    width: 100%;
  }

  .send-confirm-sheet {
    padding: 16px 14px;
  }
}

/* -------------------------------------------------------------
   M7. HISTORY VIEW — prevent overflow, truncate text
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .history-row {
    gap: 8px;
    padding: 10px 12px;
    overflow: hidden;
    max-width: 100%;
  }

  .history-row-body {
    min-width: 0;
    overflow: hidden;
  }

  .history-row-recipient {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .history-row-tpl {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .history-row-date {
    width: 50px;
    font-size: 10px;
  }

  .history-status-badge {
    font-size: 10px;
    padding: 2px 6px;
  }
}

@media (max-width: 380px) {
  .history-row {
    gap: 6px;
    padding: 9px 10px;
  }

  .history-row-date {
    width: 44px;
    font-size: 9px;
  }

  .history-row-recipient {
    font-size: 12px;
  }

  .history-row-tpl {
    font-size: 11px;
  }

  .history-row-cost {
    font-size: 11px;
  }
}

/* -------------------------------------------------------------
   M8. ADDITIONAL MOBILE FIXES — 480px and below
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  /* Stats dashboard adjustments */
  .stats-dashboard-wrap {
    padding: 12px 12px 0;
  }

  .stat-value {
    font-size: 22px;
  }

  .stat-cell {
    padding: 8px 12px 12px;
  }

  /* Search bar */
  .search-wrap {
    padding: 10px 12px 0;
  }

  /* Filter pills */
  .filter-pills {
    padding: 0 12px 10px;
  }

  /* Category list */
  .category-list {
    padding: 10px 12px 90px;
  }

  .category-row {
    gap: 10px;
    padding: 12px 12px;
  }

  /* Template list */
  .tpl-list {
    padding: 10px 12px 90px;
  }

  /* Card grid — search/favorites */
  .card-grid {
    gap: 8px;
    padding: 10px 12px 90px;
  }

  /* Recent chips */
  .recents-shelf-scroller {
    padding: 0 12px 10px;
  }

  .recent-chip {
    width: 148px;
  }

  /* Toast — prevent overflow */
  .toast {
    max-width: calc(100vw - 24px);
    white-space: normal;
    text-align: center;
  }

  /* Low balance banner */
  .low-balance-banner {
    margin: 8px 12px 2px;
  }

  /* Settings */
  .settings-list {
    padding: 12px;
  }
}

/* -------------------------------------------------------------
   M9. EXTRA SMALL SCREENS — 380px and below
   ------------------------------------------------------------- */
@media (max-width: 380px) {
  /* Stats */
  .stats-dashboard-wrap {
    padding: 10px 10px 0;
  }

  .stat-value {
    font-size: 20px;
  }

  .stat-label {
    font-size: 10px;
  }

  .stat-cell {
    padding: 7px 10px 10px;
  }

  /* Header */
  .app-header {
    padding: 0 8px;
  }

  .header-title {
    font-size: 15px;
  }

  /* Search */
  .search-wrap {
    padding: 8px 10px 0;
  }

  .search-box {
    height: 40px;
    padding: 0 10px;
  }

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

  /* Filter pills */
  .filter-pills {
    padding: 0 10px 8px;
    gap: 5px;
  }

  .pill {
    padding: 5px 10px;
    font-size: 12px;
  }

  /* Bank grid */
  .bank-grid {
    padding: 8px 10px 90px;
  }

  /* Category list */
  .category-list {
    padding: 8px 10px 90px;
  }

  .category-row {
    gap: 8px;
    padding: 10px 10px;
  }

  .category-row-icon {
    width: 34px;
    height: 34px;
  }

  .category-row-name {
    font-size: 13px;
  }

  /* Template list */
  .tpl-list {
    padding: 8px 10px 90px;
  }

  /* Card grid */
  .card-grid {
    gap: 6px;
    padding: 8px 10px 90px;
  }

  .card-body {
    padding: 9px 26px 9px 10px;
  }

  .card-title {
    font-size: 12px;
  }

  /* Low balance banner */
  .low-balance-banner {
    margin: 6px 10px 2px;
    padding: 8px 10px;
    gap: 8px;
  }

  .low-balance-text {
    font-size: 12px;
  }

  /* Settings */
  .settings-list {
    padding: 10px;
  }

  .settings-row {
    padding: 11px 12px;
    font-size: 13px;
  }

  /* Action bars */
  .preview-action-bar {
    padding: 8px 10px calc(8px + var(--safe-bottom));
  }

  .slots-action-bar {
    padding: 8px 10px calc(8px + var(--safe-bottom));
  }
}
