:root {
  --bg-color: #0d1117;
  --surface-color: rgba(22, 27, 34, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --primary: #58a6ff;
  --danger: #f85149;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --success: #3fb950;
  --input-bg: rgba(13, 17, 23, 0.8);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  /* subtle radial glow for aesthetic */
  background-image: radial-gradient(circle at 15% 50%, rgba(88, 166, 255, 0.05), transparent 25%),
                    radial-gradient(circle at 85% 30%, rgba(248, 81, 73, 0.05), transparent 25%);
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.title-section {
  text-align: center;
  flex: 1;
}

.header-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.5rem;
  z-index: 10;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: -webkit-linear-gradient(120deg, #58a6ff, #bc8cff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
  margin-top: 1rem;
}

header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.glass-card {
  background: var(--surface-color);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.legend-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.legend-item.disabled {
  opacity: 0.5;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.legend-text {
  flex: 1;
  font-weight: 500;
}

.legend-value {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-right: 0.5rem;
}

.filter-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: all 0.2s;
  font-size: 1.1rem;
}

.filter-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input {
  background-color: var(--input-bg);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.8rem;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  transition: border-color 0.2s, box-shadow 0.2s;
  color-scheme: dark;
  width: 300px;
  max-width: 100%;
  box-sizing: border-box;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

/* Chrome autofill dark mode fix */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active{
  -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  transition: background-color 5000s ease-in-out 0s;
}

.btn {
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  font-family: inherit;
  font-size: 1rem;
}

.btn:active {
  transform: scale(0.98);
}

.btn:hover {
  opacity: 0.9;
}

.btn-primary {
  background-color: var(--primary);
  color: #000;
}

.btn-danger {
  background-color: var(--danger);
  color: #fff;
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.btn-outline:hover {
  border-color: var(--text-secondary);
  background-color: rgba(255, 255, 255, 0.05);
}

/* Analysis Section */
.analysis-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 1rem;
}

.date-filters {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 2rem;
}

.chart-container h3 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
  text-align: center;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  min-height: 300px;
  overflow: visible;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.summary-card {
  text-align: center;
  padding: 1.5rem;
  border-radius: 16px;
  transition: transform 0.2s ease;
}

.summary-card:hover {
  transform: translateY(-2px);
}

.summary-card h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.summary-amount {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

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

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

.difference-summary .summary-amount {
  color: var(--primary);
}

/* Responsiveness for summary cards */
@media (max-width: 768px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }
}

/* Responsiveness */
@media (max-width: 768px) {
  .forms-wrapper {
    grid-template-columns: 1fr;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
  }
  
  .filter-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Transaction List */
.transaction-list-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.transaction-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.transaction-table th, 
.transaction-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--glass-border);
}

.transaction-table th {
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.transaction-table tbody tr {
  transition: background-color 0.2s;
}

.transaction-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

.transaction-income {
  background-color: rgba(63, 185, 80, 0.05);
}

.transaction-expense {
  background-color: rgba(248, 81, 73, 0.05);
}

.transaction-income:hover {
  background-color: rgba(63, 185, 80, 0.1);
}

.transaction-expense:hover {
  background-color: rgba(248, 81, 73, 0.1);
}

.type-badge {
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  display: inline-block;
}

.type-income {
  background-color: rgba(63, 185, 80, 0.15);
  color: var(--success);
}

.type-expense {
  background-color: rgba(248, 81, 73, 0.15);
  color: var(--danger);
}

.action-btn {
  background: none;
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background-color: var(--primary);
  color: #000;
  border-color: var(--primary);
}

.action-btn-danger:hover {
  background-color: var(--danger) !important;
  border-color: var(--danger) !important;
  color: #fff !important;
}

/* Modal Styling */
.modal {
  margin: auto;
  min-width: 400px;
  max-width: 90vw;
  color: var(--text-primary);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: var(--text-primary);
}

/* Custom date display input */
.date-display-input {
  cursor: pointer;
  caret-color: transparent;
  user-select: none;
}

.date-display-input:hover {
  border-color: var(--text-secondary);
}

.date-display-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

/* Toast Notification */
.toast {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(-1rem);
  background: rgba(30, 37, 48, 0.95);
  color: var(--text-primary);
  padding: 0.9rem 1.6rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.toast::before {
  content: '✓';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  background: var(--success);
  color: #000;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast[data-type="error"]::before {
  content: '✕';
  background: var(--danger);
  color: #fff;
}

/* Chart.js Legend Styling */
.chartjs-legend {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  max-height: 200px !important;
  overflow-y: auto !important;
  padding: 10px !important;
}

.chartjs-legend li {
  display: flex !important;
  align-items: center !important;
  margin: 5px 10px !important;
  cursor: pointer !important;
  font-size: 11px !important;
}

/* Custom Legend */
.custom-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(22, 27, 34, 0.5);
  border-radius: 8px;
  border: 1px solid var(--glass-border);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.85rem;
  border: 1px solid transparent;
}

.legend-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--glass-border);
}

.legend-item.disabled {
  opacity: 0.4;
  text-decoration: line-through;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-text {
  font-weight: 500;
  color: var(--text-primary);
}

.legend-value {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* Mobile responsiveness for transaction table */
@media (max-width: 768px) {
  .transaction-table th:nth-child(6),
  .transaction-table td:nth-child(6) {
    display: none; /* Hide Description column on mobile */
  }
  
  .transaction-table th,
  .transaction-table td {
    padding: 0.5rem 0.3rem; /* Reduce padding on mobile */
    font-size: 0.8rem; /* Smaller font */
  }
  
  .transaction-table th:nth-child(1),
  .transaction-table td:nth-child(1) {
    width: 30px; /* Smaller # column */
  }
  
  .transaction-table th:nth-child(2),
  .transaction-table td:nth-child(2) {
    width: 60px; /* Smaller Type column */
  }
  
  .action-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
  }
}

/* Even more compact for very small screens */
@media (max-width: 480px) {
  .transaction-table th:nth-child(1),
  .transaction-table td:nth-child(1) {
    display: none; /* Hide # column on very small screens */
  }
  
  .transaction-table th:nth-child(2),
  .transaction-table td:nth-child(2) {
    display: none; /* Hide Type column on very small screens */
  }
  
  .transaction-table th:nth-child(4),
  .transaction-table td:nth-child(4) {
    font-size: 0.7rem; /* Smaller date text */
  }
  
  .transaction-table th:nth-child(5),
  .transaction-table td:nth-child(5) {
    font-size: 0.75rem;
    font-weight: 600;
  }
}

.light-theme {
  --bg-color: #f6f8fa;
  --surface-color: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(0, 0, 0, 0.1);
  --primary: #0969da;
  --danger: #da3633;
  --text-primary: #24292f;
  --text-secondary: #57606a;
  --success: #238636;
  --input-bg: rgba(255, 255, 255, 0.8);
}

.light-theme body {
  background-image: radial-gradient(circle at 15% 50%, rgba(9, 105, 218, 0.05), transparent 25%),
                    radial-gradient(circle at 85% 30%, rgba(218, 54, 51, 0.05), transparent 25%);
}

.light-theme input:-webkit-autofill,
.light-theme input:-webkit-autofill:hover, 
.light-theme input:-webkit-autofill:focus, 
.light-theme input:-webkit-autofill:active{
  -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  transition: background-color 5000s ease-in-out 0s;
}

.light-theme .toast {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}

.light-theme .custom-legend {
  background: rgba(255, 255, 255, 0.5);
}

.light-theme .transaction-table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.light-theme .transaction-income {
  background-color: rgba(35, 134, 54, 0.05);
}

.light-theme .transaction-expense {
  background-color: rgba(218, 54, 51, 0.05);
}

.light-theme .transaction-income:hover {
  background-color: rgba(35, 134, 54, 0.1);
}

.light-theme .transaction-expense:hover {
  background-color: rgba(218, 54, 51, 0.1);
}

.light-theme .type-income {
  background-color: rgba(35, 134, 54, 0.15);
}

.light-theme .type-expense {
  background-color: rgba(218, 54, 51, 0.15);
}

.light-theme .btn-outline:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.light-theme .glass-card {
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}

.light-theme .modal::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.2s;
}

.sortable:hover {
  color: var(--text-primary);
}

.sortable:hover .sort-icon {
  color: var(--primary);
}

.sort-icon {
  margin-left: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.sort-asc .sort-icon::before {
  content: '↑';
}

.sort-desc .sort-icon::before {
  content: '↓';
}
