@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap");

:root {
  --bg: #f7f2ea;
  --bg-accent: #fff7e1;
  --card: #ffffff;
  --text: #1f1b16;
  --muted: #6f6258;
  --border: rgba(31, 27, 22, 0.15);
  --accent: #d46a41;
  --accent-strong: #b5502b;
  --button-text: #ffffff;
  --error: #c0352b;
  --success: #2f7d32;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --shadow-card: 0 12px 30px rgba(31, 27, 22, 0.12);
  --shadow-soft: 0 8px 20px rgba(31, 27, 22, 0.1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  background:
    radial-gradient(1200px 600px at 10% -20%, rgba(212, 106, 65, 0.2), transparent 60%),
    radial-gradient(800px 500px at 90% 0%, rgba(31, 27, 22, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg-accent), var(--bg));
}

.page {
  min-height: 100vh;
  padding: var(--space-6) var(--space-5) var(--space-7);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-width: 560px;
  margin: 0 auto;
  animation: fade-up 0.5s ease;
}

.header {
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid rgba(31, 27, 22, 0.1);
  box-shadow: var(--shadow-card);
}

.header h1 {
  margin: 0 0 var(--space-1);
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.forbidden-card {
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--border);
  text-align: center;
  font-size: 16px;
}

.form-section {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(31, 27, 22, 0.08);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  background: rgba(31, 27, 22, 0.08);
  padding: var(--space-2);
  border-radius: var(--radius-lg);
}

.entry-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  background: rgba(31, 27, 22, 0.06);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.tab-button {
  border: none;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.entry-tab {
  border: none;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab-button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 6px 14px rgba(31, 27, 22, 0.12);
}

.entry-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 6px 14px rgba(31, 27, 22, 0.1);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  font-size: 14px;
  color: var(--muted);
}

.field span {
  text-transform: none;
  letter-spacing: 0.4px;
  font-size: 12px;
  font-weight: 600;
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: #fffaf3;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}

.date-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

.today-button {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background: #fffaf3;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.date-row input {
  flex: 1 1 180px;
  min-width: 0;
}

.today-button:focus-visible {
  outline: 2px solid rgba(212, 106, 65, 0.6);
  outline-offset: 2px;
}

.input-wrap input {
  border: none;
  padding: 0;
  background: transparent;
  flex: 1;
  font-size: 16px;
  color: var(--text);
}

.input-wrap input:focus {
  outline: none;
}

.input-wrap:focus-within {
  outline: 2px solid rgba(212, 106, 65, 0.35);
  border-color: rgba(212, 106, 65, 0.6);
}

.input-suffix {
  font-size: 16px;
  color: var(--muted);
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

input {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 16px;
  color: var(--text);
  background: #fffaf3;
}

textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 15px;
  color: var(--text);
  background: #fffaf3;
  resize: vertical;
  min-height: 72px;
  font-family: inherit;
}

input:focus {
  outline: 2px solid rgba(212, 106, 65, 0.35);
  border-color: rgba(212, 106, 65, 0.6);
}

textarea:focus {
  outline: 2px solid rgba(212, 106, 65, 0.35);
  border-color: rgba(212, 106, 65, 0.6);
}

.input-wrap input {
  border: none;
  padding: 0;
  background: transparent;
}

.input-wrap input:focus {
  outline: none;
  border-color: transparent;
}

.error {
  min-height: 18px;
  font-size: 12px;
  color: var(--error);
}

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: rgba(192, 53, 43, 0.12);
  border: 1px solid rgba(192, 53, 43, 0.3);
  color: var(--error);
  margin-bottom: var(--space-3);
  font-size: 14px;
}

#income-save,
#expense-save {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border: none !important;
  background: var(--accent) !important;
  color: var(--button-text) !important;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
}

#income-save:disabled,
#expense-save:disabled {
  cursor: not-allowed;
  background: rgba(212, 106, 65, 0.45) !important;
  transform: none;
}

#income-save:focus,
#income-save:focus-visible,
#income-save:hover,
#expense-save:focus,
#expense-save:focus-visible,
#expense-save:hover {
  background: var(--accent) !important;
  color: var(--button-text) !important;
}

#income-save:focus,
#expense-save:focus {
  outline: none;
}

#income-save:not(:disabled):active,
#expense-save:not(:disabled):active {
  transform: translateY(1px);
  background: var(--accent-strong) !important;
}

.success {
  margin-top: var(--space-3);
  color: var(--success);
  font-size: 14px;
}

.stats-card,
.stats-section {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  border: 1px solid rgba(31, 27, 22, 0.08);
  box-shadow: var(--shadow-soft);
  position: relative;
}

.history-section {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  border: 1px solid rgba(31, 27, 22, 0.08);
  box-shadow: var(--shadow-soft);
}

.history-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.history-filters {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: var(--space-4);
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  min-width: 140px;
}

.filter-field input,
.filter-field select {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  appearance: none;
}

.filter-field input:focus,
.filter-field select:focus {
  outline: none;
  border-color: rgba(212, 106, 65, 0.7);
  box-shadow: 0 0 0 2px rgba(212, 106, 65, 0.2);
}

