/* ============================================================
   TEDDYDOO — App CSS (FinApp-inspired mobile-first PWA)
   ============================================================ */

:root {
  --ink: #0a0a0a;
  --ink2: #141210;
  --surface: #0f0d0b;
  --surface2: #181513;
  --cream: #f5f0e8;
  --cream-2: #ebe3d4;
  --warm: #c8965a;
  --warm-2: #e8b87a;
  --warm-soft: rgba(200,150,90,0.12);
  --warm-border: rgba(200,150,90,0.22);
  --muted: #8a7e6f;
  --muted-2: #6b6055;
  --danger: #e85a5a;
  --success: #4ac98a;
  --warning: #e8b87a;
  --info: #6fa5d9;
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.1);

  --header-h: 60px;
  --tabbar-h: 64px;
  --radius: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-card: 0 4px 18px rgba(0,0,0,0.35);
  --shadow-pop:  0 16px 40px rgba(0,0,0,0.55);

  font-size: 16px;
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Noto Kufi Arabic', system-ui, -apple-system, sans-serif;
  background: var(--ink);
  color: var(--cream);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Grain overlay everywhere */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  opacity: 0.5;
}

a { color: var(--warm); text-decoration: none; }
a:hover { color: var(--warm-2); }

img { max-width: 100%; height: auto; display: block; }
input, button, select, textarea { font-family: inherit; }

/* ============================================================
   LAYOUT — App Header + App Capsule + Bottom Tabs
   ============================================================ */

#appCapsule {
  padding-top: var(--header-h);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

.appHeader {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}
.appHeader.no-border { border-bottom: none; }
.appHeader.transparent { background: transparent; backdrop-filter: none; }

.appHeader .left,
.appHeader .right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.appHeader .pageTitle {
  font-size: 1rem;
  font-weight: 700;
  color: var(--cream);
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.headerButton {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
  text-decoration: none;
  font-size: 1.25rem;
}
.headerButton:hover { background: rgba(255,255,255,0.05); }
.headerButton:active { transform: scale(0.95); }
.headerButton .badge {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 18px; height: 18px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 100px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  box-shadow: 0 0 0 2px var(--ink);
}
.headerButton .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--warm-soft);
  border: 1px solid var(--warm-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--warm);
  font-weight: 700;
  font-size: 0.85rem;
}

/* Bottom Tab Bar */
.appBottomMenu {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  z-index: 100;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--muted);
  gap: 0.15rem;
  position: relative;
  transition: color 0.15s;
  padding-top: 6px;
}
.tab-item .icon { font-size: 1.35rem; line-height: 1; }
.tab-item .name { font-size: 0.65rem; font-weight: 600; letter-spacing: 0.02em; }
.tab-item:hover { color: var(--cream); }
.tab-item.active { color: var(--warm); }
.tab-item.active::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 32px; height: 3px;
  background: var(--warm);
  border-radius: 0 0 4px 4px;
}
.tab-item .dot-badge {
  position: absolute;
  top: 8px;
  right: calc(50% - 18px);
  min-width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--ink);
}
.tab-item .num-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  min-width: 16px; height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: 100px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--ink);
}

/* The big center floating tab (used on dashboard for "add gift") */
.tab-item.action-button {
  flex: 0 0 70px;
  position: relative;
}
.tab-item.action-button .action-btn-inner {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--warm);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-top: -22px;
  box-shadow: 0 8px 20px rgba(200,150,90,0.4);
  border: 4px solid var(--ink);
}

/* ============================================================
   SECTIONS / CARDS / FORMS
   ============================================================ */

.section {
  padding: 1.25rem 1rem;
}
.section.full { padding: 1.25rem 0; }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}
.section-heading .title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--cream);
}
.section-heading .link {
  font-size: 0.8rem;
  color: var(--warm);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-body { padding: 1.25rem; }
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: 0.95rem; font-weight: 700; color: var(--cream); }
.card-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

