:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --line: #d9e0dc;
  --line-strong: #bcc9c2;
  --text: #18221d;
  --muted: #66736c;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --credit: #15803d;
  --credit-soft: #dcfce7;
  --debit: #b42318;
  --debit-soft: #fee4e2;
  --warning-soft: #fff7ed;
  --shadow: 0 10px 30px rgba(20, 34, 27, .06);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
h1, h2, p { letter-spacing: 0; }
h1 { font-size: 1.8rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
p { margin: 0; }

button, .button {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 750;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
}

button:hover, .button:hover { background: var(--accent-dark); }

.button.secondary {
  background: white;
  border-color: var(--line-strong);
  color: var(--text);
}

.button.danger {
  background: white;
  border-color: #f4b4ad;
  color: var(--debit);
}

.small { min-height: 30px; padding: 0 9px; font-size: .84rem; }

.app-header {
  align-items: center;
  background: #10231f;
  color: white;
  display: grid;
  gap: 28px;
  grid-template-columns: auto 1fr auto;
  min-height: 58px;
  padding: 0 max(22px, calc((100vw - 1500px) / 2));
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 1.15rem; font-weight: 850; }

.app-header nav {
  align-items: center;
  display: flex;
  gap: 6px;
}

.app-header nav a {
  border-radius: 5px;
  color: #c9d8d0;
  font-size: .92rem;
  font-weight: 700;
  padding: 8px 10px;
}

.app-header nav a:hover,
.app-header nav a.active {
  background: rgba(255, 255, 255, .10);
  color: white;
}

.account-menu {
  align-items: center;
  display: flex;
  gap: 12px;
}

.account-menu span { color: #c9d8d0; font-size: .88rem; }
.text-button {
  background: transparent;
  border-color: rgba(255, 255, 255, .2);
  min-height: 32px;
}

.app-main {
  margin: 0 auto;
  max-width: 1540px;
  padding: 24px;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.page-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--accent);
  font-size: .74rem;
  font-weight: 850;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.month-filter {
  align-items: center;
  display: flex;
  gap: 8px;
}

.summary-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.summary-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.summary-grid span {
  color: var(--muted);
  display: block;
  font-size: .8rem;
  margin-bottom: 7px;
}

.summary-grid strong {
  font-size: 1.32rem;
  font-variant-numeric: tabular-nums;
}

.positive { color: var(--credit); }
.negative { color: var(--debit); }
.muted { color: var(--muted); }

.sheet-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  padding: 16px;
}

.section-head {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head p {
  color: var(--muted);
  font-size: .85rem;
  margin-top: 4px;
}

.opening-balance {
  position: relative;
}

.opening-balance summary {
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: .86rem;
  font-weight: 750;
  list-style: none;
  padding: 8px 10px;
}

.opening-balance form {
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  padding: 14px;
  position: absolute;
  right: 0;
  top: 42px;
  width: 280px;
  z-index: 5;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
}

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

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

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: .76rem;
  font-weight: 850;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
}

tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }

.daily-table {
  max-height: 465px;
}

.daily-table table { min-width: 720px; }
.daily-table td:first-child { width: 190px; }
.daily-table td:first-child small {
  color: var(--muted);
  display: block;
  font-size: .72rem;
  margin-top: 2px;
}

.balance-cell { font-weight: 850; }
.today-row td { background: #ecf8f5; }
.negative-row .balance-cell { background: var(--debit-soft); }

.quick-entry {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: 130px 110px minmax(170px, 1.2fr) 120px 140px 125px minmax(150px, 1fr) auto;
}

.edit-form, .login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 auto;
  max-width: 760px;
  padding: 22px;
}

.login-panel {
  grid-template-columns: 1fr;
  max-width: 420px;
  width: 100%;
}

.login-panel > div { margin-bottom: 8px; }
.login-panel .form-grid { display: grid; gap: 14px; }

