:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --accent: #10b981;
  --danger: #ef4444;
  --warning: #f59e42;
  --bg: #f8fafc;
  --surface: #fff;
  --border: #e5e7eb;
  --text: #222;
  --muted: #6b7280;
  --shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.07);
  --radius: 12px;
}

/* Dark Mode */
html.dark {
  --primary: #60a5fa;
  --primary-light: #93c5fd;
  --accent: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --shadow: 0 2px 16px 0 rgba(0, 0, 0, 0.32);
}

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

body {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  transition: background 0.3s, box-shadow 0.3s;
}

h1 {
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 0.5em;
}

h2,
h3 {
  color: var(--primary-light);
  font-weight: 600;
  margin-top: 1.5em;
}

/* Header bar */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Dark mode toggle */
.dark-toggle {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45em 1em;
  font-size: 1.15em;
  cursor: pointer;
  transition: background 0.2s, border 0.2s, transform 0.15s;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.dark-toggle:hover {
  border-color: var(--primary);
  transform: scale(1.07);
}

/* Controls */
.controls {
  margin-top: 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

input[type=range] {
  width: 220px;
  margin-left: 0.5rem;
  accent-color: var(--primary);
}

/* Drop zone */
.drop-zone {
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 2.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.25s, background 0.25s, transform 0.15s;
  margin-bottom: 1.2em;
  position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.04);
  transform: scale(1.005);
}

html.dark .drop-zone:hover,
html.dark .drop-zone.drag-over {
  background: rgba(96, 165, 250, 0.08);
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.06);
}

.drop-zone-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.3em;
}

.drop-zone-content p {
  margin: 0.3em 0;
  font-size: 1.05em;
  color: var(--text);
}

.drop-zone-hint {
  font-size: 0.9em !important;
  color: var(--muted) !important;
}

.drop-zone-browse {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.drop-zone-browse:hover {
  color: var(--accent);
}

.drop-zone input[type="file"] {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

input#search {
  padding: 0.5em 1em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 1em;
  transition: border 0.2s;
  color: var(--text);
}

input#search:focus {
  border: 1.5px solid var(--primary);
  outline: none;
}

select#filter {
  padding: 0.5em 1em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 1em;
  transition: border 0.2s;
  color: var(--text);
}

select#filter:focus {
  border: 1.5px solid var(--primary);
  outline: none;
}

/* Table */
table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin-top: 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0.5rem;
  text-align: center;
  font-size: 1em;
}

th {
  background: var(--bg);
  color: var(--primary);
  font-weight: 600;
  cursor: default;
  user-select: none;
}

th.sortable {
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

th.sortable:hover {
  color: var(--accent);
}

tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.025);
}

html.dark tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.04);
}

tr:hover td {
  background: #e0e7ff;
  transition: background 0.2s;
}

html.dark tr:hover td {
  background: rgba(96, 165, 250, 0.12);
}

/* Charts */
.chart-container {
  display: flex;
  flex-wrap: wrap;
  gap: 2.7rem;
  margin-top: 2.7rem;
  justify-content: center;
  align-items: stretch;
  width: 100%;
}

.chart-box {
  flex: 1 1 450px;
  min-width: 350px;
  max-width: 850px;
  height: 520px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  box-sizing: border-box;
  position: relative;
}

.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-box-pie {
  min-width: 300px;
  max-width: 500px;
  height: 480px;
}

/* Section */
.section {
  margin-top: 2rem;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow);
}

.section h3 {
  margin-bottom: 0.5rem;
  color: var(--primary);
}

/* Lists */
.top-list {
  list-style: none;
  padding: 0;
  margin: 0.5em 0 1em 0;
}

.top-list li {
  margin: 0.25rem 0;
  padding: 0.4em 0.7em;
  border-radius: var(--radius);
  background: #f1f5f9;
  color: var(--primary);
  font-weight: 500;
  font-size: 1em;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}

html.dark .top-list li {
  background: var(--bg);
}

.top-list li:last-child {
  margin-bottom: 0.5em;
}

.error {
  color: var(--danger);
  font-weight: 500;
  margin-top: 0.5em;
}

.slider-label {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.slider-label span {
  width: 2.5rem;
  text-align: center;
  color: var(--primary-light);
  font-weight: 600;
}

/* Footer */
footer {
  margin-top: 2rem;
  font-size: 0.95em;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 1.5em;
  letter-spacing: 0.2px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(30, 41, 59, 0.18);
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px);
}

html.dark .modal {
  background: rgba(0, 0, 0, 0.55);
}

.modal-content {
  background: var(--surface);
  padding: 2rem 2.5rem;
  border-radius: var(--radius);
  min-width: 320px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--primary-light);
  animation: modalIn 0.25s cubic-bezier(.4, 2, .6, 1) both;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 1rem;
  font-size: 2rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--danger);
}

.modal h2 {
  margin-top: 0;
  color: var(--primary);
  font-size: 1.3em;
  font-weight: 600;
}

.modal-chart {
  width: 100% !important;
  max-width: 600px;
  margin: 1rem auto;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.modal-details {
  margin-top: 1rem;
}

.modal-details table {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 0.5em;
}

.modal-details th,
.modal-details td {
  padding: 0.4rem 0.3rem;
  font-size: 0.98em;
  border-bottom: 1px solid var(--border);
}

.modal-details th {
  background: var(--bg);
  color: var(--primary-light);
  font-weight: 600;
}

.modal-details tr:last-child td {
  border-bottom: none;
}

.modal-details .explanation {
  font-size: 0.97em;
  color: var(--muted);
  margin-top: 0.5em;
  background: #f1f5f9;
  border-radius: var(--radius);
  padding: 0.5em 1em;
}

html.dark .modal-details .explanation {
  background: var(--bg);
}

/* Export buttons */
.export-bar {
  display: flex;
  gap: 0.7rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.btn-export {
  padding: 0.5em 1.2em;
  border-radius: var(--radius);
  border: 1.5px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.95em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.12s;
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.btn-export:hover {
  background: var(--primary);
  color: #fff;
  transform: scale(1.04);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.3rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination button {
  padding: 0.35em 0.85em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border 0.15s;
}

.pagination button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.pagination button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Responsive */
@media (max-width: 1200px) {
  .chart-container {
    gap: 1.7rem;
  }

  .chart-box {
    max-width: 100%;
    min-width: 0;
    height: 400px;
    padding: 1rem;
  }

  .chart-box-pie {
    max-width: 100%;
    min-width: 0;
    height: 380px;
  }
}

@media (max-width: 900px) {
  .chart-container {
    flex-direction: column;
    align-items: stretch;
    gap: 1.2rem;
  }

  .chart-box {
    max-width: 100%;
    min-width: 0;
    height: 350px;
    padding: 0.9rem;
  }

  .chart-box-pie {
    height: 320px;
  }

  body {
    padding: 0.5rem;
  }

  .modal-content {
    padding: 1rem;
  }
}

@media (max-width: 600px) {
  .chart-box {
    height: 250px;
    padding: 0.5rem;
  }

  .chart-box-pie {
    height: 220px;
  }

  body {
    padding: 0.2rem;
  }

  .modal-content {
    padding: 0.5rem;
  }
}