:root {
  --blue: #4183F5;
  --blue-dark: #1E5BD9;
  --blue-darker: #1742A8;
  --blue-light: #EEF4FF;
  --blue-faint: #F8FBFF;
  --charcoal: #1F2937;
  --charcoal-soft: #374151;
  --green: #10B981;
  --green-bg: #ECFDF5;
  --orange: #F59E0B;
  --orange-bg: #FFFBEB;
  --red: #EF4444;
  --red-bg: #FEF2F2;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-150: #ECEEF1;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --white: #FFFFFF;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.05);
  --shadow-blue: 0 8px 24px rgba(65, 131, 245, 0.25);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, system-ui, sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  background: var(--gray-50);
  color: var(--charcoal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  font-size: 15px;
  letter-spacing: -0.01em;
}

button, a, input, select, textarea, [role="button"] { touch-action: manipulation; font-family: inherit; }

.hidden { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }

/* ===================== Login ===================== */
.login-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
  padding: calc(48px + env(safe-area-inset-top)) max(30px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(30px, env(safe-area-inset-left));
  background: linear-gradient(160deg, var(--blue) 0%, var(--blue-dark) 60%, var(--blue-darker) 100%);
  color: var(--white);
  position: relative;
  overflow: hidden;
}
.login-container::before {
  content: '';
  position: absolute; top: -120px; left: -100px;
  width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255,255,255,0.18), transparent 70%);
  pointer-events: none;
}
.login-container::after {
  content: '';
  position: absolute; bottom: -160px; right: -120px;
  width: 420px; height: 420px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255,255,255,0.10), transparent 70%);
  pointer-events: none;
}
.login-logo {
  width: 180px; margin-bottom: 22px; position: relative; z-index: 1;
  background: var(--white);
  padding: 14px 22px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.02em; position: relative; z-index: 1; }
.login-subtitle { font-size: 14px; opacity: 0.78; margin-bottom: 36px; font-weight: 500; position: relative; z-index: 1; }
.pin-display { display: flex; gap: 14px; margin-bottom: 36px; position: relative; z-index: 1; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.5); background: transparent;
  transition: all 0.18s ease;
}
.pin-dot.filled { background: var(--white); border-color: var(--white); transform: scale(1.1); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 280px; position: relative; z-index: 1; }
.pin-btn {
  width: 72px; height: 72px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.10); color: var(--white); font-size: 24px; font-weight: 500;
  cursor: pointer; transition: all 0.12s ease; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px);
}
.pin-btn:active { background: rgba(255,255,255,0.28); transform: scale(0.94); }
.pin-btn-empty { visibility: hidden; }
.pin-btn-delete svg { width: 22px; height: 22px; }
.pin-error { color: #FCA5A5; font-size: 13px; margin-top: 18px; min-height: 18px; font-weight: 500; position: relative; z-index: 1; }
.pin-hint { font-size: 12px; opacity: 0.55; margin-top: 8px; position: relative; z-index: 1; }
.pin-hint b { font-weight: 700; }

/* ===================== App Header ===================== */
.app-header {
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--white);
  border-bottom: 1px solid var(--gray-150);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  background: rgba(255,255,255,0.92);
}
.header-logo { height: 30px; }
.header-title { flex: 1; font-size: 15px; font-weight: 700; color: var(--charcoal); letter-spacing: -0.01em; }
.header-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--blue-light); color: var(--blue);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.header-btn:active { background: var(--blue); color: var(--white); transform: scale(0.95); }
.header-btn svg { width: 18px; height: 18px; }

/* ===================== Content ===================== */
.app-content {
  padding: 18px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  min-height: calc(100dvh - 56px);
}

