:root {
  --green: #2E7D32;
  --green-light: #4CAF50;
  --green-dark: #1B5E20;
  --gold: #FFB300;
  --gold-light: #FFD54F;
  --white: #FFFFFF;
  --gray-50: #FAFAFA;
  --gray-100: #F5F5F5;
  --gray-200: #EEEEEE;
  --gray-300: #E0E0E0;
  --gray-400: #BDBDBD;
  --gray-500: #9E9E9E;
  --gray-600: #757575;
  --gray-700: #616161;
  --gray-800: #424242;
  --gray-900: #212121;
  --red: #D32F2F;
  --blue: #1976D2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --max-width: 480px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--white);
  position: relative;
}

/* Landing page */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-hero {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  color: var(--white);
  padding: 60px 24px 48px;
  text-align: center;
}

.landing-logo {
  width: 96px;
  height: 96px;
  border-radius: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.landing-hero h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.landing-hero .flash { color: var(--gold); }

.landing-hero p {
  font-size: 18px;
  opacity: 0.9;
  margin-bottom: 32px;
  line-height: 1.5;
}

.landing-steps {
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.step-num {
  width: 36px;
  height: 36px;
  background: var(--green);
  color: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.step-text h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.step-text p {
  font-size: 14px;
  color: var(--gray-600);
  line-height: 1.4;
}

.landing-features {
  padding: 0 24px 32px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.feature-card {
  background: var(--gray-50);
  padding: 16px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.feature-card .icon { font-size: 28px; margin-bottom: 8px; }
.feature-card p { font-size: 13px; color: var(--gray-700); font-weight: 500; }

.landing-footer {
  padding: 24px;
  text-align: center;
  margin-top: auto;
}

.landing-footer a {
  color: var(--gray-500);
  font-size: 13px;
  text-decoration: none;
  margin: 0 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  gap: 8px;
}

.btn-primary {
  background: var(--gold);
  color: var(--gray-900);
}
.btn-primary:hover { background: var(--gold-light); }

.btn-green {
  background: var(--green);
  color: var(--white);
}
.btn-green:hover { background: var(--green-light); }

.btn-outline {
  background: transparent;
  color: var(--green);
  border: 2px solid var(--green);
}

.btn-block { width: 100%; }

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
  border-radius: var(--radius-sm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--green);
  margin-bottom: 8px;
}

.login-card .subtitle {
  color: var(--gray-600);
  margin-bottom: 32px;
  font-size: 15px;
}

.input-group {
  margin-bottom: 16px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

input[type="email"],
input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.2s;
  background: var(--white);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
}

.check-email {
  text-align: center;
  padding: 40px 24px;
}

.check-email .icon { font-size: 48px; margin-bottom: 16px; }
.check-email h2 { margin-bottom: 8px; }
.check-email p { color: var(--gray-600); line-height: 1.5; }

/* App shell */
.app-header {
  background: var(--green);
  color: var(--white);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
}

.app-header .user-menu {
  width: 32px;
  height: 32px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
}

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

.header-logout {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--white);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.header-logout:hover {
  background: rgba(255,255,255,0.3);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  text-decoration: none;
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
}

.nav-item .nav-icon { font-size: 22px; }

.nav-item.active {
  color: var(--green);
}

.scan-btn {
  width: 56px;
  height: 56px;
  background: var(--green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -24px;
  box-shadow: var(--shadow-lg);
  color: var(--white);
  font-size: 28px;
  border: 4px solid var(--white);
}

/* Page content */
.page-content {
  padding: 20px;
  padding-bottom: 80px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* Dashboard */
.summary-card {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  color: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.summary-card .label {
  font-size: 13px;
  opacity: 0.8;
  margin-bottom: 4px;
}

.summary-card .amount {
  font-size: 36px;
  font-weight: 800;
}

.summary-card .vs-last {
  font-size: 13px;
  margin-top: 8px;
  opacity: 0.9;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title a {
  color: var(--green);
  font-size: 13px;
  text-decoration: none;
  font-weight: 500;
}

/* Category bars */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.category-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.category-icon { font-size: 20px; width: 28px; text-align: center; }

.category-info { flex: 1; }

.category-name {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}

.category-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  margin-top: 4px;
  overflow: hidden;
}

.category-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--green);
  transition: width 0.5s ease;
}

.category-bar-fill.over { background: var(--red); }

/* Cards */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.card-title {
  font-weight: 600;
  font-size: 15px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--gray-600);
}

/* Receipt items */
.receipt-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}

.receipt-item:last-child { border-bottom: none; }

.receipt-item .item-name {
  font-size: 14px;
  flex: 1;
}

.receipt-item .item-category {
  font-size: 12px;
  color: var(--gray-500);
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: 4px;
  margin: 0 8px;
}

.receipt-item .item-price {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

/* Scan page */
.camera-container {
  width: 100%;
  aspect-ratio: 3/4;
  background: var(--gray-900);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  margin-bottom: 16px;
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-area {
  position: relative;
  background: var(--gray-900);
  border-radius: var(--radius);
  overflow: hidden;
}

.scan-area video {
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  display: block;
}

.scan-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  background: var(--gray-900);
}

.receipt-preview img {
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.camera-frame {
  width: 85%;
  height: 70%;
  border: 2px dashed rgba(255,255,255,0.5);
  border-radius: var(--radius);
}

.capture-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--white);
  border: 4px solid var(--green);
  cursor: pointer;
  margin: 0 auto;
  display: block;
  transition: transform 0.1s;
}

.capture-btn:active { transform: scale(0.9); }

/* Processing */
.processing {
  text-align: center;
  padding: 60px 24px;
}

.processing .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

/* Budget progress */
.budget-progress {
  margin-bottom: 16px;
}

.budget-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.budget-header .name { font-weight: 500; font-size: 14px; }
.budget-header .amounts { font-size: 13px; color: var(--gray-600); }

.progress-bar {
  height: 10px;
  background: var(--gray-200);
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 5px;
  background: var(--green);
  transition: width 0.5s ease;
}

.progress-fill.warning { background: var(--gold); }
.progress-fill.danger { background: var(--red); }

/* Admin */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--green);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--gray-600);
  margin-top: 4px;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 8px 12px;
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--gray-100);
}

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.tag-green { background: #E8F5E9; color: var(--green); }
.tag-gold { background: #FFF8E1; color: #F57F17; }
.tag-red { background: #FFEBEE; color: var(--red); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-500);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--gray-700); margin-bottom: 8px; }
.empty-state p { font-size: 14px; line-height: 1.5; margin-bottom: 20px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: var(--max-width);
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

.modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: var(--white);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 300;
  animation: toast-in 0.3s ease;
}

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

/* Settings */
.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 13px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.settings-row label { font-size: 15px; }

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
}

.toggle input { display: none; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: var(--white);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--green);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

/* Responsive */
@media (min-width: 481px) {
  body { background: var(--gray-100); }
  #app { box-shadow: var(--shadow-lg); }
}

/* Utility */
.text-center { text-align: center; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-gold { color: var(--gold); }
.text-gray { color: var(--gray-600); }
.text-sm { font-size: 13px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* Shopping Lists */
.list-card { background: var(--white); border-radius: 12px; padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.list-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.list-count { font-size: 13px; color: var(--gray-500); }
.list-progress { margin-bottom: 12px; }
.list-card-actions { display: flex; gap: 8px; }
.header-action { background: none; border: 2px solid var(--white); color: var(--white); font-size: 24px; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; }
.back-btn { color: var(--white); text-decoration: none; font-size: 24px; margin-right: 8px; }

.add-item-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.add-item-bar input[type="text"] { flex: 1; }
.qty-input { width: 60px !important; flex: none !important; }

.suggestions { background: var(--white); border: 1px solid var(--gray-200); border-radius: 8px; max-height: 200px; overflow-y: auto; margin-bottom: 12px; }
.suggestion-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--gray-100); font-size: 14px; }
.suggestion-item:hover { background: var(--gray-50); }
.suggestion-item:last-child { border-bottom: none; }

.list-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--white); border-radius: 8px; margin-bottom: 6px; }
.list-item.checked { opacity: 0.5; }
.list-item.checked .item-text { text-decoration: line-through; }
.check-label { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; }
.check-label input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--green); }
.item-text { font-size: 15px; }
.item-qty { font-size: 12px; color: var(--gray-500); margin-left: 6px; background: var(--gray-100); padding: 2px 6px; border-radius: 4px; }
.checked-divider { font-size: 13px; color: var(--gray-400); padding: 12px 0 6px; border-top: 1px solid var(--gray-200); margin-top: 8px; }
.list-footer { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--white); border-radius: 16px; padding: 24px; width: 100%; max-width: 360px; }
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

