@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@200;300;400;500;600&family=Mitr:wght@300;400;500;600&display=swap');

:root {
  /* Colors */
  --bg-gradient: linear-gradient(135deg, #FFEBF0 0%, #EBF4FF 50%, #F3E8FF 100%);
  --text-main: #334155;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  
  --primary: #9F7AEA;
  --primary-hover: #805AD5;
  --primary-bg: #F3E8FF;
  
  --income: #10B981;
  --income-hover: #059669;
  --income-bg: #ECFDF5;
  
  --expense: #F43F5E;
  --expense-hover: #E11D48;
  --expense-bg: #FFF1F2;

  /* Glassmorphism Constants */
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-bg-hover: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.05);
  --glass-shadow-inset: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  
  /* Category Colors */
  --cat-food: #FFADAD;
  --cat-shopping: #FFD6A5;
  --cat-transport: #CAFFBF;
  --cat-bills: #FDFFB6;
  --cat-entertainment: #FFC6FF;
  --cat-education: #9BF6FF;
  --cat-health: #A0C4FF;
  --cat-salary: #BDB2FF;
  --cat-investment: #C1F0E8;
  --cat-other: #D3D3D3;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Kanit', sans-serif;
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  padding: 20px 10px;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: 'Mitr', sans-serif;
  font-weight: 500;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Glassmorphism Utility */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-shadow-inset);
  border-radius: 24px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-hover:hover {
  background: var(--glass-bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.08), var(--glass-shadow-inset);
}

/* Header Section */
header {
  text-align: center;
  margin-bottom: 30px;
  padding: 24px;
}

header h1 {
  font-size: 2.2rem;
  background: linear-gradient(45deg, #E285FF, #7FA4FF, #7BFFDF);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
  margin-bottom: 5px;
}

header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}

/* Dashboard Summary Cards */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.summary-card {
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.summary-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 70%);
  transform: scale(1.5);
  pointer-events: none;
}

.summary-card .card-title {
  font-size: 0.95rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.summary-card .card-title svg {
  width: 20px;
  height: 20px;
}

.summary-card .card-value {
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.card-balance {
  border-left: 6px solid var(--primary);
}
.card-balance .card-value {
  color: var(--text-main);
}

.card-income {
  border-left: 6px solid var(--income);
}
.card-income .card-value {
  color: var(--income);
}

.card-expense {
  border-left: 6px solid var(--expense);
}
.card-expense .card-value {
  color: var(--expense);
}

.card-savings {
  border-left: 6px solid #EC4899;
}
.card-savings .card-value {
  color: #EC4899;
}

.card-investment {
  border-left: 6px solid #3B82F6;
}
.card-investment .card-value {
  color: #3B82F6;
}

/* Main Grid Layout */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
}

@media (min-width: 992px) {
  .main-grid {
    grid-template-columns: 4fr 6fr;
  }
}

/* Cards Panels */
.panel {
  padding: 24px;
  height: fit-content;
}

.panel-title {
  font-size: 1.3rem;
  color: var(--text-main);
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px dashed rgba(159, 122, 234, 0.15);
  padding-bottom: 12px;
}

.panel-title-text {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title-text svg {
  width: 24px;
  height: 24px;
  color: var(--primary);
}

/* Donut Chart Styling */
.chart-container {
  position: relative;
  margin: 0 auto 20px auto;
  max-width: 280px;
  min-height: 250px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chart-empty {
  text-align: center;
  color: var(--text-light);
  padding: 40px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.chart-empty svg {
  width: 60px;
  height: 60px;
  opacity: 0.6;
}

/* Budget Tracker */
.budget-box {
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  padding: 16px;
  margin-top: 20px;
}

.budget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.budget-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
}

.budget-edit-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.2s;
}

.budget-edit-btn:hover {
  opacity: 0.8;
  text-decoration: underline;
}

.budget-values {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.budget-spent {
  font-weight: 600;
}

.budget-limit {
  color: var(--text-muted);
}

.budget-progress-bar {
  background: rgba(0, 0, 0, 0.05);
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.budget-progress-fill {
  background: linear-gradient(90deg, #10B981, #34D399);
  height: 100%;
  width: 0%;
  border-radius: 99px;
  transition: width 0.5s ease-out, background 0.3s;
}

.budget-progress-fill.warning {
  background: linear-gradient(90deg, #F59E0B, #FBBF24);
}

.budget-progress-fill.danger {
  background: linear-gradient(90deg, #EF4444, #F87171);
}

/* Control & Filter Panel */
.controls-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

@media (min-width: 600px) {
  .controls-bar {
    grid-template-columns: 1fr 1fr;
  }
}

.search-input-wrapper {
  position: relative;
}

.search-input-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-light);
}

.form-control {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.6);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.3s;
}

.form-control:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 4px rgba(159, 122, 234, 0.15);
}

.search-input-wrapper .form-control {
  padding-left: 42px;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 5px;
  margin-bottom: 20px;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  padding: 8px 16px;
  border-radius: 99px;
  border: 1px solid rgba(0, 0, 0, 0.04);
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.filter-tab:hover {
  background: rgba(255, 255, 255, 0.8);
}

.filter-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 500;
}

/* Transaction List Grouping */
.transaction-group {
  margin-bottom: 20px;
  animation: fadeIn 0.4s ease-out;
}

.group-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-left: 8px;
  display: flex;
  justify-content: space-between;
}

.group-summary {
  display: flex;
  gap: 12px;
}

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

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

.transaction-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.transaction-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.transaction-item:hover {
  background: rgba(255, 255, 255, 0.8);
  transform: translateX(4px);
  border-color: rgba(159, 122, 234, 0.2);
}

.item-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0; /* Ensures text truncation works */
}

.category-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #334155;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.06);
}

