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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-attachment: fixed;
  color: #333;
  line-height: 1.6;
  padding: 20px;
  min-height: 100vh;
}

h1, h2 {
  color: #333;
}

header {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  margin-bottom: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

header h1 {
  background: linear-gradient(135deg, #5568d3 0%, #6a3d99 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 28px;
  font-weight: bold;
}

#app {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  padding: 0;
  margin-bottom: 30px;
}

section {
  background: white;
  padding: 28px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid #e5e7eb;
}

section h2 {
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 3px solid #5568d3;
  color: #1f2937;
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

input, button, select {
  width: 100%;
  padding: 12px 16px;
  margin-top: 8px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 15px;
  transition: all 0.3s;
  font-family: inherit;
  background-color: white;
}

input:focus, select:focus {
  outline: none;
  border-color: #5568d3;
  box-shadow: 0 0 0 3px rgba(85, 104, 211, 0.15);
  background-color: #fafbff;
}

input::placeholder {
  color: #9ca3af;
}

label {
  display: block;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-hint {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  font-style: italic;
}

button:not(.dynamic-btn):not(#removeAllDataButton) {
  background: linear-gradient(135deg, #5568d3 0%, #6a3d99 100%);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(85, 104, 211, 0.3);
  margin-top: 8px;
}

button:not(.dynamic-btn):not(#removeAllDataButton):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(85, 104, 211, 0.4);
}

button:active {
  transform: translateY(0);
}

ul {
  list-style-type: none;
  padding: 0;
  margin-top: 16px;
}

li {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-left: 4px solid #5568d3;
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: all 0.2s;
}

li:hover {
  background: #f3f4f6;
  border-left-width: 6px;
}

.item-list:empty::after {
  content: 'No items yet. Add one using the form above.';
  display: block;
  text-align: center;
  color: #9ca3af;
  padding: 32px;
  font-style: italic;
}

/* Override list styles for tenant and billing grids */
#tenantList, #billingList {
  padding: 0;
  background: transparent;
}

#tenantList li, #billingList li {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

#tenantList li:hover, #billingList li:hover {
  background: transparent;
  border: none;
}

#removeAllDataButton {
  background-color: #7f1d1d;
  color: white;
  border: 3px solid #7f1d1d;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 700;
  width: auto;
  margin: 0;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(127, 29, 29, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#removeAllDataButton:hover {
  background-color: #991b1b;
  border-color: #991b1b;
  box-shadow: 0 4px 8px rgba(127, 29, 29, 0.6);
  transform: translateY(-1px);
}


#result {
  margin-top: 32px;
  background: white;
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid #e5e7eb;
}

#result h2 {
  color: #1f2937;
  font-size: 24px;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 3px solid #5568d3;
  display: flex;
  align-items: center;
  gap: 8px;
}

#resultInteractions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0;
  gap: 20px;
  flex-wrap: wrap;
}

#calculateButton {
  width: auto;
  padding: 12px 32px;
  background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%);
  font-size: 16px;
  font-weight: 700;
}

#calculateButton:hover {
  box-shadow: 0 4px 12px rgba(8, 145, 178, 0.4);
}

#save {
  display: flex;
  gap: 12px;
}

#save button {
  width: auto;
  padding: 10px 24px;
  margin: 0;
}

#resultDiv {
  background: #fafbff;
  padding: 24px;
  border-radius: 12px;
  min-height: 100px;
}

#resultDiv:empty::after {
  content: 'Click "Calculate" to see results';
  display: block;
  text-align: center;
  color: #9ca3af;
  padding: 48px;
  font-size: 16px;
  font-style: italic;
}

.collapsible-content {
  display: none;
  padding-left: 20px;
  margin-top: 10px;
}

.collapsible-content.show {
  display: block;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 500px;
  }
}

@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
  }

  #save {
    gap: 10px;
  }
  
  header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  #removeAllDataButton {
    width: 100%;
  }
}


.dynamic-container {
  margin-top: 24px;
  background: #ffffff;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid #e5e7eb;
}

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

.dynamic-heading {
  color: #5568d3;
  font-size: 22px;
  margin: 0;
  font-weight: 700;
}

.date-range {
  background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%);
  color: white;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
}

.dynamic-list {
  list-style-type: none;
  padding-left: 0;
  margin: 0;
}

.dynamic-list li {
  padding: 14px;
  border-left: 4px solid #5568d3;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #f9fafb;
  transition: all 0.2s ease;
}

.dynamic-list li:hover {
  background: #f3f4f6;
  border-left-color: #3b4a9a;
  transform: translateX(4px);
}

.dynamic-btn {
  padding: 10px 18px;
  margin-top: 10px;
  margin-right: 10px;
  background-color: #7f1d1d;
  color: white;
  border: 3px solid #7f1d1d;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(127, 29, 29, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 12px;
}

.dynamic-btn:hover {
  background-color: #991b1b;
  border-color: #991b1b;
  box-shadow: 0 4px 8px rgba(127, 29, 29, 0.6);
  transform: translateY(-1px);
}

