:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel2: #21242c;
  --border: #2a2e37;
  --text: #e6e8eb;
  --muted: #8b93a1;
  --accent: #4c8dff;
  --good: #3ecf8e;
  --bad: #ff5d5d;
  --violet: #8b5cf6;
  --amber: #e8a33d;
  --upload: #2dd4bf;
}
* { box-sizing: border-box; }
body {
  background:
    radial-gradient(1100px 500px at 8% -10%, rgba(76,141,255,0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(139,92,246,0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  padding: 24px;
}
a { color: var(--accent); text-decoration: none; }
input, button, select {
  background: #12141a;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn-orange { background: var(--amber); border-color: var(--amber); color: #fff; transition: background 0.15s, border-color 0.15s; }
button.btn-orange.file-pending { background: var(--bad); border-color: var(--bad); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

/* top bar */
.top-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.top-bar-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #6ea8ff, var(--accent) 55%, #2f5fc9);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-mark svg { width: 17px; height: 17px; }
.logo-text { font-size: 15px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.logo-text .dim { color: var(--muted); font-weight: 400; }
nav { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 4px; width: fit-content; }
nav a { padding: 7px 16px; border-radius: 7px; font-size: 13px; color: var(--muted); transition: background 0.15s, color 0.15s; }
nav a:hover { background: #262a33; color: var(--text); }
nav a.active { background: var(--accent); color: #fff; }

/* stat strip */
.stat-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-card {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(160deg, var(--panel2), var(--panel));
  border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 14px 8px 10px; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.stat-icon { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 17px; height: 17px; }
.stat-icon.dl { background: linear-gradient(135deg, #6ea8ff, var(--accent) 75%); box-shadow: 0 1px 3px rgba(76,141,255,0.4); }
.stat-icon.ul { background: linear-gradient(135deg, #6ee7dc, var(--upload) 75%); box-shadow: 0 1px 3px rgba(45,212,191,0.4); }
.stat-icon.tor { background: linear-gradient(135deg, #c4a4ff, var(--violet) 75%); box-shadow: 0 1px 3px rgba(139,92,246,0.4); }
.stat-text { display: flex; flex-direction: column; line-height: 1.25; }
.stat-text .label { font-size: 11px; color: var(--muted); }
.stat-text .value { font-size: 15px; font-weight: 700; }
.stat-card.hero { background: none; border: none; box-shadow: none; padding: 4px 26px 4px 4px; }
.stat-card.hero .stat-icon { width: 44px; height: 44px; }
.stat-card.hero .stat-icon svg { width: 21px; height: 21px; }
.stat-card.hero .stat-text .label { font-size: 12px; }
.stat-card.hero .value { font-size: 27px; font-weight: 800; letter-spacing: 0.2px; }
.glow-text-dl { color: #8fbcff; text-shadow: 0 0 14px rgba(76,141,255,0.85), 0 0 28px rgba(76,141,255,0.4); }
.glow-text-ul { color: #7ee9dd; text-shadow: 0 0 14px rgba(45,212,191,0.85), 0 0 28px rgba(45,212,191,0.4); }
.glow-text-tor { color: #c4a4ff; text-shadow: 0 0 14px rgba(139,92,246,0.85), 0 0 28px rgba(139,92,246,0.4); }

/* cards */
.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.vm-card { border: 2px solid var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,0.35); margin-bottom: 22px; }
.empty-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }

/* instance head */
.instance-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.instance-head h3 { margin: 0; font-size: 15px; }
.instance-head h3 a { color: var(--text); }
.instance-head h3 a:hover { color: var(--accent); }
.instance-head-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.instance-speed { font-size: 12px; color: var(--muted); }
.vm-error { color: var(--bad); font-size: 13px; }
.collapse-btn { background: transparent; border: none; color: var(--muted); padding: 0 4px; font-size: 13px; line-height: 1; }
.collapse-btn:hover { color: var(--text); }

/* add-torrent form */
.add-torrent-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.add-torrent-form select { padding: 4px 8px; font-size: 12px; }
.file-picker-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid #3a6fd6;
  background: linear-gradient(135deg, #6ea8ff, var(--accent) 65%, #2f5fc9);
  color: #fff; cursor: pointer; flex-shrink: 0; box-shadow: 0 1px 3px rgba(76,141,255,0.35);
  transition: transform 0.1s, box-shadow 0.1s;
}
.file-picker-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(76,141,255,0.45); }
.file-picker-btn svg { width: 16px; height: 16px; }
.file-count { font-size: 12px; color: var(--accent); white-space: nowrap; font-weight: 600; }
.add-torrent-form button { padding: 4px 9px; font-size: 12px; }
.test-result { font-size: 13px; margin-left: 4px; }
.status-ok { color: var(--good); }
.status-error { color: var(--bad); }

/* bulk bar */
.bulk-bar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(76,141,255,0.1); border: 1px solid rgba(76,141,255,0.35);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 10px;
}
.bulk-bar .bulk-count { font-size: 13px; font-weight: 600; margin-right: 6px; }
.clear-selection-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 12px; padding: 6px 12px; margin-left: auto; }
.clear-selection-btn:hover { color: var(--text); background: #262a33; }

/* table */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
.torrents-table { table-layout: fixed; width: 100%; }
.torrents-table th:nth-child(1), .torrents-table td:nth-child(1) { width: 3%; }
.torrents-table th:nth-child(2), .torrents-table td:nth-child(2) { width: 12%; white-space: nowrap; }
.torrents-table th:nth-child(3), .torrents-table td:nth-child(3) { width: 6%; }
.torrents-table th:nth-child(4), .torrents-table td:nth-child(4) { width: 6%; }
.torrents-table th:nth-child(5), .torrents-table td:nth-child(5) { width: 8%; }
.torrents-table th:nth-child(6), .torrents-table td:nth-child(6) { width: 4%; }
.torrents-table th:nth-child(7), .torrents-table td:nth-child(7) { width: 6%; }
.torrents-table th:nth-child(8), .torrents-table td:nth-child(8) { width: 6%; }
.torrents-table th:nth-child(9), .torrents-table td:nth-child(9) { width: 6%; }
.torrents-table th:nth-child(10), .torrents-table td:nth-child(10) { width: 6%; }
.torrents-table th:nth-child(11), .torrents-table td:nth-child(11) { width: 6%; }
.torrents-table th:nth-child(12), .torrents-table td:nth-child(12) { width: 5%; }
.torrents-table th:nth-child(13), .torrents-table td:nth-child(13) { width: 5%; }
.torrents-table th:nth-child(14), .torrents-table td:nth-child(14) { width: 6%; }
.torrents-table th:nth-child(15), .torrents-table td:nth-child(15) { width: 6%; }
.torrents-table th:nth-child(16), .torrents-table td:nth-child(16) { width: 9%; }
.torrents-table td, .torrents-table th { overflow: hidden; text-overflow: ellipsis; }
.torrents-table .progress-bar, .torrents-table .row-actions { overflow: visible; }
.torrents-table .col-group-end { border-right: 1px solid var(--border); }
.torrents-table tbody tr[data-hash]:hover td { background: rgba(255,255,255,0.035); }
.num-strong { font-weight: 700; color: var(--text); }
.muted-cell { color: var(--muted); font-size: 12px; }
.eta-cell { color: var(--amber); font-size: 12px; font-weight: 600; }

.checkbox-col { text-align: center; width: 32px; }
.checkbox-col input {
  -webkit-appearance: none; appearance: none; box-sizing: border-box;
  display: inline-block; width: 17px !important; height: 17px !important;
  min-width: 17px; max-width: 17px; margin: 0; padding: 0; border-radius: 50%;
  border: 1.5px solid var(--border); background: #12141a; cursor: pointer;
  position: relative; vertical-align: middle; transition: border-color 0.15s, background 0.15s;
}
.checkbox-col input:hover { border-color: var(--accent); }
.checkbox-col input:checked { background: var(--accent); border-color: var(--accent); }
.checkbox-col input:checked::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px;
  background: #fff; border-radius: 50%; transform: translate(-50%, -50%);
}

.expand-btn {
  background: #12141a; border: 1px solid var(--border); color: var(--muted);
  width: 18px; height: 18px; padding: 0; border-radius: 4px; font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; margin-right: 6px; vertical-align: middle;
}
.expand-btn:hover { color: var(--text); background: #1a1d24; }
.files-panel { padding: 10px 4px; }
.files-table { width: 100%; font-size: 12px; }
.files-table th { color: var(--muted); font-weight: 500; padding: 4px 8px; }
.files-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.files-table .progress-bar { width: 80px; height: 12px; }
.peers-link { background: none; border: none; padding: 0; color: var(--text); font-size: inherit; cursor: pointer; text-decoration: underline dotted; text-decoration-color: var(--muted); }
.peers-link:hover { color: var(--accent); }

.progress-bar { background: #12141a; border-radius: 999px; height: 15px; width: 110px; overflow: hidden; position: relative; border: 1px solid var(--border); }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.3s; }
.progress-fill.progress-downloading { background: linear-gradient(90deg, #6ea8ff, var(--accent)); }
.progress-fill.progress-seeding { background: linear-gradient(90deg, #6ee7dc, var(--upload)); }
.progress-fill.progress-paused { background: linear-gradient(90deg, #ffc069, var(--amber)); }
.progress-fill.progress-error { background: linear-gradient(90deg, #ff7a7a, var(--bad)); }
.progress-fill.progress-other { background: var(--muted); }
.progress-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }

.swarm-icon { display: inline-flex; vertical-align: middle; margin-right: 4px; }
.swarm-icon svg { width: 12px; height: 12px; }
.swarm-icon.seeds { color: var(--good); }
.swarm-icon.peers { color: var(--accent); }

.status-badge { font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-badge.status-downloading { color: var(--accent); }
.status-badge.status-seeding { color: var(--upload); }
.status-badge.status-paused { color: var(--violet); }
.status-badge.status-error { color: var(--bad); }
.status-badge.status-other { color: var(--muted); }

.tag-select {
  -webkit-appearance: none; appearance: none; border: none; border-radius: 999px;
  color: #fff; font-size: 10px; font-weight: 600; padding: 3px 16px 3px 7px; cursor: pointer;
  max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 4px center; background-size: 10px;
}
.tag-select option { color: #000; }

.speed-dl-low { color: var(--accent); }
.speed-dl-mid { color: var(--accent); font-weight: 600; }
.speed-dl-high { color: var(--accent); font-weight: 700; text-shadow: 0 0 6px rgba(76,141,255,0.55); }
.speed-up-low { color: var(--upload); }
.speed-up-mid { color: var(--upload); font-weight: 600; }
.speed-up-high { color: var(--upload); font-weight: 700; text-shadow: 0 0 6px rgba(45,212,191,0.55); }
.torrent-count { color: var(--amber); }

.row-actions { white-space: nowrap; padding-right: 2px; padding-left: 2px; }
.row-actions .icon-btn { width: 24px; height: 24px; margin-right: 2px; }
.row-actions .icon-btn svg { width: 13px; height: 13px; }
.row-actions .icon-btn .file-badge { width: 11px; height: 11px; right: -2px; bottom: -2px; }
.row-actions .icon-btn .file-badge svg { width: 6px; height: 6px; }
.row-actions .icon-btn:last-child { margin-right: 0; }
.icon-btn {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0; position: relative; border-radius: 50%; border: none; cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn.remove-only { background: linear-gradient(135deg, #ffc069, #e8a33d 70%); box-shadow: 0 1px 3px rgba(232,163,61,0.35); }
.icon-btn.remove-only:hover { box-shadow: 0 3px 8px rgba(232,163,61,0.5); }
.icon-btn.remove-with-files { background: linear-gradient(135deg, #ff7a7a, #e14747 70%); box-shadow: 0 1px 3px rgba(225,71,71,0.4); }
.icon-btn.remove-with-files:hover { box-shadow: 0 3px 8px rgba(225,71,71,0.55); }
.icon-btn.action-play { background: linear-gradient(135deg, #6ee7dc, var(--upload) 70%); box-shadow: 0 1px 3px rgba(45,212,191,0.4); }
.icon-btn.action-play:hover { box-shadow: 0 3px 8px rgba(45,212,191,0.55); }
.icon-btn.action-pause { background: linear-gradient(135deg, #c4a4ff, var(--violet) 70%); box-shadow: 0 1px 3px rgba(139,92,246,0.4); }
.icon-btn.action-pause:hover { box-shadow: 0 3px 8px rgba(139,92,246,0.55); }
.icon-btn .file-badge {
  position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px;
  background: #7a1f1f; border: 2px solid var(--panel); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn .file-badge svg { width: 8px; height: 8px; }

/* gear menu */
.gear-menu { position: relative; }
.gear-btn {
  background: linear-gradient(135deg, #c4a4ff, var(--violet) 70%);
  border: none; color: #fff; width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(139,92,246,0.4); transition: transform 0.1s, box-shadow 0.1s;
}
.gear-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(139,92,246,0.55); }
.gear-btn svg { width: 28px !important; height: 28px !important; }
.gear-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; min-width: 180px; z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.gear-dropdown.open { display: block; }
.gear-dropdown a, .gear-dropdown button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 2px solid transparent; color: var(--text);
  font-size: 13px; padding: 7px 9px; border-radius: 8px; box-sizing: border-box;
}
.gear-dropdown a:hover, .gear-dropdown button:hover { background: #262a33; }
.gear-dropdown a:active, .gear-dropdown button:active, .gear-dropdown a:focus-visible, .gear-dropdown button:focus-visible { border-color: var(--amber); outline: none; }
.gear-dropdown a.active { background: var(--accent); color: #fff; }
.menu-icon { width: 24px; height: 24px; border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.menu-icon svg { width: 13px; height: 13px; }
.gear-divider { height: 1px; background: var(--border); margin: 4px 2px; }

/* tags page */
.tag-card { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.tag-card + .tag-card { border-top: 1px solid var(--border); }
.tag-swatch { width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.35); }
.tag-card .name { flex: 1; font-size: 14px; font-weight: 600; }
input[type=color] { padding: 2px 4px; width: 42px; height: 32px; cursor: pointer; }

/* instances page */
.entity-card { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.entity-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.entity-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.entity-icon svg { width: 19px; height: 19px; }
.entity-title { flex: 1; min-width: 0; }
.entity-title strong { display: block; font-size: 14px; }
.entity-title .sub { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: auto; }
.entity-form-grid { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; width: 100%; }
.entity-divider { height: 1px; background: var(--border); margin: 14px 0; }
.field-label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.field-group, .field { flex: 1; min-width: 160px; }
.field-group input, .field input { width: 100%; }
.field label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 12px; }
.reorder-btns { display: flex; flex-direction: column; gap: 2px; }
.reorder-btn { width: 22px; height: 15px; border-radius: 4px; background: #12141a; border: 1px solid var(--border); color: var(--muted); }
.reorder-btn svg { width: 11px; height: 11px; }
.reorder-btn:hover:not(:disabled) { background: #1a1d24; color: var(--text); }
.reorder-btn:disabled { opacity: 0.25; cursor: not-allowed; }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 100; }
.modal-overlay.open { display: flex; }
.modal-box { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--border); border-radius: 14px; padding: 24px 26px; max-width: 380px; width: 90%; box-shadow: 0 24px 60px rgba(0,0,0,0.55); }
.modal-icon { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; background: linear-gradient(135deg, #ff7a7a, var(--bad) 70%); }
.modal-icon svg { width: 20px; height: 20px; }
.modal-box p { margin: 0 0 20px; font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { padding: 8px 18px; font-size: 13px; }

/* login page */
.login-box { max-width: 320px; margin: 80px auto; }
.login-box .field { margin-bottom: 12px; }
.login-box label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.login-box input { width: 100%; }
.login-box button { width: 100%; }
.error-msg { color: var(--bad); font-size: 13px; margin-bottom: 10px; }

@media (max-width: 720px) {
  body { padding: 12px; }
  .stat-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
}
