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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --text: #e8eaf0;
  --text-muted: #7a80a0;
  --primary: #4f7cff;
  --primary-hover: #3d6aee;
  --primary-dark: #1e3a8a;
  --danger: #e05252;
  --danger-hover: #c93d3d;
  --success: #34c97c;
  --warning: #f0a73a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --header-h: 60px;
  --nav-h: 48px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Utilities ───────────────────────────────────────── */
.hidden { display: none !important; }
.screen { min-height: 100vh; }
.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 8px; padding: 8px 12px; background: rgba(224,82,82,0.12); border-radius: var(--radius-sm); border: 1px solid rgba(224,82,82,0.25); }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm); border: none;
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  transition: background 0.15s, opacity 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-icon { background: none; border: none; color: var(--text-muted); padding: 6px; cursor: pointer; border-radius: var(--radius-sm); font-size: 1rem; }
.btn-icon:hover { color: var(--text); background: var(--surface2); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* ── Login ───────────────────────────────────────────── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: radial-gradient(ellipse at 50% 0%, #1e2d5a 0%, var(--bg) 70%);
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px 32px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow); text-align: center;
}
.brand-logo { font-size: 2.5rem; margin-bottom: 10px; }
.brand-title { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.brand-sub { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 28px; }
.login-box form { text-align: left; }

/* ── App Header ──────────────────────────────────────── */
.app-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  height: var(--header-h); position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 900px; margin: 0 auto; padding: 0 16px;
  height: 100%; display: flex; align-items: center; justify-content: space-between;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 1.6rem; }
.header-title { font-weight: 700; font-size: 1rem; line-height: 1.2; }
.header-sub { font-size: 0.75rem; color: var(--text-muted); }
.header-actions { display: flex; gap: 8px; }

/* ── Tab Nav ─────────────────────────────────────────── */
.tab-nav {
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; padding: 0 16px; max-width: 900px; margin: 0 auto;
  position: sticky; top: var(--header-h); z-index: 99;
}
.tab-btn {
  background: none; border: none; color: var(--text-muted);
  padding: 14px 20px; font-size: 0.9rem; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text); }

/* ── Tab Content ─────────────────────────────────────── */
.tab-content { max-width: 900px; margin: 0 auto; padding: 16px; }
.tab-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 10px; flex-wrap: wrap;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .tab-toolbar select {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; cursor: pointer;
}

/* ── Summary Bar ─────────────────────────────────────── */
.summary-bar {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px;
  display: flex; gap: 20px; align-items: center;
  font-size: 0.85rem; margin-bottom: 12px;
}
.summary-bar span { color: var(--text-muted); }
.summary-bar span strong { color: var(--text); }

/* ── Card List ───────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.empty-state {
  text-align: center; color: var(--text-muted); padding: 48px 20px;
  font-size: 0.9rem; background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Expense Card ────────────────────────────────────── */
.expense-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 12px;
  transition: border-color 0.15s;
}
.expense-card:hover { border-color: var(--primary); }
.expense-receipt-thumb {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  object-fit: cover; cursor: pointer; flex-shrink: 0;
  border: 1px solid var(--border);
}
.expense-receipt-placeholder {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 1.3rem; flex-shrink: 0;
  border: 1px solid var(--border);
}
.expense-info { flex: 1; min-width: 0; }
.expense-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.expense-vendor { font-weight: 600; font-size: 1rem; }
.expense-amount { font-weight: 700; font-size: 1.05rem; color: var(--success); margin-left: auto; }
.expense-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.expense-date { font-size: 0.8rem; color: var(--text-muted); }
.expense-description { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-actions { display: flex; gap: 4px; flex-shrink: 0; }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 20px; font-size: 0.72rem; font-weight: 500;
}
.badge-category { background: rgba(79,124,255,0.15); color: var(--primary); }
.badge-property { background: rgba(52,201,124,0.12); color: var(--success); }

/* ── Property Card ───────────────────────────────────── */
.property-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; align-items: center; gap: 14px;
  transition: border-color 0.15s;
}
.property-card:hover { border-color: var(--primary); }
.property-icon { font-size: 1.8rem; flex-shrink: 0; }
.property-info { flex: 1; min-width: 0; }
.property-name { font-weight: 600; font-size: 1rem; }
.property-address { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }
.property-actions { display: flex; gap: 4px; }

/* ── Forms ───────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.9rem;
  width: 100%; transition: border-color 0.15s; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Receipt Upload ──────────────────────────────────── */
