:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #eef1f8;
  --line: #d8dfeb;
  --text: #172033;
  --muted: #5e677d;
  --accent: #0c5a74;
  --accent-strong: #083e51;
  --danger: #9f2f2f;
  --shadow: 0 12px 30px rgba(14, 24, 45, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(circle at 0% 0%, #e2ecf7 0, var(--bg) 55%);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.userspace-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.userspace-sidebar {
  background: linear-gradient(160deg, #0d2034, #132f46);
  color: #f5f8fc;
  padding: 2rem 1.1rem;
  border-right: 1px solid rgba(255, 255, 255, 0.09);
}

.brand-block {
  margin-bottom: 2rem;
  padding: 0.8rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
}

.brand-eyebrow {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.brand-title {
  margin: 0.4rem 0 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.nav-group + .nav-group {
  margin-top: 0.9rem;
}

.nav-link,
.nav-sublink,
.nav-label {
  text-decoration: none;
  display: block;
  border-radius: 10px;
}

.nav-link,
.nav-label {
  padding: 0.55rem 0.75rem;
  font-weight: 600;
}

.nav-sublink {
  margin: 0.3rem 0 0 0.6rem;
  padding: 0.45rem 0.6rem;
  color: rgba(245, 248, 252, 0.87);
}

.nav-link.active,
.nav-label.active,
.nav-sublink.active {
  background: rgba(230, 240, 251, 0.18);
}

.userspace-main {
  padding: 1.6rem 2rem 2.4rem;
}

.userspace-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.userspace-header h1 {
  margin: 0;
}

.userspace-header p {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.card-grid {
  display: grid;
  gap: 1rem;
}

.card-grid.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

.form-grid.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.metric-card {
  background: linear-gradient(130deg, #ffffff 0%, #f7fbff 100%);
}

.metric-alert {
  border-color: #e3c3a1;
  background: linear-gradient(130deg, #fff7f0 0%, #fff2e2 100%);
}

.metric-label {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.78rem;
  font-weight: 600;
}

.metric-value {
  margin: 0.2rem 0 0;
  font-size: 1.8rem;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.swatch {
  width: 36px;
  height: 20px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: var(--swatch-color);
  display: inline-block;
  margin-right: 0.45rem;
  vertical-align: middle;
}

.primary-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.primary-link:hover {
  color: var(--accent-strong);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.primary,
.secondary {
  border: 0;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

button.primary,
.primary {
  background: var(--accent);
  color: #fff;
}

button.secondary,
.secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--line);
}

.range-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.range-preset {
  display: inline-flex;
  align-items: center;
  min-height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.range-preset:hover,
.range-preset.active {
  border-color: var(--accent);
  background: #e7f3f7;
  color: var(--accent-strong);
}

label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: #fff;
  margin-bottom: 0.75rem;
}

.message {
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #eef5ff;
  border: 1px solid #c6dcff;
}

.message.error {
  background: #fceaea;
  border-color: #f1c2c2;
  color: #792323;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state {
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.45rem 0.7rem;
  margin: 0;
}

.detail-grid dt {
  font-weight: 600;
  color: var(--muted);
}

.detail-grid dd {
  margin: 0;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 1.4rem;
}

@media (max-width: 980px) {
  .userspace-shell {
    grid-template-columns: 1fr;
  }

  .userspace-sidebar {
    padding-bottom: 1rem;
  }

  .card-grid.two-up {
    grid-template-columns: 1fr;
  }

  .form-grid.two-up {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .userspace-main {
    padding: 1rem;
  }
}

/* Expense notes: keep table columns readable on narrow screens */
.expense-notes-cell {
  max-width: 14rem;
  word-break: break-word;
  font-size: 0.9rem;
  color: var(--muted);
}

textarea.expense-notes-input {
  min-height: 5.5rem;
  resize: vertical;
}

/* Etsy receipt JSON display: scroll on small screens, readable font */
.receipt-json {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
  padding: 1rem;
  background: var(--surface-alt);
  border-radius: var(--radius);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
