/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:        #0f1117;
  --bg-surface:     #161b24;
  --bg-elevated:    #1e2636;
  --bg-hover:       #242d3e;
  --green-primary:  #22c55e;
  --green-dim:      #16a34a;
  --green-muted:    #14532d;
  --green-glow:     rgba(34, 197, 94, 0.15);
  --text-primary:   #f0f4f8;
  --text-secondary: #8a9ab5;
  --text-muted:     #4a5568;
  --border:         #1e2d3d;
  --sidebar-width:  240px;
  --topbar-height:  64px;
  --radius:         10px;
  --radius-lg:      14px;
  --transition:     0.2s ease;
}

html { height: 100%; }

body {
  height: 100%;
  display: flex;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Overlay (mobile) ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  backdrop-filter: blur(2px);
}
.overlay.active { display: block; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
  color: var(--green-primary);
  line-height: 1;
}

.logo-text {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
}
.close-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ── Nav ── */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.sidebar-nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--green-glow);
  color: var(--green-primary);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-label { white-space: nowrap; }

/* ── Sidebar footer ── */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green-primary), var(--green-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Main wrapper ── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.menu-btn svg { width: 22px; height: 22px; display: block; }
.menu-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.page-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.date-badge {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Content area ── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

.page-header {
  margin-bottom: 28px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.4px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Placeholder cards ── */
.placeholder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.placeholder-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.placeholder-card.accent {
  border-color: rgba(34, 197, 94, 0.3);
  background: linear-gradient(135deg, var(--bg-surface), rgba(34, 197, 94, 0.05));
}

.placeholder-icon {
  font-size: 20px;
  color: var(--green-primary);
  line-height: 1;
}

.placeholder-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.placeholder-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: -0.5px;
}

/* ── Coming soon banner ── */
.coming-soon-banner {
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.coming-soon-banner span::before {
  content: '🚧 ';
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

/* ── Mobile ── */
@media (max-width: 768px) {
  body { overflow: auto; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }

  .close-btn { display: flex; align-items: center; justify-content: center; }
  .menu-btn  { display: flex; align-items: center; justify-content: center; }

  .content { padding: 20px 16px; }

  .placeholder-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 400px) {
  .placeholder-grid { grid-template-columns: 1fr; }
}

/* ── Dashboard Summary Cards ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 32px;
}

.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.summary-card.accent {
  border-color: rgba(34, 197, 94, 0.3);
  background: linear-gradient(135deg, var(--bg-surface), rgba(34, 197, 94, 0.04));
}

.summary-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--green-glow);
  border: 1px solid rgba(34, 197, 94, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--green-primary);
}

.summary-icon svg { width: 18px; height: 18px; }

.summary-icon.red  { background: rgba(248,113,113,0.1); border-color: rgba(248,113,113,0.25); color: #f87171; }
.summary-icon.blue { background: rgba(59,130,246,0.1);  border-color: rgba(59,130,246,0.25);  color: #60a5fa; }
.summary-icon.amber{ background: rgba(245,158,11,0.1);  border-color: rgba(245,158,11,0.25);  color: #fbbf24; }

.summary-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.summary-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.summary-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.summary-sub {
  font-size: 11px;
  color: var(--text-muted);
}

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

.section-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.section-meta {
  font-size: 12px;
  color: var(--green-primary);
  background: var(--green-glow);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
}

/* ── Category balance cards ── */
.cat-balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.cat-bal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--transition);
}

.cat-bal-card:hover { border-color: var(--text-muted); }

.cat-bal-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cat-bal-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.cat-bal-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.cat-bal-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.cat-bal-alloc {
  font-size: 11px;
  color: var(--text-muted);
}

.cat-bal-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--green-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Rent progress bar */
.cat-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cat-progress-bar {
  height: 5px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}

.cat-progress-fill {
  height: 100%;
  background: var(--green-primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.cat-progress-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* Badges */
.cat-bal-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

.badge.rollover    { background: rgba(34,197,94,0.1);  color: var(--green-primary); border: 1px solid rgba(34,197,94,0.2); }
.badge.no-rollover { background: rgba(248,113,113,0.1);color: #f87171; border: 1px solid rgba(248,113,113,0.2); }
.badge.auto        { background: rgba(245,158,11,0.1); color: #fbbf24; border: 1px solid rgba(245,158,11,0.2); }

/* Dashboard responsive */
@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-value { font-size: 18px; }
  .cat-balance-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
  .summary-grid { grid-template-columns: 1fr; }
  .cat-balance-grid { grid-template-columns: 1fr; }
}

/* ── Receipt Scanner ── */
.scanner-upload-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
  overflow: hidden;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--green-primary);
  background: var(--green-glow);
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  gap: 8px;
  text-align: center;
}

.drop-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  transition: background var(--transition), border-color var(--transition);
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  background: var(--green-glow);
  border-color: var(--green-primary);
}

.drop-icon svg {
  width: 24px;
  height: 24px;
  color: var(--green-primary);
}

.drop-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.drop-browse {
  background: none;
  border: none;
  color: var(--green-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.drop-browse:hover { color: #4ade80; }

.drop-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Preview state */
.drop-preview {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.drop-preview img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.preview-filename {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.preview-remove {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  width: fit-content;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.preview-remove:hover {
  color: #f87171;
  border-color: #f87171;
  background: rgba(248, 113, 113, 0.08);
}

/* Process button */
.scanner-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.btn-process {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--green-primary);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}

.btn-process svg { width: 16px; height: 16px; }

.btn-process:hover:not(:disabled) { background: #4ade80; }

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

/* Results section */
.scanner-results {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.results-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.results-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
}

/* Table */
.table-wrapper { overflow-x: auto; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.items-table thead th {
  text-align: left;
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.col-item     { width: 45%; }
.col-price    { width: 15%; }
.col-category { width: 30%; }
.col-actions  { width: 10%; }

.items-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.items-table tbody tr:last-child { border-bottom: none; }
.items-table tbody tr:hover:not(.placeholder-row) { background: var(--bg-hover); }

.items-table td {
  padding: 12px 16px;
  color: var(--text-primary);
  vertical-align: middle;
}

/* Empty state */
.placeholder-row td { padding: 0; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 52px 24px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.empty-state svg {
  width: 36px;
  height: 36px;
  opacity: 0.4;
}

/* Category dropdown */
.cat-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  padding: 6px 10px;
  width: 100%;
  cursor: pointer;
  appearance: none;
  -webkit-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='%238a9ab5' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  transition: border-color var(--transition), background var(--transition);
}

.cat-select:focus {
  outline: none;
  border-color: var(--green-primary);
  background-color: var(--bg-hover);
}

/* Category color coding */
.cat-select[data-cat="mine-food"]  { border-left: 3px solid #22c55e; }
.cat-select[data-cat="mine-spend"] { border-left: 3px solid #3b82f6; }
.cat-select[data-cat="split"]      { border-left: 3px solid #f59e0b; }
.cat-select[data-cat="hers"]       { border-left: 3px solid #ec4899; }

/* Price cell */
.price-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text-primary);
}

/* Total row */
.total-row td {
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  color: var(--green-primary);
  background: var(--bg-elevated);
  border-top: 2px solid var(--border);
}

/* Delete button */
.btn-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
  transition: color var(--transition), background var(--transition);
}

.btn-delete:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
}

/* Footer buttons */
.results-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.btn-primary, .btn-secondary {
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn-primary {
  background: var(--green-primary);
  color: #000;
  border: none;
}

.btn-primary:hover { background: #4ade80; }

.btn-secondary {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* Utility */
.hidden { display: none !important; }

/* Scanner mobile */
@media (max-width: 600px) {
  .drop-zone-inner { padding: 36px 16px; }

  .col-item     { width: 40%; }
  .col-price    { width: 20%; }
  .col-category { width: 30%; }

  .results-footer { flex-direction: column; }
  .btn-primary, .btn-secondary { width: 100%; text-align: center; }
}
