:root {
  --primary: #0d1b2a;
  --primary-deep: #07111e;
  --panel: rgba(13, 27, 42, 0.82);
  --panel-strong: rgba(15, 31, 48, 0.95);
  --border: rgba(100, 116, 139, 0.38);
  --border-bright: rgba(0, 182, 214, 0.42);
  --secondary: #00b6d6;
  --secondary-dark: #078eaa;
  --accent: #22c55e;
  --slate: #64748b;
  --light: #f6f8fa;
  --muted: #9aa8bb;
  --field: rgba(7, 17, 30, 0.72);
  --field-focus: rgba(0, 182, 214, 0.16);
  --danger: #fb7185;
}

html,
body {
  box-sizing: border-box;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--light);
  cursor: default;
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(0, 182, 214, 0.18), transparent 28%),
    radial-gradient(circle at 92% 18%, rgba(34, 197, 94, 0.12), transparent 24%),
    linear-gradient(145deg, var(--primary-deep), var(--primary));
}

body * {
  box-sizing: border-box;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.options-page {
  min-width: 680px;
  padding: 24px;
}

.popup-page {
  width: 360px;
  min-width: 0;
  max-width: 100vw;
  max-height: 600px;
  padding: 14px;
  overflow: auto;
}

.dialog-page {
  width: 100%;
  min-width: 0;
  padding: 10px;
  overflow: hidden;
}

.settings-shell {
  width: min(920px, 100%);
  margin: 0 auto;
}

.popup-page .settings-shell,
.popup-page .app-header {
  width: 100%;
}

.dialog-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 62px);
}

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(920px, 100%);
  margin: 0 auto 18px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(13, 27, 42, 0.94), rgba(7, 17, 30, 0.86));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(246, 248, 250, 0.06);
}

.app-header.compact {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
}

.popup-page .app-header {
  margin-bottom: 10px;
  padding: 12px 14px;
}

.app-mark {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border-radius: 8px;
  filter: drop-shadow(0 0 18px rgba(0, 182, 214, 0.42));
}

.compact .app-mark {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
}

.popup-page .app-mark {
  width: 44px;
  height: 44px;
  flex-basis: 44px;
}

.app-titleGroup {
  min-width: 0;
}

.app-titleGroup h1 {
  margin: 0;
  color: var(--light);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.05;
}

.compact .app-titleGroup h1 {
  font-size: 19px;
}

.popup-page .app-titleGroup h1 {
  font-size: 22px;
}

.app-titleGroup span {
  display: block;
  margin-top: 5px;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.panel {
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(246, 248, 250, 0.05);
}

.panel-section {
  display: flex;
}

.panel-section-header {
  align-items: center;
  min-height: 50px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 17, 30, 0.42);
}

.panel-section-header > .text-section-header {
  color: var(--light);
  font-size: 16px;
  font-weight: 750;
}

.panel-section-formElements {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  gap: 12px;
  padding: 18px;
}

.dialog-shell > .panel-section-formElements {
  flex: 1;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.panel-section-separator {
  height: 1px;
  background: var(--border);
}

.panel-formElements-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  margin: 0;
}

.panel-formElements-item.stacked {
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
}

.panel-formElements-item.choice-row {
  align-items: center;
  flex-direction: row;
  flex-wrap: nowrap;
}

