/* CSS Variables */
:root {
  --bg: #f7f7fb;
  --card: #ffffff;
  --primary: #4a4aff;
  --primary-dark: #2c2cff;
  --text: #222;
  --muted: #666;
  --radius: 14px;
  --shadow: 0 4px 15px rgba(0,0,0,0.08);
  --danger: #ff4444;
  --success: #4caf50;
  --border: #e0e0e0;
}

[data-theme="dark"] {
  --bg: #0f0f13;
  --card: #1a1a20;
  --text: #eaeaea;
  --muted: #999;
  --primary: #7c7cff;
  --primary-dark: #5b5bff;
  --shadow: 0 4px 15px rgba(255,255,255,0.05);
  --border: #2a2a30;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  padding: 20px;
  background: var(--bg);
  margin: 0;
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  -webkit-tap-highlight-color: transparent;
}

.page { 
  max-width: 600px; 
  margin: 0 auto; 
}

h2 {
  margin-top: 0;
}

/* Buttons */
.btn { 
  padding: 14px 20px;
  background: var(--primary); 
  color: #fff; 
  border-radius: var(--radius); 
  width: 100%; 
  margin-bottom: 10px; 
  border: none; 
  box-shadow: var(--shadow); 
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--primary);
}

.btn-secondary {
  background: var(--muted);
}

.btn-small {
  padding: 10px 16px;
  font-size: 14px;
  margin-top: 12px;
}

/* Top bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.total-display {
  color: var(--primary);
  font-size: 1.5rem;
}

/* Budget Page */
.budget-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  gap: 15px;
}

.budget-header h2 {
  margin: 0;
}

.budget-summary {
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.budget-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.budget-row:last-child {
  border-bottom: none;
}

.budget-remaining {
  margin-top: 10px;
  padding-top: 15px;
  border-top: 2px solid var(--primary);
  font-size: 1.1rem;
}

.budget-amount {
  color: var(--primary);
  font-weight: 600;
}

.budget-remaining .budget-amount {
  font-size: 1.3rem;
}

.budget-item {
  background: var(--card);
  padding: 12px;
  margin-bottom: 8px;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
}

.budget-item:hover {
  box-shadow: var(--shadow);
}

/* Category */
.category {
  background: var(--card);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.category:hover {
  border-color: var(--primary);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.category-header b {
  font-size: 1.1rem;
}

.category-arrow {
  font-size: 1.2rem;
  transition: transform 0.3s ease;
  color: var(--muted);
}

.category.expanded .category-arrow {
  transform: rotate(90deg);
}

/* Category Items Container */
.category-items { 
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0;
}

.category.expanded .category-items {
  padding-top: 12px;
}

/* Individual Item */
.item { 
  background: var(--card); 
  padding: 12px;
  margin-bottom: 8px;
  border-left: 4px solid var(--primary); 
  border-radius: var(--radius);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
}

.item:hover {
  box-shadow: var(--shadow);
}

.item-content {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 12px;
}

.item-checkbox {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
}

.item-label {
  flex: 1;
  cursor: pointer;
  user-select: none;
}

.item-label.checked {
  text-decoration: line-through;
  opacity: 0.6;
}

.item-price {
  color: var(--primary);
  font-weight: 600;
  margin-left: 8px;
}

/* Delete Button */
.delete-btn {
  background: var(--danger);
  color: white;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  font-weight: 500;
}

.delete-btn:hover {
  background: #cc0000;
  transform: scale(1.05);
}

.category-delete-btn {
  padding: 4px 8px;
  font-size: 12px;
}

/* Empty State */
.empty-message {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 20px;
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

/* Bottom Sheet Popup */
.sheet {
  position: fixed; 
  bottom: -100%; 
  left: 0; 
  width: 100%; 
  background: var(--card);
  border-radius: 20px 20px 0 0; 
  padding: 25px; 
  box-shadow: 0 -4px 30px rgba(0,0,0,0.3);
  transition: bottom 0.35s ease;
  z-index: 1000;
  max-height: 80vh;
  overflow-y: auto;
}

.sheet.show { 
  bottom: 0; 
}

.sheet h3 {
  margin-top: 0;
  margin-bottom: 20px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--card);
  padding: 30px;
  border-radius: var(--radius);
  max-width: 400px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.modal-content h3 {
  margin-top: 0;
  margin-bottom: 15px;
}

.modal-content p {
  margin-bottom: 25px;
  color: var(--muted);
}

.modal-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Form Inputs */
input, select { 
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  margin-bottom: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.2s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Navbar */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--card);
  box-shadow: var(--shadow);
  z-index: 50;
  padding: 12px 20px;
  border-bottom: 2px solid var(--border);
}

.nav-container {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  justify-content: center;
}

.nav-btn {
  padding: 10px 20px;
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  flex: 1;
  max-width: 150px;
}

.nav-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-2px);
}

.nav-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Add padding to body when navbar is visible */
body.with-navbar {
  padding-top: 80px;
}

/* Theme Toggle */
#themeToggle {
  position: fixed;
  top: 15px;
  right: 15px;
  background: var(--card);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 100;
  transition: all 0.2s ease;
  font-size: 1.2rem;
  border: 2px solid transparent;
}

#themeToggle:hover {
  border-color: var(--primary);
  transform: scale(1.05);
}

/* Loading & Messages */
.message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: slideDown 0.3s ease;
}

.message.error {
  background: var(--danger);
  color: white;
}

.message.success {
  background: var(--success);
  color: white;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Responsive */
@media (max-width: 640px) {
  body {
    padding: 15px;
  }
  
  .modal-content {
    padding: 20px;
  }
  
  .modal-buttons {
    grid-template-columns: 1fr;
  }
}
