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

body {
  background: #0e0e0e;
  color: #e0e0e0;
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  min-height: 48px;
  border-bottom: 1px solid #1e1e1e;
}

.logo {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #4ade80;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.header-btn svg { width: 12px; height: 12px; flex-shrink: 0; }

.logout-btn        { color: #c49968; border-color: #4a3a25; }
.logout-btn:hover  { color: #f59e0b; border-color: #f59e0b88; }

#profile-btn       { color: #6c98aa; border-color: #2a3d48; }
#profile-btn:hover { color: #22d3ee; border-color: #22d3ee88; }

.loading-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid #2a2a2a;
  border-top-color: #4ade80;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.nas-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 3px;
  border: 1px solid #3a3a3a;
  color: #b0b0b0;
}
.nas-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.nas-status-unknown,
.nas-status-unconfigured { color: #888; border-color: #3a3a3a; }
.nas-status-unreachable  { color: #f87171; border-color: #f8717188; }
.nas-status-idle         { color: #b0b0b0; border-color: #3a3a3a; }
.nas-status-waking       { color: #f59e0b; border-color: #f59e0b88; }
.nas-status-waking::before { animation: nas-pulse 1s ease-in-out infinite; }
.nas-status-running      { color: #4ade80; border-color: #4ade8088; }

@keyframes nas-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}

/* ── Login page ──────────────────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: #161616;
  border: 1px solid #1e1e1e;
  border-radius: 5px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 280px;
}

.login-logo {
  text-align: center;
  margin-bottom: 8px;
}

.login-card input {
  background: #0e0e0e;
  border: 1px solid #3a3a3a;
  color: #e0e0e0;
  padding: 9px 11px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s;
}
.login-card input:focus { border-color: #4ade8088; }

.login-btn {
  padding: 9px 11px;
  margin-top: 4px;
}
.login-btn:hover { background: #152a1a; color: #4ade80; border-color: #4ade8088; }

.login-err {
  color: #ef4444;
  font-size: 12px;
  min-height: 15px;
  text-align: center;
}

/* ── Nav ─────────────────────────────────────────────────────────────────── */

nav {
  display: flex;
  padding: 0 20px;
  border-bottom: 1px solid #1e1e1e;
}

nav .nav-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 22px;
  min-height: 48px;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}
nav .nav-btn svg { width: 15px; height: 15px; }
nav .nav-btn:hover        { color: #6a9b78; }
nav .nav-btn.active       { color: #4ade80; border-bottom-color: #4ade80; }
nav .nav-btn.active:hover { color: #4ade80; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

main {
  padding: 14px;
  max-width: 1100px;
  margin: 0 auto;
}

.view {
  display: none;
  flex-direction: column;
  gap: 10px;
}
.view.active { display: flex; }

/* ── Sub-nav (in-view tabs) ──────────────────────────────────────────────── */

.subnav {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid #1e1e1e;
}

.subnav-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #a0a0a0;
  padding: 9px 16px;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}
.subnav-btn:hover  { color: #6a9b78; }
.subnav-btn.active { color: #4ade80; border-bottom-color: #4ade80; }

.subview {
  display: none;
  flex-direction: column;
  gap: 10px;
}
.subview.active { display: flex; }

/* ── Torrent search ──────────────────────────────────────────────────────── */

.torrent-search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.torrent-search-form input {
  flex: 1;
  background: #0e0e0e;
  border: 1px solid #3a3a3a;
  color: #e0e0e0;
  padding: 9px 11px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s;
}
.torrent-search-form input:focus { border-color: #4ade8088; }
.torrent-search-form button {
  padding: 9px 14px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.torrent-search-form button svg { width: 12px; height: 12px; flex-shrink: 0; }

.torrent-results-table td        { word-break: break-word; vertical-align: middle; }
.torrent-results-table .seeders  { color: #4ade80; }
.torrent-results-table th:nth-child(3),
.torrent-results-table th:nth-child(4),
.torrent-results-table th:nth-child(5),
.torrent-results-table td:nth-child(3),
.torrent-results-table td:nth-child(4),
.torrent-results-table td:nth-child(5) { text-align: right; white-space: nowrap; }
.torrent-results-table th:nth-child(2),
.torrent-results-table td:nth-child(2) { white-space: nowrap; }

.torrent-link                    { color: #e0e0e0; text-decoration: none; }
.torrent-link:hover              { color: #4ade80; }
.torrent-info                    { margin-left: 4px; text-decoration: none; }
.torrent-info:hover              { color: #22d3ee; }

.indexer-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid;
}
.indexer-tpb     { color: #f59e0b; border-color: #f59e0b66; }
.indexer-yts     { color: #60a5fa; border-color: #60a5fa66; }
.indexer-nyaa    { color: #4ade80; border-color: #4ade8066; }
.indexer-eztv    { color: #c084fc; border-color: #c084fc66; }
.indexer-default { color: #a8a8a8; border-color: #3a3a3a; }

.torrent-toggle {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 7px 10px;
  text-align: center;
  background: #161616;
  border: 1px dashed #3a3a3a;
  color: #b0b0b0;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.torrent-toggle:hover { color: #4ade80; border-color: #4ade8088; }

/* ── Active downloads ────────────────────────────────────────────────────── */

.downloads-label { margin-top: 4px; }

.download-row {
  background: #0e0e0e;
  border: 1px solid #1e1e1e;
  border-radius: 3px;
  padding: 7px 10px;
  margin-bottom: 4px;
}

.download-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
}

.download-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: #e0e0e0;
}

.download-meta {
  font-size: 11px;
  flex-shrink: 0;
  white-space: nowrap;
  color: #b0b0b0;
}

.download-actions {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.download-actions button {
  padding: 3px 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.download-actions button svg { width: 12px; height: 12px; flex-shrink: 0; }

.download-bar {
  height: 3px;
  background: #1a1a1a;
  border-radius: 1px;
  overflow: hidden;
}
.download-bar-fill {
  height: 100%;
  background: #4ade80;
  transition: width 0.5s ease, background 0.2s ease;
}
.download-bar-fill.paused   { background: #facc15; }
.download-bar-fill.error    { background: #ef4444; }
.download-bar-fill.finished { background: #60a5fa; }

.torrent-add-cell { width: 1%; }
.torrent-add-btn  {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.torrent-add-btn svg { width: 12px; height: 12px; flex-shrink: 0; }

.torrent-added {
  color: #4ade80;
  border-color: #4ade8088;
  cursor: default;
}
.torrent-added:hover {
  color: #4ade80;
  border-color: #4ade8088;
}

.card {
  background: #161616;
  border: 1px solid #1e1e1e;
  border-radius: 5px;
  padding: 12px 14px;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #a8a8a8;
  margin-bottom: 10px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-header .section-label { margin-bottom: 0; }

.card-header button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.card-header button svg { width: 12px; height: 12px; flex-shrink: 0; }

/* ── Gauges ──────────────────────────────────────────────────────────────── */

.gauge-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  gap: 4px;
}

.gauge-row + .gauge-sub-label { margin-top: 16px; }

.gauge-sub-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #a8a8a8;
  margin-bottom: 10px;
}

.gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.gauge-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #a8a8a8;
}

.gauge-svg {
  width: 150px;
  height: 150px;
}

.gauge-track {
  fill: none;
  stroke: #1e1e1e;
  stroke-width: 7;
}

.gauge-fill {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 251.33;
  transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
}

.gauge-val {
  fill: #e8e8e8;
  font-size: 18px;
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  text-anchor: middle;
  dominant-baseline: middle;
}

.gauge-sub {
  fill: #888;
  font-size: 10px;
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  text-anchor: middle;
}

/* ── Disk metric rows ────────────────────────────────────────────────────── */

.metric-head {
  display: flex;
  justify-content: space-between;
  color: #a8a8a8;
}

.metric-name { color: #e0e0e0; font-weight: 600; }

/* ── Bars ────────────────────────────────────────────────────────────────── */

.bar-track {
  height: 10px;
  background: #222;
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}

.bar-fill.ok     { background: #4ade80; }
.bar-fill.warn   { background: #facc15; }
.bar-fill.danger { background: #ef4444; }

/* ── Disk rows ───────────────────────────────────────────────────────────── */

.disk-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}
.disk-row:last-child { margin-bottom: 0; }

/* ── Tables (containers + images) ───────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 0 8px 6px;
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #888;
  font-weight: 600;
}

td {
  padding: 6px 8px;
  border-top: 1px solid #1a1a1a;
  vertical-align: middle;
}

tr:hover td { background: #191919; }

/* ── Status dot ──────────────────────────────────────────────────────────── */

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  flex-shrink: 0;
}
.dot.running    { background: #4ade80; box-shadow: 0 0 4px #4ade8088; }
.dot.paused     { background: #facc15; }
.dot.restarting { background: #60a5fa; }
.dot.exited,
.dot.dead,
.dot.created    { background: #555; }

/* ── Action buttons ──────────────────────────────────────────────────────── */

.actions { display: flex; gap: 4px; justify-content: flex-end; }
.actions button {
  min-width: 84px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.actions button svg { width: 12px; height: 12px; flex-shrink: 0; }

table th:last-child,
table td:last-child { text-align: right; }

button {
  background: #1e1e1e;
  border: 1px solid #3a3a3a;
  color: #b0b0b0;
  padding: 3px 9px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
button:hover        { color: #e8e8e8; border-color: #4a4a4a; }
button:disabled     { opacity: 0.4; cursor: default; }
button:disabled:hover { color: #b0b0b0; border-color: #3a3a3a; }

/* Per-action color: legible at rest, livelier on hover. No fill change. */
button.btn-start    { color: #6a9b78; border-color: #34503e; }
button.btn-start:hover    { color: #4ade80; border-color: #4ade8088; }

button.btn-stop     { color: #c49968; border-color: #4a3a25; }
button.btn-stop:hover     { color: #f59e0b; border-color: #f59e0b88; }

button.btn-rebuild  { color: #7a90b0; border-color: #344058; }
button.btn-rebuild:hover  { color: #60a5fa; border-color: #60a5fa88; }

button.btn-edit     { color: #6c98aa; border-color: #2a3d48; }
button.btn-edit:hover     { color: #22d3ee; border-color: #22d3ee88; }

button.btn-delete   { color: #b06868; border-color: #4a2d2d; }
button.btn-delete:hover   { color: #ef4444; border-color: #ef444488; }

/* ── Share distribution bar ──────────────────────────────────────────────── */

.share-bar {
  height: 6px;
  display: flex;
  border-radius: 2px;
  overflow: hidden;
  background: #1a1a1a;
  margin-top: 4px;
}
.share-segment {
  height: 100%;
  min-width: 1px;
}

.share-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
  font-size: 11px;
  color: #a8a8a8;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.legend-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

/* ── NAS disks ───────────────────────────────────────────────────────────── */

.nas-disk-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nas-disk-row {
  display: grid;
  grid-template-columns: 70px 1fr 90px 60px 90px;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid #1a1a1a;
}
.nas-disk-row:first-child { border-top: none; }

/* ── Image tags ──────────────────────────────────────────────────────────── */

.tag {
  display: inline-block;
  background: #1e1e1e;
  border: 1px solid #3a3a3a;
  padding: 2px 7px;
  border-radius: 3px;
  margin-right: 3px;
}

/* ── Role badge ──────────────────────────────────────────────────────────── */

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid #3a3a3a;
}
.role-badge.role-admin  { color: #4ade80; border-color: #4ade8066; }
.role-badge.role-viewer { color: #a8a8a8; }

/* ── 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-card {
  background: #161616;
  border: 1px solid #1e1e1e;
  border-radius: 5px;
  padding: 20px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header .section-label { margin-bottom: 0; }
.modal-target { color: #e0e0e0; letter-spacing: 0; text-transform: none; }

.modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 19px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}
.modal-close:hover { background: none; color: #ef4444; }

/* ── Profile form ────────────────────────────────────────────────────────── */

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-form input,
.profile-form select {
  background: #0e0e0e;
  border: 1px solid #3a3a3a;
  color: #e0e0e0;
  padding: 9px 11px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s;
}
.profile-form input:focus,
.profile-form select:focus { border-color: #4ade8088; }

.profile-form button {
  padding: 9px 11px;
  margin-top: 4px;
  justify-content: center;
}

.form-msg {
  font-size: 12px;
  min-height: 15px;
  text-align: center;
}
.form-msg.ok  { color: #4ade80; }
.form-msg.err { color: #ef4444; }

/* ── Sort Logs ───────────────────────────────────────────────────────────── */

.sortlog-card {
  background: #0e0e0e;
  border: 1px solid #1e1e1e;
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.sortlog-card-fail { border-color: #5a1f1f; }

.sortlog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.sortlog-head:hover .sortlog-source { color: #ffffff; }

.sortlog-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.sortlog-chevron {
  color: #888;
  font-size: 12px;
  width: 10px;
  flex-shrink: 0;
}

.sortlog-source {
  color: #e0e0e0;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sortlog-head-meta {
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.sortlog-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}
.sortlog-badge-ok      { background: #163a22; color: #6dd896; border: 1px solid #2a5a3a; }
.sortlog-badge-fail    { background: #3a1616; color: #ef6e6e; border: 1px solid #5a2a2a; }
.sortlog-badge-running { background: #1f2c3a; color: #6ab0e0; border: 1px solid #2f4a66; }

.sortlog-summary {
  margin-top: 6px;
  font-size: 12px;
  color: #c8c8c8;
  line-height: 1.45;
}

.sortlog-detail {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #1e1e1e;
}

.sortlog-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #888;
  margin: 8px 0 6px;
}

.sortlog-text {
  font-size: 12px;
  color: #c8c8c8;
  background: #161616;
  border-left: 2px solid #3a3a3a;
  padding: 6px 9px;
  margin-bottom: 5px;
  border-radius: 0 3px 3px 0;
  white-space: pre-wrap;
}

.sortlog-cmd {
  margin-bottom: 5px;
}

.sortlog-cmd-desc {
  font-size: 11px;
  color: #a8a8a8;
  margin-bottom: 2px;
}

.sortlog-cmd-arg {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: #d4d4d4;
  background: #161616;
  border: 1px solid #242424;
  border-radius: 3px;
  padding: 6px 9px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

.sortlog-result-block {
  margin-top: 10px;
  padding: 8px 10px;
  background: #131313;
  border-radius: 3px;
  font-size: 12px;
  color: #d4d4d4;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */

.dim { color: #a8a8a8; }
.muted { color: #a8a8a8; }

/* ── Responsive: tablet (641-960px) ──────────────────────────────────────── */

@media (max-width: 960px) {
  header { padding: 0 14px; }
  nav { padding: 0 14px; }
  nav .nav-btn { padding: 0 14px; letter-spacing: 1px; }
  main { padding: 12px; }
  .gauge-svg { width: 120px; height: 120px; }
  th { padding: 0 6px 6px; }
  td { padding: 6px; }
  .actions button { min-width: 68px; }
}

/* ── Responsive: phone (≤640px) ──────────────────────────────────────────── */

@media (max-width: 640px) {
  /* Header */
  header { padding: 0 10px; min-height: 44px; }
  .header-right { gap: 6px; }
  .logo { font-size: 12px; letter-spacing: 2px; }
  #last-update { display: none; }
  #user-info {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .header-btn span { display: none; }
  .header-btn { padding: 4px 6px; }
  .header-btn svg { width: 14px; height: 14px; }
  .nas-status {
    padding: 2px 6px;
    font-size: 10px;
    letter-spacing: 0.5px;
  }
  .nas-status::before { width: 6px; height: 6px; }

  /* Nav */
  nav { padding: 0 4px; overflow-x: auto; }
  nav .nav-btn {
    padding: 0 8px;
    letter-spacing: 0.5px;
    font-size: 11px;
    min-height: 42px;
    gap: 0;
    flex: 1;
    justify-content: center;
  }
  nav .nav-btn svg { display: none; }

  /* Main + cards */
  main { padding: 10px; }
  .view { gap: 8px; }
  .card { padding: 10px; }
  .card-header { flex-wrap: wrap; gap: 8px; }

  /* Sub-nav */
  .subnav-btn { padding: 8px 10px; letter-spacing: 0.5px; }

  /* Gauges: 3 across, smaller */
  .gauge-svg { width: 90px; height: 90px; }
  .gauge-row { gap: 2px; }
  .gauge { gap: 4px; }
  .gauge-label { font-size: 10px; letter-spacing: 1px; }

  /* Tables → stacked cards */
  #container-list table,
  #image-list table,
  #user-list table,
  .torrent-results-table,
  #container-list thead,
  #image-list thead,
  #user-list thead,
  .torrent-results-table thead,
  #container-list tbody,
  #image-list tbody,
  #user-list tbody,
  .torrent-results-table tbody { display: block; }

  #container-list thead,
  #image-list thead,
  #user-list thead,
  .torrent-results-table thead { display: none; }

  #container-list tr,
  #image-list tr,
  #user-list tr,
  .torrent-results-table tr {
    display: block;
    background: #0e0e0e;
    border: 1px solid #1e1e1e;
    border-radius: 3px;
    padding: 8px 10px;
    margin-bottom: 6px;
  }
  #container-list tr:hover td,
  #image-list tr:hover td,
  #user-list tr:hover td,
  .torrent-results-table tr:hover td { background: transparent; }

  #container-list td,
  #image-list td,
  #user-list td,
  .torrent-results-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
    border-top: none;
    text-align: left;
    word-break: break-word;
    white-space: normal;
  }
  #container-list td[data-label]::before,
  #image-list td[data-label]::before,
  #user-list td[data-label]::before,
  .torrent-results-table td[data-label]::before {
    content: attr(data-label);
    color: #888;
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    flex-shrink: 0;
  }

  /* Cells without data-label (action cells, torrent add cell) */
  table td:last-child:not([data-label]) {
    justify-content: flex-end;
    padding-top: 6px;
  }
  .actions { flex-wrap: wrap; }
  .actions button { min-width: auto; padding: 4px 6px; }
  .actions button span { display: none; }

  /* Torrent results: numeric cells should not right-align in stacked mode */
  .torrent-results-table th:nth-child(3),
  .torrent-results-table th:nth-child(4),
  .torrent-results-table th:nth-child(5),
  .torrent-results-table td:nth-child(3),
  .torrent-results-table td:nth-child(4),
  .torrent-results-table td:nth-child(5) { text-align: left; white-space: normal; }
  .torrent-results-table th:nth-child(2),
  .torrent-results-table td:nth-child(2) { white-space: normal; }
  .torrent-results-table .torrent-add-cell { width: auto; }

  /* NAS disk rows: 2-row stack */
  .nas-disk-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "name status"
      "model size"
      "temp temp";
    gap: 2px 8px;
    padding: 8px 0;
  }
  .nas-disk-row > :nth-child(1) { grid-area: name; }
  .nas-disk-row > :nth-child(2) { grid-area: model; font-size: 11px; }
  .nas-disk-row > :nth-child(3) { grid-area: size; text-align: right; }
  .nas-disk-row > :nth-child(4) { grid-area: temp; }
  .nas-disk-row > :nth-child(5) { grid-area: status; justify-self: end; }

  /* Active downloads */
  .download-row-top { flex-wrap: wrap; }
  .download-name { flex: 1 1 100%; }
  .download-meta { font-size: 10px; }

  /* Forms: bump to 16px to suppress iOS focus zoom */
  .torrent-search-form { gap: 6px; }
  .torrent-search-form input,
  .login-card input,
  .profile-form input,
  .profile-form select { font-size: 16px; }

  /* Modals */
  .modal-card {
    width: min(300px, calc(100vw - 24px));
    padding: 16px;
  }

  /* Login */
  .login-card { width: min(280px, calc(100vw - 24px)); }
}

/* ── Responsive: small phone (≤480px) ────────────────────────────────────── */

@media (max-width: 480px) {
  .torrent-search-form { flex-direction: column; }
  .torrent-search-form button { width: 100%; justify-content: center; }
  nav .nav-btn { padding: 0 6px; font-size: 10px; }
  .gauge-svg { width: 78px; height: 78px; }
}