/* listView like FinApp */
.listView {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  list-style: none;
}
.listView .item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.listView .item:last-child { border-bottom: none; }
.listView .item:hover { background: rgba(255,255,255,0.02); }
.listView .item .icon-box {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--warm-soft);
  border: 1px solid var(--warm-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  color: var(--warm);
}
.listView .item .in {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.listView .item .in .label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.listView .item .in .meta {
  font-size: 0.75rem;
  color: var(--muted);
}
.listView .item .end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}
.form-group .label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
  display: block;
  letter-spacing: 0.02em;
}
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}
.input-wrapper:focus-within {
  border-color: var(--warm);
  background: var(--surface);
}
.form-control {
  width: 100%;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  color: var(--cream);
  font-size: 0.95rem;
  outline: none;
}
.form-control::placeholder { color: var(--muted-2); }
.form-control:disabled { opacity: 0.5; }
textarea.form-control { min-height: 110px; resize: vertical; }
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(0% + 18px) 50%, calc(0% + 24px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-left: 2.5rem;
}

.input-wrapper .icon-end,
.input-wrapper .clear-input {
  position: absolute;
  left: 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  white-space: nowrap;
  user-select: none;
  background: transparent;
  color: var(--cream);
  line-height: 1;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 0.95rem 1.8rem; font-size: 0.95rem; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.78rem; }
.btn-block { width: 100%; display: flex; }

.btn-primary {
  background: var(--warm);
  color: var(--ink);
  border-color: var(--warm);
}
.btn-primary:hover { background: var(--warm-2); border-color: var(--warm-2); }

.btn-secondary {
  background: var(--surface2);
  color: var(--cream);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface); border-color: var(--warm-border); }

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--cream);
}
.btn-ghost:hover { border-color: var(--warm); color: var(--warm); }

.btn-danger {
  background: rgba(232,90,90,0.12);
  color: var(--danger);
  border-color: rgba(232,90,90,0.3);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-icon {
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Toggle / Switch */
.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  cursor: pointer;
  transition: 0.2s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  right: 2px; top: 2px;
  background: var(--cream);
  border-radius: 50%;
  transition: 0.2s var(--ease);
}
.switch input:checked + .slider {
  background: var(--warm);
  border-color: var(--warm);
}
.switch input:checked + .slider::before {
  transform: translateX(-20px);
  background: var(--ink);
}

/* Badges / Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--cream-2);
}
.chip.warm   { background: var(--warm-soft); border-color: var(--warm-border); color: var(--warm); }
.chip.success { background: rgba(74,201,138,0.12); border-color: rgba(74,201,138,0.3); color: var(--success); }
.chip.danger  { background: rgba(232,90,90,0.12); border-color: rgba(232,90,90,0.3); color: var(--danger); }
.chip.info    { background: rgba(111,165,217,0.12); border-color: rgba(111,165,217,0.3); color: var(--info); }

/* Hero "wallet card" (used on dashboard top) */
.wallet-card {
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, #1a1614 0%, #0e0c0a 100%);
  border: 1px solid var(--warm-border);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-pop);
}
.wallet-card::before {
  content: '';
  position: absolute;
  top: -50%; right: -20%;
  width: 280px; height: 280px;
  background: radial-gradient(circle, rgba(200,150,90,0.18) 0%, transparent 70%);
  pointer-events: none;
}
.wallet-card .label {
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  color: var(--warm);
  text-transform: uppercase;
  font-family: 'Sora', sans-serif;
  margin-bottom: 0.4rem;
}
.wallet-card .value {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: 'Sora', sans-serif;
  line-height: 1;
}
.wallet-card .sub { font-size: 0.85rem; color: var(--muted); margin-top: 0.35rem; }
.wallet-card .actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
  position: relative;
  z-index: 1;
}

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}
.stat-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  text-align: center;
}
.stat-cell .num {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--warm);
  font-family: 'Sora', sans-serif;
}
.stat-cell .lbl { font-size: 0.7rem; color: var(--muted); margin-top: 0.15rem; }

/* Toast (in-app) */
.toast-container {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 1rem + env(safe-area-inset-bottom));
  left: 1rem; right: 1rem;
  z-index: 9000;
  display: flex; flex-direction: column; gap: 0.5rem;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--cream);
  border-radius: var(--radius);
  padding: 0.85rem 1.2rem;
  font-size: 0.88rem;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  pointer-events: auto;
  animation: toastIn 0.35s var(--ease);
  max-width: 380px;
}
.toast.success { border-color: rgba(74,201,138,0.4); }
.toast.error   { border-color: rgba(232,90,90,0.4); }
.toast.warn    { border-color: rgba(232,184,122,0.4); }
@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Modals / Sheets */
.action-sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 950;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.action-sheet-backdrop.show { opacity: 1; pointer-events: auto; }