.category-icon-wrapper svg {
  width: 22px;
  height: 22px;
}

.item-info {
  min-width: 0;
}

.item-title {
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.item-right {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: 10px;
}

.item-amount {
  font-weight: 600;
  font-size: 1.1rem;
  text-align: right;
  white-space: nowrap;
}

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

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

.item-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.transaction-item:hover .item-actions {
  opacity: 1;
}

.action-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.action-btn svg {
  width: 16px;
  height: 16px;
}

.btn-edit {
  color: var(--primary);
}
.btn-edit:hover {
  background: var(--primary-bg);
}

.btn-delete {
  color: var(--expense);
}
.btn-delete:hover {
  background: var(--expense-bg);
}

/* Empty State */
.list-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.list-empty svg {
  width: 64px;
  height: 64px;
  opacity: 0.5;
}

/* Add / Primary Action Button */
.btn-container {
  display: flex;
  gap: 12px;
  margin-top: 15px;
}

.btn {
  padding: 12px 24px;
  border-radius: 16px;
  border: none;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.btn-primary {
  background: var(--primary);
  color: white;
  flex: 1;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(159, 122, 234, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Secondary Actions Box (Export/Import/Reset) */
.settings-box {
  margin-top: 24px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.3);
  border: 1px dashed rgba(159, 122, 234, 0.2);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.btn-secondary {
  background: white;
  color: var(--text-muted);
  border: 1px solid rgba(0,0,0,0.06);
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 12px;
}

.btn-secondary:hover {
  background: #f8fafc;
  color: var(--text-main);
  transform: translateY(-1px);
}

.btn-danger-secondary {
  background: white;
  color: var(--expense);
  border: 1px solid rgba(244, 63, 94, 0.15);
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 12px;
}

.btn-danger-secondary:hover {
  background: var(--expense-bg);
  transform: translateY(-1px);
}

/* Modal Dialog Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-out;
  padding: 20px 15px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 480px;
  margin: auto;
  background: white;
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(31, 38, 135, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.8);
  transform: translateY(40px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  padding: 24px;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.25rem;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  transition: background 0.2s;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

.modal-close svg {
  width: 20px;
  height: 20px;
}

/* Form Grouping & Custom Radio Selectors */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Type Toggle (Income / Expense) */
.type-toggle {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 16px;
}

.type-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 10px;
  color: var(--text-muted);
  transition: all 0.2s;
}

.type-btn.active.income {
  background: var(--income);
  color: white;
}

.type-btn.active.expense {
  background: var(--expense);
  color: white;
}

/* Grid for Categories selector */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.category-select-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px 4px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.category-select-item:hover {
  background: #f8fafc;
}

.category-select-item.selected {
  background: var(--primary-bg);
  border-color: var(--primary);
}

.category-select-item .icon-circle {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  color: var(--text-main);
  box-shadow: inset 0 -1.5px 0 rgba(0,0,0,0.05);
}

.category-select-item.selected .icon-circle {
  background: var(--primary);
  color: white;
}

.category-select-item svg {
  width: 18px;
  height: 18px;
}

.category-select-item span {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
}

.category-select-item.selected span {
  color: var(--primary-hover);
  font-weight: 600;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1100;
}

.toast {
  background: var(--text-main);
  color: white;
  padding: 12px 24px;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUpToast 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), fadeOut 0.3s 2.7s forwards;
}

.toast.success {
  background: #10B981;
}

.toast.error {
  background: #F43F5E;
}

.toast.info {
  background: #3B82F6;
}

/* Custom categories color variables matching background styles */
.cat-bg-food { background-color: rgba(255, 173, 173, 0.25); color: #B34444; }
.cat-bg-shopping { background-color: rgba(255, 214, 165, 0.35); color: #B37122; }
.cat-bg-transport { background-color: rgba(202, 255, 191, 0.35); color: #3E8033; }
.cat-bg-bills { background-color: rgba(253, 255, 182, 0.45); color: #8F8C1D; }
.cat-bg-entertainment { background-color: rgba(255, 198, 255, 0.35); color: #A647A6; }
.cat-bg-education { background-color: rgba(155, 246, 255, 0.35); color: #21737A; }
.cat-bg-health { background-color: rgba(160, 196, 255, 0.35); color: #2D589E; }
.cat-bg-salary { background-color: rgba(189, 178, 255, 0.35); color: #5144A8; }
.cat-bg-investment { background-color: rgba(59, 130, 246, 0.25); color: #1E3A8A; }
.cat-bg-savings { background-color: rgba(236, 72, 153, 0.25); color: #BE185D; }
.cat-bg-other { background-color: rgba(211, 211, 211, 0.35); color: #5E5E5E; }

/* Animations Keyframes */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUpToast {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Responsive fixes for modal on very small screens */
@media (max-width: 400px) {
  .categories-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Center date input value and its label in the modal */
.form-group label[for="transactionDate"] {
  text-align: center;
}

#transactionDate {
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
}

#transactionDate::-webkit-date-and-time-value {
  text-align: center;
  min-height: 1.5em;
}