.dynamic-text {
  margin-bottom: 10px;
  line-height: 1.6;
  white-space: pre-line;
}

/* Enhanced Result Display Styles */
.summary-section {
  margin-bottom: 30px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.summary-box {
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.summary-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.summary-box-blue {
  background: linear-gradient(135deg, #5568d3 0%, #6a3d99 100%);
  color: white;
  border: 3px solid #3b4a9a;
}

.summary-box-teal {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  border: 3px solid #4f46e5;
}

.summary-box-purple {
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  color: white;
  border: 3px solid #6d28d9;
}

.summary-box-orange {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  border: 3px solid #b45309;
}

.summary-box-green {
  background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
  color: white;
  border: 3px solid #0f766e;
  position: relative;
}

.summary-box-green::before {
  content: '↓';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 24px;
  font-weight: bold;
}

.summary-label {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 8px;
  font-weight: 500;
}

.summary-value {
  font-size: 28px;
  font-weight: bold;
}

.tenants-heading {
  margin-top: 30px;
  margin-bottom: 20px;
  color: #1f2937;
  font-size: 24px;
  font-weight: 700;
  border-bottom: 3px solid #5568d3;
  padding-bottom: 12px;
  position: relative;
  user-select: none;
  cursor: pointer;
  transition: color 0.3s ease;
}

.tenants-heading.collapsible::after {
  content: '▼';
  position: absolute;
  right: 0;
  transition: transform 0.3s ease;
  font-size: 18px;
  color: #5568d3;
}

.tenants-heading.collapsible.expanded::after {
  transform: rotate(180deg);
}

.tenants-heading.collapsible:hover {
  color: #5568d3;
}

.tenants-heading.collapsible:hover::after {
  color: #3b4a9a;
}

.tenants-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease-out;
}

.tenants-container.show {
  max-height: 10000px;
  transition: max-height 1s ease-in;
}

.tenant-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
  border: 1px solid #e5e7eb;
  transition: all 0.3s ease;
}

.tenant-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transform: translateY(-2px);
}

.tenant-header {
  background: linear-gradient(135deg, #5568d3 0%, #6a3d99 100%);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tenant-header h4 {
  margin: 0;
  font-size: 20px;
}

.total-badge {
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 16px;
  position: relative;
}

.total-badge.payment {
  background-color: #f59e0b;
  border: 2px solid #d97706;
  color: white;
}

.total-badge.payment::before {
  content: '↑ ';
  font-weight: bold;
}

.total-badge.refund {
  background-color: #14b8a6;
  border: 2px solid #0d9488;
  color: white;
}

.total-badge.refund::before {
  content: '↓ ';
  font-weight: bold;
}

.tenant-details {
  padding: 20px;
}

.info-row {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f0f0;
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-weight: 600;
  color: #374151;
  display: block;
  margin-bottom: 5px;
}

.info-value {
  color: #1f2937;
  font-size: 16px;
}

.rates-list {
  list-style: none;
  padding-left: 0;
  margin-top: 10px;
}

.rates-list li {
  padding: 8px 14px;
  margin: 6px 0;
  background: #f3f4f6;
  border-left: 4px solid #5568d3;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 14px;
}

.rates-list li:hover {
  background: #e5e7eb;
  border-left-color: #3b4a9a;
  transform: translateX(4px);
}

.pending-section {
  margin-top: 20px;
  background: #f9fafb;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.pending-header {
  padding: 14px 18px;
  background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%);
  color: white;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.3s ease;
  position: relative;
}

.pending-header::after {
  content: '▼';
  position: absolute;
  right: 18px;
  transition: transform 0.3s ease;
  font-size: 16px;
}

.pending-header.expanded::after {
  transform: rotate(180deg);
}

.pending-header:hover {
  background: linear-gradient(135deg, #0e7490 0%, #0c4a6e 100%);
}

.pending-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out;
}

.pending-content.show {
  max-height: 1000px;
  transition: max-height 0.6s ease-in;
}

.pending-list {
  list-style: none;
  padding: 18px;
  margin: 0;
  background: white;
}

.pending-list li {
  padding: 12px 14px;
  margin: 10px 0;
  background: #f9fafb;
  border-left: 4px solid #0891b2;
  border-radius: 6px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 14px;
  color: #1f2937;
  transition: all 0.2s ease;
}

.pending-list li:hover {
  background: #f3f4f6;
  border-left-color: #0e7490;
  transform: translateX(4px);
}

@media (max-width: 768px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }
  
  .tenants-container {
    grid-template-columns: 1fr;
  }
  
  .tenant-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }
  
  .total-badge {
    align-self: flex-end;
  }
  
  #resultInteractions {
    flex-direction: column;
    gap: 15px;
  }
  
  #calculateButton {
    width: 100%;
  }
  
  #save {
    width: 100%;
  }
  
  #save button {
    flex: 1;
  }
}