.button-outline {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.button-outline:hover,
.button-outline:focus-visible {
  border-color: rgba(212, 106, 65, 0.7);
  background: rgba(212, 106, 65, 0.08);
  outline: none;
}

.button-outline:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.history-page {
  font-size: 13px;
  color: var(--muted);
}

.history-list {
  display: grid;
  gap: var(--space-3);
}

.history-row {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: #fffaf3;
}

.history-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.history-title {
  font-size: 15px;
  font-weight: 600;
}

.history-meta {
  font-size: 12px;
  color: var(--muted);
}

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

.history-amount {
  font-size: 16px;
  font-weight: 600;
  color: var(--success);
}

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

.history-comment {
  font-size: 13px;
  color: var(--muted);
}

.history-loading {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.history-skeleton {
  height: 56px;
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    rgba(31, 27, 22, 0.06),
    rgba(31, 27, 22, 0.12),
    rgba(31, 27, 22, 0.06)
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

.history-empty {
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: 14px;
}

.calendar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 27, 22, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  z-index: 50;
}

.calendar-card {
  width: min(360px, 100%);
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  border: 1px solid rgba(31, 27, 22, 0.08);
  box-shadow: 0 14px 30px rgba(31, 27, 22, 0.18);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.calendar-title {
  font-size: 15px;
  font-weight: 600;
}

.calendar-nav {
  border: 1px solid var(--border);
  background: #fffaf3;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: 14px;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-2);
}

.calendar-day {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-2) 0;
  text-align: center;
  font-size: 13px;
  cursor: pointer;
  background: #fffaf3;
}

.calendar-day.muted {
  opacity: 0.35;
  cursor: default;
}

.calendar-day.today {
  border-color: rgba(212, 106, 65, 0.6);
}

.calendar-day.selected {
  background: var(--accent);
  color: var(--button-text);
  border-color: rgba(212, 106, 65, 0.7);
}

.calendar-day:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.calendar-day:focus-visible {
  outline: 2px solid rgba(212, 106, 65, 0.6);
  outline-offset: 2px;
}

.calendar-close {
  margin-top: var(--space-4);
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background: rgba(31, 27, 22, 0.08);
  color: var(--text);
  cursor: pointer;
}

.stats-today-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: var(--space-4) var(--space-5);
  border: 1px solid rgba(31, 27, 22, 0.08);
  box-shadow: var(--shadow-soft);
}

.stats-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.stats-scroll-hint {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: var(--space-3);
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: var(--space-2) var(--space-4);
  background: #fffaf3;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  border-color: rgba(212, 106, 65, 0.7);
  color: var(--text);
  box-shadow: 0 6px 12px rgba(212, 106, 65, 0.12);
}

.stats-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-3);
}

.stats-today {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  margin: 0;
}

.stats-today span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.stats-today strong {
  font-size: 22px;
}

.stats-today-count {
  font-size: 13px;
  color: var(--muted);
}

.stats-total span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.stats-total strong {
  font-size: 28px;
  letter-spacing: 0.5px;
}

.stats-hint {
  font-size: 12px;
  color: var(--muted);
}

.stats-chart {
  width: 100%;
  min-height: 160px;
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding-bottom: var(--space-5);
  min-width: 100%;
}

.stats-chart-wrap {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-2);
}

.stats-loading {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-2);
  height: 160px;
  margin-bottom: var(--space-2);
  align-items: flex-end;
}

.skeleton-bar {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    rgba(31, 27, 22, 0.06),
    rgba(31, 27, 22, 0.12),
    rgba(31, 27, 22, 0.06)
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.bar {
  flex: 1;
  background: linear-gradient(180deg, rgba(212, 106, 65, 0.9), rgba(212, 106, 65, 0.4));
  border-radius: 8px 8px 4px 4px;
  min-height: 4px;
  min-width: 18px;
  cursor: pointer;
  position: relative;
  transform-origin: bottom;
  animation: rise 0.45s ease both;
  animation-delay: calc(var(--i) * 40ms);
}

.stats-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 180px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: rgba(31, 27, 22, 0.96);
  color: #fff;
  box-shadow: 0 12px 24px rgba(31, 27, 22, 0.35);
  font-size: 12px;
  display: grid;
  gap: var(--space-2);
  pointer-events: none;
  z-index: 3;
}

.tooltip-title {
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 13px;
}

.tooltip-row span {
  color: rgba(255, 255, 255, 0.7);
}

.tooltip-row strong {
  font-weight: 600;
}

.bar span {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.bar.show-label span {
  opacity: 1;
}

.stats-chart.dense .bar span {
  font-size: 9px;
}

.stats-empty {
  margin-top: var(--space-3);
  color: var(--muted);
  font-size: 14px;
}

.input-wrap input {
  font-family: inherit;
}

.tab-button:focus-visible,
.entry-tab:focus-visible,
.chip:focus-visible,
#income-save:focus-visible,
#expense-save:focus-visible {
  outline: 2px solid rgba(212, 106, 65, 0.6);
  outline-offset: 2px;
}

.stats-chart:empty {
  min-height: 0;
}

.radio-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
}

.radio-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #fffaf3;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.radio-option input {
  accent-color: var(--accent);
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rise {
  from {
    transform: scaleY(0.6);
    opacity: 0.3;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

.hidden {
  display: none;
}

@media (max-width: 480px) {
  .page {
    padding: var(--space-5) var(--space-4) var(--space-7);
  }

  .header h1 {
    font-size: 24px;
  }

  .today-button {
    flex: 1 1 100%;
    text-align: center;
  }

  .history-filters,
  .history-pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-field {
    min-width: 100%;
  }

  .history-page {
    text-align: center;
  }
}
