* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #212121;
  --text-secondary: #757575;
  --income: #4caf50;
  --expense: #f44336;
  --border: #e0e0e0;
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1e1e1e;
  --text: #ffffff;
  --text-secondary: #b0b0b0;
  --border: #2c2c2c;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: pan-y;
  overflow-x: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 14px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.period-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.15s;
}

.period-btn:active {
  background: var(--border);
  transform: scale(0.9);
}

.period-label {
  font-size: 12px;
  font-weight: 700;
  min-width: 94px;
  text-align: center;
}

.settings-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.15s;
}

.settings-btn:active {
  transform: scale(0.9);
  background: var(--border);
}

.filter-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.15s;
}

.filter-btn:active {
  transform: scale(0.9);
  background: var(--border);
}

.balance-container {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 14px auto 54px;
}

#donutChart {
  position: absolute;
  top: 0;
  left: 0;
  width: 160px;
  height: 160px;
}

.balance-info {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.balance-label {
  font-size: 9px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 500;
}

.balance-amount {
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.balance-amount:active {
  opacity: 0.7;
}

.balance-currency {
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 500;
}

.summary {
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
}

.summary-item {
  flex: 1;
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.summary-label {
  font-size: 9px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 500;
}

.summary-amount {
  font-size: 14px;
  font-weight: 700;
}

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

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

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

.category-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 7px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.category-item:active {
  transform: scale(0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.category-icon {
  font-size: 22px;
  margin-bottom: 6px;
}

.category-name {
  font-size: 8px;
  font-weight: 600;
  margin-bottom: 3px;
}

.category-amount {
  font-size: 10px;
  font-weight: 700;
  color: var(--expense);
}

.add-btn {
  position: fixed;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  color: white;
  border: none;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}

.add-btn-circle {
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: white;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 10;
}

.add-btn-circle:active {
  transform: scale(0.9);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.expense-btn {
  right: 20px;
  background: #f44336;
}

.expense-btn-circle {
  right: 14px;
  bottom: -46px;
  background: #f44336;
}

.expense-btn-circle:active {
  transform: scale(0.9);
}

.income-btn {
  right: 90px;
  background: #4caf50;
}

.income-btn-circle {
  left: 14px;
  bottom: -46px;
  background: #4caf50;
}

.income-btn-circle:active {
  transform: scale(0.9);
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 100%;
  border-radius: 16px 16px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-overflow-scrolling: touch;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
}

.modal-header h3 {
  font-size: 14px;
  font-weight: 700;
}

.modal-close {
  width: 26px;
  height: 26px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  border-radius: 50%;
  transition: transform 0.15s;
}

.modal-close:active {
  transform: scale(0.9);
}

.modal-body {
  padding: 16px;
}

.amount-input-container {
  text-align: center;
  margin-bottom: 16px;
  padding: 14px 0;
  background: var(--bg);
  border-radius: 12px;
}

.amount-input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 36px;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  outline: none;
}

.type-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.type-btn {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--border);
  background: transparent;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}

.type-btn.active {
  background: #2196f3;
  border-color: #2196f3;
  color: white;
}

.category-select {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.category-select-item {
  padding: 12px 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.category-select-item:active {
  transform: scale(0.92);
}

.category-select-item.selected {
  border-color: #2196f3;
  background: rgba(33, 150, 243, 0.15);
  box-shadow: 0 0 0 1px #2196f3;
}

.category-select-icon {
  font-size: 22px;
  margin-bottom: 6px;
}

.category-select-name {
  font-size: 9px;
  font-weight: 600;
}

.category-select-item.new-category {
  border: 2px dashed var(--border);
  background: transparent;
}

.category-select-item.new-category:hover {
  border-color: #2196f3;
  background: rgba(33, 150, 243, 0.05);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 14px;
}

.emoji-btn {
  padding: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn:active {
  transform: scale(0.92);
}

.emoji-btn.selected {
  border-color: #2196f3;
  background: rgba(33, 150, 243, 0.15);
  box-shadow: 0 0 0 1px #2196f3;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  margin-bottom: 16px;
}

.color-btn {
  width: 100%;
  height: 34px;
  border: 3px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.color-btn:active {
  transform: scale(0.92);
}

.color-btn.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--text);
}

.note-input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text);
  margin-bottom: 16px;
}

.save-btn {
  width: 100%;
  padding: 13px;
  background: #2196f3;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}

.save-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 6px rgba(33, 150, 243, 0.2);
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-item label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
}

.setting-item select,
.setting-item input {
  padding: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text);
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.action-btn {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.action-btn:active {
  transform: scale(0.97);
  background: var(--bg);
}

.txn-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.txn-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.txn-info {
  flex: 1;
}

.txn-category {
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 2px;
}

.txn-note {
  font-size: 8px;
  color: var(--text-secondary);
}

.txn-amount {
  font-size: 11px;
  font-weight: 600;
}

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

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

.txn-delete {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--expense);
  font-size: 14px;
  cursor: pointer;
  margin-left: 6px;
}

.account-selector {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: 12px;
}

.account-selector-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.account-selector-buttons {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.account-btn {
  padding: 8px 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.account-btn:active {
  transform: scale(0.95);
}

.account-btn.selected {
  border-color: #2196f3;
  background: rgba(33, 150, 243, 0.15);
  color: #2196f3;
  box-shadow: 0 0 0 1px #2196f3;
}

.setting-section {
  margin-bottom: 16px;
}

.setting-section h4 {
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.account-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.account-info {
  flex: 1;
}

.account-name {
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 3px;
}

.account-balance {
  font-size: 9px;
  color: var(--text-secondary);
}

.account-delete {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--expense);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}

/* Category Management Styles */
.category-list, .budget-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  margin-bottom: 16px;
}

.manage-category-item {
  display: flex;
  align-items: center;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.manage-category-icon {
  font-size: 20px;
  width: 30px;
  text-align: center;
}

.manage-category-details {
  flex: 1;
  padding-left: 10px;
  font-size: 11px;
  font-weight: 600;
}

.manage-category-actions {
  display: flex;
  gap: 4px;
}

.category-action-btn {
  padding: 6px 10px;
  border: none;
  background: #2196f3;
  color: white;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.category-action-btn.delete {
  background: var(--expense);
}

.category-action-btn:active {
  opacity: 0.8;
}

/* Budget Styles */

.budget-item {
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border-left: 5px solid #2196f3; /* Indicator color */
}

.budget-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.budget-category-name {
  font-size: 12px;
  font-weight: 700;
}

.budget-amount-limit {
  font-size: 12px;
  font-weight: 700;
  color: #2196f3;
}

.budget-tracking {
  margin-top: 8px;
}

.budget-progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.budget-progress-fill {
  height: 100%;
  background: var(--income);
  transition: width 0.3s;
}

.budget-spent-info {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-secondary);
}

.budget-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}


.calculator-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 16px;
}

.calc-btn {
  padding: 14px;
  border: none;
  background: var(--bg);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
  min-height: 42px;
}

.calc-btn:active {
  transform: scale(0.92);
  opacity: 0.7;
}

.calc-btn.operator {
  background: #e3f2fd;
  color: #2196f3;
}

.calc-btn.clear {
  background: #ffebee;
  color: #f44336;
}

.calc-btn.equals {
  background: #2196f3;
  color: white;
  grid-column: span 3;
  font-size: 17px;
}

.category-percentages {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.category-percentage-item {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.category-percentage-icon {
  font-size: 16px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.category-percentage-value {
  font-size: 8px;
  font-weight: 800;
  color: var(--text);
  background: var(--surface);
  padding: 3px 6px;
  border-radius: 7px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
}

.filter-section {
  margin-bottom: 16px;
}

.filter-section h4 {
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.filter-accounts {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.filter-account-btn {
  padding: 8px 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.filter-account-btn:active {
  transform: scale(0.95);
}

.filter-account-btn.selected {
  border-color: #2196f3;
  background: rgba(33, 150, 243, 0.15);
  color: #2196f3;
  box-shadow: 0 0 0 1px #2196f3;
}

.filter-periods {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.filter-period-btn {
  padding: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.filter-period-btn:active {
  transform: scale(0.95);
}

.filter-period-btn.selected {
  border-color: #2196f3;
  background: rgba(33, 150, 243, 0.15);
  color: #2196f3;
  box-shadow: 0 0 0 1px #2196f3;
}

.date-input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text);
  margin-bottom: 8px;
}

