:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #202521;
  --muted: #68736b;
  --line: #dde3dc;
  --green: #1f8a5b;
  --green-soft: #dff2e8;
  --red: #c64b4b;
  --red-soft: #f8e3e3;
  --amber: #b8781f;
  --amber-soft: #f8ecd8;
  --blue: #316e9f;
  --blue-soft: #dfecf6;
  --shadow: 0 18px 45px rgba(39, 49, 43, 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;
}

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

button {
  cursor: pointer;
}

a {
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 278px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  background: #1f2a24;
  color: #f9fbf7;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f4dc;
  color: #1f2a24;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: #b9c7bd;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dce7df;
  text-align: left;
  padding: 0 14px;
}

.nav-item:hover,
.nav-item.active {
  background: #314039;
  border-color: #4a5b52;
  color: #ffffff;
}

.sidebar-panel {
  margin-top: auto;
  padding: 16px;
  border: 1px solid #405047;
  border-radius: 8px;
  display: grid;
  gap: 10px;
}

.sidebar-panel span {
  color: #c8d5cd;
  font-size: 13px;
}

.sidebar-panel input {
  width: 100%;
  border: 1px solid #53645b;
  border-radius: 8px;
  background: #18221d;
  color: #ffffff;
  padding: 10px;
}

.content {
  min-width: 0;
  padding: 28px clamp(18px, 2.5vw, 36px);
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 30px;
}

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

.ghost-btn,
.danger-btn,
.primary-btn,
.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
}

.primary-btn {
  border-color: #1f704f;
  background: var(--green);
  color: #ffffff;
  font-weight: 700;
}

.danger-btn {
  border-color: #e4b7b7;
  background: #fff4f4;
  color: #a73333;
}

.link-btn {
  min-height: 32px;
  color: var(--green);
  border: 0;
  background: transparent;
  padding: 0;
}

.file-btn {
  display: inline-grid;
  place-items: center;
}

.file-btn input {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

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

.summary-card {
  padding: 18px;
  display: grid;
  gap: 8px;
  min-height: 136px;
}

.summary-card span,
.summary-card small {
  color: var(--muted);
}

.summary-card strong {
  font-size: 26px;
  overflow-wrap: anywhere;
}

.summary-card.income {
  border-top: 5px solid var(--green);
}

.summary-card.expense {
  border-top: 5px solid var(--red);
}

.summary-card.balance {
  border-top: 5px solid var(--blue);
}

.summary-card.debt {
  border-top: 5px solid var(--amber);
}

.summary-card.receivable {
  border-top: 5px solid #4b8f8c;
}

.summary-card.saving {
  border-top: 5px solid #6f63c7;
}

.dashboard-grid,
.work-grid,
.report-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.panel,
.form-panel {
  padding: 18px;
}

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

.panel-header h3,
.form-panel h3 {
  margin: 0;
  font-size: 18px;
}

.panel-header span {
  color: var(--muted);
  font-size: 14px;
}

.meter {
  height: 14px;
  border-radius: 999px;
  background: #eef2ef;
  overflow: hidden;
}

.meter div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 0.2s ease;
}

