/* STR App — design tokens & base styles */

:root {
  --bg: #fafaf8;
  --bg-elev: #ffffff;
  --bg-sunken: #f4f3ef;
  --border: #e8e6e0;
  --border-strong: #d8d5cd;
  --text: #1a1a17;
  --text-secondary: #5c5a54;
  --text-tertiary: #8a8780;
  --text-quaternary: #b5b2a9;
  --accent: #2d5f3f;
  --accent-hover: #244d33;
  --accent-soft: #e8f0ea;
  --income: #2d5f3f;
  --expense: #b84d3e;
  --income-soft: #e8f0ea;
  --expense-soft: #f5e6e2;
  --warn: #b8862d;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 16, 0.04);
  --shadow: 0 1px 3px rgba(20, 20, 16, 0.06), 0 4px 12px rgba(20, 20, 16, 0.04);
  --shadow-lg: 0 4px 12px rgba(20, 20, 16, 0.08), 0 24px 48px rgba(20, 20, 16, 0.1);
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-serif: 'Fraunces', ui-serif, Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #17181a;
  --bg-elev: #1f2124;
  --bg-sunken: #121315;
  --border: #2a2c30;
  --border-strong: #3a3d42;
  --text: #f2f1ed;
  --text-secondary: #b5b2a9;
  --text-tertiary: #8a8780;
  --text-quaternary: #5c5a54;
  --accent: #7cb993;
  --accent-hover: #8cc9a3;
  --accent-soft: #1f2e25;
  --income: #7cb993;
  --expense: #e38472;
  --income-soft: #1f2e25;
  --expense-soft: #2e1f1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4), 0 24px 48px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
}

button { font-family: inherit; }

/* ─── Layout ──────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 0;
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.sidebar-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 500;
  font-style: italic;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 450;
  cursor: default;
  user-select: none;
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
  transition: background 0.12s;
}

.nav-item:hover { background: var(--bg-sunken); color: var(--text); }
.nav-item.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.nav-item-icon {
  width: 16px;
  height: 16px;
  opacity: 0.75;
  flex-shrink: 0;
}

.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}

.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, oklch(0.72 0.06 45), oklch(0.62 0.08 25));
  display: grid; place-items: center;
  color: white;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.main {
  background: var(--bg-sunken);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: -0.015em;
}

.topbar-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content { padding: 24px 32px 64px; max-width: 1400px; }

/* ─── Buttons ─────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: default;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-sunken); }
.btn svg { width: 14px; height: 14px; }

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

.btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn.accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg-sunken); }

.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  cursor: default;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }

/* ─── Cards ───────────────────────────────────────────────────────── */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad { padding: 20px; }
.card-pad-lg { padding: 24px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

/* ─── Tables ──────────────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-tertiary);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  white-space: nowrap;
}
.table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { cursor: default; transition: background 0.08s; }
.table tbody tr:hover { background: var(--bg-sunken); }
.table tbody tr:last-child td { border-bottom: 0; }

.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ─── Pills / badges ──────────────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--bg-sunken);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill.income { background: var(--income-soft); color: var(--income); border-color: transparent; }
.pill.expense { background: var(--expense-soft); color: var(--expense); border-color: transparent; }
.pill.auto { background: transparent; color: var(--text-tertiary); font-size: 10.5px; padding: 1px 6px; }
.pill.dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8;
}

.dot {
  width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}

/* ─── Forms ───────────────────────────────────────────────────────── */

.input, .select, .textarea {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: all 0.12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--bg-sunken);
}
.textarea { height: auto; padding: 10px 12px; min-height: 72px; resize: vertical; font-family: inherit; }

.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.form-row .hint { font-size: 11.5px; color: var(--text-tertiary); }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-elev);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  height: 26px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 5px;
  cursor: default;
}
.segmented button.active { background: var(--bg-sunken); color: var(--text); box-shadow: var(--shadow-sm); }

/* ─── KPIs ────────────────────────────────────────────────────────── */

.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.kpi-label {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 0.005em;
}
.kpi-value {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.kpi-value.sm { font-size: 22px; }
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  margin-top: 6px;
}
.kpi-delta.up { color: var(--income); }
.kpi-delta.down { color: var(--expense); }

/* ─── Grid helpers ────────────────────────────────────────────────── */

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }

/* ─── House photo placeholder ─────────────────────────────────────── */

.house-photo {
  position: relative;
  overflow: hidden;
  background: var(--bg-sunken);
}

/* ─── Modal / sheet ───────────────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; background: rgba(10, 10, 8, 0.3);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: grid; place-items: center;
  padding: 24px;
}
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--border);
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.side-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 440px;
  max-width: 100vw;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 90;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Stripes (for photo placeholder) ─────────────────────────────── */

.stripes {
  background-image: repeating-linear-gradient(
    135deg,
    rgba(255,255,255,0.05) 0,
    rgba(255,255,255,0.05) 1px,
    transparent 1px,
    transparent 12px
  );
}

/* ─── Tooltip/popover tweaks ──────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-sunken);
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ─── Utilities ───────────────────────────────────────────────────── */

.hsep { height: 1px; background: var(--border); margin: 16px 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.muted { color: var(--text-tertiary); }
.small { font-size: 12.5px; }
.xs { font-size: 11.5px; }
.serif { font-family: var(--font-serif); font-weight: 400; letter-spacing: -0.01em; }
.mono { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }

/* receipt icon */
.receipt-chip {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text-tertiary);
}
.receipt-chip:hover { color: var(--text); border-color: var(--border-strong); }
