:root {
  /* Dark mode (default) color palette - optimized for contrast */
  --primary-color: #5ba3ff; /* vibrant blue */
  --accent-color: #e6c54f; /* bright gold */
  --secondary-color: #e8e8e8;
  --light-gray: #1b1f2b; /* row alt - subtle contrast */
  --dark-gray: #f5f8ff; /* text - high contrast white-blue */
  --white: #0d0d0d; /* panel background */
  --bg: #000000; /* page background - pure black */
  --panel-bg: linear-gradient(180deg, #0d0d0d, #1a1a1a);
  --header-grad-start: #1f4a6b;
  --header-grad-end: #0f2a3f;
  --header-text: #ffffff;
  --cell-border: rgba(255, 255, 255, 0.15);
  --row-hover: rgba(230, 197, 79, 0.1);
  --footer-bg: rgba(230, 197, 79, 0.05);
  --accent-gold: #e6c54f;
  --sorted-bg: rgba(230, 197, 79, 0.15);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

/* Light mode overrides - optimized for contrast */
.light-mode {
  --primary-color: #0056c7;
  --accent-color: #c79a00;
  --secondary-color: #424242;
  --light-gray: #f8f8f8;
  --dark-gray: #1c1c1c;
  --white: #ffffff;
  --bg: #fafafa;
  --panel-bg: linear-gradient(180deg, #ffffff, #f5f5f5);
  --header-grad-start: #0056c7;
  --header-grad-end: #003d8f;
  --header-text: #ffffff;
  --cell-border: #d0d0d0;
  --row-hover: #f0f4f8;
  --footer-bg: #f8f8f8;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --accent-gold: #0056c7;
  --sorted-bg: rgba(0, 86, 199, 0.1);
}

.light-mode h1 {
  color: var(--primary-color);
}

body {
  font-family: "Roboto", sans-serif;
  background: var(--bg);
  color: var(--dark-gray);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Heading bar at top */
.heading-bar {
  background: linear-gradient(
    135deg,
    var(--header-grad-start),
    var(--header-grad-end)
  );
  padding: 20px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-bottom: 2px solid var(--accent-gold);
}

.heading-title {
  color: var(--header-text);
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 2rem;
}

.light-mode .heading-bar {
  background: linear-gradient(135deg, #ffffff, #f0f4f8);
  border-bottom: 3px solid var(--primary-color);
  box-shadow: 0 3px 10px rgba(0, 86, 199, 0.15);
}

.light-mode .heading-title {
  color: var(--primary-color);
  text-shadow: 0 1px 2px rgba(0, 86, 199, 0.1);
}

/* Footer bar at bottom */
.footer-bar {
  background: linear-gradient(
    135deg,
    var(--header-grad-start),
    var(--header-grad-end)
  );
  padding: 16px 20px;
  text-align: center;
  margin-top: auto;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
  border-top: 2px solid var(--accent-gold);
}

.light-mode .footer-bar {
  background: linear-gradient(135deg, #f0f4f8, #ffffff);
  border-top: 3px solid var(--primary-color);
  box-shadow: 0 -3px 10px rgba(0, 86, 199, 0.15);
}

.footer-bar p {
  margin: 0;
  color: var(--header-text);
  font-size: 0.95rem;
  font-weight: 500;
}

.light-mode .footer-bar p {
  color: #424242;
}

.footer-bar .github-link {
  color: var(--accent-gold);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  transition: color 0.2s ease, transform 0.2s ease;
  margin-left: 8px;
}

.footer-bar .github-link:hover {
  color: #ffffff;
  transform: translateY(-1px);
}

.footer-bar .github-link i {
  font-size: 1.2rem;
  vertical-align: middle;
}

.light-mode .footer-bar .github-link {
  color: var(--primary-color);
}

.light-mode .footer-bar .github-link:hover {
  color: #003d8f;
}

/* Smooth transitions when switching themes */
body,
.container,
table thead th,
th,
td,
tfoot th {
  transition: background-color 240ms ease, color 240ms ease,
    border-color 240ms ease;
}

.container {
  max-width: 1400px;
  margin: 30px auto;
  padding: 32px;
  background: var(--panel-bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--cell-border);
  flex: 1;
}

/* Wider container on larger screens */
@media (min-width: 1600px) {
  .container {
    max-width: 1600px;
  }
}

.buttons-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 15px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

/* File input positioned in top-right corner */
.file-input-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
}

/* Theme toggle positioned in top-right corner outside container */
.theme-toggle-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: rgba(0, 0, 0, 0.05);
  border: 2px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

.theme-toggle-btn:hover {
  transform: scale(1.08);
  background-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.3);
  border-width: 2.5px;
}

.theme-toggle-btn:active {
  transform: scale(0.96);
}

/* Light mode theme button styling */
.light-mode .theme-toggle-btn {
  background-color: rgba(0, 86, 199, 0.05);
}

.light-mode .theme-toggle-btn:hover {
  background-color: rgba(0, 86, 199, 0.1);
}

/* Print button positioned in bottom-right corner outside container */
.print-btn-floating {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.print-btn-floating:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.print-btn-floating:active {
  transform: scale(0.95);
}

/* Dark mode: print button matches other buttons (golden) */
body:not(.light-mode) .print-btn-floating {
  background-color: #e6c54f;
  color: #0d0d0d;
}

body:not(.light-mode) .print-btn-floating:hover {
  background-color: #f5d663;
}

/* Light mode: print button uses primary blue */
.light-mode .print-btn-floating {
  background-color: #0056c7;
  color: #ffffff;
}

.light-mode .print-btn-floating:hover {
  background-color: #0042a0;
}

.print-btn-floating .btn-icon {
  margin-right: 0; /* No margin for circular button */
}

.container {
  position: relative;
}

/* File input styled as a button matching overall design */
input[type="file"] {
  display: none; /* Hide native input */
}

/* File input wrapper button styling via label element */
.file-input-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  padding: 11px 20px;
  cursor: pointer;
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  transition: background-color 0.25s ease, box-shadow 0.25s ease,
    transform 0.1s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.file-input-button:hover {
  background-color: #0042a0;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}

.file-input-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Dark mode: file input button matches generate button (golden) */
body:not(.light-mode) .file-input-button {
  background-color: #e6c54f;
  color: #0d0d0d;
}

body:not(.light-mode) .file-input-button:hover {
  background-color: #f5d663;
}

.file-count-text {
  margin-top: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--dark-gray);
  text-align: center;
  min-height: 1.2em; /* Prevent layout shift */
}

.light-mode .file-count-text {
  color: var(--secondary-color);
}

/* Stack the file input button and count vertically */
.file-input-wrapper {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.column-toggle-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 20px;
  align-items: start;
  padding: 18px 16px;
  border-radius: 8px;
  background: var(--row-hover);
  border: 1.5px solid var(--cell-border);
  margin-bottom: 24px;
}

.column-toggle-container strong {
  grid-column: 1 / -1;
  text-align: center;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--dark-gray);
}

.column-toggle-container label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--dark-gray);
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.column-toggle-container label:hover {
  background: var(--sorted-bg);
}

/* Improve native checkbox appearance slightly */
.column-toggle-container input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-gold);
  cursor: pointer;
}

/* Light mode: blue checkboxes */
.light-mode .column-toggle-container input[type="checkbox"] {
  accent-color: #0052b3;
}

/* Buttons: small icon spacing */
.btn-icon {
  margin-right: 8px;
  vertical-align: middle;
  opacity: 0.95;
}
.buttons-container button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Dark mode: button icons should be black for golden buttons */
body:not(.light-mode) button:not(#resetButton):not(#themeToggle) .btn-icon {
  color: #0d0d0d;
}

body:not(.light-mode) .file-input-button .btn-icon {
  color: #0d0d0d;
}

/* Light mode: button icons should be white for blue buttons */
.light-mode button .btn-icon,
.light-mode .file-input-button .btn-icon {
  color: #ffffff;
}

/* Reset button icon stays white in both modes */
#resetButton .btn-icon {
  color: #ffffff;
}