.receipt-upload-area {
  background: var(--surface2); border: 2px dashed var(--border);
  border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
  cursor: pointer; transition: border-color 0.15s;
}
.receipt-upload-area:hover { border-color: var(--primary); }
.upload-placeholder { padding: 28px; text-align: center; }
.upload-icon { font-size: 2.2rem; margin-bottom: 8px; }
.upload-label { font-size: 0.9rem; font-weight: 500; color: var(--text); }
.upload-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.receipt-preview {
  position: relative; display: flex; align-items: center;
  justify-content: center; flex-direction: column; gap: 10px; padding: 14px;
}
.receipt-preview img { max-height: 200px; max-width: 100%; border-radius: var(--radius-sm); }
.ocr-status {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px; font-size: 0.85rem; color: var(--text-muted);
}
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modals ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  z-index: 200; display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 20px; }
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0; width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow);
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius); }
}
.modal-sm { max-width: 420px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text-muted); font-size: 1.1rem;
  cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .header-actions .btn-ghost:first-child { display: none; }
  .expense-card { flex-wrap: wrap; }
  .expense-amount { font-size: 0.95rem; }
  .tab-btn { padding: 12px 14px; font-size: 0.85rem; }
}

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

/* ── Two-step expense modal ── */
.review-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.review-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #2a2a3e;
  flex-shrink: 0;
}

.review-ocr-badge {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  flex: 1;
  line-height: 1.4;
}

.badge-all-found {
  background: #1a2e1a;
  color: #4ade80;
  border: 1px solid #166534;
}

.badge-missing {
  background: #2a1f10;
  color: #fbbf24;
  border: 1px solid #78350f;
}

.field-missing input,
.field-missing select,
.field-missing textarea {
  border-color: #f59e0b !important;
  background: #1c1a0f !important;
}

.field-missing label {
  color: #fbbf24;
}

.optional-label {
  font-size: 11px;
  color: #555;
  font-weight: 400;
}

.required-star {
  color: #f87171;
}

.receipt-upload-area {
  cursor: pointer;
  min-height: 160px;
}


/* ── Reports ── */
.reports-toolbar {
  flex-wrap: wrap;
  gap: 10px;
}
.report-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.report-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.report-doc {
  padding: 0 4px 40px;
  max-width: 900px;
  margin: 0 auto;
}
.report-title-block {
  text-align: center;
  padding: 24px 0 16px;
  border-bottom: 1px solid #2a2a3e;
  margin-bottom: 20px;
}
.report-title-block h2 {
  font-size: 22px;
  color: #e0e0e0;
  margin: 0 0 4px;
}
.report-title-block h3 {
  font-size: 16px;
  color: #a5b4fc;
  font-weight: 500;
  margin: 0 0 6px;
}
.report-generated {
  font-size: 12px;
  color: #555;
  margin: 0;
}
.report-summary-card {
  background: #13131e;
  border: 1px solid #2a2a3e;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.report-summary-total {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  color: #e0e0e0;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #2a2a3e;
}
.report-summary-total strong { color: #4ade80; }
.report-summary-cats { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.report-cat-row { display: flex; gap: 12px; font-size: 13px; color: #888; }
.report-cat-row span:last-child { color: #ccc; }
.report-property-section {
  background: #0f0f1a;
  border: 1px solid #1e1e2e;
  border-radius: 10px;
  margin-bottom: 20px;
  overflow: hidden;
}
.report-prop-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px;
  background: #13131e;
  border-bottom: 1px solid #1e1e2e;
}
.report-prop-name { font-size: 15px; font-weight: 600; color: #e0e0e0; }
.report-prop-address { font-size: 12px; color: #666; margin-top: 2px; }
.report-prop-total { font-size: 16px; font-weight: 700; color: #a5b4fc; }
.report-cat-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid #1e1e2e;
}
.report-cat-pill {
  display: flex;
  gap: 6px;
  background: #1a1a2e;
  border: 1px solid #2a2a3e;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
}
.cat-label { color: #888; }
.cat-amt { color: #ccc; font-weight: 500; }
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.report-table th {
  padding: 8px 12px;
  text-align: left;
  color: #555;
  font-weight: 500;
  border-bottom: 1px solid #1e1e2e;
}
.report-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #0d0d18;
  color: #ccc;
}
.report-table tr:last-child td { border-bottom: none; }
.report-table .text-right { text-align: right; }
.report-table .text-muted { color: #555; }
.badge-sm { font-size: 10px; padding: 2px 6px; }
.report-table-total td {
  font-weight: 600;
  color: #e0e0e0;
  background: #13131e;
  border-top: 1px solid #2a2a3e;
}

/* Print styles */
@media print {
  body { background: white !important; color: black !important; }
  .app-header, .tab-nav, .tab-toolbar, #tab-expenses, #tab-properties,
  #login-screen, .modal-overlay { display: none !important; }
  #tab-reports { display: block !important; }
  .reports-toolbar { display: none !important; }
  .report-doc { color: black; }
  .report-title-block h2, .report-title-block h3 { color: black; }
  .report-summary-card, .report-property-section { border: 1px solid #ccc; }
  .report-prop-header { background: #f5f5f5; }
  .report-table th { color: #333; }
  .report-table td { color: #111; }
  .report-table-total td { background: #f5f5f5; }
  .report-prop-total, .report-summary-total strong { color: #1a5c1a; }
  .report-cat-pill { border: 1px solid #ddd; }
  .cat-label { color: #555; }
}
