:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #25253d;
  --text: #e8e8f0;
  --text2: #9a9ab5;
  --accent: #d4a76a;
  --accent2: #b8935a;
  --success: #6bcf7f;
  --warning: #f0c040;
  --danger: #e85555;
  --border: #2e2e4a;
  --radius: 12px;
  --font: 'Inter', -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.screen { display: none; }
.screen.active { display: block; }

/* PIN Screen */
.pin-container {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 20px;
}
.logo { margin-bottom: 8px; line-height: 0; }
.pin-container h1 {
  font-size: 28px; font-weight: 700; margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), #e8c99b);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
#pin-message { color: var(--text2); font-size: 14px; margin-bottom: 24px; text-align: center; }
.pin-dots { display: flex; gap: 16px; margin-bottom: 32px; }
.dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--accent); transition: all 0.2s;
}
.dot.filled { background: var(--accent); transform: scale(1.15); }
.dot.error { border-color: var(--danger); background: var(--danger); animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.pin-pad {
  display: grid; grid-template-columns: repeat(3, 72px);
  gap: 12px; justify-content: center;
}
.pin-pad button {
  width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font-size: 24px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.pin-pad button:active { background: var(--accent); color: white; transform: scale(0.95); }
.pin-empty { visibility: hidden; }
.pin-delete { font-size: 20px !important; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.app-header h2 {
  font-size: 20px;
  background: linear-gradient(135deg, var(--accent), #e8c99b);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-actions { display: flex; gap: 8px; }
.btn-icon {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.btn-icon:hover { background: var(--accent); color: white; }

/* File Menu */
.file-menu-wrap { position: relative; }
.file-menu {
  position: absolute; top: 42px; right: 0; z-index: 150;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  min-width: 200px; padding: 6px 0; box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.file-menu-item {
  display: block; width: 100%; padding: 10px 16px; border: none; background: none;
  color: var(--text); font-size: 14px; text-align: left; cursor: pointer;
  font-family: var(--font); transition: background 0.1s;
}
.file-menu-item:hover { background: var(--bg3); }
.file-menu-danger { color: var(--danger); }
.file-menu-danger:hover { background: rgba(232,85,85,0.15); }
.file-menu-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* Section header */
.section-header { display: flex; align-items: center; justify-content: space-between; }

/* Tabs */
.tab-nav {
  display: flex; background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 0 12px; overflow-x: auto;
}
.tab {
  flex: 1; padding: 12px 16px; border: none; background: none;
  color: var(--text2); font-size: 13px; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s;
  white-space: nowrap; font-family: var(--font);
}
.tab[data-tab="dashboard"].active { color: #3b82f6; border-bottom-color: #3b82f6; }
.tab[data-tab="expenses"].active { color: #ef4444; border-bottom-color: #ef4444; }
.tab[data-tab="budget"].active { color: #9ca3af; border-bottom-color: #9ca3af; }
.tab[data-tab="scan"].active { color: #22c55e; border-bottom-color: #22c55e; }
.tab[data-tab="summary"].active { color: #a855f7; border-bottom-color: #a855f7; }
.tab[data-tab="import"].active { color: #f59e0b; border-bottom-color: #f59e0b; }
.tab-content { display: none; padding: 16px 20px; padding-bottom: 80px; }
.tab-content.active { display: block; }

/* Summary Cards */
.summary-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 4px;
}
.total-card { grid-column: 1 / -1; background: linear-gradient(135deg, #1a5ab8, #3b82f6); }
.total-card .card-label { color: rgba(255,255,255,0.8); }
.total-card .card-value { color: white; font-size: 32px; }
.card-label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 1px; }
.card-value { font-size: 22px; font-weight: 700; }

/* Chart */
.chart-container {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 20px; text-align: center;
}
.chart-container h3 { font-size: 14px; color: var(--text2); margin-bottom: 12px; }
.chart-container canvas { max-width: 240px; margin: 0 auto; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text2); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

/* Expense List */
.expense-list { display: flex; flex-direction: column; gap: 8px; }
.expense-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; transition: all 0.15s;
}
.expense-item:hover { border-color: #ef4444; }
.expense-icon {
  width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 18px; flex-shrink: 0;
}
.expense-info { flex: 1; min-width: 0; }
.expense-vendor { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.expense-amount { font-size: 16px; font-weight: 600; text-align: right; flex-shrink: 0; }

/* Controls */
.expense-controls { display: flex; gap: 8px; margin-bottom: 16px; }
.expense-controls input, .expense-controls select {
  flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font-size: 14px; font-family: var(--font);
}

/* FAB */
.fab {
  position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px;
  border-radius: 50%; border: none; background: #ef4444; color: white;
  font-size: 28px; cursor: pointer; box-shadow: 0 4px 20px rgba(239,68,68,0.4);
  transition: all 0.2s; z-index: 50;
}
.fab:hover { transform: scale(1.1); }

/* Scan Area */
.scan-area { max-width: 500px; margin: 0 auto; }
.camera-container {
  position: relative; width: 100%; aspect-ratio: 4/3; background: #000;
  border-radius: var(--radius); overflow: hidden; display: none;
}
.camera-container.active { display: block; }
#camera-feed { width: 100%; height: 100%; object-fit: cover; }
.scan-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.scan-frame {
  width: 80%; height: 60%; border: 2px solid #22c55e; border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
}
.scan-actions { display: flex; gap: 8px; margin: 16px 0; justify-content: center; }
.scan-divider {
  text-align: center; margin: 16px 0; position: relative;
  color: var(--text2); font-size: 13px;
}
.scan-divider::before, .scan-divider::after {
  content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border);
}
.scan-divider::before { left: 0; }
.scan-divider::after { right: 0; }
.file-upload-label {
  display: block; padding: 40px 20px; border: 2px dashed var(--border); border-radius: var(--radius);
  text-align: center; color: var(--text2); cursor: pointer; transition: all 0.2s;
}
.file-upload-label:hover { border-color: #22c55e; color: #22c55e; }
.file-upload-label input { display: none; }
.scan-preview { margin-top: 16px; }
.scan-preview img { width: 100%; border-radius: var(--radius); margin-bottom: 12px; }
.scan-buttons { display: flex; gap: 8px; }
.scan-result {
  margin-top: 16px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.scan-loading {
  text-align: center; padding: 40px; color: var(--text2);
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: #22c55e;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Budget */
.budget-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.budget-header h3 { font-size: 16px; }
.budget-list { display: flex; flex-direction: column; gap: 12px; }
.budget-item {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.budget-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.budget-cat { font-weight: 500; text-transform: capitalize; }
.budget-amounts { font-size: 13px; color: var(--text2); }
.budget-bar {
  width: 100%; height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden;
}
.budget-fill { height: 100%; border-radius: 4px; transition: width 0.4s; }
.budget-fill.ok { background: var(--success); }
.budget-fill.warn { background: var(--warning); }
.budget-fill.over { background: var(--danger); }
.budget-totals {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px;
}
.budget-total-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 4px; text-align: center;
}
.budget-total-card .card-value { font-size: 18px; }
.budget-detail-row {
  display: flex; justify-content: space-between; font-size: 12px; color: var(--text2);
  margin-bottom: 6px; gap: 4px; flex-wrap: wrap;
}
.budget-pct {
  font-size: 11px; color: var(--text2); margin-top: 4px; text-align: right;
}

/* Buttons */
.btn {
  padding: 10px 20px; border: none; border-radius: 8px; font-size: 14px;
  font-weight: 500; cursor: pointer; transition: all 0.15s; font-family: var(--font);
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent2); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #111; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--bg2); border-radius: 16px 16px 0 0; padding: 24px;
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; }
.btn-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--bg3); color: var(--text); font-size: 20px; cursor: pointer;
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); font-size: 14px; font-family: var(--font);
}
.form-group textarea { resize: vertical; }

/* Export */
.export-options { display: flex; flex-direction: column; }

/* Category summary */
.category-summary-section { margin-top: 20px; }
.category-summary-section h3 { font-size: 14px; color: var(--text2); margin-bottom: 12px; }
.category-summary { display: flex; flex-direction: column; gap: 6px; }
.cat-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px;
}
.cat-row-icon { font-size: 18px; width: 28px; text-align: center; flex-shrink: 0; }
.cat-row-name { flex: 1; font-size: 14px; font-weight: 500; text-transform: capitalize; }
.cat-row-count { font-size: 12px; color: var(--text2); margin-right: 8px; }
.cat-row-total { font-size: 15px; font-weight: 600; flex-shrink: 0; }

/* Recent section */
.recent-section { margin-top: 20px; }
.recent-section h3 { font-size: 14px; color: var(--text2); margin-bottom: 12px; }

/* Responsive */
@media (min-width: 768px) {
  .tab-content { max-width: 600px; margin: 0 auto; }
  .modal-content { border-radius: 16px; margin-bottom: 20px; }
  .modal { align-items: center; }
}

/* Summary tab */
.summary-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;
}
.summary-header h3 { font-size: 18px; }
.summary-header select {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font-size: 13px; font-family: var(--font);
}
.summary-totals-bar {
  display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto;
}
.summary-total-chip {
  padding: 10px 16px; border-radius: var(--radius); background: var(--bg2);
  border: 1px solid var(--border); text-align: center; min-width: 100px; flex-shrink: 0;
}
.summary-total-chip .chip-label { font-size: 11px; color: var(--text2); text-transform: uppercase; }
.summary-total-chip .chip-value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.summary-cat-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.15s;
}
.summary-cat-card:hover { border-color: var(--accent); }
.summary-cat-top {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.summary-cat-icon { font-size: 22px; width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.summary-cat-info { flex: 1; }
.summary-cat-name { font-size: 15px; font-weight: 600; text-transform: capitalize; }
.summary-cat-meta { font-size: 12px; color: var(--text2); margin-top: 1px; }
.summary-cat-amount { font-size: 18px; font-weight: 700; text-align: right; flex-shrink: 0; }
.summary-cat-bar {
  width: 100%; height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden;
}
.summary-cat-fill { height: 100%; border-radius: 3px; transition: width 0.4s; }
.summary-cat-items {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); display: none;
}
.summary-cat-items.open { display: block; }
.summary-item-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--border);
}
.summary-item-row:last-child { border-bottom: none; }
.summary-item-vendor { color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-item-date { color: var(--text2); font-size: 11px; margin: 0 8px; flex-shrink: 0; }
.summary-item-amount { color: var(--text); font-weight: 500; flex-shrink: 0; }

/* Consolidated summary table */
.summary-consolidated-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.summary-consolidated-table th {
  padding: 10px 8px; text-align: left; font-size: 12px; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
}
.summary-consolidated-table td {
  padding: 12px 8px; border-bottom: 1px solid var(--border);
}
.summary-consolidated-table tfoot td {
  padding: 12px 8px;
}
.summary-cat-row:hover {
  background: var(--bg3);
}
.summary-detail-row {
  background: var(--bg);
}
.summary-detail-row td {
  padding: 8px 8px !important;
  border-bottom-color: var(--bg2) !important;
}

/* Import */
.import-area { max-width: 600px; margin: 0 auto; }
.import-area h3 { font-size: 18px; }
.csv-table {
  width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px;
}
.csv-table th, .csv-table td {
  padding: 6px 8px; border: 1px solid var(--border); text-align: left;
  white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis;
}
.csv-table th { background: var(--bg3); color: var(--text2); font-weight: 500; }
.csv-table td { color: var(--text); }

/* Install banner */
.install-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center;
  justify-content: center; gap: 12px; z-index: 200;
  font-size: 14px;
}

/* Inactivity timeout banner */
.timeout-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--warning); color: #111; text-align: center;
  padding: 8px; font-size: 13px; font-weight: 500; z-index: 200;
}
