:root {
  --bg: #0a1924;
  --bg2: #112f45;
  --panel: rgba(9, 28, 44, 0.78);
  --line: rgba(120, 197, 255, 0.2);
  --text: #e9f7ff;
  --muted: #9bb8ca;
  --accent: #36d69f;
  --accent2: #58b4ff;
  --danger: #ff8f8f;
  --control-bg: rgba(6, 21, 34, 0.92);
  --control-bg-hover: rgba(12, 34, 52, 0.96);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, #1f607e 0%, var(--bg) 40%),
    linear-gradient(130deg, var(--bg), var(--bg2));
  font-family: "IBM Plex Sans", sans-serif;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 34px 34px;
  pointer-events: none;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1500px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem) 0 3rem;
  display: grid;
  gap: 1rem;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  min-width: 0;
}

.hero {
  padding: 1.3rem 1.4rem;
}

.hero h1 {
  margin: 0.4rem 0 0.55rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.4rem, 3.3vw, 2.4rem);
  line-height: 1.12;
}

.subline {
  margin: 0;
  color: var(--muted);
}

.badge {
  margin: 0;
  color: #d6fff2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

.language-nav {
  display: flex;
  gap: 0.55rem;
  justify-content: flex-end;
  margin: 0 0 0.6rem;
}

.language-nav a {
  text-decoration: none;
  color: #d5edff;
  font-size: 0.78rem;
  font-family: "Space Grotesk", sans-serif;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: rgba(14, 42, 60, 0.75);
}

.language-nav a:hover {
  background: rgba(24, 71, 100, 0.9);
}

.language-nav a.is-active {
  background: linear-gradient(125deg, var(--accent), var(--accent2));
  color: #032f20;
  border-color: transparent;
  font-weight: 700;
}

.controls,
.sync-controls {
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  align-items: end;
}

.menu-panel {
  padding: 1rem;
}

.menu-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.menu-group h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.menu-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.menu-btn {
  width: auto;
  min-width: 180px;
  height: 2.2rem;
  padding: 0 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.menu-btn.is-active {
  background: linear-gradient(125deg, var(--accent), var(--accent2));
  color: #032f20;
  border-color: transparent;
}

.menu-btn:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  filter: saturate(0.75);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.checkbox-group {
  align-self: end;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.6rem;
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.actions button {
  width: auto;
  min-width: 180px;
}

label,
h2,
h3 {
  font-family: "Space Grotesk", sans-serif;
}

h2,
h3 {
  margin: 0 0 0.6rem;
}

select,
input,
button {
  width: 100%;
  min-width: 0;
  height: 2.55rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--text);
  padding: 0 0.8rem;
  font-size: 0.95rem;
}

select {
  appearance: none;
  color-scheme: dark;
  padding-right: 3rem;
  background-image: linear-gradient(45deg, transparent 50%, #8fd7ff 50%),
    linear-gradient(135deg, #8fd7ff 50%, transparent 50%),
    linear-gradient(to right, rgba(120, 197, 255, 0.18), rgba(120, 197, 255, 0.18));
  background-position: calc(100% - 20px) calc(50% - 3px), calc(100% - 14px) calc(50% - 3px),
    calc(100% - 2.65rem) 50%;
  background-size: 6px 6px, 6px 6px, 1px 1.4rem;
  background-repeat: no-repeat;
}

select:hover,
input:hover {
  background: var(--control-bg-hover);
}

select:disabled,
input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid #78c5ff;
  outline-offset: 1px;
}

select option,
select optgroup {
  background: #0f2b40;
  color: var(--text);
}

button {
  cursor: pointer;
  background: linear-gradient(125deg, var(--accent), var(--accent2));
  color: #032f20;
  font-weight: 700;
  transition: filter 120ms ease;
}

button:hover {
  filter: brightness(1.05);
}

button:disabled {
  cursor: not-allowed;
  filter: none;
}

input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  border: 0;
  padding: 0;
  accent-color: var(--accent);
}

.button-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.status {
  margin: 0;
  color: var(--muted);
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.status[hidden] {
  display: none;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.metric {
  padding: 1rem;
}

.metric p {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-family: "Space Grotesk", sans-serif;
}

.chart-panel,
.table-panel {
  padding: 1rem;
}

.tab-panel {
  padding: 1rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.tab-btn {
  width: auto;
  min-width: 170px;
  height: 2.35rem;
}

.tab-btn.is-active {
  background: linear-gradient(125deg, var(--accent), var(--accent2));
  color: #032f20;
  border-color: rgba(102, 220, 255, 0.5);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.chart-box {
  height: clamp(220px, 30vh, 330px);
  width: 100%;
}

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

.status-panel {
  padding: 1rem;
}

.sync-log {
  margin: 0.8rem 0 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 280px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.02);
  color: #b9d2e4;
}

.table-meta {
  margin: 0 0 0.7rem;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}

.event-table-wrap {
  max-height: min(50vh, 34rem);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
}

#eventsTable {
  min-width: 760px;
}

#listsTable {
  min-width: 620px;
}

#filesTable {
  min-width: 420px;
}

#candidatesTable {
  min-width: 760px;
}

th,
td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  white-space: normal;
  vertical-align: top;
}