/* ===================== Bottom Nav ===================== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: rgba(255,255,255,0.96);
  border-top: 1px solid var(--gray-150);
  padding: 8px max(4px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
  z-index: 100;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0 4px; border: none; background: none; cursor: pointer;
  color: var(--gray-400); font-size: 10px; font-weight: 600;
  transition: color 0.18s ease;
  letter-spacing: 0.02em;
  position: relative;
  min-height: 48px;
}
.nav-btn.active { color: var(--blue); }
.nav-btn svg { width: 22px; height: 22px; transition: transform 0.18s ease; }
.nav-btn.active svg { transform: translateY(-1px); }
.nav-btn::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; border-radius: 0 0 3px 3px;
  background: var(--blue); opacity: 0;
  transition: opacity 0.2s ease;
}
.nav-btn.active::before { opacity: 1; }
.nav-label { font-weight: 600; }

/* ===================== Cards ===================== */
.card {
  background: var(--white); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-150);
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.card:active { transform: scale(0.995); box-shadow: var(--shadow-xs); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.card-title { font-size: 14px; font-weight: 700; color: var(--charcoal); letter-spacing: -0.01em; }
.card-subtitle { font-size: 12.5px; color: var(--gray-500); line-height: 1.5; }
.card-value { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }

/* ===================== Status Bar ===================== */
.status-bar { height: 5px; border-radius: 3px; background: var(--gray-150); margin-top: 10px; overflow: hidden; }
.status-bar-fill { height: 100%; border-radius: 3px; transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
.status-green { background: var(--green); }
.status-orange { background: var(--orange); }
.status-red { background: var(--red); }

/* ===================== Badges ===================== */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-green { background: var(--green-bg); color: #065F46; }
.badge-orange { background: var(--orange-bg); color: #92400E; }
.badge-red { background: var(--red-bg); color: #991B1B; }
.badge-blue { background: var(--blue-light); color: var(--blue-dark); }

/* ===================== Quick Actions ===================== */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.quick-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--gray-150); background: var(--white);
  font-size: 13.5px; font-weight: 600; color: var(--charcoal-soft);
  cursor: pointer; transition: all 0.15s ease;
  box-shadow: var(--shadow-xs);
  text-align: left;
}
.quick-btn:active { background: var(--blue-light); border-color: var(--blue); color: var(--blue-dark); transform: scale(0.985); }
.quick-btn svg { width: 18px; height: 18px; color: var(--blue); flex-shrink: 0; }

/* ===================== Section Header ===================== */
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin: 22px 0 10px; padding: 0 4px;
}
.section-title { font-size: 13px; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.06em; }
.section-link { font-size: 13px; color: var(--blue); font-weight: 600; cursor: pointer; border: none; background: none; padding: 4px 8px; border-radius: 6px; transition: background 0.15s ease; }
.section-link:active { background: var(--blue-light); }

/* ===================== Stats Row ===================== */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 14px 10px; text-align: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-150);
}
.stat-value { font-size: 24px; font-weight: 800; color: var(--blue); letter-spacing: -0.03em; line-height: 1.1; }
.stat-label { font-size: 11px; color: var(--gray-500); margin-top: 4px; font-weight: 500; }

/* ===================== Forms ===================== */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; letter-spacing: -0.005em; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); font-size: 16px; color: var(--charcoal);
  background: var(--white); transition: all 0.18s ease;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--gray-400); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(65,131,245,0.12);
}
.form-textarea { resize: vertical; min-height: 84px; font-family: inherit; line-height: 1.5; }
.form-checkbox-group { display: flex; flex-wrap: wrap; gap: 7px; }
.form-checkbox {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--gray-200);
  border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
  color: var(--gray-700);
}
.form-checkbox:active { transform: scale(0.97); }
.form-checkbox.selected { background: var(--blue-light); border-color: var(--blue); color: var(--blue-dark); font-weight: 600; }

