:root {
  --primary: #7C3AED;
  --primary-dark: #6D28D9;
  --primary-light: #A78BFA;
  --primary-bg: #F5F3FF;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --info: #3B82F6;
  --text: #1F2937;
  --text-secondary: #6B7280;
  --text-light: #9CA3AF;
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --border: #E5E7EB;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(124,58,237,0.06);
  --shadow-lg: 0 4px 20px rgba(124,58,237,0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-height: 72px;
  --header-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.menu-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: background 0.2s;
}
.menu-btn:active { background: var(--primary-bg); }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 14px;
}

.app-title { font-size: 18px; font-weight: 700; color: var(--primary); }

.app-logo {
  height: 28px;
  width: auto;
  max-width: 96px;
  object-fit: contain;
  display: block;
  border-radius: 6px;
  flex-shrink: 0;
}

.period-selector {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
}
.period-selector button {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.period-selector button:active { background: var(--primary-bg); }

/* Side Nav */
.side-nav-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0; visibility: hidden;
  transition: all 0.3s;
}
.side-nav-overlay.open { opacity: 1; visibility: visible; }

.side-nav {
  position: fixed; top: 0; left: 0;
  width: 280px; height: 100%;
  background: var(--card);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.side-nav.open { transform: translateX(0); }

.side-nav-header {
  padding: 14px 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}
.side-nav-logo {
  margin-bottom: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
}
.side-nav-header h3 { font-size: 14px; margin-top: 4px; }
.side-nav-header p { font-size: 11px; opacity: 0.85; }

.side-nav-menu { flex: 1; padding: 4px 0; overflow-y: auto; }
.side-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  color: var(--text);
  font-size: 13px; font-weight: 500;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}
.side-nav-item:active, .side-nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-left-color: var(--primary);
}
.side-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.side-nav-footer { padding: 10px 14px; border-top: 1px solid var(--border); }

/* Main Content */
.main-content {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  min-width: 0;
  overflow-x: hidden;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-purple {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-lg);
}
.card-purple .label { font-size: 13px; opacity: 0.85; margin-bottom: 4px; }
.card-purple .amount { font-size: 32px; font-weight: 700; }

.summary-cards {
  display: flex; gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  margin-bottom: 16px;
}
.summary-cards::-webkit-scrollbar { display: none; }

