/* Use flex to center content vertically and horizontally, keeping Arial font */
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #f0f0f0;
  font-family: Arial, sans-serif;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Container that holds the entire layout */
#container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  /* fill the vertical space */
  box-sizing: border-box;
  width: 100%;
  max-width: 800px;
  padding: 20px;
  margin: 0 auto;
}
/* Treemap container with equal padding for all sides */
#chart-container {
  width: 100%;
  max-width: 700px;
  /* extra width to accommodate 600px SVG + padding */
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
  padding: 50px 50px;
  /* smaller equal gap on all sides */
  margin-bottom: 40px;
  /* spacing below the treemap container */
}
/* Center the SVG within the treemap container and make it responsive */
#chart-container svg {
  display: block;
  margin: 0 auto;
  width: 100%;
  height: auto;
  max-width: 600px;
}
/* Update Table Container */
#table-container {
  width: 100%;
  max-width: 700px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
  padding: 20px;
  margin-bottom: 40px;
}

/* Desktop tables layout */
.desktop-tables {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

/* Mobile table - hidden by default */
.mobile-only {
  display: none;
}
/* Tables should have a flexible width */
table {
  width: 100%;
  flex: 1;
  /* Adjust to prevent overlapping */
  border-collapse: collapse;
  margin: 0;
  min-width: 0;
}
table thead th {
  text-align: center;
  padding: 5px;
}
table tbody tr td {
  border: none;
  padding: 8px 5px;
  /* row height */
  text-align: center;
  vertical-align: middle;
}
/* Circle indicating color */
.color-circle {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.category-name {
  vertical-align: middle;
}
/* Center text in inputs, hide spin arrows */
table td input {
  width: 60px;
  height: 35px;
  text-align: center;
  font-size: 14px;
  box-sizing: border-box;
  appearance: textfield;
  -moz-appearance: textfield;
  /* hide spin for Firefox */
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
/* Text inside treemap rectangles */
.treemap-rect-text {
  fill: #fff;
  font-size: 14px;
  text-anchor: middle;
  alignment-baseline: middle;
  pointer-events: none;
}

/* Mobile-specific styles */
@media screen and (max-width: 768px) {
  #container {
    padding: 30px;
    min-height: auto;
    max-width: 100%;
  }

  #chart-container {
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 6px;
    max-width: 100%;
  }

  #table-container {
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 6px;
    max-width: 100%;
  }

  /* Hide desktop tables and show mobile table */
  .desktop-tables {
    display: none;
  }

  .mobile-only {
    display: table;
    width: 100%;
  }

  table {
    width: 100%;
  }

  table thead th {
    padding: 4px 2px;
    font-size: 12px;
    font-weight: bold;
  }

  table tbody tr td {
    padding: 4px 2px;
    font-size: 11px;
  }

  table td input {
    width: 50px;
    height: 30px;
    font-size: 12px;
    touch-action: manipulation;
  }

  .treemap-rect-text {
    font-size: 10px;
  }

  .color-circle {
    width: 8px;
    height: 8px;
    margin-right: 4px;
  }

  .category-name {
    font-size: 13px;
  }

  /* Style for mobile increment/decrement buttons */
  table td button {
    width: 25px;
    height: 25px;
    font-size: 14px;
    touch-action: manipulation;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
  }

  table td button:hover {
    background: #e0e0e0;
  }

  table td button:active {
    background: #d0d0d0;
    transform: scale(0.95);
  }
}

@media screen and (max-width: 480px) {
  #container {
    padding: 20px;
  }

  #chart-container {
    padding: 8px;
    margin-bottom: 10px;
  }

  #table-container {
    padding: 8px;
    margin-bottom: 10px;
  }

  /* Hide desktop tables and show mobile table */
  .desktop-tables {
    display: none;
  }

  .mobile-only {
    display: table;
    width: 100%;
  }

  table {
    width: 100%;
  }

  table thead th {
    padding: 3px 1px;
    font-size: 11px;
  }

  table tbody tr td {
    padding: 3px 1px;
    font-size: 10px;
  }

  table td input {
    width: 45px;
    height: 28px;
    font-size: 11px;
  }

  .color-circle {
    width: 6px;
    height: 6px;
    margin-right: 3px;
  }

  .category-name {
    font-size: 11px;
  }

  .treemap-rect-text {
    font-size: 8px;
  }

  table td button {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }
}
