:root {
  --bg: #f5f6f2;
  --panel: #ffffff;
  --ink: #17201d;
  --muted: #68736f;
  --line: #dfe5dd;
  --soft: #eef2ec;
  --primary: #0f766e;
  --primary-dark: #0b5f58;
  --good: #167446;
  --bad: #b42318;
  --warn: #a16207;
  --shadow: 0 12px 30px rgba(24, 32, 29, 0.07);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #b9c6bf;
}

.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.primary:hover {
  background: var(--primary-dark);
}

.danger {
  color: var(--bad);
}

.ghost {
  background: transparent;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  background: rgba(245, 246, 242, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  font-weight: 800;
  font-size: 20px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab {
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--muted);
}

.tab.active,
.tab:hover {
  background: #e6ece6;
  color: var(--ink);
}

.sync {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

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

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: 31px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

p {
  margin: 7px 0 0;
  color: var(--muted);
}

.panel,
.metric,
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  min-width: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.day-metrics {
  margin-bottom: 14px;
}

.metric {
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 24px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(420px, 0.85fr);
  gap: 14px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 14px;
}

.chart-wrap {
  height: 360px;
}

.chart {
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

.axis,
.grid-line {
  stroke: #d7ddd6;
  stroke-width: 1;
}

.balance-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.4;
}

.zero-line {
  stroke: var(--bad);
  stroke-width: 1.4;
  stroke-dasharray: 5 5;
}

.negative-band {
  fill: rgba(180, 35, 24, 0.1);
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
}

input[type="checkbox"] {
  min-height: 0;
  width: 18px;
  height: 18px;
}

.table-wrap {
  overflow: auto;
  width: 100%;
  max-height: 560px;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

.day-table {
  min-width: 980px;
}

.compact-table {
  min-width: 0;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
}

td input,
td select {
  width: 100%;
  min-width: 95px;
}

.date-cell {
  min-width: 138px;
  white-space: nowrap;
}

.date-cell strong {
  display: block;
  font-variant-numeric: tabular-nums;
}

.date-cell span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}

.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.positive {
  color: var(--good);
}

.negative {
  color: var(--bad);
}

.weekend {
  background: #f7f3ea;
}

.holiday {
  background: #fff1ef;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  margin: 1px 4px 1px 0;
}

.month-summary {
  display: grid;
  gap: 2px;
  margin-top: 12px;
}

.month-row {
  display: grid;
  grid-template-columns: 80px repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.month-name {
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.month-value {
  display: grid;
  gap: 2px;
  min-width: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.month-value span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.month-value strong {
  font-size: 13px;
  white-space: nowrap;
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

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

.bank-grid {
  margin-bottom: 14px;
}

.bank-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.bank-status div,
.bank-foot {
  background: #f8faf7;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.bank-status span,
.bank-foot span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.bank-status strong,
.bank-foot strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.steps {
  margin: 12px 0 0;
  padding-left: 22px;
  color: var(--muted);
}

.steps li {
  margin: 8px 0;
}

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

.bank-form {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) auto minmax(0, 1.3fr) auto;
  gap: 10px;
  align-items: end;
}

.bank-form input,
.bank-form select {
  width: 100%;
}

.bank-foot {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
}

.login-card h1 {
  font-size: 34px;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.error {
  color: var(--bad);
  background: #fff1ef;
  border: 1px solid #ffd1cb;
  border-radius: 7px;
  padding: 9px 10px;
}

.success {
  color: var(--good);
  background: #edf8f1;
  border: 1px solid #c8ead4;
  border-radius: 7px;
  padding: 9px 10px;
}

code {
  background: #eef2ec;
  border-radius: 4px;
  padding: 1px 4px;
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

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

@media (max-width: 1080px) {
  .topbar,
  .grid,
  .metrics,
  .settings-grid,
  .bank-status,
  .bank-cards,
  .bank-form,
  .bank-foot {
    grid-template-columns: 1fr;
  }

  .sync {
    justify-content: start;
  }
}

@media (max-width: 640px) {
  main,
  .topbar {
    padding: 16px;
  }

  .page-head {
    display: grid;
    align-items: start;
  }

  h1 {
    font-size: 26px;
  }

  .chart-wrap {
    height: 280px;
  }

  .metric strong {
    font-size: 22px;
  }

  .month-row {
    grid-template-columns: 74px 1fr 1fr;
    gap: 8px;
  }

  .month-value {
    text-align: left;
  }

  .month-value:last-child {
    grid-column: 2 / 4;
  }
}