.summary-card {
  min-width: 150px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.summary-card .label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.summary-card .value { font-size: 22px; font-weight: 700; }
.summary-card .change { font-size: 12px; margin-top: 4px; }
.summary-card .change.up { color: var(--success); }
.summary-card .change.down { color: var(--danger); }

/* Period dropdown (replaces old tab strip) */
/* period-dropdown styles defined with ads section below */

/* Legacy period tabs kept for safety if any leftover markup */
.period-tabs {
  display: flex;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.period-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 8px;
  transition: all 0.2s;
}
.period-tab.active {
  background: var(--primary);
  color: white;
}

/* Ads carousel under header */
.ads-carousel {
  margin: 0 0 14px;
  min-height: 0;
}
.ads-carousel:empty { display: none; }
.ads-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  gap: 10px;
  padding: 2px 2px 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.ads-track::-webkit-scrollbar { display: none; }
.ads-slide {
  flex: 0 0 94%;
  scroll-snap-align: start;
  border-radius: 18px;
  padding: 16px 18px;
  color: #fff;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  text-decoration: none;
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.22);
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.ads-slide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ads-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.ads-badge.sponsored {
  background: #FBBF24;
  color: #78350F;
}
.ads-slide h4 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.15;
}
.ads-slide p {
  margin: 0;
  font-size: 13px;
  opacity: 0.92;
  line-height: 1.3;
  font-weight: 600;
}
.ads-chars {
  font-size: 18px;
  letter-spacing: 2px;
  animation: adsBounce 1.4s ease-in-out infinite;
}
@keyframes adsBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.period-dropdown-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}
.period-dropdown {
  width: auto;
  min-width: 120px;
  max-width: 140px;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 28px 8px 10px;
}
.ad-color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.ad-color {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.ad-color.active { box-shadow: 0 0 0 2px var(--text); }
.ad-status {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.ad-status-pending { background: #FEF3C7; color: #92400E; }
.ad-status-approved { background: #D1FAE5; color: #065F46; }
.ad-status-rejected { background: #FEE2E2; color: #991B1B; }

.ad-crop-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ad-crop-dialog {
  width: min(640px, 100%);
  max-height: 90vh;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ad-crop-header,
.ad-crop-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.ad-crop-actions {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}
.ad-crop-body {
  height: min(58vh, 420px);
  background: #111;
}
.ad-crop-body img {
  display: block;
  max-width: 100%;
}

.header-right { position: relative; display: flex; align-items: center; gap: 8px; }
.notif-bell {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 99px;
  background: #EF4444;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(340px, 92vw);
  max-height: 70vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15,23,42,.16);
  z-index: 80;
}
.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
}
.notif-panel-list { padding: 8px; }
.notif-item {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}
.notif-item.unread {
  border-color: rgba(124,58,237,.35);
  background: #F5F3FF;
}
.notif-item .title { font-weight: 700; font-size: 13px; }
.notif-item .body { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.notif-item .meta { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
.zekat-info-card {
  background: linear-gradient(135deg, #0EA5E9, #0284C7);
  color: #fff;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}
.zekat-info-card .zekat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255,255,255,0.2);
  display: grid;
  place-items: center;
  font-size: 20px;
}
.zekat-info-card .label { font-size: 13px; opacity: 0.9; }
.zekat-info-card .amount { font-size: 22px; font-weight: 800; margin-top: 2px; }
.zekat-info-card .base { font-size: 12px; opacity: 0.85; margin-top: 4px; }

/* Progress Bar */
.progress-section { margin-bottom: 16px; }
.progress-header { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 4px;
  transition: width 0.5s ease;
}
.progress-labels { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }

/* Transaction List */
.tx-list { list-style: none; }
.tx-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-info .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-info .meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.tx-amount { font-weight: 700; font-size: 15px; text-align: right; }
.tx-amount.income { color: var(--success); }
.tx-amount.expense { color: var(--danger); }

/* Category Breakdown */
.cat-item { margin-bottom: 14px; }
.cat-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cat-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; }
.cat-amount { font-size: 13px; color: var(--text-secondary); }
.cat-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 3px; transition: width 0.5s; }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 12px;
  color: var(--text-light);
  font-size: 11px; font-weight: 500;
  transition: color 0.2s;
  position: relative;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 24px; height: 24px; }

.nav-add-btn {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white;
  margin-top: -28px;
  box-shadow: 0 4px 15px rgba(124,58,237,0.4);
  transition: transform 0.2s;
}
.nav-add-btn:active { transform: scale(0.95); }
.nav-add-btn svg { width: 28px; height: 28px; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group + .form-group { margin-top: 2px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.form-input {
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  box-sizing: border-box;
  line-height: 1.4;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,0.1); background: var(--card); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.modal .form-group { margin-bottom: 18px; }
.modal .form-input, .modal .form-select { min-height: 52px; }
.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
}

.phone-input-group {
  display: flex; gap: 8px; align-items: stretch;
  position: relative;
  z-index: 5;
}
.country-select {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  min-width: 118px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.country-select .flag {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}
.country-select .code { font-size: 14px; font-weight: 700; color: var(--text); }

.country-flag-wrap {
  position: relative;
  width: 28px;
  height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 3px;
  background: #f3f4f6;
}
.country-flag-img {
  width: 28px;
  height: 20px;
  object-fit: cover;
  border-radius: 3px;
  display: block;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
}
.country-flag-fallback {
  display: none;
  font-size: 9px;
  font-weight: 800;
  color: #6b7280;
  letter-spacing: 0.02em;
}
.country-flag-wrap.is-fallback .country-flag-fallback { display: inline; }

.country-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: min(340px, calc(100vw - 40px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
  z-index: 100;
  display: none;
  overflow: hidden;
  flex-direction: column;
}
.country-dropdown.open { display: flex; }
.country-search-wrap {
  flex: 0 0 auto;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.country-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}
.country-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,0.1); }
.country-options {
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 280px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}
.country-options::-webkit-scrollbar { width: 6px; }
.country-options::-webkit-scrollbar-track { background: transparent; }
.country-options::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 99px;
}
.country-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  padding: 11px 12px;
  cursor: pointer;
  font-size: 14px;
  border: none;
  background: transparent;
  text-align: left;
  color: inherit;
  box-sizing: border-box;
}
.country-option:hover, .country-option.selected { background: var(--primary-bg); }
.country-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.country-dial {
  flex-shrink: 0;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 13px;
}
.country-empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Skeleton / shimmer loading */
.skeleton {
  background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 37%, #e5e7eb 63%);
  background-size: 400% 100%;
  animation: shimmer 1.25s ease infinite;
  border-radius: 10px;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
.skeleton-page { padding: 16px; display: grid; gap: 12px; }
.skeleton-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 10px;
}
.skeleton-line { height: 12px; width: 100%; }
.skeleton-line.sm { width: 40%; }
.skeleton-line.md { width: 70%; }
.skeleton-line.lg { height: 22px; width: 55%; }

.pin-input-group {
  display: flex; gap: 12px; justify-content: center;
}
.pin-digit {
  width: 56px; height: 56px;
  text-align: center;
  font-size: 24px; font-weight: 700;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  outline: none;
  transition: border-color 0.2s;
}
.pin-digit:focus { border-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  transition: all 0.2s;
  width: 100%;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(124,58,237,0.3);
}
.btn-primary:active { transform: scale(0.98); }
.btn-outline {
  border: 1.5px solid var(--primary);
  color: var(--primary);
  background: transparent;
}
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; }

/* Auth Pages */
.auth-page {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: 24px 20px;
  background: linear-gradient(180deg, var(--primary-bg) 0%, var(--bg) 40%);
}
.auth-logo {
  text-align: center;
  padding: 40px 0 32px;
}
.auth-logo-img {
  display: block;
  width: min(140px, 42vw);
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  border-radius: 10px;
}
.auth-logo h1 {
  font-size: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-logo p { color: var(--text-secondary); margin-top: 12px; font-size: 15px; }
.auth-form { flex: 1; }
.auth-footer { text-align: center; padding: 20px 0; font-size: 14px; color: var(--text-secondary); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: all 0.3s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 20px; font-weight: 700; }
.modal-close {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text-secondary);
}

/* Section Title */
.section-title {
  font-size: 16px; font-weight: 700;
  margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.section-title a { font-size: 13px; font-weight: 500; color: var(--primary); }

/* Chart placeholder */
.chart-container {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  height: 200px;
  position: relative;
}

/* Tabs */
.type-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: nowrap;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.type-tabs::-webkit-scrollbar {
  display: none;
  height: 0;
}
.type-tab {
  flex: 0 0 auto;
  white-space: nowrap;
  scroll-snap-align: start;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: #E5E7EB;
  color: #1F2937;
  border: 1.5px solid #D1D5DB;
  transition: all 0.2s;
}
.type-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.4; }

/* Badge */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger { background: #FEE2E2; color: #991B1B; }

/* Toast */
.toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  z-index: 999;
  transition: transform 0.3s ease;
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Language Switcher */
.lang-switch {
  display: flex; gap: 4px;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
}
.lang-btn {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px; font-weight: 600;
  color: #1F2937;
  background: #E5E7EB;
  border: 1px solid #D1D5DB;
  transition: all 0.2s;
}
.lang-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Credit Cards */
.credit-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.credit-card.borrowed { border-left-color: var(--danger); }
.credit-card.lent { border-left-color: var(--success); }

/* Item row in add form */
.item-row {
  display: flex; gap: 8px; align-items: end; margin-bottom: 8px;
}
.item-row .form-group { flex: 1; margin-bottom: 0; }

@media (min-width: 481px) {
  .app-container { box-shadow: var(--shadow-lg); }
}

/* Swipe to delete */
.swipe-list { list-style: none; padding: 0; margin: 0; overflow: hidden; }
.swipe-item {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.swipe-item:last-child { border-bottom: none; }
.swipe-actions {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  z-index: 1;
}
.swipe-delete-btn {
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.swipe-content {
  position: relative;
  z-index: 2;
  background: var(--card);
  transition: transform 0.2s ease;
  touch-action: pan-y;
}
.swipe-content.swiping { transition: none; }

.swipe-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
  padding: 8px 0 12px;
}

.item-row-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.item-row-card .row-total {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-align: right;
  margin-top: 6px;
}

.tax-section { display: none; }
.tax-section.visible { display: block; }

.discount-summary {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.discount-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
}
.discount-row strong {
  color: var(--text);
  font-size: 14px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
}

.stock-convert-hint {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--primary-bg);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 8px;
  line-height: 1.45;
}

.upload-card {
  background: #fff;
  border-radius: 18px;
  padding: 18px 16px 16px;
  border: 1px solid #E8ECF1;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}
.upload-card-head {
  margin-bottom: 14px;
}
.upload-card-title {
  font-size: 16px;
  font-weight: 700;
  color: #1F2937;
  margin-bottom: 4px;
}
.upload-card-sub {
  font-size: 12px;
  color: #9CA3AF;
}
.upload-dropzone {
  border: 1.5px dashed #A8C5F0;
  border-radius: 14px;
  min-height: 132px;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  background: #FBFCFE;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.upload-dropzone:active { transform: scale(0.99); }
.upload-dropzone.dragover,
.upload-dropzone:focus {
  border-color: #5B8DEF;
  background: #F3F8FF;
  box-shadow: 0 0 0 4px rgba(91, 141, 239, 0.12);
  outline: none;
}
.upload-dropzone.uploading {
  opacity: 0.85;
  pointer-events: none;
}
.upload-folder-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-drop-text {
  font-size: 13px;
  color: #9CA3AF;
  font-weight: 500;
  text-align: center;
}
.upload-source-btns {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
  justify-content: center;
}
.upload-source-btn {
  border: 1px solid #D6E4F7;
  background: #fff;
  color: #5B8DEF;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
}
.upload-source-btn:active {
  background: #F3F8FF;
}
.upload-files-section {
  margin-top: 0;
}
.upload-files-label {
  font-size: 12px;
  color: #9CA3AF;
  margin-bottom: 10px;
  font-weight: 500;
}
.upload-file-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.upload-file-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #5B8DEF;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.upload-file-body {
  flex: 1;
  min-width: 0;
}
.upload-file-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.upload-file-name {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-file-remove {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #F3F4F6;
  color: #6B7280;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}
.upload-file-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.upload-file-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: #E5E7EB;
  overflow: hidden;
}
.upload-file-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: #5B8DEF;
  transition: width 0.15s ease;
}
.upload-file-fill.done {
  background: #5B8DEF;
}
.upload-file-pct {
  font-size: 12px;
  color: #9CA3AF;
  font-weight: 600;
  min-width: 36px;
  text-align: right;
}
.upload-file-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #22C55E;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.upload-file-preview-link {
  display: block;
  margin-top: 12px;
}
.upload-file-thumb {
  width: 100%;
  max-height: 140px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid #E5E7EB;
  background: #F9FAFB;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-secondary); }
.detail-value { font-weight: 600; text-align: right; max-width: 60%; }

.category-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
}

@media (prefers-color-scheme: dark) {
  /* Keep light theme for consistency with reference design */
}

/* ---- PWA Install Prompt ---- */
.pwa-install-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.pwa-install-overlay.open {
  opacity: 1;
  visibility: visible;
}
.pwa-install-sheet {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 24px 24px 20px 20px;
  padding: 22px 20px 20px;
  position: relative;
  box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.18);
  transform: translateY(24px);
  transition: transform 0.28s ease;
}
.pwa-install-overlay.open .pwa-install-sheet {
  transform: translateY(0);
}
.pwa-install-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #F3F4F6;
  color: #6B7280;
  font-size: 14px;
}
.pwa-install-logo-wrap {
  display: flex;
  justify-content: center;
  margin: 4px 0 14px;
}
.pwa-install-logo {
  width: auto;
  max-width: 110px;
  height: 36px;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(124, 58, 237, 0.28);
  object-fit: contain;
}
.pwa-install-title {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: #111827;
  margin-bottom: 6px;
}
.pwa-install-sub {
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
  color: #6B7280;
  margin-bottom: 14px;
}
.pwa-install-benefits {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pwa-install-benefits li {
  font-size: 13px;
  color: #374151;
  background: #F5F3FF;
  border-radius: 12px;
  padding: 10px 12px;
  position: relative;
  padding-left: 34px;
}
.pwa-install-benefits li::before {
  content: "✓";
  position: absolute;
  left: 12px;
  top: 10px;
  color: #7C3AED;
  font-weight: 700;
}
.pwa-ios-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.pwa-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #F9FAFB;
  border-radius: 12px;
  padding: 10px 12px;
}
.pwa-step span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #7C3AED;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pwa-step p {
  margin: 0;
  font-size: 13px;
  color: #374151;
  line-height: 1.4;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.pwa-ios-share {
  color: #007AFF;
  flex-shrink: 0;
  vertical-align: middle;
}
.pwa-install-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pwa-install-actions .btn {
  width: 100%;
}
@media (min-width: 640px) {
  .pwa-install-overlay { align-items: center; }
  .pwa-install-sheet { border-radius: 24px; }
}

/* Customs tax estimator */
.customs-suggest {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface, #fff);
  max-height: 220px;
  overflow: auto;
}
.customs-suggest:empty { display: none; }
.customs-suggest-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: inherit;
}
.customs-suggest-item:last-child { border-bottom: 0; }
.customs-suggest-item strong { font-size: 13px; }
.customs-suggest-item span { font-size: 12px; color: var(--text-secondary); }
.customs-suggest-item.muted { cursor: default; color: var(--text-secondary); }
.customs-suggest-item:not(.muted):hover { background: rgba(124, 58, 237, 0.06); }
