/* General Reset & Base Styling */
* {
  box-sizing: border-box;
}
body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #fff;
  color: #343a40;
}

/* Header & Footer */
header {
  position: relative;
  padding: 0.5em 1em;
  background-color: #f8f9fa;
  text-align: center;
}
header nav {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}
header h1 {
  margin: 0;
  font-size: 1.5em;
}

footer {
  text-align: center;
  padding: 1em;
  background-color: #f8f9fa;
  margin-top: 2em;
  font-size: 0.9em;
  color: #666;
}

/* Navigation Menu Styles */
nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
nav li {
  position: relative;
}
nav li a.dropbtn {
  display: block;
  color: #343a40;
  padding: 8px 16px;
  text-decoration: none;
}
nav li a.dropbtn:hover,
nav li a.dropbtn:focus,
.dropdown:hover .dropbtn {
  background-color: #ddd;
}
nav li.dropdown {
  display: inline-block;
}
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f8f9fa;
  min-width: 160px;
  z-index: 1;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
  color: #343a40;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}
.dropdown-content a:hover {
  background-color: #ddd;
}
.dropdown:hover .dropdown-content {
  display: block;
}
.menu-icon {
  font-size: 20px;
  margin-right: 8px;
  vertical-align: middle;
}

/* Layout Containers */
.container {
  padding: 1em;
}
.row {
  display: flex;
  flex-wrap: wrap;
}
.col {
  flex: 1;
  min-width: 280px;
  padding: 1em;
}

/* Collapsible Cards */
.collapsible-card {
  border: 1px solid #ddd;
  background-color: #f9f9f9;
  margin-bottom: 1.5em;
  border-radius: 8px;
  overflow: hidden;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1em;
  background-color: #f2f2f2;
  cursor: pointer;
  user-select: none;
}
.card-header:hover {
  background-color: #e9e9e9;
}
.card-header h2 {
  margin: 0;
  font-size: 1.1em;
}
.card-toggle {
  transition: transform 0.3s ease;
  font-size: 1.2em;
}
.card-body {
  padding: 1em;
  display: block;
}
.card-body.collapsed {
  display: none;
}
.card-form {
  display: flex;
  flex-direction: column;
}
.card-form label {
  margin-top: 0.5em;
  font-weight: 500;
}
.card-form input,
.card-form select,
.card-form button {
  margin-top: 0.5em;
  padding: 0.5em;
  font-size: 1em;
}
.card-form input:focus,
.card-form select:focus {
  outline: 2px solid #007bff;
  outline-offset: 1px;
}
.card-form button {
  background-color: #007bff;
  color: #fff;
  border: none;
  cursor: pointer;
  margin-top: 1em;
  border-radius: 4px;
}
.card-form button:hover {
  background-color: #0056b3;
}

/* Category Container */
.category-container {
  display: flex;
  gap: 0.5em;
  align-items: center;
  margin-top: 0.5em;
}
.category-container select {
  flex: 1;
  margin-top: 0;
}
.category-container button {
  margin-top: 0;
  padding: 0.5em 1em;
  white-space: nowrap;
}

/* Icon Buttons for Edit/Delete */
button.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  padding: 0.3em;
  margin: 0 0.2em;
  color: #007bff;
  transition: color 0.2s;
}
button.icon-btn:hover {
  color: #0056b3;
}

/* Actions Cell - prevent wrapping */
.actions-cell {
  white-space: nowrap;
}

/* Table Styles */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}
.table-responsive table {
  width: 100%;
  border-collapse: collapse;
}
.table-responsive th,
.table-responsive td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}
.table-responsive tr:nth-child(even) {
  background-color: #f9f9f9;
}
.table-responsive th {
  background-color: #f2f2f2;
  color: #333;
  font-weight: 600;
}

/* Conditional Formatting */
.positive-amount {
  color: green;
  font-weight: 500;
}
.negative-amount {
  color: red;
  font-weight: 500;
}
.neutral-amount {
  color: #666;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
  background-color: #f9f9f9;
  margin: 5% auto;
  padding: 2em;
  border: 1px solid #ddd;
  width: 90%;
  max-width: 600px;
  border-radius: 8px;
  position: relative;
}
.modal-content h2 {
  margin-top: 0;
}
.modal-content ul {
  padding-left: 1.5em;
}
.modal-content li {
  margin-bottom: 0.5em;
}
.modal-form form {
  display: flex;
  flex-direction: column;
}
.modal-form label {
  margin-top: 1em;
  font-weight: 500;
}
.modal-form input,
.modal-form select,
.modal-form button {
  margin-top: 0.5em;
  padding: 0.5em;
  width: 100%;
}
.modal-form button {
  margin-top: 1em;
}
.close-btn {
  color: #aaa;
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}
.close-btn:hover,
.close-btn:focus {
  color: #000;
}
#close-modal-btn {
  margin-top: 1em;
  width: auto;
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 0.75em 1.5em;
  border-radius: 4px;
  cursor: pointer;
}
#close-modal-btn:hover {
  background-color: #0056b3;
}

/* Chart Container */
.bar-chart-container {
  position: relative;
  width: 100%;
  max-width: 800px;
  height: 400px;
  margin: 0 auto 1em auto;
}

/* Balance Display */
#balance-display {
  text-align: center;
  font-size: 1.3em;
  padding: 0.5em;
  margin-bottom: 1em;
  border-radius: 4px;
  background-color: #f8f9fa;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .row {
    flex-direction: column;
  }
  .col {
    width: 100%;
  }
  .bar-chart-container {
    height: 300px;
  }
}

@media (max-width: 600px) {
  header {
    text-align: center;
  }
  header nav {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
  }
  header h1 {
    font-size: 1.2em;
  }
  .col {
    padding: 0.5em;
  }
  .card-header h2 {
    font-size: 1em;
  }
  .card-form input,
  .card-form button,
  .card-form select {
    font-size: 1em;
  }
  .table-responsive table,
  .table-responsive th,
  .table-responsive td {
    font-size: 0.85em;
    padding: 6px;
  }
  .bar-chart-container {
    height: 250px;
  }
  .category-container {
    flex-direction: column;
  }
  .category-container select,
  .category-container button {
    width: 100%;
  }
}

/* Print Styles */
@media print {
  header nav,
  .card-form,
  button.icon-btn,
  .modal {
    display: none !important;
  }
  .collapsible-card {
    break-inside: avoid;
  }
  .card-body {
    display: block !important;
  }
}