button {
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  padding: 12px 25px;
  cursor: pointer;
  border-radius: 6px;
  font-weight: 700;
  transition: background-color 0.25s ease, box-shadow 0.25s ease,
    transform 0.1s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

button:hover {
  background-color: #0042a0;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Dark mode: make buttons golden with better contrast */
body:not(.light-mode) button:not(#resetButton):not(#themeToggle) {
  background-color: #e6c54f;
  color: #0d0d0d;
}

body:not(.light-mode) button:not(#resetButton):not(#themeToggle):hover {
  background-color: #f5d663;
}

#resetButton {
  background-color: #e53935;
  color: #ffffff;
}

#resetButton:hover {
  background-color: #c62828;
}

/* Export button uses same colors as generate button (handled by general button rules and dark mode override) */

/* Table wrapper provides horizontal scrolling for wide tables */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border-radius: 10px;
}

/* table visuals */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 20px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--white);
}

/* Keep header visible when scrolling horizontally */
table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(
    180deg,
    var(--header-grad-start),
    var(--header-grad-end)
  );
  color: var(--header-text);
  font-weight: 600;
  padding: 14px 32px 14px 16px; /* Increased right padding for sorting indicators */
}

th,
td {
  border-bottom: 1.5px solid var(--cell-border);
  text-align: left;
  padding: 15px 18px;
  color: var(--dark-gray);
}

thead th {
  color: var(--header-text);
  font-weight: 600;
}

