:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e2e5ea;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --income: #16803d;
  --income-bg: #e7f6ec;
  --expense: #b91c1c;
  --expense-bg: #fbe9e9;
  --radius: 10px;
  --gutter: 16px;
  --max-width: 900px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--gutter);
  padding-bottom: 48px;
}

/* Very large external screens: give the layout more breathing room */
@media (min-width: 1600px) {
  :root { --max-width: 1100px; }
  body { font-size: 17px; }
}

h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 12px; }

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

button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
  font-weight: 600;
}
button.danger { color: var(--expense); border-color: var(--expense); }
button.link {
  border: none;
  background: none;
  color: var(--primary);
  min-height: auto;
  padding: 4px 0;
  text-decoration: underline;
}
button:disabled { opacity: .5; cursor: default; }

input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="tel"], select, textarea {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  width: 100%;
}
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }

.banner {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--expense-bg);
  color: var(--expense);
  padding: 12px var(--gutter);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.banner.hidden { display: none; }
.banner button { background: none; border: none; color: inherit; font-weight: 700; min-height: auto; padding: 4px 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.center-screen {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-box { width: 100%; max-width: 380px; }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tabs button { flex: 1 1 auto; }
.tabs button.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.topbar .who { color: var(--muted); font-size: .9rem; }

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.file-card { cursor: pointer; }
.file-card h3 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.file-card .dates { color: var(--muted); font-size: .85rem; margin-bottom: 10px; }
.amounts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.pill { border-radius: 999px; padding: 4px 10px; font-size: .85rem; font-weight: 600; }
.pill.income { background: var(--income-bg); color: var(--income); }
.pill.expense { background: var(--expense-bg); color: var(--expense); }
.net { font-weight: 700; }
.net.positive { color: var(--income); }
.net.negative { color: var(--expense); }

.row-list { display: flex; flex-direction: column; gap: 10px; }
.row-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}
.row-item .main { flex: 1 1 220px; }
.row-item .amount { font-weight: 700; white-space: nowrap; }
.row-item .amount.income { color: var(--income); }
.row-item .amount.expense { color: var(--expense); }
.row-item .meta { color: var(--muted); font-size: .85rem; }
.row-item .actions { display: flex; gap: 8px; }
.row-item .actions button { min-height: 36px; padding: 0 10px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px 14px;
}
.form-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

.share-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.share-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.empty-state { color: var(--muted); text-align: center; padding: 32px 12px; }

.back-link { margin-bottom: 10px; }

/* Tablet / small laptop */
@media (min-width: 640px) {
  .auth-box { max-width: 420px; }
}

/* Portrait phones: stack the topbar and give tabs room to wrap to two lines cleanly */
@media (max-width: 420px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .row-item .actions { width: 100%; }
  .row-item .actions button { flex: 1; }
}