.action-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  border-radius: 24px 24px 0 0;
  padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  z-index: 1000;
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  max-height: 85vh;
  overflow-y: auto;
}
.action-sheet.show { transform: translateY(0); }
.action-sheet::before {
  content: '';
  display: block;
  width: 36px; height: 4px;
  background: var(--border-strong);
  border-radius: 4px;
  margin: 0 auto 1rem;
}
.action-sheet h3 {
  font-size: 1.05rem;
  margin-bottom: 0.85rem;
  text-align: center;
}

/* Avatar / Image */
.imaged {
  border-radius: 50%;
  object-fit: cover;
}
.w28 { width: 28px; height: 28px; }
.w32 { width: 32px; height: 32px; }
.w40 { width: 40px; height: 40px; }
.w48 { width: 48px; height: 48px; }
.w64 { width: 64px; height: 64px; }
.w80 { width: 80px; height: 80px; }
.w96 { width: 96px; height: 96px; }

/* Loader */
#loader {
  position: fixed;
  inset: 0;
  background: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: opacity 0.4s;
}
#loader.hide { opacity: 0; pointer-events: none; }
.loading-spin {
  width: 36px; height: 36px;
  border: 3px solid rgba(200,150,90,0.2);
  border-top-color: var(--warm);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state .icon-box {
  width: 80px; height: 80px;
  margin: 0 auto 1rem;
  border-radius: 22px;
  background: var(--warm-soft);
  border: 1px solid var(--warm-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  color: var(--warm);
}
.empty-state h3 { color: var(--cream); margin-bottom: 0.4rem; font-size: 1rem; }
.empty-state p  { font-size: 0.85rem; max-width: 280px; margin: 0 auto; line-height: 1.7; }

/* Install banner */
.install-banner {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 1rem + env(safe-area-inset-bottom));
  left: 1rem; right: 1rem;
  background: var(--surface);
  border: 1px solid var(--warm-border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-pop);
  z-index: 800;
  animation: slideUp 0.3s var(--ease);
}
.install-banner.hide { display: none; }
.install-banner .icon-box {
  width: 38px; height: 38px;
  background: var(--warm-soft);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  color: var(--warm);
  flex-shrink: 0;
}
.install-banner .body { flex: 1; min-width: 0; }
.install-banner .body strong { font-size: 0.88rem; }
.install-banner .body small { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 0.1rem; }

@keyframes slideUp {
  from { transform: translateY(80px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* utility */
.mt-1 { margin-top: 0.25rem; } .mt-2 { margin-top: 0.5rem; } .mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; } .mt-5 { margin-top: 1.5rem; } .mt-6 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.25rem; } .mb-2 { margin-bottom: 0.5rem; } .mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; } .mb-5 { margin-bottom: 1.5rem; } .mb-6 { margin-bottom: 2rem; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-warm { color: var(--warm); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-bold { font-weight: 700; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; } .gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.75rem; } .gap-4 { gap: 1rem; }
.hidden { display: none !important; }

/* Logo */
.brand {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.04em;
  color: var(--cream);
  text-decoration: none;
}
.brand span { color: var(--warm); }

/* Desktop: keep mobile-app look in a centered 480px column */
@media (min-width: 768px) {
  body {
    background:
      radial-gradient(ellipse at top, rgba(200,150,90,0.06), transparent 60%),
      var(--ink);
  }
  #appCapsule, .appHeader, .appBottomMenu {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
  }
  .appHeader {
    border-radius: 0;
  }
  .appBottomMenu {
    border-radius: 0;
  }
  .install-banner, .toast-container {
    max-width: 480px;
    margin: 0 auto;
  }
}

/* Larger desktop landing pages may want full width — opt-out class */
.no-app-frame #appCapsule,
.no-app-frame .appHeader,
.no-app-frame .appBottomMenu {
  max-width: none;
}