/* Sorting indicators and sorted-column highlight */
thead th {
  position: relative;
}
/* default neutral indicator for sortable columns */
thead th.sortable::after {
  content: "⇅";
  position: absolute;
  right: 16px; /* Adjusted to match new padding */
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.65);
}
thead th.sort-asc::after {
  content: "▲";
}
thead th.sort-desc::after {
  content: "▼";
}

/* highlight active sorted column (header + cells) */
.sorted-col {
  background-color: var(--sorted-bg);
}

tbody tr:nth-child(even) {
  background-color: var(--light-gray);
}

tbody tr:hover {
  background-color: var(--row-hover);
}

/* Responsive adjustments */
@media (max-width: 800px) {
  .buttons-container {
    gap: 8px;
  }
  .column-toggle-container {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  .column-toggle-container label {
    font-size: 0.85rem;
    padding: 5px 6px;
  }
  table tbody {
    max-height: 40vh;
  }
  .theme-toggle-btn {
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
  }
  .heading-title {
    font-size: 1.6rem;
  }
  .footer-bar p {
    font-size: 0.85rem;
  }
  .container {
    margin: 20px auto;
  }
}

@media (max-width: 480px) {
  .column-toggle-container {
    grid-template-columns: 1fr;
    gap: 8px 12px;
  }
  button {
    padding: 9px 14px;
    font-size: 0.85rem;
  }
  .file-input-button {
    padding: 9px 14px;
    font-size: 0.85rem;
  }
  .file-count-text {
    font-size: 0.8rem;
    margin-top: 6px;
  }
  .theme-toggle-btn {
    top: 10px;
    right: 10px;
    width: 38px;
    height: 38px;
  }
  .heading-title {
    font-size: 1.4rem;
  }
  .heading-bar {
    padding: 16px;
  }
  .footer-bar {
    padding: 12px 16px;
  }
  .footer-bar p {
    font-size: 0.8rem;
  }
  .container {
    margin: 15px;
    padding: 20px;
  }
}

tfoot {
  background-color: var(--footer-bg);
  font-weight: bold;
  color: var(--dark-gray);
}

tfoot th {
  padding: 12px 14px;
}

/* small utility: make headers look interactive */
thead th.sortable {
  cursor: pointer;
}

/* theme-driven icon swap for theme toggle */
/* show sun by default (dark mode) and moon in light mode - apply requested colors */
.theme-toggle-btn .icon-sun,
.theme-toggle-btn .icon-moon {
  display: inline-block;
  font-size: 1.05rem; /* slightly larger than button text */
  line-height: 1;
  vertical-align: middle;
}

/* Default (dark mode): show sun, color it gold */
.theme-toggle-btn .icon-sun {
  display: inline-block;
  color: var(--accent-gold); /* #e6c54f */
}
.theme-toggle-btn .icon-moon {
  display: none;
}

/* Light mode: hide sun, show moon colored blue */
body.light-mode .theme-toggle-btn .icon-sun {
  display: none;
}
body.light-mode .theme-toggle-btn .icon-moon {
  display: inline-block;
  color: var(--primary-color); /* #0056c7 in light-mode */
}

/* Print styles - hide UI elements and optimize table for printing */
@media print {
  /* Hide all UI elements including floating buttons */
  .heading-bar {
    display: none;
  }
  .footer-bar {
    display: none;
  }
  .buttons-container {
    display: none;
  }
  .column-toggle-container {
    display: none;
  }
  .theme-toggle-btn {
    display: none;
  }
  .print-btn-floating {
    display: none;
  }
  .file-input-wrapper {
    display: none;
  }

  /* Adjust body for print */
  body {
    background: white;
    color: black;
    margin: 0;
    padding: 0;
  }

  /* Adjust container for print */
  .container {
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: white;
    border: none;
    box-shadow: none;
    flex: none;
  }

  /* Table print styling */
  .table-wrapper {
    width: 100%;
    overflow: visible;
    border-radius: 0;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0;
    border-radius: 0;
    background: white;
    page-break-inside: avoid;
  }

  table thead th {
    position: static;
    background: #f0f0f0;
    color: black;
    font-weight: bold;
    padding: 10px;
    border: 1px solid #999;
    text-align: left;
  }

  table tbody tr {
    page-break-inside: avoid;
  }

  table tbody td {
    padding: 8px 10px;
    border: 1px solid #ddd;
    background: white;
    color: black;
  }

  table tbody tr:nth-child(even) {
    background: white;
  }

  table tbody tr:hover {
    background: white;
  }

  table tfoot {
    background: #f0f0f0;
    font-weight: bold;
  }

  table tfoot th {
    padding: 10px;
    border: 1px solid #999;
    background: #f0f0f0;
    color: black;
  }

  /* Ensure all text is visible in print */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }
}
