:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ec;
  --border: rgba(0, 0, 0, 0.08);
  --border-2: rgba(0, 0, 0, 0.15);
  --text: #1a1a1a;
  --text-2: #5f5e5a;
  --text-3: #888780;
  --accent: #c15f3c;
  --accent-bg: #faece7;
  --danger: #a32d2d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --surface: #252523;
    --surface-2: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --border-2: rgba(255, 255, 255, 0.2);
    --text: #f0ede4;
    --text-2: #b4b2a9;
    --text-3: #888780;
    --accent-bg: #4a1b0c;
  }
}
body.dark {
  --bg: #1a1a1a;
  --surface: #252523;
  --surface-2: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --border-2: rgba(255, 255, 255, 0.2);
  --text: #f0ede4;
  --text-2: #b4b2a9;
  --text-3: #888780;
  --accent-bg: #4a1b0c;
}
body.light {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ec;
  --border: rgba(0, 0, 0, 0.08);
  --border-2: rgba(0, 0, 0, 0.15);
  --text: #1a1a1a;
  --text-2: #5f5e5a;
  --text-3: #888780;
  --accent-bg: #faece7;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
.app { max-width: 1100px; margin: 0 auto; padding: 2rem 1.25rem; }
.hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.hdr-brand { display: flex; align-items: center; gap: 12px; }
.hdr-logo { height: 44px; width: auto; display: block; }
.hdr-app { font-size: 20px; font-weight: 500; letter-spacing: -0.3px; }
.sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 1.5rem; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 1rem; }
.stat-l { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.stat-v { font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat-v-sm { font-size: 16px; padding-top: 4px; }

.card { background: var(--surface); border: 0.5px solid var(--border); border-radius: 12px; padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.card-title { font-size: 15px; font-weight: 500; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.full { width: 100%; margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.file-label { font-size: 13px; color: var(--text-2); cursor: pointer; padding: 8px 14px; border: 0.5px solid var(--border-2); border-radius: 8px; background: transparent; }
.file-label:hover { background: var(--surface-2); }

input, select, button { font-family: inherit; font-size: 14px; }
input[type="text"], input[type="number"], input[type="date"], select {
  height: 36px; padding: 0 10px; border: 0.5px solid var(--border-2);
  border-radius: 8px; background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: none; box-shadow: 0 0 0 2px var(--accent); }

button {
  height: 36px; padding: 0 16px; border: 0.5px solid var(--border-2);
  border-radius: 8px; background: transparent; color: var(--text);
  cursor: pointer; font-weight: 500;
}
button:hover { background: var(--surface-2); }
button:active { transform: scale(0.98); }
.btn-primary { background: var(--text); color: var(--surface); border-color: var(--text); margin-left: auto; }
.btn-primary:hover { opacity: 0.85; background: var(--text); }

.toolbar { display: flex; gap: 10px; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.toolbar input[type="text"] { flex: 1; min-width: 180px; }
.toolbar select { max-width: 200px; }

.list-card { padding: 0; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); }
th.right { text-align: right; } th.center { text-align: center; }
td { padding: 12px; border-top: 0.5px solid var(--border); vertical-align: middle; }
td.right { text-align: right; font-variant-numeric: tabular-nums; }
td.center { text-align: center; }
.vendor-notes { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.cat-pill { background: var(--surface-2); padding: 3px 10px; border-radius: 6px; font-size: 12px; }
.small-btn { height: 24px; padding: 0 10px; font-size: 12px; }
.del-btn { height: 24px; padding: 0 8px; font-size: 14px; border: none; color: var(--text-3); }
.del-btn:hover { color: var(--danger); background: transparent; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--text-2); font-size: 14px; }

/* Role-based visibility */
body[data-role="viewer"] .admin-only { display: none !important; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100; }
.modal { background: var(--surface); border-radius: 12px; padding: 1rem; max-width: 90vw; max-height: 90vh; overflow: auto; }
.modal-hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 1rem; }
.modal img { max-width: 100%; max-height: 70vh; display: block; }

.banner { background: var(--accent-bg); color: var(--accent); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 1rem; }
.hdr-actions { display: flex; align-items: center; gap: 8px; }
.logout-btn { font-size: 13px; color: var(--text-2); text-decoration: none; padding: 6px 12px; border: 0.5px solid var(--border-2); border-radius: 8px; white-space: nowrap; }
.logout-btn:hover { background: var(--surface-2); color: var(--text); }
.theme-btn { width: 36px; height: 36px; padding: 0; font-size: 16px; border: 0.5px solid var(--border-2); border-radius: 8px; }
body.dark { color-scheme: dark; }
body.light { color-scheme: light; }

.tabs { display: flex; gap: 4px; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 16px; font-size: 14px; font-weight: 500; color: var(--text-2); cursor: pointer; margin-bottom: -1px; }
.tab:hover { color: var(--text); background: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.grid-3 { grid-template-columns: repeat(3, 1fr); }
.line-items-hdr { display: grid; grid-template-columns: 1fr 180px 110px 36px; gap: 8px; padding: 0 2px 4px; font-size: 12px; color: var(--text-3); }
.line-items-hdr .right { text-align: right; }
.line-row { display: grid; grid-template-columns: 1fr 180px 110px 36px; gap: 8px; margin-bottom: 8px; }
.line-row input, .line-row select { width: 100%; }
.line-remove { padding: 0; width: 36px; color: var(--text-3); border: none; font-size: 16px; }
.line-remove:hover { color: var(--danger); background: transparent; }
.btn-add-line { background: none; border: 0.5px dashed var(--border-2); color: var(--text-2); font-size: 13px; width: 100%; margin-bottom: 12px; }
.btn-add-line:hover { background: var(--surface-2); }
.report-presets { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.preset-btn { height: 32px; padding: 0 12px; font-size: 13px; background: var(--surface-2); border-color: var(--border-2); }
.preset-btn:hover { background: var(--border-2); }
.preset-year { height: 32px; font-size: 13px; }
.report-form { display: flex; flex-direction: column; gap: 12px; }
.report-range { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.report-range label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.report-type { display: flex; gap: 20px; flex-wrap: wrap; }
.report-type label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.report-period { font-size: 13px; color: var(--text-2); margin: 1rem 0 0.75rem; }
.report-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 1.25rem; }
.report-stat { background: var(--surface); border: 0.5px solid var(--border); border-radius: 10px; padding: 0.875rem 1rem; }
.report-stat-l { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.report-stat-v { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.report-stat-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.report-section-title { font-size: 13px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; margin: 1.25rem 0 0.5rem; }
.report-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 1rem; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th { text-align: left; padding: 10px 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); }
.report-table th.right { text-align: right; }
.report-table td { padding: 10px 12px; border-top: 0.5px solid var(--border); vertical-align: middle; }
.report-table td.right { text-align: right; font-variant-numeric: tabular-nums; }
.report-table tfoot td { border-top: 1px solid var(--border-2); background: var(--surface-2); }

.tax-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.tax-label { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.tax-row input { width: 160px; }
