:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #20242a;
  --muted: #6a717c;
  --line: #ded7cb;
  --soft-line: #ece5da;
  --green: #167a5b;
  --green-soft: #d9f3e9;
  --red: #b94747;
  --red-soft: #f6dfdc;
  --blue: #2f6f9f;
  --blue-soft: #dcebf7;
  --yellow: #b47d13;
  --yellow-soft: #f9edcf;
  --violet: #6c5aa8;
  --ink: #14213d;
  --shadow: 0 18px 55px rgba(33, 36, 42, 0.12);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #171717;
  --surface: #222221;
  --surface-strong: #292927;
  --text: #f4f1ea;
  --muted: #b8b1a8;
  --line: #3a3935;
  --soft-line: #2f2e2b;
  --green-soft: rgba(38, 170, 124, 0.18);
  --red-soft: rgba(212, 89, 89, 0.18);
  --blue-soft: rgba(65, 143, 198, 0.18);
  --yellow-soft: rgba(227, 171, 55, 0.18);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(22, 122, 91, 0.08), transparent 35%),
    linear-gradient(315deg, rgba(180, 125, 19, 0.1), transparent 40%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0;
}

.hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

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

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

.auth-panel {
  display: grid;
  gap: 18px;
  width: min(100%, 430px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--soft-line);
}

.auth-panel h1 {
  margin: 4px 0 0;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.05;
}

.auth-form {
  display: grid;
  gap: 13px;
  padding: 0;
}

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

.auth-form label span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(185, 71, 71, 0.3);
  border-radius: var(--radius);
  background: var(--red-soft);
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 750;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.82);
  backdrop-filter: blur(18px);
}

body.dark .sidebar {
  background: rgba(34, 34, 33, 0.85);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.brand-mark svg {
  width: 27px;
  height: 27px;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 1.05rem;
}

.brand span {
  max-width: 160px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.3;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.nav-item.active {
  box-shadow: 0 10px 24px rgba(33, 36, 42, 0.08);
}

.sidebar-card {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.sidebar-card strong,
.sidebar-card small {
  display: block;
}

.sidebar-card strong {
  margin-top: 5px;
  font-size: 0.95rem;
}

.sidebar-card small {
  margin-top: 8px;
  color: var(--muted);
}

.meter {
  overflow: hidden;
  height: 9px;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--soft-line);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #49b88f);
  transition: width 300ms ease;
}

.main {
  display: grid;
  gap: 22px;
  align-content: start;
  padding: 26px;
}

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

.topbar h1,
.panel h2,
.modal-head h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

.topbar h1 {
  margin-top: 4px;
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.tiny-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.data-status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 850;
  white-space: nowrap;
}

.data-status.online {
  border-color: rgba(22, 122, 91, 0.26);
  background: var(--green-soft);
  color: var(--green);
}

.data-status.offline {
  border-color: var(--line);
}

.primary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: var(--radius);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.primary-button {
  gap: 9px;
  padding: 0 15px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
}

.ghost-button {
  padding: 0 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 750;
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.primary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(33, 36, 42, 0.12);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 22px;
}

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

.summary-card {
  min-height: 146px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  box-shadow: 0 12px 28px rgba(33, 36, 42, 0.07);
}

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

.summary-card strong {
  display: block;
  margin-top: 16px;
  font-size: clamp(1.45rem, 2.8vw, 2.15rem);
  line-height: 1;
}

.summary-card small {
  margin-top: 14px;
}

.accent-green {
  border-top: 4px solid var(--green);
}

.accent-red {
  border-top: 4px solid var(--red);
}

.accent-blue {
  border-top: 4px solid var(--blue);
}

.accent-yellow {
  border-top: 4px solid var(--yellow);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.86fr) minmax(360px, 1.14fr);
  gap: 22px;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 34px rgba(33, 36, 42, 0.08);
}

.panel-head,
.filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 17px;
}