.choice-pair {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.panel-formElements-item > label:first-child {
  flex: 0 0 158px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.dialog-page .panel-formElements-item > label:first-child {
  flex-basis: 116px;
}

.panel-formElements-item.stacked > label:first-child {
  flex-basis: auto;
}

.panel-formElements-item input[type="text"],
.panel-formElements-item input[type="password"],
.panel-formElements-item select.browser-style,
textarea.browser-style {
  width: 100%;
  min-width: 0;
}

.browser-style {
  appearance: none;
}

input[type="text"],
input[type="password"],
select.browser-style,
textarea.browser-style {
  color: var(--light);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
  background: var(--field);
  box-shadow: inset 0 1px 0 rgba(246, 248, 250, 0.04);
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

input[type="text"],
input[type="password"],
select.browser-style {
  height: 36px;
  padding: 0 11px;
}

textarea.browser-style {
  min-height: 92px;
  resize: vertical;
  padding: 10px 11px;
}

select.browser-style {
  color-scheme: dark;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--secondary) 50%),
    linear-gradient(135deg, var(--secondary) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 15px,
    calc(100% - 12px) 15px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select.browser-style option,
select.browser-style optgroup {
  color: var(--light);
  background-color: var(--primary-deep);
}

select.browser-style option:checked {
  background-color: var(--secondary-dark);
}

input[type="text"]:hover,
input[type="password"]:hover,
select.browser-style:hover,
textarea.browser-style:hover {
  border-color: var(--border-bright);
}

input[type="text"]:focus,
input[type="password"]:focus,
select.browser-style:focus,
textarea.browser-style:focus {
  border-color: var(--secondary);
  background-color: var(--field-focus);
  box-shadow: 0 0 0 3px rgba(0, 182, 214, 0.14);
}

input[type="text"]:disabled,
input[type="password"]:disabled,
select.browser-style:disabled,
textarea.browser-style:disabled {
  color: var(--slate);
  opacity: 0.72;
}

input[type="text"]:invalid:not(:focus),
input[type="password"]:invalid:not(:focus),
textarea.browser-style:invalid:not(:focus) {
  border-color: var(--danger);
}

.browser-style input[type="radio"],
.browser-style input[type="checkbox"] {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin: 0;
  border: 1px solid var(--border);
  background: rgba(7, 17, 30, 0.85);
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.browser-style input[type="radio"] {
  border-radius: 50%;
}

.browser-style input[type="checkbox"] {
  border-radius: 5px;
}

.browser-style input[type="radio"]::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: scale(0);
  background: var(--light);
  transition: transform 160ms ease;
}

.browser-style input[type="checkbox"]::before {
  content: "";
  width: 9px;
  height: 5px;
  transform: rotate(-45deg) scale(0);
  border-left: 2px solid var(--light);
  border-bottom: 2px solid var(--light);
  transition: transform 160ms ease;
}

.browser-style input[type="radio"]:checked,
.browser-style input[type="checkbox"]:checked {
  border-color: var(--secondary);
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  box-shadow: 0 0 0 3px rgba(0, 182, 214, 0.12);
}

.browser-style input[type="radio"]:checked::before,
.browser-style input[type="checkbox"]:checked::before {
  transform: scale(1);
}

.browser-style input[type="checkbox"]:checked::before {
  transform: rotate(-45deg) scale(1);
}

.browser-style input[type="radio"] + label,
.browser-style input[type="checkbox"] + label {
  color: var(--light);
  font-size: 13px;
  font-weight: 600;
}

.browser-style input[type="radio"]:disabled,
.browser-style input[type="checkbox"]:disabled,
.browser-style input[type="radio"]:disabled + label,
.browser-style input[type="checkbox"]:disabled + label {
  color: var(--slate);
  opacity: 0.72;
}

.panel-formElements-item.choice-row > input[type="checkbox"] + label {
  flex: 1 1 auto;
  min-width: 0;
}

.panel-section-footer {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding: 0;
}

.dialog-shell .panel-section-footer {
  margin-top: 8px;
}

.dialog-page .panel-formElements-item {
  min-height: 30px;
}

.dialog-page input[type="text"],
.dialog-page input[type="password"],
.dialog-page select.browser-style {
  height: 32px;
}

.dialog-page .panel-section-footer-button {
  min-height: 36px;
}

.panel-section-footer-button {
  flex: 1 1 0;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--light);
  background: rgba(100, 116, 139, 0.16);
  text-align: center;
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.panel-section-footer-button:not(:disabled):hover {
  border-color: var(--border-bright);
  background: rgba(100, 116, 139, 0.24);
  transform: translateY(-1px);
}

.panel-section-footer-button:not(:disabled):active {
  transform: translateY(0);
}

.panel-section-footer-button.default:not(:disabled) {
  border-color: rgba(0, 182, 214, 0.72);
  background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
  box-shadow: 0 12px 22px rgba(0, 182, 214, 0.22);
  font-weight: 800;
}

.panel-section-footer-button.default:not(:disabled):hover {
  background: linear-gradient(135deg, #18d4ee, var(--secondary));
}

.panel-section-footer-button:disabled {
  color: var(--slate);
  opacity: 0.62;
}

.panel-section-footer-separator {
  display: none;
}

.source-note {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.source-note a {
  color: var(--secondary);
  font-weight: 700;
  text-decoration: none;
}

.source-note a:hover {
  color: var(--light);
  text-decoration: underline;
}

.tab-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.tab-button,
.panel-action-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(7, 17, 30, 0.56);
  font-weight: 800;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

.tab-button:hover,
.panel-action-button:hover {
  border-color: var(--border-bright);
  color: var(--light);
}

.tab-button.active {
  border-color: rgba(0, 182, 214, 0.7);
  color: var(--light);
  background: rgba(0, 182, 214, 0.16);
}

.tab-panel[hidden] {
  display: none;
}

.sync-status {
  min-height: 19px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.sync-status.error {
  color: var(--danger);
}

.status-header {
  justify-content: space-between;
  gap: 12px;
}

.panel-action-button {
  min-height: 32px;
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 12px;
}

.current-server-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.current-server-line strong {
  min-width: 0;
  overflow: hidden;
  color: var(--light);
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

.speed-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.speed-meter {
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(7, 17, 30, 0.48);
}

.speed-meter span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.speed-meter strong {
  display: block;
  margin-top: 4px;
  color: var(--light);
  font-size: 20px;
  line-height: 1.1;
}

.status-message {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
}

.status-message.error {
  color: var(--danger);
}

.torrent-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.torrent-row {
  display: grid;
  gap: 8px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
}

.torrent-row:first-child {
  border-top: 0;
}

.torrent-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.torrent-name {
  min-width: 0;
  overflow: hidden;
  color: var(--light);
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.torrent-state {
  flex: 0 0 auto;
  max-width: 160px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.torrent-progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
}

.torrent-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(100, 116, 139, 0.28);
}

.torrent-progress-fill {
  width: var(--progress-width, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
}

.torrent-progress-value {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

@media (max-width: 720px) {
  .options-page {
    min-width: 0;
    padding: 14px;
  }

  .panel-formElements-item {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-formElements-item.choice-row {
    align-items: center;
    flex-direction: row;
  }

  .panel-formElements-item.context-menu-row {
    flex-wrap: wrap;
  }

  .options-page .panel-formElements-item > label:first-child {
    flex-basis: auto;
  }

  .options-page .panel-formElements-item.context-menu-row > label:first-child {
    flex-basis: 100%;
  }

  .dialog-page .panel-formElements-item {
    align-items: center;
    flex-direction: row;
  }

  .app-titleGroup h1 {
    font-size: 24px;
  }
}
