/* ---------- My Design ---------- */
:root {
  --bg: #f0f2f7;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e2e6f0;
  --text-primary: #1a1d2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --balance-color: #2563eb;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
  --font-main: "DM Sans", sans-serif;
  --font-mono: "DM Mono", monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface-2: #242740;
  --border: #2d3150;
  --text-primary: #f1f3f9;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --balance-color: #60a5fa;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  transition:
    background var(--transition),
    color var(--transition);
  line-height: 1.6;
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  box-shadow: var(--shadow-md);
  transition:
    transform var(--transition),
    box-shadow var(--transition);
}
.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

/* ---------- Layout ---------- */
.app-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* ---------- Header ---------- */
.app-header {
  margin-bottom: 1.75rem;
  animation: fadeDown 0.5s ease both;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo-mark {
  font-size: 1.75rem;
}
.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition:
    background var(--transition),
    border-color var(--transition);
  animation: fadeUp 0.4s ease both;
}

/* ---------- Balance Card ---------- */
.balance-card {
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 60%, #60a5fa 100%);
  border: none;
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
  margin-bottom: 1rem;
  color: #fff;
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.4s ease both;
}
.balance-card::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}
.balance-card::after {
  content: "";
  position: absolute;
  bottom: -30px;
  left: 20px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}
.balance-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 0.4rem;
}
.balance-amount {
  font-size: 3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  line-height: 1.1;
  transition: transform 0.3s ease;
}
.balance-amount.bump {
  animation: bump 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
.balance-subinfo {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  opacity: 0.75;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.dot {
  opacity: 0.5;
}

/* ---------- Monthly Summary ---------- */
.monthly-summary {
  margin-bottom: 1rem;
  animation-delay: 0.05s;
}
.monthly-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}
.stat-item {
  text-align: center;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
}
.stat-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-top: 0.2rem;
}
.month-select {
  font-family: var(--font-main);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}
.month-select:focus {
  border-color: var(--accent);
}

/* ---------- Section Header ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------- Form Card ---------- */
.form-card {
  margin-bottom: 1rem;
  animation-delay: 0.1s;
}
.form-group {
  margin-bottom: 1rem;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.form-input,
.form-select {
  width: 100%;
  padding: 0.7rem 1rem;
  font-family: var(--font-main);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
  appearance: none;
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}
.form-input:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background: var(--surface);
}
.form-input::placeholder {
  color: var(--text-muted);
}

/* Add button */
.btn-add {
  width: 100%;
  padding: 0.9rem;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition:
    background var(--transition),
    transform var(--transition),
    box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}
.btn-add:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
}
.btn-add:active {
  transform: translateY(0);
}
.btn-icon {
  font-size: 1.2rem;
  font-weight: 300;
}

.form-error {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 500;
}
.hidden {
  display: none !important;
}

/* ---------- Bottom Grid ---------- */
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  animation-delay: 0.15s;
}

/* ---------- Transaction List ---------- */
.transactions-card {
  animation-delay: 0.2s;
}
.sort-select {
  font-family: var(--font-main);
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.5rem;
}
.sort-select:focus {
  border-color: var(--accent);
}

.tx-list {
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.tx-list::-webkit-scrollbar {
  width: 4px;
}
.tx-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.5rem;
}
.empty-state p {
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Transaction Item */
.tx-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.3s ease both;
}
.tx-item:last-child {
  border-bottom: none;
}
.tx-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.tx-info {
  flex: 1;
  min-width: 0;
}
.tx-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-amount {
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
}
.tx-cat-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.15rem;
}

.btn-delete {
  flex-shrink: 0;
  padding: 0.35rem 0.65rem;
  font-family: var(--font-main);
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: var(--danger);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background var(--transition),
    transform var(--transition);
}
.btn-delete:hover {
  background: var(--danger-hover);
  transform: scale(1.05);
}

/* ---------- Chart Card ---------- */
.chart-card {
  animation-delay: 0.25s;
}
.chart-wrap {
  position: relative;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-wrap canvas {
  max-height: 200px;
}
.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  gap: 0.4rem;
}
.chart-empty span {
  font-size: 1.5rem;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: center;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  margin-top: 2rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---------- Animations ---------- */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes bump {
  0%,
  100% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.06);
  }
  70% {
    transform: scale(0.97);
  }
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20%,
  60% {
    transform: translateX(-4px);
  }
  40%,
  80% {
    transform: translateX(4px);
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  .app-wrapper {
    padding: 1rem 0.75rem 4rem;
  }
  .balance-amount {
    font-size: 2.2rem;
  }
  .bottom-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .monthly-stats {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .limit-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .limit-input-wrap {
    width: 100%;
  }
}