th {
  color: #b6ddff;
  background: rgba(18, 52, 75, 0.95);
  position: sticky;
  top: 0;
  z-index: 2;
}

.table-sort-btn {
  width: auto;
  min-width: 0;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.table-sort-btn:hover {
  filter: none;
  color: #e9f7ff;
}

#listsTable th:nth-child(2),
#listsTable td:nth-child(2),
#candidatesTable th:nth-child(2),
#candidatesTable td:nth-child(2),
#candidatesTable th:nth-child(3),
#candidatesTable td:nth-child(3),
#candidatesTable th:nth-child(4),
#candidatesTable td:nth-child(4) {
  min-width: 140px;
}

#eventsTable th:nth-child(5),
#eventsTable td:nth-child(5),
#eventsTable th:nth-child(6),
#eventsTable td:nth-child(6) {
  white-space: nowrap;
}

#eventsTable th:nth-child(1),
#eventsTable td:nth-child(1),
#eventsTable th:nth-child(2),
#eventsTable td:nth-child(2),
#eventsTable th:nth-child(3),
#eventsTable td:nth-child(3),
#eventsTable th:nth-child(4),
#eventsTable td:nth-child(4) {
  min-width: 150px;
}

tbody tr:hover {
  background: rgba(80, 181, 255, 0.09);
}

.event-row {
  cursor: pointer;
}

.selected-row {
  background: rgba(78, 184, 255, 0.16);
}

.detail-panel {
  padding: 1rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr;
  gap: 1rem;
}

.detail-grid-wide {
  grid-template-columns: 1fr;
  margin-top: 1rem;
}

.detail-grid > div {
  min-width: 0;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

.meta-card {
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.meta-label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.meta-value {
  display: block;
  color: var(--text);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.small-table table td,
.small-table table th {
  font-size: 0.85rem;
}

@media (max-width: 1040px) {
  .menu-columns,
  .chart-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .layout {
    width: min(1500px, calc(100% - 1rem));
    gap: 0.8rem;
  }

  .controls,
  .sync-controls {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    width: 100%;
    min-width: 0;
    flex: 1 1 220px;
  }

  .table-wrap {
    border-radius: 8px;
  }

  #eventsTable {
    min-width: 640px;
  }

  #candidatesTable {
    min-width: 620px;
  }

  #listsTable {
    min-width: 520px;
  }

  #filesTable {
    min-width: 360px;
  }

  th,
  td {
    padding: 0.55rem 0.6rem;
    font-size: 0.9rem;
  }

  .tab-btn {
    min-width: 0;
    flex: 1 1 160px;
  }
}

@media (max-width: 560px) {
  .hero,
  .menu-panel,
  .controls,
  .table-panel,
  .detail-panel {
    padding: 0.85rem;
  }

  .menu-btn {
    width: 100%;
    min-width: 0;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .chart-box {
    height: 220px;
  }

  #eventsTable {
    min-width: 560px;
  }

  #candidatesTable {
    min-width: 560px;
  }

  #listsTable {
    min-width: 460px;
  }

  #filesTable {
    min-width: 320px;
  }
}
