/* TorDown UI - Clean themeable stylesheet */
* {
  box-sizing: border-box;
}

:root {
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --success: #34d399;
  --warning: #f59e0b;
  --danger: #f87171;

  /* Default: dark */
  --bg: #0b1220;
  --surface: #111a2b;
  --surface-2: #162238;
  --text: #e5eefc;
  --muted: #9fb0cb;
  --border: #243752;
  --overlay: rgba(7, 12, 22, 0.72);
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fbff;
  --text: #101a2c;
  --muted: #5f6f87;
  --border: #d9e2f0;
  --overlay: rgba(10, 16, 28, 0.55);
  --shadow: 0 14px 26px rgba(17, 25, 40, 0.15);
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 0 0, rgba(96, 165, 250, 0.1), transparent 36%), var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(8px);
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.section {
  margin-bottom: 22px;
}

.add-section,
.torrents-container,
.stat-card,
.resource-item,
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.add-section {
  padding: 16px;
}

.add-form .form-group {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: stretch;
}

.form-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.form-input::placeholder {
  color: var(--muted);
}

.form-input-file,
.form-input-hidden {
  display: none;
}

.upload-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
}

.upload-trigger.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.selected-file-name {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.form-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.form-hint.error {
  color: var(--danger);
}

.btn-primary,
.btn-secondary,
.btn-icon,
.btn-close,
.actions button,
.details-quick-actions button,
.details-actions button,
.download-file-btn,
.play-file-btn,
.delete-file-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  background: var(--primary-strong);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.14s ease, background-color 0.14s ease, border-color 0.14s ease;
}

.btn-primary,
.details-quick-actions .btn-action:not(.btn-danger),
.details-actions button:not(.btn-danger):not(.delete-file-btn) {
  color: #fff;
}

:root[data-theme="light"] .btn-primary,
:root[data-theme="light"] .details-quick-actions .btn-action:not(.btn-danger),
:root[data-theme="light"] .details-actions button:not(.btn-danger):not(.delete-file-btn) {
  color: var(--text);
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-icon:hover,
.btn-close:hover,
.actions button:hover,
.details-quick-actions button:hover,
.details-actions button:hover,
.download-file-btn:hover,
.play-file-btn:hover,
.delete-file-btn:hover {
  transform: translateY(-1px);
}

.btn-secondary,
.btn-icon,
.btn-close,
.details-actions button,
.play-file-btn,
.download-file-btn {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-icon,
.btn-close {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.9;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.actions button svg,
.details-quick-actions button svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.9;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-right: 6px;
  vertical-align: -2px;
}

.btn-icon.btn-danger,
.actions button[data-action="remove"],
.details-quick-actions .btn-danger,
.delete-file-btn {
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.45);
}

:root[data-theme="light"] .actions button[data-action="remove"],
:root[data-theme="light"] .delete-file-btn {
  color: #991b1b;
}

.actions button[data-action="download-zip"],
.download-zip-btn {
  background: rgba(96, 165, 250, 0.18);
  color: #dbeafe;
  border-color: rgba(96, 165, 250, 0.45);
}

:root[data-theme="light"] .actions button[data-action="download-zip"],
:root[data-theme="light"] .download-zip-btn {
  color: #1e40af;
}

.stats-header,
.resources-header,
.torrents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stats-header h2,
.resources-header h2,
.torrents-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.torrent-count {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.stat-card {
  padding: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
}

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

.resource-item {
  padding: 14px;
}

.resource-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.resource-value .value {
  font-size: 1.2rem;
  font-weight: 700;
}

.resource-value-gauge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.resource-gauge {
  --percent: 0;
  width: 78px;
  height: 78px;
  min-width: 78px;
  min-height: 78px;
  flex-shrink: 0;
  border-radius: 50%;
  background: conic-gradient(
    var(--primary-strong) calc(var(--percent) * 1%),
    var(--border) 0
  );
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px var(--border);
}

.resource-gauge-inner {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.resource-gauge .value {
  font-size: 0.92rem;
  line-height: 1;
}

.resource-value .detail,
.metric {
  color: var(--muted);
  font-size: 0.88rem;
}

.resource-value .detail-long {
  display: block;
  line-height: 1.35;
  word-break: break-word;
}

.torrents-container {
  overflow: hidden;
}

@media (max-width: 520px) {
  .torrents-container {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
}

.torrents-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.torrents-table th,
.torrents-table td {
  text-align: left;
  vertical-align: middle;
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.torrents-table th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.torrents-table tbody tr:hover {
  background: color-mix(in srgb, var(--surface-2) 90%, transparent);
}

.torrents-table tbody tr.active-row {
  background: rgba(96, 165, 250, 0.09);
}

.torrents-table td.name {
  font-weight: 600;
  min-width: 210px;
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.torrents-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 26px;
}

.status-pill {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: capitalize;
  border: 1px solid transparent;
}

.status-pill.downloading {
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.35);
}

.status-pill.completed,
.status-pill.seeding {
  color: #bbf7d0;
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.35);
}

.status-pill.paused {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.35);
}

.stat-block {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-2) 86%, #000 14%);
  overflow: hidden;
}

.progress-bar span,
.progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #60a5fa);
  transition: width 0.24s ease;
}

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