label {
  color: #2b3832;
  display: grid;
  font-size: .8rem;
  font-weight: 750;
  gap: 5px;
}

.check-control {
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  display: flex;
  font-size: .82rem;
  gap: 7px;
  min-height: 38px;
  padding: 7px 9px;
}

.check-control input {
  min-height: auto;
  width: auto;
}

[hidden] { display: none !important; }

input, select, textarea {
  background: white;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 7px 9px;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
  outline: none;
}

.span-2 { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.entries-table table { min-width: 780px; }
.type-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: .72rem;
  font-weight: 850;
  padding: 4px 7px;
}
.type-badge.credit { background: var(--credit-soft); color: var(--credit); }
.type-badge.debit { background: var(--debit-soft); color: var(--debit); }

.row-actions {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions form { display: inline-flex; }

.forecast-scroll {
  overflow-x: auto;
  padding-bottom: 8px;
}

.forecast-chart {
  align-items: end;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(36, 58px);
  height: 370px;
  min-width: max-content;
  padding: 14px 8px 0;
}

.forecast-column {
  display: grid;
  grid-template-rows: 40px 270px 24px;
  height: 100%;
  text-align: center;
}

.forecast-value {
  font-size: .68rem;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.forecast-bar-area {
  align-items: end;
  border-bottom: 1px solid var(--line-strong);
  display: flex;
  justify-content: center;
}

.forecast-bar {
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  width: 32px;
}

.positive-bar { background: #34a853; }
.negative-bar { background: #dc554b; }
.forecast-label { color: var(--muted); font-size: .68rem; padding-top: 5px; }

.planning-settings {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(140px, 1fr)) auto;
}

.percent-input { display: flex; }
.percent-input input { border-radius: 5px 0 0 5px; }
.percent-input span {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line-strong);
  border-left: 0;
  border-radius: 0 5px 5px 0;
  display: flex;
  padding: 0 10px;
}

.planning-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.planning-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 18px;
}

.planning-card-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.planning-card-head span { color: var(--muted); font-size: .78rem; font-weight: 850; }
.planning-card-head strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }

.planning-progress {
  background: #e9efec;
  border-radius: 999px;
  height: 9px;
  margin: 18px 0;
  overflow: hidden;
}

.planning-progress i { display: block; height: 100%; }
.planning-card.essential .planning-progress i { background: #0f766e; }
.planning-card.leisure .planning-progress i { background: #c2410c; }
.planning-card.investment .planning-progress i { background: #2563eb; }

.planning-card dl { display: grid; gap: 9px; margin: 0; }
.planning-card dl div { display: flex; justify-content: space-between; }
.planning-card dt { color: var(--muted); }
.planning-card dd { font-weight: 750; margin: 0; }

.flash {
  border: 1px solid transparent;
  border-radius: 6px;
  margin-bottom: 14px;
  padding: 10px 12px;
}
.flash.success { background: var(--credit-soft); border-color: #bbf7d0; color: #14532d; }
.flash.error { background: var(--debit-soft); border-color: #fecaca; color: #7f1d1d; }

.empty { text-align: center; }
pre {
  background: #111827;
  border-radius: 6px;
  color: white;
  overflow: auto;
  padding: 14px;
  text-align: left;
}

@media (max-width: 1050px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-entry { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .description-field, .notes-field { grid-column: auto; }
  .planning-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .app-header {
    gap: 10px;
    grid-template-columns: 1fr auto;
    padding: 10px 14px;
  }
  .app-header nav { grid-column: 1 / -1; grid-row: 2; }
  .account-menu span { display: none; }
  .app-main { padding: 14px; }
  .page-head, .section-head {
    align-items: stretch;
    flex-direction: column;
  }
  .month-filter { align-items: stretch; }
  .month-filter input { flex: 1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .quick-entry, .edit-form { grid-template-columns: 1fr; }
  .planning-settings { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .opening-balance form {
    left: 0;
    right: auto;
    width: min(300px, calc(100vw - 60px));
  }
}