.panel h2,
.modal-head h2 {
  margin-top: 4px;
  font-size: 1.15rem;
}

select,
input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  outline: none;
}

select {
  padding: 0 36px 0 12px;
}

input {
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 159, 0.16);
}

.chart-panel {
  position: relative;
}

.chart-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 294px;
}

#expenseChart {
  width: min(100%, 310px);
  max-width: 310px;
  aspect-ratio: 1;
}

.chart-center {
  position: absolute;
  display: grid;
  place-items: center;
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.chart-center span {
  color: var(--muted);
  font-size: 0.78rem;
}

.chart-center strong {
  max-width: 110px;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: 1rem;
}

.legend {
  display: grid;
  gap: 9px;
  margin-top: 8px;
}

.legend-row,
.transaction-item,
.budget-card,
.card-tile {
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.legend-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 0.88rem;
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

.legend-row strong {
  color: var(--text);
  font-size: 0.9rem;
}

.transaction-list {
  display: grid;
  gap: 10px;
}

.transaction-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px;
}

.transaction-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
}

.transaction-icon.expense {
  background: var(--red-soft);
  color: var(--red);
}

.transaction-icon.income {
  background: var(--green-soft);
  color: var(--green);
}

.transaction-title {
  min-width: 0;
}

.transaction-title strong,
.transaction-title small {
  display: block;
}

.transaction-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-title small {
  margin-top: 4px;
  color: var(--muted);
}

.amount {
  font-weight: 850;
  text-align: right;
}

.amount.expense {
  color: var(--red);
}

.amount.income {
  color: var(--green);
}

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

.budget-card,
.card-tile {
  padding: 15px;
}

.budget-card header,
.card-tile header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.budget-card h3,
.card-tile h3 {
  margin: 0;
  font-size: 1rem;
}

.budget-card p,
.card-tile p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.budget-progress {
  margin-top: 16px;
}

.budget-progress .meter {
  margin-top: 8px;
}

.budget-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.84rem;
}

.status-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 850;
  white-space: nowrap;
}

.status-pill.warning {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.status-pill.danger {
  background: var(--red-soft);
  color: var(--red);
}

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

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

th,
td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--soft-line);
  text-align: left;
}

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

td {
  color: var(--text);
}

.align-right {
  text-align: right;
}

.row-actions {
  width: 68px;
  text-align: right;
}

.delete-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--red);
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--soft-line);
  font-size: 0.86rem;
}

.budget-board {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.card-tile {
  min-height: 210px;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 40%),
    var(--card-bg, #14213d);
}

.card-tile p,
.card-tile .tiny-label {
  color: rgba(255, 255, 255, 0.76);
}

.card-number {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 42px;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.card-total {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}

.card-total strong {
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}

dialog {
  width: min(94vw, 560px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(20, 33, 61, 0.42);
  backdrop-filter: blur(4px);
}

form {
  padding: 18px;
}

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft-line);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 850;
}

.segmented input:checked + span {
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(33, 36, 42, 0.08);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
  margin-top: 16px;
}

.form-grid label {
  display: grid;
  gap: 7px;
}

.form-grid label span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.modal-actions {
  justify-content: space-between;
  margin-top: 18px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .summary-grid,
  .budget-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-grid,
  .budget-board,
  .cards-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand,
  .sidebar-card {
    display: none;
  }

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

  .nav-item {
    justify-content: center;
    min-height: 48px;
    padding: 0;
  }

  .nav-item span {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .topbar,
  .panel-head,
  .filters-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .filters {
    width: 100%;
  }

  .top-actions .primary-button,
  .top-actions .ghost-button,
  .filters input,
  .filters select {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .summary-grid,
  .budget-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .filters,
  .modal-actions {
    flex-wrap: wrap;
  }

  .primary-button span {
    white-space: nowrap;
  }

  .transaction-item {
    grid-template-columns: auto 1fr;
  }

  .transaction-item .amount {
    grid-column: 2;
    text-align: left;
  }
}
