:root {
  color-scheme: dark;

  /* Material Design 3-inspired system color roles (dark). */
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;

  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-on-secondary: #332d41;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;

  --md-sys-color-tertiary: #efb8c8;
  --md-sys-color-on-tertiary: #492532;
  --md-sys-color-tertiary-container: #633b48;
  --md-sys-color-on-tertiary-container: #ffd8e4;

  --md-sys-color-error: #f2b8b5;
  --md-sys-color-on-error: #601410;

  --md-sys-color-background: #141218;
  --md-sys-color-on-background: #e6e0e9;

  --md-sys-color-surface: #141218;
  --md-sys-color-on-surface: #e6e0e9;
  --md-sys-color-on-surface-variant: #cac4d0;

  --md-sys-color-surface-container-low: #1d1b20;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-surface-container-highest: #36343b;

  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;

  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;

  --md-sys-state-focus-outline-width: 2px;

  --app-max-width: 1200px;
  --app-page-padding: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.4;
}

a {
  color: var(--md-sys-color-primary);
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.top-app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.top-app-bar__inner {
  max-width: var(--app-max-width);
  margin: 0 auto;
  padding: 16px var(--app-page-padding);
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-app-bar__title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.content {
  flex: 1;
  max-width: var(--app-max-width);
  margin: 0 auto;
  padding: 16px var(--app-page-padding) 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
}

.surface-card {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  padding: 16px 20px;
}

.controls__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: flex-start; /* Changed from end to flex-start to prevent helper text pushing elements */
}

.m3-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.m3-label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-helper {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-input,
.m3-select {
  height: 48px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.m3-input::placeholder {
  color: var(--md-sys-color-outline);
}

.m3-input:focus-visible,
.m3-select:focus-visible {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.m3-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px dashed var(--md-sys-color-outline-variant);
  background: transparent;
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.m3-checkbox:hover {
  background: var(--md-sys-color-surface-container-high);
}

.m3-checkbox__input {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--md-sys-color-primary);
}

.m3-checkbox__label {
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

.version-manager {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.version-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.m3-button {
  height: 48px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 6px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
}

.m3-button:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-highest);
}

.m3-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.m3-button--danger {
  border-color: var(--md-sys-color-error);
  color: var(--md-sys-color-error);
}

/* Media queries previously altering version-actions grid removed since it uses flex column now */

/* Data Table container with elevation scaling suitable for M2 */
.mdc-data-table {
  background: transparent;
  border: none;
  box-shadow: none;
  overflow-x: visible;
}

.mdc-data-table table {
  width: 100%;
  border-collapse: collapse;
}

.mdc-data-table thead {
  display: none;
}

.mdc-data-table tbody {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.mdc-data-table tr {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  padding: 16px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  position: relative;
  transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.mdc-data-table .server-row {
  cursor: pointer;
}

.server-name-content {
  position: relative;
  padding-right: 36px;
}

.favorite-indicator {
  position: absolute;
  top: 0;
  right: 0;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-primary);
  font-size: 0.78rem;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.65);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.favorite-indicator svg {
  display: block;
}

.server-row--favorite {
  border-color: var(--md-sys-color-primary-container);
}

.favorite-indicator--visible {
  opacity: 1;
  transform: scale(1);
  animation: favorite-pop 0.18s ease-out;
}

@keyframes favorite-pop {
  from {
    opacity: 0;
    transform: scale(0.4);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (hover: hover) and (pointer: fine) {
  .mdc-data-table tr:hover {
    background: var(--md-sys-color-surface-container-high);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  }
}

.mdc-data-table td {
  display: block;
  border: none;
  padding: 0;
  text-align: left !important;
  white-space: normal;
}

.mdc-data-table td::before {
  display: none;
}

.mdc-data-table td .td-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

/* 1: Server name */
.mdc-data-table td:nth-child(1) {
  grid-column: 1 / -1;
  padding-right: 60px;
}
.mdc-data-table td:nth-child(1) .server-label {
  font-size: 1.1rem;
  color: var(--md-sys-color-primary);
  margin-bottom: 4px;
}

/* 2: Map */
.mdc-data-table td:nth-child(2) {
  grid-column: 1;
}

/* 3: Mode */
.mdc-data-table td:nth-child(3) {
  grid-column: 2;
}

/* 4: Slots */
.mdc-data-table td:nth-child(4) {
  position: absolute;
  top: 16px;
  right: 16px;
  width: auto;
}
.mdc-data-table td:nth-child(4) .td-content {
  align-items: flex-end;
  text-align: right;
}
.mdc-data-table td:nth-child(4) .server-label {
  background: var(--md-sys-color-surface-container-highest);
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
}

/* 5: Version */
.mdc-data-table td:nth-child(5) {
  grid-column: 1 / -1;
  border-top: 1px dashed var(--md-sys-color-outline-variant);
  padding-top: 12px;
  margin-top: 4px;
}
.mdc-data-table td:nth-child(5) .td-content {
  flex-direction: row;
  justify-content: space-between;
  width: 100%;
  align-items: center;
}

.server-label {
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 2px;
}

.server-sub-label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.server-updated-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  background: var(--md-sys-color-surface-container-low);
  border: 1px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 24px 16px;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
}
.controls-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.m3-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  margin-bottom: 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding-bottom: 8px;
}

.version-input-group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
}

.m3-icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 6px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 24px; /* Matches the height of the label+gap */
}

.m3-icon-button:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.m3-icon-button.sub-active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.version-popout {
  margin-top: 12px;
  padding: 16px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
