:root {
  color-scheme: light;
  --bg: #f4f5f0;
  --panel: #ffffff;
  --ink: #1c211d;
  --muted: #657066;
  --line: #dfe4dc;
  --accent: #24745a;
  --accent-dark: #17513e;
  --warning: #b95b22;
  --danger: #b52f2f;
  --positive: #16623f;
  --shadow: 0 12px 30px rgba(34, 44, 36, 0.08);
}

* {
  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;
}

body.is-locked {
  overflow: hidden;
}

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

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(244, 245, 240, 0.96);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 6px;
  font-size: 1.8rem;
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 800;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(16px, 4vw, 48px) 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
}

h2 {
  font-size: 1rem;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 48px) 40px;
}

.status-pill {
  min-width: 86px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.summary-card {
  min-height: 108px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.summary-card span,
.panel-header span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.summary-card strong {
  font-size: clamp(1.25rem, 2vw, 2rem);
}

.workspace {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

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

.settings-panel .form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(36, 116, 90, 0.15);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
}

.month-income-toggle {
  padding-bottom: 8px;
  white-space: nowrap;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  align-self: end;
  background: var(--accent);
  color: #fff;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-button:hover {
  background: #eef2ec;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.ghost-button {
  background: #eef2ec;
  color: var(--ink);
}

.danger-button {
  background: #f7e7e7;
  color: var(--danger);
}

.lists {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 18px;
  margin-top: 18px;
}

.month-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.month-toolbar > div {
  display: flex;
  align-items: end;
  gap: 14px;
}

.month-state {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfa;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
}

.list-tools {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 220px);
  gap: 12px;
  margin-bottom: 14px;
}

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

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

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td:last-child,
th:last-child {
  width: 132px;
  text-align: right;
}

.money-income {
  color: var(--positive);
  font-weight: 800;
}

.money-expense {
  color: var(--danger);
  font-weight: 800;
}

.installment-badge {
  display: block;
  width: max-content;
  max-width: 100%;
  margin-top: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2ec;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.forecast-panel {
  margin-top: 18px;
}

.ai-panel {
  margin-top: 18px;
}

.ai-question-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

.aggregate-area {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.aggregate-form {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 14px;
}

.aggregate-result {
  display: grid;
  gap: 12px;
}

.aggregate-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.aggregate-summary span,
.ai-meta {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.ai-response {
  min-height: 90px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  white-space: pre-wrap;
  line-height: 1.5;
}

.ai-chat {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.ai-message {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-question {
  color: var(--ink);
  font-weight: 800;
}

.ai-answer {
  color: var(--ink);
  white-space: pre-wrap;
  line-height: 1.5;
}

.chart-panel {
  margin-top: 18px;
}

.category-chart {
  display: grid;
  gap: 12px;
}

.category-row {
  display: grid;
  gap: 7px;
}

.category-label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.9rem;
}

.category-label span {
  color: var(--muted);
  font-weight: 800;
}

.category-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2ec;
}

.category-bar {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--accent);
}

.empty-chart {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.modal {
  width: min(440px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(28, 33, 29, 0.45);
}

.modal-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

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

.forecast-item {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
  display: grid;
  gap: 8px;
}

.forecast-item h3 {
  margin: 0;
  font-size: 0.95rem;
}

.forecast-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.forecast-total {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-weight: 900;
}

@media (max-width: 1180px) {
  .summary-grid,
  .month-toolbar,
  .workspace,
  .lists,
  .forecast-grid,
  .aggregate-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-panel .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .month-toolbar,
  .month-toolbar > div,
  .ai-question-form,
  .category-label,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .workspace,
  .lists,
  .list-tools,
  .forecast-grid,
  .aggregate-form,
  .form-grid,
  .settings-panel .form-grid {
    grid-template-columns: 1fr;
  }

  td:last-child,
  th:last-child {
    width: 118px;
  }

  .panel {
    padding: 14px;
  }
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: #fff;
    color: #111;
  }

  .topbar,
  main {
    padding-left: 0;
    padding-right: 0;
  }

  .top-actions,
  .workspace,
  .row-actions,
  .login-screen,
  .status-pill {
    display: none !important;
  }

  .summary-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .lists {
    grid-template-columns: 1fr;
  }

  .forecast-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .summary-card,
  .panel,
  .forecast-item {
    box-shadow: none;
    break-inside: avoid;
  }

  td:last-child,
  th:last-child {
    display: none;
  }
}