.chart {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: end;
  gap: 10px;
  height: 210px;
  margin-top: 22px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.bar {
  display: grid;
  align-items: end;
  gap: 6px;
  height: 100%;
}

.bar-fill {
  max-height: 100%;
  min-height: 6px;
  border-radius: 8px 8px 0 0;
  background: var(--green);
}

.bar.expense .bar-fill {
  background: var(--red);
}

.bar.saving .bar-fill {
  background: #6f63c7;
}

.bar-label {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.form-panel {
  align-self: start;
  display: grid;
  gap: 12px;
}

.form-panel input,
.form-panel select,
.form-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fbfcfa;
  color: var(--ink);
}

.form-panel textarea {
  min-height: 92px;
  resize: vertical;
}

.data-list,
.compact-list,
.breakdown,
.report-summary,
.filter-panel {
  display: grid;
  gap: 10px;
}

.data-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.row-main {
  min-width: 0;
}

.row-main strong {
  display: block;
  overflow-wrap: anywhere;
}

.row-main span,
.row-main small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.row-side {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.amount {
  font-weight: 800;
}

.actions {
  display: flex;
  gap: 8px;
}

.inline-form {
  margin: 0;
}

.mini-btn {
  min-width: 34px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.row-main .status {
  display: inline-flex;
  width: fit-content;
}

.status.good {
  background: var(--green-soft);
  color: #13613e;
}

.status.warn {
  background: var(--amber-soft);
  color: #81500e;
}

.status.bad {
  background: var(--red-soft);
  color: #973636;
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.report-item,
.breakdown-row {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

.breakdown-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: #edf1ee;
  overflow: hidden;
}

.progress div {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.compact-progress {
  margin-top: 8px;
  max-width: 360px;
}

.saving-preview {
  display: grid;
  gap: 5px;
  border: 1px solid var(--blue-soft);
  border-radius: 8px;
  background: #f3f8fc;
  color: var(--muted);
  padding: 12px;
  line-height: 1.4;
}

.saving-preview strong {
  color: var(--ink);
}

.saving-preview span {
  display: block;
}

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

.category-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.category-box h4 {
  margin: 0 0 10px;
}

.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 9px;
}

.debt-history {
  margin-top: 10px;
}

.debt-history summary {
  width: fit-content;
  color: var(--green);
  cursor: pointer;
  font-weight: 700;
}

.history-row {
  display: grid;
  gap: 3px;
  border-left: 3px solid var(--line);
  margin-top: 8px;
  padding: 8px 0 8px 10px;
}

.history-row span {
  color: var(--ink);
  font-weight: 700;
}

.history-row.payment {
  border-left-color: var(--green);
}

.history-row.withdrawal {
  border-left-color: var(--red);
}

.inline-pay-form {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) minmax(160px, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.inline-pay-form input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
}

.filter-panel {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 16px;
}

.filter-panel .primary-btn {
  align-self: end;
}

.filter-panel [hidden] {
  display: none;
}

.filter-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.filter-panel input,
.filter-panel select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fbfcfa;
  color: var(--ink);
}

@media (max-width: 1060px) {
  .dashboard-grid,
  .work-grid,
  .report-layout,
  .filter-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    background: #ffffff;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
    gap: 14px;
    border-radius: 0 0 18px 18px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .nav-item {
    justify-content: center;
    min-height: 44px;
    padding: 0 10px;
    text-align: center;
    font-size: 14px;
  }

  .sidebar-panel {
    margin-top: 0;
    padding: 12px;
  }

  .content {
    padding: 16px;
  }

  .topbar,
  .data-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
    margin-bottom: 16px;
  }

  .topbar h2 {
    font-size: 26px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .summary-card,
  .panel,
  .form-panel {
    box-shadow: none;
  }

  .summary-card {
    min-height: 112px;
    padding: 16px;
  }

  .dashboard-grid,
  .work-grid,
  .report-layout,
  .category-grid {
    gap: 12px;
    margin-top: 12px;
  }

  .data-row {
    grid-template-columns: 1fr;
  }

  .row-side {
    justify-items: start;
  }

  .chart {
    height: 180px;
    gap: 7px;
  }

  .bar-label {
    font-size: 11px;
  }

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

  .inline-pay-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .brand h1 {
    font-size: 16px;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  .nav-item {
    font-size: 13px;
  }

  .panel,
  .form-panel {
    padding: 14px;
  }

  .report-item,
  .breakdown-top {
    grid-template-columns: 1fr;
  }

  .breakdown-top {
    display: grid;
  }
}

@media print {
  .sidebar,
  .topbar-actions,
  .form-panel,
  .nav-list {
    display: none !important;
  }

  .app-shell,
  .content,
  .report-layout {
    display: block;
  }

  .content {
    padding: 0;
  }
}

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

.auth-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-brand {
  color: var(--ink);
  margin-bottom: 22px;
}

.auth-brand p {
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form input,
.auth-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.auth-link {
  width: 100%;
  margin-top: 12px;
}

.auth-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 18px 0 0;
}

.alert {
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  line-height: 1.4;
}

.alert.error {
  background: var(--red-soft);
  color: #973636;
}

.alert.success {
  background: var(--green-soft);
  color: #13613e;
}
