:root {
  --brand: #2FA044;
  --brand-dark: #1E6E3A;
  --background: #F5F8F6;
  --card: #FFFFFF;
  --text: #1D2B22;
  --muted: #6B7A70;
  --border: #E3EBE5;
  --error: #C0392B;
  --income: #2FA044;
  --expense: #D9534F;
  --warning: #B88400;
  --on-brand: #FFFFFF;
  --radius: 14px;
  --side: 20px;
  --field: 52px;
  --nav: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

/* One phone-wide column; on a wide screen it is centred instead of stretched. */
#app {
  position: relative;
  max-width: 480px;
  min-height: 100%;
  margin: 0 auto;
  background: var(--background);
}

@media (min-width: 720px) {
  body { background: #E9EFEA; }
  #app { box-shadow: 0 0 0 1px var(--border); }
}

button, input { font: inherit; color: inherit; }

.btn {
  display: block;
  width: 100%;
  min-height: var(--field);
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-plain { background: transparent; color: var(--brand-dark); }
.btn-outline { background: var(--card); color: var(--text); border: 1px solid var(--border); text-align: left; }
.btn-outline.is-active { border-color: var(--brand); color: var(--brand-dark); }

.field {
  display: block;
  width: 100%;
  height: var(--field);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
.field:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.label { display: block; margin: 16px 0 6px; color: var(--muted); font-size: 14px; }
.message { min-height: 22px; margin: 14px 0; color: var(--error); font-size: 14px; }
.muted, .message.muted { color: var(--muted); }

/* Sign-in */
#login {
  padding: calc(48px + env(safe-area-inset-top)) var(--side) calc(24px + env(safe-area-inset-bottom));
}
.brand-mark {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--brand); color: var(--on-brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px;
}
#login h1 { margin: 24px 0 6px; font-size: 26px; }
#login .btn { margin-top: 20px; }
#login-code { letter-spacing: 6px; font-size: 22px; text-align: center; }

/* Shell */
#shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.shell-header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) var(--side) 12px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.shell-company {
  flex: 1; min-width: 0; min-height: 44px; padding: 0;
  border: 0; background: transparent; text-align: left;
  font-weight: 600; font-size: 17px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shell-company:not(:disabled) { cursor: pointer; }
.shell-account {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--background); color: var(--brand-dark); font-weight: 700; cursor: pointer;
}
.shell-body { flex: 1; padding: var(--side); padding-bottom: calc(var(--nav) + 24px + env(safe-area-inset-bottom)); }
.shell-body h2 { margin: 0 0 8px; font-size: 22px; }
.shell-nav {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 480px;
  display: flex; height: calc(var(--nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
}
.shell-tab {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.shell-tab.is-active { color: var(--brand-dark); box-shadow: inset 0 3px 0 var(--brand); }

/* Bottom sheet */
#sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(29, 43, 34, 0.45); }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 480px;
  max-height: 80%; overflow-y: auto;
  padding: 20px var(--side) calc(20px + env(safe-area-inset-bottom));
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
}
.sheet-card h3 { margin: 0 0 12px; font-size: 18px; }
.sheet-card .btn { margin-top: 10px; }

/* Areas */
.area-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.area-head h2 { margin: 0; }
.chips { display: flex; gap: 8px; margin: 12px 0; overflow-x: auto; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--card); color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip.is-active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
#cash-search-form { margin: 0 0 12px; }

.card {
  margin: 0 0 12px; padding: 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.card.is-done { opacity: 0.6; }
.card-title, .section-title { margin: 0 0 10px; font-size: 16px; }
.section-title { margin: 18px 0 10px; }
.card p { margin: 0 0 6px; }
.kpi { font-size: 30px; font-weight: 700; }
.pair { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.pair-caption { color: var(--muted); }
.pair-value { font-weight: 600; white-space: nowrap; }
.small { font-size: 13px; }
.center { text-align: center; }
.wrap { white-space: normal; }
.is-income { color: var(--income); }
.is-expense { color: var(--expense); }
.is-warning { color: var(--warning); }

.banner {
  display: block; width: 100%; margin: 0 0 12px; padding: 12px 14px;
  border: 1px solid #F0D58A; border-radius: var(--radius);
  background: #FFF8E1; color: #6B4E00; font-size: 14px; text-align: left;
}
.banner-link { cursor: pointer; }
.btn-center { text-align: center; margin-top: 8px; }

.chart { display: block; width: 100%; height: auto; margin: 4px 0 10px; }
.chart-donut { max-width: 220px; margin: 4px auto 14px; }
.legend { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.legend-dot { flex: none; width: 12px; height: 12px; border-radius: 3px; }
.legend-caption { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-value { color: var(--muted); white-space: nowrap; }

.row { display: flex; align-items: center; gap: 12px; }
.row-main { flex: 1; min-width: 0; }
.row-main p, .row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title { font-weight: 600; }
.row-title.wrap { white-space: normal; }
.row-side { flex: none; text-align: right; }
.row-value { font-weight: 700; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  background: var(--background); color: var(--muted); font-size: 12px; font-weight: 600;
}
.badge.is-overdue { background: #FBE9E7; color: var(--expense); }
.badge.is-paid { background: #E6F4EA; color: var(--brand-dark); }
.rate { padding: 8px 0; border-top: 1px solid var(--border); }
