:root {
  --background: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --text: #18221e;
  --muted: #66736d;
  --border: #dce4e0;
  --primary: #176b4d;
  --primary-dark: #10513a;
  --primary-soft: #e5f4ed;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(25, 60, 45, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 48px 20px;
  color: var(--text);
  background:
    radial-gradient(circle at top left, #e1f0e9 0, transparent 34rem),
    var(--background);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.app-container {
  width: min(100%, 960px);
  margin: 0 auto;
}

.page-header {
  margin-bottom: 32px;
}

.eyebrow,
.step-label {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 3.25rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.intro {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.dashboard-panel,
.income-panel,
.expense-panel,
.summary-section,
.category-panel,
.history-panel {
  padding: 28px;
  border: 1px solid rgba(220, 228, 224, 0.9);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dashboard-panel,
.income-panel,
.expense-panel {
  margin-bottom: 22px;
}

.category-panel,
.history-panel {
  margin-top: 22px;
}

.section-heading,
.summary-heading,
.dashboard-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.dashboard-heading {
  align-items: end;
}

.period-display {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.period-display strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
}

.dashboard-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 0.45fr);
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

.period-filter {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.period-filter legend {
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 700;
}

.filter-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}

.filter-option {
  position: relative;
  cursor: pointer;
}

.filter-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.filter-option span {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 750;
  text-align: center;
  transition:
    color 160ms ease,
    background 160ms ease;
}

.filter-option input:checked + span {
  color: #ffffff;
  background: var(--primary);
}

.filter-option input:focus-visible + span {
  outline: 3px solid rgba(23, 107, 77, 0.3);
  outline-offset: 2px;
}

.dashboard-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.dashboard-summary-card {
  min-width: 0;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.dashboard-summary-card p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.dashboard-summary-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.1rem, 3vw, 1.35rem);
}

.period-balance-card {
  border-color: #bfe0d1;
  background: var(--primary-soft);
}

.period-balance-card p,
.period-balance-card strong {
  color: var(--primary-dark);
}

.chart-section {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.chart-section h3 {
  margin: 0 0 14px;
  font-size: 1rem;
}

.chart-container {
  position: relative;
  height: 330px;
}

.chart-empty-state {
  display: grid;
  height: 100%;
  margin: 0;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.currency-badge {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 750;
}

.income-form,
.expense-form {
  display: grid;
  gap: 18px;
}

.income-fields,
.expense-fields {
  display: grid;
  gap: 18px;
}

.income-fields {
  grid-template-columns: 2fr 1fr 1fr;
}

.expense-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 700;
}

.form-control {
  width: 100%;
  min-height: 52px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: 0;
  color: var(--text);
  background: var(--surface-soft);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 107, 77, 0.12);
}

.form-control::placeholder {
  color: #97a39e;
}

select.form-control {
  cursor: pointer;
}

[aria-invalid="true"] {
  border-color: var(--danger);
}

.currency-input:has(input[aria-invalid="true"]) {
  border-color: var(--danger);
}

.currency-input {
  display: flex;
  align-items: center;
  min-height: 52px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.currency-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 107, 77, 0.12);
}

.currency-input > span {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-right: 1px solid var(--border);
  color: var(--primary);
  font-weight: 750;
}

.currency-input input {
  width: 100%;
  min-width: 0;
  padding: 13px 14px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.currency-input input::placeholder {
  color: #97a39e;
}

button {
  min-height: 52px;
  padding: 0 24px;
  border: 0;
  border-radius: 12px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 750;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

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

.edit-mode-message {
  margin: 0;
  padding: 11px 14px;
  border: 1px solid #bfe0d1;
  border-radius: 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.secondary-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface-soft);
}

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

[hidden] {
  display: none !important;
}

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

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 3px solid rgba(23, 107, 77, 0.3);
  outline-offset: 3px;
}

.validation-message {
  min-height: 24px;
  margin: 9px 0 -5px;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 650;
}

.summary-heading {
  align-items: end;
}

.summary-note {
  max-width: 280px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

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

.summary-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.summary-card p {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}

.summary-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  letter-spacing: -0.03em;
}

.remaining-card {
  border-color: #bfe0d1;
  background: var(--primary-soft);
}

.remaining-card p,
.remaining-card strong {
  color: var(--primary-dark);
}

.category-totals-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.category-total-card {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.category-total-card dt {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.category-total-card dd {
  min-width: 0;
  margin: 0;
  color: var(--primary-dark);
  font-weight: 750;
  overflow-wrap: anywhere;
  text-align: right;
}

.income-history-list,
.expense-history-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.income-history-panel {
  border-color: #bfe0d1;
}

.history-item,
.empty-state {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 28px;
  padding: 18px 20px;
}

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

.history-main h3 {
  margin: 0 0 7px;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.4;
}

.category-label {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.75rem;
  font-weight: 700;
}

.history-detail {
  min-width: 116px;
}

.history-detail p {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.history-detail strong,
.history-detail time {
  display: block;
  white-space: nowrap;
  font-size: 0.9rem;
}

.history-detail strong {
  color: var(--primary-dark);
}

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

.history-action-button {
  min-height: 38px;
  padding: 0 13px;
  font-size: 0.82rem;
}

.edit-button {
  border: 1px solid var(--border);
  color: var(--primary-dark);
  background: var(--surface);
}

.edit-button:hover {
  background: var(--primary-soft);
}

.delete-button {
  border: 1px solid #f0c5c1;
  color: var(--danger);
  background: #fff5f4;
}

.delete-button:hover {
  color: #ffffff;
  background: var(--danger);
}

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

@media (max-width: 700px) {
  body {
    padding: 32px 16px;
  }

  .dashboard-panel,
  .income-panel,
  .expense-panel,
  .summary-section,
  .category-panel,
  .history-panel {
    padding: 22px;
  }

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

  .dashboard-controls {
    grid-template-columns: 1fr;
  }

  .dashboard-summary-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .period-display {
    text-align: left;
  }

  .chart-container {
    height: 300px;
  }

  .category-totals-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .income-fields,
  .expense-fields {
    grid-template-columns: 1fr;
  }

  .summary-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .summary-note {
    text-align: left;
  }

  .history-item {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
  }

  .history-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  button {
    width: 100%;
  }

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

  .history-actions {
    grid-column: auto;
    justify-content: stretch;
  }

  .history-detail strong,
  .history-detail time {
    white-space: normal;
  }

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

  .filter-option span {
    padding-inline: 6px;
  }

  .chart-section {
    padding: 16px;
  }

  .chart-container {
    height: 270px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions button,
  .history-action-button {
    width: 100%;
  }
}

/* Application shell and navigation */
body {
  padding: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 100vh;
  padding: 24px 16px;
  color: #ffffff;
  background: #123f31;
  box-shadow: 8px 0 30px rgba(18, 63, 49, 0.12);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 13px;
  color: var(--primary-dark);
  background: #dff2e9;
  font-weight: 800;
}

.sidebar-brand strong,
.sidebar-brand div > span {
  display: block;
}

.sidebar-brand strong {
  line-height: 1.25;
}

.sidebar-brand div > span {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.67);
  font-size: 0.75rem;
}

.brand-mark svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-nav {
  display: grid;
  gap: 7px;
  margin-top: 22px;
}

.nav-link {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  font-size: 0.9rem;
  text-align: left;
}

.nav-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.09);
}

.nav-link.is-active {
  border-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
}

.nav-link:focus-visible {
  outline-color: #ffffff;
}

.nav-icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  min-height: 76px;
  align-items: center;
  gap: 14px;
  padding: 12px 28px;
  border-bottom: 1px solid rgba(220, 228, 224, 0.9);
  background: rgba(244, 247, 245, 0.94);
  backdrop-filter: blur(12px);
}

.topbar p {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.025em;
}

.sidebar-toggle {
  display: none;
  width: 44px;
  min-height: 44px;
  padding: 0;
  place-items: center;
  font-size: 1.3rem;
}

.sidebar-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.view-container {
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 30px 28px 112px;
}

.view-container > [data-view] {
  margin: 0 0 22px;
}

.sidebar-overlay {
  display: none;
}

.quick-add-container {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 70;
  display: grid;
  justify-items: end;
  gap: 12px;
}

.quick-add-button {
  position: relative;
  display: grid;
  width: 60px;
  min-height: 60px;
  padding: 0;
  place-items: center;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 12px 30px rgba(16, 81, 58, 0.3);
}

.quick-add-button::before,
.quick-add-button::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 2.5px;
  border-radius: 999px;
  background: #ffffff;
  content: "";
  transition: transform 160ms ease;
}

.quick-add-button::before {
  transform: translate(-50%, -50%);
}

.quick-add-button::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.quick-add-button[aria-expanded="true"]::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.quick-add-button[aria-expanded="true"]::after {
  transform: translate(-50%, -50%) rotate(135deg);
}

.quick-add-menu {
  display: grid;
  min-width: 190px;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 16px 40px rgba(24, 34, 30, 0.18);
}

.quick-add-menu button {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 13px;
  color: var(--text);
  background: transparent;
  font-size: 0.88rem;
  text-align: left;
}

.quick-add-menu button:hover {
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.quick-add-menu button svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  color: var(--primary);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 800px) {
  body {
    padding: 0;
  }

  body.navigation-open {
    overflow: hidden;
  }

  body.navigation-open .quick-add-container {
    z-index: 30;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    width: min(84vw, 280px);
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 200ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: grid;
    width: 44px;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    display: block;
    width: 100%;
    min-height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(8, 24, 18, 0.48);
    cursor: default;
  }

  .topbar {
    padding: 10px 16px;
  }

  .view-container {
    padding: 22px 16px 110px;
  }

  .quick-add-container {
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
  }

  .quick-add-button {
    width: 58px;
    min-height: 58px;
  }
}
