:root {
  --bg: #0f0f12;
  --surface: #18181c;
  --border: #2a2a30;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --error: #ef4444;
  --warn: #eab308;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.header {
  margin-bottom: 1.5rem;
}

.header-with-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.header-text {
  flex: 1;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.current-user {
  font-size: 0.9rem;
  color: var(--text-muted);
}

a.current-user {
  color: var(--accent);
  text-decoration: none;
}

a.current-user:hover {
  text-decoration: underline;
}

.header h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.password-gate {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.password-gate.hidden {
  display: none;
}

.auth-page .auth-main {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 2rem;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  width: 100%;
  max-width: 360px;
}

.auth-box h2 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.auth-box label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-box input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.auth-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-box button {
  width: 100%;
  padding: 0.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}

.auth-box button:hover {
  background: var(--accent-hover);
}

.auth-box button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.auth-error {
  color: var(--error);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.auth-error.hidden {
  display: none;
}

.account-info {
  margin-bottom: 2rem;
}

.account-username,
.account-role {
  margin: 0.25rem 0;
  color: var(--text-muted);
}

.users-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.users-section.hidden {
  display: none;
}

.users-section h2 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
}

.users-section h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  color: var(--text-muted);
}

.users-add {
  margin-bottom: 1.5rem;
}

.users-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.users-add-form input,
.users-add-form select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.users-add-form input:focus,
.users-add-form select:focus {
  outline: none;
  border-color: var(--accent);
}

.users-list-wrap {
  margin-top: 1rem;
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.users-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.users-list li:last-child {
  border-bottom: none;
}

.users-list .user-name {
  font-weight: 500;
}

.users-list .user-role {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.users-list .user-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.users-list .user-actions select {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}

.users-list .btn-delete-user {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: 4px;
  cursor: pointer;
}

.users-list .btn-delete-user:hover {
  background: rgba(239, 68, 68, 0.15);
}

.password-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 320px;
}

.password-box label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.password-box input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.password-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.password-box button {
  width: 100%;
  padding: 0.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}

.password-box button:hover {
  background: var(--accent-hover);
}

.password-hint {
  margin: 0.75rem 0 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.main {
  opacity: 1;
  transition: opacity 0.2s;
}

.main.locked {
  opacity: 0.5;
  pointer-events: none;
}

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.path-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.path-row label {
  flex: 0 0 auto;
  font-size: 0.9rem;
  color: var(--text-muted);
  min-width: 110px;
}

.path-row input {
  flex: 1;
  min-width: 180px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.path-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.input-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.input-row input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.input-row input:focus {
  outline: none;
  border-color: var(--accent);
}

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

#download-btn {
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#download-btn:hover {
  background: var(--accent-hover);
}

#download-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary {
  padding: 0.5rem 0.75rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.jobs-section h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.downloads-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px;
}

.downloads-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.downloads-list[hidden] {
  display: none;
}

.download-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.download-item:last-child {
  border-bottom: none;
}

.download-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.download-item.no-outline {
  outline: none;
}

.download-item-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.download-item-body {
  flex: 1;
  min-width: 0;
}

.download-item-name {
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}

.download-item-meta.status-error,
.download-item-meta.status-needs_login {
  color: var(--error);
}

.download-item-meta.status-done {
  color: var(--accent);
}

.download-item-from-to {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.download-item-from-to-line {
  white-space: normal;
  word-break: break-all;
  margin-top: 2px;
}

.download-item-from-to-line:first-child {
  margin-top: 0;
}

.download-item-from-to-label {
  flex-shrink: 0;
  color: var(--text-muted);
}

.download-item-from-to-value {
  color: var(--text);
}

.download-item-progress {
  margin-top: 6px;
}

.download-item-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.download-item-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.download-item-progress-indeterminate .download-item-progress-fill {
  width: 30%;
  animation: download-indeterminate 1s ease-in-out infinite;
}

@keyframes download-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.download-item-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.download-item-cancel.btn-cancel,
.download-item-pause.btn-pause,
.download-item-resume.btn-resume {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-pause {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 4px;
  cursor: pointer;
}

.btn-pause:hover {
  background: rgba(234, 179, 8, 0.15);
}

.btn-resume {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
}

.btn-resume:hover {
  background: rgba(34, 197, 94, 0.15);
}

.download-item-progress-fill.download-item-progress-paused {
  background: var(--warn);
}

.download-item-meta.status-paused {
  color: var(--text-muted);
}

.load-more-sentinel {
  height: 1px;
  width: 100%;
  pointer-events: none;
  visibility: hidden;
}

.no-downloads {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.no-downloads[hidden] {
  display: none;
}

.no-downloads-illustration {
  width: 96px;
  height: 96px;
  margin-bottom: 1rem;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round' opacity='0.5'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E") center no-repeat;
}

.btn-cancel {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: 4px;
  cursor: pointer;
}

.btn-cancel:hover {
  background: rgba(239, 68, 68, 0.15);
}

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  max-width: 320px;
  z-index: 50;
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast.error {
  background: var(--error);
  color: #fff;
}

.toast.success {
  background: var(--accent);
  color: #fff;
}

.toast.info {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.debug-panel {
  margin-top: 2rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.debug-panel.hidden {
  display: none;
}
.debug-panel h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
}
.debug-panel p {
  margin: 0.25rem 0;
}