.actions button {
  padding: 6px 10px;
  font-size: 0.78rem;
  line-height: 1;
}

.torrents-empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  font-size: 2rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay);
  padding: 14px;
}

.modal[hidden] {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
}

.modal-content {
  position: relative;
  width: min(1100px, 95vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-fullwidth {
  width: min(1280px, 97vw);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-body {
  padding: 14px 16px;
  overflow: auto;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* Details panel */
.details-quick-actions,
.details-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.details-quick-actions {
  margin-bottom: 12px;
}

.details-quick-actions .btn-action {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.details-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.meta-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px;
}

.meta-item .label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.meta-item .value {
  font-weight: 700;
  font-size: 0.94rem;
  word-break: break-word;
}

.details-info-hash {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  color: var(--muted);
}

.details-info-hash code {
  color: var(--text);
  word-break: break-all;
}

.info-banner {
  margin: 10px 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.table-wrapper {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.files-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 860px;
}

.files-table th,
.files-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  vertical-align: middle;
}

.files-table th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.files-table .file-path {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-table .file-actions {
  white-space: nowrap;
  display: flex;
  gap: 6px;
}

.files-table .download-file-btn,
.files-table .play-file-btn,
.files-table .delete-file-btn {
  padding: 5px 8px;
  font-size: 0.76rem;
  border-radius: 8px;
}

.selection-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.selection-files {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 400px;
}

.selection-file-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.selection-file-item:last-child {
  border-bottom: 0;
}

.selection-file-name {
  font-weight: 600;
}

.selection-file-size {
  color: var(--muted);
  font-size: 0.82rem;
}

.cleanup-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.summary-item,
.cleanup-mode,
.result-stat,
.result-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px;
}

.summary-label,
.mode-desc,
.result-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-value,
.result-value {
  color: var(--text);
  font-weight: 700;
}

.cleanup-modes {
  display: grid;
  gap: 8px;
}

.cleanup-mode {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.cleanup-progress,
.cleanup-result {
  margin-top: 10px;
}

.result-message {
  margin-bottom: 8px;
  font-weight: 700;
}

.result-error {
  color: #fecaca;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: 10px;
  padding: 10px;
}

.notification-bar {
  position: fixed;
  top: -120px;
  left: 0;
  right: 0;
  z-index: 2200;
  padding: 10px 16px;
  text-align: center;
  transition: top 0.24s ease;
}

.notification-bar.notification-show {
  top: 0;
}

.notification-bar.notification-success {
  background: rgba(52, 211, 153, 0.88);
  color: #04110c;
}

.notification-bar.notification-error {
  background: rgba(248, 113, 113, 0.9);
  color: #2d0f0f;
}

.app-footer {
  padding: 14px 24px 22px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.app-footer a:hover {
  text-decoration: underline;
}

.zip-progress-wrap {
  max-width: 560px;
  margin: 0 auto;
  text-align: left;
}

.zip-progress-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.zip-progress-bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.16);
}

.zip-progress-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
}

.zip-progress-meta {
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8rem;
}

@media (max-width: 1100px) {
  .stats-grid,
  .resources-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .main {
    padding: 12px;
  }

  .header-container {
    padding: 10px 12px;
  }

  .add-form .form-group {
    grid-template-columns: 1fr;
  }

  .resources-grid,
  .stats-grid,
  .details-meta,
  .cleanup-summary {
    grid-template-columns: 1fr;
  }

  .resource-value-gauge {
    justify-content: flex-start;
  }

  .torrents-table th:nth-child(4),
  .torrents-table th:nth-child(5),
  .torrents-table td:nth-child(4),
  .torrents-table td:nth-child(5) {
    display: none;
  }

  .actions {
    flex-direction: column;
    gap: 4px;
  }

  .actions button {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.75rem;
  }
}

@media (max-width: 520px) {
  .torrents-table th:nth-child(3),
  .torrents-table th:nth-child(6),
  .torrents-table td:nth-child(3),
  .torrents-table td:nth-child(6) {
    display: none;
  }

  .torrents-table {
    min-width: 420px;
  }

  .modal-content {
    width: 96vw;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 10px;
  }
}
