:root {
  --bg: #0f172a;
  --card: #111827;
  --muted: #334155;
  --text: #e5e7eb;
  --accent: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
}

/* Base */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: #0b1020;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: #93c5fd;
  text-decoration: none;
}
header {
  padding: 16px 20px;
  background: linear-gradient(90deg, #0ea5e9, #22c55e);
  color: #0b1020;
  font-weight: 700;
}

.container {
  max-width: 1100px;
  margin: 20px auto;
  padding: 0 12px;
}

/* Grid: mobile-first single column */
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

/* Upper section responsive grid: 1 → 2 → 3 columns */
.section-grid {
  grid-template-columns: 1fr;
}
@media (min-width: 820px) {
  .section-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1200px) {
  .section-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* For any grid you want always single column (e.g., Add vs Settlement stack) */
.always-one {
  grid-template-columns: 1fr !important;
}

.card {
  background: #0f172a;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02), 0 8px 30px rgba(0, 0, 0, 0.25);
}

h2,
h3 {
  margin: 8px 0 10px;
}

/* Controls */
input,
select,
button,
textarea {
  width: 100%;
  padding: 12px 12px;
  border-radius: 10px;
  border: 1px solid #243244;
  background: #0b1325;
  color: var(--text);
}
button {
  cursor: pointer;
  background: #1f2937;
  transition: transform 0.06s ease;
}
button:active {
  transform: translateY(1px);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #243244;
  background: #0b1325;
  color: var(--text);
}
.btn-ghost {
  background: transparent;
  border-color: #1f2937;
}
.btn-pill {
  border-radius: 999px;
}

/* Flexible rows that wrap nicely */
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row > * {
  flex: 1 1 240px;
  min-width: 200px;
}

/* Toolbars */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Period form grid */
.period-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) {
  .period-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.muted {
  color: #9ca3af;
  font-size: 0.9rem;
}
.pill {
  display: inline-block;
  background: #1f2a3a;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: #a5b4fc;
}

.money {
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
}
.ok {
  color: var(--accent);
}
.bad {
  color: var(--danger);
}
.warn {
  color: var(--warn);
}

/* Tables: mobile-friendly horizontal scroll */
/* .table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}
th,
td {
  padding: 8px;
  border-bottom: 1px solid #1f2937;
  text-align: left;
} */

/* Prevent page-wide overflow */
body {
  overflow-x: hidden;
}
.card {
  max-width: 100%;
}

/* Controls never exceed container width */
input,
select,
button,
textarea {
  max-width: 100%;
}

/* Tables: only widen inside a scroll wrapper */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
} /* no global min-width */
.table-wrap > table {
  min-width: 560px;
} /* apply only when wrapped */
@media (max-width: 420px) {
  .table-wrap > table {
    min-width: 480px;
  }
}

th,
td {
  padding: 8px;
  border-bottom: 1px solid #1f2937;
  text-align: left;
}

/* Rows: shrink nicely on narrow screens */
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row > * {
  flex: 1 1 240px;
  min-width: 0;
} /* allow shrinking */

.right {
  text-align: right;
}
.small {
  font-size: 0.85rem;
}

/* Tiny spacing tweaks for very small screens */
@media (max-width: 420px) {
  header {
    padding: 14px 14px;
  }
  .container {
    padding: 0 10px;
  }
}

/* --- Period card: truly responsive --- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Prev / Next buttons: 2-up on phones, inline on wide screens */
.nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
@media (min-width: 700px) {
  .nav-row {
    display: flex;
    gap: 8px;
  }
  .nav-row .btn {
    width: auto;
  }
}

/* Month / Year / Remember: 1 col on phones, 2 on tablets, 3 on desktop */
.period-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  margin-top: 10px;
}
@media (min-width: 600px) {
  .period-grid {
    grid-template-columns: 1fr 1fr;
  }
}
@media (min-width: 980px) {
  .period-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* Ensure buttons/inputs never force overflow on narrow screens */
.btn,
input,
select,
button {
  min-width: 0;
}

/* Unified action buttons */
.btn-sm {
  padding: 6px 10px;
  font-size: 0.9rem;
  border-radius: 8px;
}
.btn-primary {
  background: #2563eb;
  border-color: #2563eb;
}
.btn-secondary {
  background: #1f2937;
  border-color: #243244;
}
.btn-danger {
  background: #7f1d1d;
  border-color: #b91c1c;
}
/* horizontal pair */
.btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}
.btn-row form {
  margin: 0;
  display: inline;
}

/* --- Responsive stack for narrow screens (expenses table) --- */
.stack-table > table {
  min-width: 0 !important;
} /* override any min-width */

@media (max-width: 680px) {
  .stack-table thead {
    display: none;
  }
  .stack-table tbody tr {
    display: block;
    padding: 10px 12px;
    margin-bottom: 10px;
    border: 1px solid #1f2937;
    border-radius: 12px;
    background: #0f172a;
  }
  .stack-table tbody tr td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: none;
  }
  .stack-table tbody tr td[data-label]::before {
    content: attr(data-label);
    color: #9ca3af;
    font-size: 0.85rem;
  }
  .stack-table tbody tr td.right {
    text-align: right;
  }
  .stack-table tbody tr td.actions {
    justify-content: flex-end;
  }

  /* summary row (Total variable) */
  .stack-table tbody tr.summary-row {
    display: block;
    background: transparent;
    border: none;
    padding: 0;
    margin: 4px 0 0;
  }
  .stack-table tbody tr.summary-row td {
    display: block;
    text-align: right;
    padding: 6px 0;
  }
}

/* ============= Collapsible cards ============= */
details.card {
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
}
details.card > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 14px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1f2937;
  font-weight: 600;
}
details.card > .content {
  padding: 14px;
}
summary::-webkit-details-marker {
  display: none;
}
.chev {
  font-size: 12px;
  opacity: 0.75;
  transition: transform 0.18s ease;
}
details[open] > summary .chev {
  transform: rotate(180deg);
}

/* Equal gap after top-level sections (apply class="section" to those) */
.section {
  margin-bottom: 16px;
}

/* Top grid: two equal columns on desktop, stack on mobile */
.top-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 1024px) {
  .top-grid.two-cols {
    grid-template-columns: 1fr 1fr;
  }
}

/* Roommates table embedded in top card */
.roommates-compact .table-wrap > table {
  min-width: 0 !important;
}
.roommates-compact td:nth-child(2) {
  word-break: break-all;
} /* emails wrap */

/* --- End of file --- */
