:root {
  /* Light Theme Variables */
  --background-color: #f5f5f5;
  --text-color: #212529;
  --element-bg-color: #fff;
  --border-color: #ced4da;
  --highlight-color: #007bff;
  --button-bg-color: #007bff;
  --button-text-color: #fff;
  --chart-grid-color: rgba(0, 0, 0, 0.7);
  /* Changed grid color */
  --chart-text-color: #212529;
  --chart-line-color: #007bff;
  /* Added line color */
  --table-header-bg-color: #e9ecef;
}

/* Dark Theme Variables (when data-theme="dark") */
html[data-theme="dark"] {
  --background-color: #212529;
  --text-color: #f8f9fa;
  --element-bg-color: #343a40;
  --border-color: #495057;
  --highlight-color: #339dff;
  --button-bg-color: #339dff;
  --button-text-color: #fff;
  --chart-grid-color: rgba(255, 255, 255, 0.2);
  /* Changed grid color */
  --chart-text-color: #fff;
  --chart-line-color: #339dff;
  /* Added line color */
  --table-header-bg-color: #495057;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 1200px;
  margin: 20px auto;
  padding: 20px;
  background-color: var(--element-bg-color);
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s ease;
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

.header h1 {
  color: var(--highlight-color);
  margin-bottom: 10px;
}

.header hr {
  border: none;
  border-top: 1px solid var(--border-color);
}

h2 {
  color: var(--highlight-color);
}

/* Input Styles */
.input-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
  flex: 0 0 25%;
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
}

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

label {
  margin-bottom: 5px;
  font-weight: 600;
}

input[type="number"] {
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  font-size: 16px;
  width: 100%;
  box-sizing: border-box;
  background-color: var(--element-bg-color);
  color: var(--text-color);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

button {
  background-color: var(--button-bg-color);
  color: var(--button-text-color);
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
}

button:hover {
  opacity: 0.8;
}

/* Layout Styles */
.content {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
}

.chart-container {
  flex-grow: 1;
  max-width: 70%;
}

.results-container {
  margin-bottom: 30px;
}

/* Table Styles */
#resultsTable {
  border-collapse: collapse;
  width: 100%;
  font-family: "Ubuntu Mono", monospace; /* Set monospace font for the whole table */
}

#resultsTable th,
#resultsTable td {
  border: 1px solid var(--border-color);
  padding: 10px;
  text-align: left; /* Default text-align to left */
}

#resultsTable th {
  background-color: var(--table-header-bg-color);
  cursor: pointer;
  user-select: none;
}

#resultsTable th.sorted-asc:after {
  content: " ▲";
}

#resultsTable th.sorted-desc:after {
  content: " ▼";
}

/* Highlight Aggregate Rows */
#resultsTable tbody tr:nth-child(-n + 3) {
  background-color: var(--table-header-bg-color);
  font-weight: bold;
}

/* Right-align data in columns starting from the second column */
#resultsTable td:nth-child(n + 2) {
  text-align: right;
}

/* Chart.js Styling */
.chart-container {
  background-color: var(--element-bg-color);
  padding: 20px;
  border-radius: 10px;
  transition: background-color 0.3s ease;
}

.chart-container canvas {
  width: 100%;
  height: 400px;
}

/* Theme Switch Styling */
.theme-toggle {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #2196f3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196f3;
}

input:checked + .slider:before {
  transform: translateX(26px);
}

/* Media Queries for Responsiveness */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --background-color: #212529;
    --text-color: #f8f9fa;
    --element-bg-color: #343a40;
    --border-color: #495057;
    --highlight-color: #339dff;
    --button-bg-color: #339dff;
    --button-text-color: #fff;
    --chart-grid-color: rgba(255, 255, 255, 0.2);
    --chart-text-color: #fff;
    --chart-line-color: #339dff;
    --table-header-bg-color: #495057;
  }
}

@media (max-width: 768px) {
  .input-row {
    flex-direction: column;
  }

  .input-group {
    width: 100%;
  }

  #resultsTable {
    font-size: 14px;
  }

  .content {
    flex-direction: column;
  }

  .chart-container {
    max-width: 100%;
  }

  .input-container {
    flex: 0 0 100%;
  }
}
