:root {
  --bg: #f5fbf6;
  --surface: rgba(225, 241, 233, 0.55);
  --surface-solid: #ecf5ef;
  --text: #171d1a;
  --text-soft: #54615b;
  --primary: #006d4f;
  --primary-press: #00543d;
  --chip: #cde8dd;
  --chip-border: #8fb6a6;
  --tag: #cde8dd;
  --tag-text: #072019;
  --ok: #138a3d;
  --bad: #cc1f1a;
  --overlay: rgba(158, 158, 158, 0.22);
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

.app {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 14px 16px 12px;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
}

.topbar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.intro-text {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--text-soft);
  max-width: 860px;
}

.seo-query-note {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-soft);
  max-width: 860px;
}

.support-link {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  text-decoration: underline;
  font-size: 13px;
}

.support-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: cover;
}

.header-menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.menu-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--chip-border);
  background: var(--surface-solid);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  position: relative;
  z-index: 31;
}

.menu-btn:hover {
  background: var(--chip);
  border-color: var(--primary);
}

.menu-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.menu-btn-bars {
  width: 16px;
  display: grid;
  gap: 3px;
}

.menu-btn-bar {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.header-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 6px;
  border-radius: 12px;
  background: var(--surface-solid);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.08);
  z-index: 30;
}

.header-menu-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
}

.header-menu-item:hover {
  background: rgba(0, 0, 0, 0.06);
}

.menu-item-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.menu-item-text {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}

.menu-item-active {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
}

.content {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 16px 24px;
}

.seo-content {
  margin-top: 14px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  padding: 16px;
}

.seo-content h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.seo-content p {
  margin: 10px 0 0;
  color: var(--text-soft);
  font-size: 14px;
}

.desktop-layout {
  display: grid;
  gap: 12px;
}

.controls-column,
.list-column {
  display: grid;
  gap: 12px;
  align-content: start;
}

.section-card,
.proxy-card,
.error-card {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.section-header {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

.section-content {
  display: none;
  padding: 0 16px 16px;
  min-width: 0;
}

.section-card.expanded .section-content {
  display: block;
}

.chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--primary);
  border-bottom: 2px solid var(--primary);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  margin-right: 4px;
}

.section-card.expanded .chevron {
  transform: rotate(-135deg);
}

.section-subtitle {
  margin: 0 0 12px;
  color: var(--text-soft);
  font-size: 13px;
}

.lang-options {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.lang-option {
  width: 100%;
  border: 1px solid var(--chip-border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}

.lang-option:hover {
  background: rgba(0, 0, 0, 0.04);
}

.lang-option.active {
  background: var(--chip);
  border-color: var(--primary);
}

.lang-radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--chip-border);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-option.active .lang-radio {
  border-color: var(--primary);
}

.lang-option.active .lang-radio::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.primary-btn,
.secondary-btn,
.chip {
  border-radius: 10px;
  border: 0;
  cursor: pointer;
  font-size: 14px;
  padding: 10px 14px;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.primary-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.primary-btn:not(:disabled):hover {
  background: var(--primary-press);
}

.secondary-btn {
  background: transparent;
  border: 1px solid #c7d8cf;
  color: var(--text);
}

.link-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  text-decoration: none;
}

.full-width {
  width: 100%;
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
}

#sortChips {
  display: flex;
  flex-direction: column;
}

.chip {
  width: 100%;
  text-align: left;
  white-space: normal;
  background: var(--chip);
  color: var(--tag-text);
  border: 1px solid var(--chip-border);
  font-weight: 600;
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.chip:disabled {
  opacity: 0.5;
  cursor: default;
}

.error-card {
  padding: 14px;
  color: #7b1f1f;
  background: #f8e2e2;
}

.hidden {
  display: none !important;
}

.proxies-list {
  display: grid;
  gap: 12px;
}

.proxy-card {
  position: relative;
  padding: 14px 16px;
  cursor: pointer;
  overflow: hidden;
}

.proxy-card.added .proxy-inner {
  opacity: 0.62;
}

.proxy-card.added::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--overlay);
  pointer-events: none;
}

.proxy-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.proxy-title {
  margin: 0;
  font-size: 18px;
}

.proxy-host {
  margin-top: 3px;
  font-size: 14px;
  color: var(--text-soft);
  word-break: break-word;
}

.tag {
  background: var(--tag);
  color: var(--tag-text);
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 9px;
  white-space: nowrap;
}

.proxy-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.location {
  color: var(--text-soft);
}

.latency.ok {
  color: var(--ok);
  font-weight: 700;
}

.latency.bad {
  color: var(--bad);
  font-weight: 700;
}

.latency.unknown {
  color: var(--text-soft);
  font-weight: 600;
}

.proxy-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-added {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 600;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.modal-card {
  width: min(420px, 100%);
  border-radius: 14px;
  background: #fff;
  padding: 16px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
}

.modal-card h2 {
  margin: 0;
  font-size: 20px;
}

.modal-meta {
  margin: 10px 0 0;
  color: #566;
  font-size: 14px;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions .primary-btn,
.modal-actions .secondary-btn {
  width: auto;
}

@media (min-width: 1040px) {
  .desktop-layout {
    grid-template-columns: minmax(320px, 360px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }

  .controls-column {
    grid-column: 1;
    position: sticky;
    top: 88px;
    align-self: start;
    z-index: 3;
    background: var(--bg);
    padding-right: 4px;
  }

  .controls-column .section-card {
    background: var(--surface-solid);
  }

  .list-column {
    grid-column: 2;
    min-width: 0;
    position: relative;
    z-index: 1;
  }

  .proxies-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .proxy-card {
    min-height: 172px;
  }

}

@media (min-width: 1440px) {
  .desktop-layout {
    grid-template-columns: 360px minmax(0, 1fr);
  }

  .proxies-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1512;
    --surface: rgba(52, 76, 68, 0.58);
    --surface-solid: #1a2722;
    --text: #dee4df;
    --text-soft: #b1ccc1;
    --chip: #344c44;
    --chip-border: #536b62;
    --tag: #344c44;
    --tag-text: #cde8dd;
    --overlay: rgba(158, 158, 158, 0.26);
    --card-shadow: 0 1px 4px rgba(0, 0, 0, 0.36);
  }

  .secondary-btn {
    border-color: #536b62;
    color: var(--text);
  }

  .modal-card {
    background: #1a2220;
    color: var(--text);
  }

  .modal-meta {
    color: var(--text-soft);
  }

  .menu-btn {
    border-color: #536b62;
    background: #1d2b26;
  }

  .menu-btn:hover {
    background: #20332d;
    border-color: #6f9184;
  }

  .header-menu {
    border-color: #31453f;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.34);
  }

  .header-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
  }

  .lang-option:hover {
    background: rgba(255, 255, 255, 0.06);
  }
}

@media (max-width: 560px) {
  .title {
    font-size: 20px;
  }

  .topbar-head {
    align-items: center;
  }

  .intro-text {
    font-size: 13px;
  }

  .proxy-title {
    font-size: 17px;
  }

  #sort-section .section-content {
    padding-left: 12px;
    padding-right: 12px;
  }
}