/* ===================== Buttons ===================== */
.btn {
  width: 100%; padding: 14px 16px; border: none; border-radius: var(--radius);
  font-size: 15px; font-weight: 700; cursor: pointer; transition: all 0.15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  letter-spacing: -0.01em;
}
.btn:disabled { cursor: not-allowed; }
.btn-primary { background: var(--blue); color: var(--white); box-shadow: var(--shadow-blue); }
.btn-primary:active { background: var(--blue-dark); transform: scale(0.985); }
.btn-primary:disabled { background: var(--gray-200); color: var(--gray-400); box-shadow: none; }
.btn-outline { background: var(--white); color: var(--blue); border: 1.5px solid var(--blue); }
.btn-outline:active { background: var(--blue-light); }
.btn-danger { background: var(--red); color: var(--white); }
.btn svg { width: 18px; height: 18px; }

/* ===================== List Items ===================== */
.list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--white);
  border-bottom: 1px solid var(--gray-100); cursor: pointer;
  transition: background 0.15s ease;
}
.list-item:active { background: var(--gray-50); }
.list-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.list-item:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.list-item-info { flex: 1; }
.list-item-title { font-size: 14px; font-weight: 600; }
.list-item-subtitle { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.list-item-value { font-size: 14px; font-weight: 700; text-align: right; }

/* ===================== Search ===================== */
.search-bar { position: relative; margin-bottom: 16px; }
.search-input {
  width: 100%; padding: 12px 14px 12px 42px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-size: 16px; background: var(--white);
  font-family: inherit; transition: all 0.18s ease;
  -webkit-appearance: none;
  appearance: none;
}
.search-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(65,131,245,0.12); }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--gray-400); display: flex; }
.search-icon svg { width: 16px; height: 16px; }

/* ===================== Page Title ===================== */
.page-title { font-size: 24px; font-weight: 800; color: var(--charcoal); margin-bottom: 4px; letter-spacing: -0.025em; }
.page-subtitle { font-size: 13.5px; color: var(--gray-500); margin-bottom: 22px; line-height: 1.5; }

/* ===================== Toast ===================== */
.toast {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--white);
  z-index: 1000; animation: toastIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
  letter-spacing: -0.005em;
  max-width: calc(100% - 32px);
}
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--blue); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===================== Spinner ===================== */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3); border-top-color: var(--white);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Empty State ===================== */
.empty-state {
  text-align: center; padding: 56px 20px; color: var(--gray-400);
  background: var(--white); border-radius: var(--radius);
  border: 1px dashed var(--gray-200);
}
.empty-state-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%; background: var(--blue-faint);
  color: var(--blue); margin-bottom: 14px;
}
.empty-state-icon svg { width: 26px; height: 26px; }
.empty-state-text { font-size: 14px; font-weight: 500; }

/* ===================== Modal ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center; z-index: 200;
}
.modal {
  background: var(--white); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px; width: 100%; max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 16px; letter-spacing: -0.02em; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--gray-100); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-600);
}
.modal-close svg { width: 16px; height: 16px; }

/* ===================== iOS install hint ===================== */
.ios-install-hint {
  position: fixed; left: 12px; right: 12px; bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--white); border: 1px solid var(--gray-150);
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--charcoal-soft); line-height: 1.4;
  z-index: 150;
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.ios-install-hint b { color: var(--charcoal); font-weight: 700; }
.ios-install-hint .share-icon {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px;
  background: var(--blue-light); color: var(--blue);
  display: flex; align-items: center; justify-content: center;
}
.ios-install-hint .share-icon svg { width: 16px; height: 16px; }
.ios-install-hint .dismiss {
  margin-left: auto; flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  border: none; background: var(--gray-100); color: var(--gray-500);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.ios-install-hint .dismiss svg { width: 14px; height: 14px; }
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================== Icon-only round button (e.g. delete row) ===================== */
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--gray-100); color: var(--gray-500);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn-danger { background: var(--red-bg); color: var(--red); }
.icon-btn-danger:active { background: var(--red); color: var(--white); }
.icon-btn svg { width: 16px; height: 16px; }
