:root {
  color-scheme: dark;
  --bg: #0d1014;
  --bg-soft: #121720;
  --surface: #171d27;
  --surface-strong: #202938;
  --surface-alt: #11161f;
  --border: #2b3444;
  --text: #eef4fb;
  --muted: #98a7ba;
  --accent: #4cb8a6;
  --accent-strong: #288f84;
  --info: #61b8ff;
  --warn: #e9b449;
  --danger: #ef6d78;
  --success: #53c37d;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(76, 184, 166, 0.08), transparent 18%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.screen {
  min-height: 100vh;
}

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
}

.topbar {
  padding: 28px 0 18px;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
}

.page {
  display: grid;
  gap: 18px;
  padding-bottom: 36px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1 {
  font-size: 34px;
  line-height: 1.08;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

h3 {
  font-size: 17px;
  line-height: 1.2;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.surface,
.pipeline-card,
.torrent-card,
.toolbar-band,
.auth-shell {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent), var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-shell {
  margin: min(15vh, 120px) auto 0;
  width: min(460px, calc(100vw - 32px));
  padding: 28px;
  display: grid;
  gap: 18px;
}

.auth-copy {
  display: grid;
  gap: 6px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-compact {
  gap: 6px;
}

.field span,
.mini-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: rgba(97, 184, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(97, 184, 255, 0.12);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px 14px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: white;
  font-weight: 600;
}

.ghost {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.danger {
  background: rgba(239, 109, 120, 0.12);
  color: #ffb1ba;
  border-color: rgba(239, 109, 120, 0.28);
}

.title-block {
  display: grid;
  gap: 6px;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.app-link {
  padding: 10px 12px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 18px;
}

.composer,
.overview {
  padding: 20px;
  display: grid;
  gap: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segment {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px 14px;
}

.segment.active {
  background: rgba(76, 184, 166, 0.14);
  border-color: rgba(76, 184, 166, 0.45);
  color: #dffcf7;
}

.segmented.compact .segment {
  padding: 8px 11px;
}

.add-form {
  display: grid;
  gap: 14px;
}

.composer-foot {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
}

.path-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #d7dfeb;
  overflow-wrap: anywhere;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stat-label {
  color: var(--muted);
}

.stat-value {
  text-align: right;
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
}

.stat-sub {
  margin-top: 6px;
  text-align: right;
  font-size: 12px;
}

.alerts {
  display: grid;
  gap: 10px;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  display: grid;
  gap: 4px;
  border: 1px solid transparent;
}

.alert.ok {
  background: rgba(83, 195, 125, 0.1);
  border-color: rgba(83, 195, 125, 0.24);
  color: #d6f6df;
}

.alert.warn {
  background: rgba(233, 180, 73, 0.12);
  border-color: rgba(233, 180, 73, 0.26);
  color: #f9e8be;
}

.alert.danger {
  background: rgba(239, 109, 120, 0.12);
  border-color: rgba(239, 109, 120, 0.26);
  color: #ffd2d6;
}

.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.pipeline-card {
  padding: 18px;
  display: grid;
  gap: 16px;
}

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

.pipeline-link {
  padding: 9px 12px;
}

.pipeline-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.pipeline-metric {
  display: grid;
  gap: 4px;
}

.pipeline-metric strong {
  font-size: 22px;
  line-height: 1;
}

.pipeline-paths {
  display: grid;
  gap: 12px;
}

.toolbar-band {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.toolbar-top,
.toolbar-bottom {
  display: flex;
  gap: 18px;
  align-items: end;
  flex-wrap: wrap;
}

.search-field {
  width: min(460px, 100%);
  display: grid;
  gap: 8px;
}

.filter-block {
  display: grid;
  gap: 8px;
}

.bulk-bar {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: linear-gradient(180deg, rgba(76, 184, 166, 0.09), transparent), var(--surface);
  border: 1px solid rgba(76, 184, 166, 0.22);
  border-radius: 8px;
}

.bulk-info {
  display: grid;
  gap: 4px;
}

.bulk-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.issues-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.issue-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent), var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.issue-card.warn {
  border-color: rgba(233, 180, 73, 0.32);
}

.issue-card.danger {
  border-color: rgba(239, 109, 120, 0.32);
}

.issue-card.ok {
  border-color: rgba(83, 195, 125, 0.28);
}

.issue-head,
.issue-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.issue-title {
  font-size: 16px;
}

.issue-list {
  display: grid;
  gap: 10px;
}

.issue-item {
  display: grid;
  gap: 3px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.issue-item:first-child {
  padding-top: 0;
  border-top: 0;
}

.issue-item strong {
  overflow-wrap: anywhere;
}

.sections {
  display: grid;
  gap: 20px;
}

.state-section {
  display: grid;
  gap: 12px;
}

.state-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
}

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

.torrent-card {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.torrent-card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.torrent-head-actions {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.torrent-card-title-wrap {
  display: grid;
  gap: 8px;
}

.torrent-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid transparent;
}

.category-badge {
  background: rgba(97, 184, 255, 0.12);
  color: #b4deff;
}

.state-badge[data-state='active'] {
  background: rgba(76, 184, 166, 0.14);
  color: #c7fff6;
}

.state-badge[data-state='seeding'] {
  background: rgba(83, 195, 125, 0.14);
  color: #d9f7e2;
}

.state-badge[data-state='paused'] {
  background: rgba(233, 180, 73, 0.14);
  color: #fae8c0;
}

.state-badge[data-state='attention'] {
  background: rgba(239, 109, 120, 0.14);
  color: #ffd1d7;
}

.state-badge[data-state='waiting'],
.state-badge[data-state='idle'] {
  background: rgba(152, 167, 186, 0.14);
  color: #d2dae6;
}

.torrent-title {
  overflow-wrap: anywhere;
}

.torrent-progress-box {
  text-align: right;
  min-width: 88px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--muted);
}

.check-pill input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
}

.torrent-card.selected {
  border-color: rgba(76, 184, 166, 0.48);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(76, 184, 166, 0.16);
}

.torrent-progress-box strong {
  font-size: 24px;
  line-height: 1;
}

.progress-bar {
  height: 9px;
  border-radius: 999px;
  background: #0b0f15;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--info), var(--accent));
}

.torrent-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.torrent-meta-grid div {
  display: grid;
  gap: 4px;
}

.torrent-path-stack {
  display: grid;
  gap: 12px;
}

.torrent-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.error {
  color: #ffb9c0;
}

.empty-state {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.dense .page,
.dense .sections,
.dense .pipeline-grid,
.dense .hero-grid {
  gap: 14px;
}

.dense .composer,
.dense .overview,
.dense .pipeline-card,
.dense .torrent-card,
.dense .toolbar-band {
  padding: 16px;
}

.dense .torrent-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.dense .torrent-card {
  gap: 12px;
}

.dense .torrent-meta-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dense .torrent-progress-box strong {
  font-size: 20px;
}

@media (max-width: 1180px) {
  .hero-grid,
  .pipeline-grid,
  .issues-panel,
  .torrent-grid {
    grid-template-columns: 1fr;
  }

  .dense .torrent-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .topbar-actions,
  .composer-foot,
  .torrent-card-head,
  .issue-head,
  .issue-actions,
  .toolbar-top,
  .toolbar-bottom,
  .bulk-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions,
  .bulk-actions {
    width: 100%;
  }

  .stats-grid,
  .pipeline-metrics,
  .torrent-meta-grid {
    grid-template-columns: 1fr;
  }

  .torrent-head-actions {
    justify-items: stretch;
  }

  .torrent-progress-box {
    text-align: left;
  }
}