/* Admin demographics */
.demo-section { margin-bottom: 20px; }
.demo-section h3 { font-size: 15px; font-weight: 700; margin-bottom: 8px; color: var(--gray-800); }

.demo-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.demo-label {
  min-width: 100px;
  font-size: 13px;
  color: var(--gray-700);
  text-align: right;
  flex-shrink: 0;
}

.demo-bar-track {
  flex: 1;
  height: 20px;
  background: var(--gray-100);
  border-radius: 4px;
  overflow: hidden;
}

.demo-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.3s;
}

.demo-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  min-width: 28px;
}

/* Admin user list */
.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
  gap: 12px;
}

.user-row strong { display: block; font-size: 14px; }
.user-row .text-sm { display: block; }

.user-meta {
  text-align: right;
  flex-shrink: 0;
}

.user-meta .text-sm { display: block; }

.badge {
  display: inline-block;
  background: var(--green);
  color: var(--white);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 2px;
}

.search-bar {
  margin-bottom: 12px;
}

.search-bar input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* Admin categories */
.cat-group { margin-bottom: 8px; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid var(--gray-100);
}

.cat-child { padding-left: 12px; }
.cat-indent { width: 12px; flex-shrink: 0; }
.cat-icon-cell { font-size: 16px; width: 24px; text-align: center; flex-shrink: 0; }

.cat-name-edit {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  font-size: 13px;
}

.cat-icon-edit {
  width: 40px;
  padding: 4px;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  font-size: 14px;
  text-align: center;
}

.add-cat-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.add-cat-row input, .add-cat-row select {
  padding: 8px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.add-cat-row input[placeholder="Category name"] { flex: 1; }

/* Multi-page receipt scanning */
.pages-preview {
  padding: 12px 0;
}

.pages-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.page-thumb {
  position: relative;
  flex-shrink: 0;
  width: 80px;
  height: 100px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid var(--green);
}

.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page-num {
  position: absolute;
  bottom: 2px;
  left: 4px;
  background: var(--green);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
}

.page-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.6);
  color: var(--white);
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pages-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.receipt-preview {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
}
