/* ══════════════════════════════════════════════════════════════
   Downloader Studio — Shared Design System
   ══════════════════════════════════════════════════════════════ */

/* ── Design tokens ─────────────────────────────────────────── */
:root {
  /* Colors */
  --bg:          #f4f5f7;
  --bg-soft:     #fafbfc;
  --surface:     #ffffff;
  --line:        rgba(17,24,39,0.10);
  --line-strong: rgba(17,24,39,0.18);
  --text:        #111827;
  --muted:       #6b7280;
  --accent:      #0a7cff;
  --accent-dark: #0062cc;
  --ok:          #0d9b5f;
  --warn:        #c27b00;
  --danger:      #d14343;

  /* Radius */
  --radius-xl:   20px;
  --radius-lg:   16px;
  --radius-md:   12px;
  --radius-sm:   8px;
  --radius-xs:   6px;

  /* Shadow */
  --shadow:      0 4px 20px rgba(15,23,42,0.08);
  --shadow-sm:   0 2px 8px  rgba(15,23,42,0.05);
  --shadow-lg:   0 12px 36px rgba(15,23,42,0.12);

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

/* ── Dark mode tokens ───────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #0f1117;
  --bg-soft:     #161b22;
  --surface:     #1c2128;
  --line:        rgba(255,255,255,0.09);
  --line-strong: rgba(255,255,255,0.18);
  --text:        #e6edf3;
  --muted:       #8b949e;
  --accent:      #58a6ff;
  --accent-dark: #79b8ff;
  --ok:          #3fb950;
  --warn:        #e3b341;
  --danger:      #f85149;
  --shadow:      0 4px 20px rgba(0,0,0,0.35);
  --shadow-sm:   0 2px 8px  rgba(0,0,0,0.25);
  --shadow-lg:   0 12px 36px rgba(0,0,0,0.45);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topbar / Navigation ────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 20px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }

.btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-xs);
}

.btn:disabled { opacity: 0.48; cursor: not-allowed; transform: none; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow); }

/* ── Forms ──────────────────────────────────────────────────── */
input[type="text"],
input[type="url"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10,124,255,0.14);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  box-shadow: 0 0 0 3px rgba(88,166,255,0.18);
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}
.modal-bg.open { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.modal-box h3 { font-size: 1rem; font-weight: 700; margin-bottom: 14px; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── Status badges ──────────────────────────────────────────── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-completed  { background: rgba(13,155,95,0.12);  color: var(--ok); }
.status-running,
.status-processing { background: rgba(10,124,255,0.12); color: var(--accent); }
.status-queued     { background: rgba(107,114,128,0.12); color: var(--muted); }
.status-failed     { background: rgba(209,67,67,0.12);  color: var(--danger); }
.status-dead_letter{ background: rgba(209,67,67,0.18);  color: var(--danger); }
.status-paused,
.status-pause_requested { background: rgba(194,123,0,0.12); color: var(--warn); }
.status-cancelled  { background: rgba(107,114,128,0.12); color: var(--muted); }

[data-theme="dark"] .status-completed   { background: rgba(63,185,80,0.15); }
[data-theme="dark"] .status-running,
[data-theme="dark"] .status-processing  { background: rgba(88,166,255,0.15); }
[data-theme="dark"] .status-failed      { background: rgba(248,81,73,0.15); }
[data-theme="dark"] .status-dead_letter { background: rgba(248,81,73,0.22); }
[data-theme="dark"] .status-paused,
[data-theme="dark"] .status-pause_requested { background: rgba(227,179,65,0.15); }

/* ── Toast notifications ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 0.86rem;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  max-width: 340px;
  display: none;
  animation: slideUp 0.2s ease;
}
.toast.open { display: block; }
.toast.ok   { border-left: 3px solid var(--ok); }
.toast.err  { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }

/* ── Progress bar ───────────────────────────────────────────── */
.progress {
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.progress i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ── Stats grid ─────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-val {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.stat-lbl {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Page wrapper ───────────────────────────────────────────── */
.page-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* ── Section heading ────────────────────────────────────────── */
.section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── Hint / caption text ────────────────────────────────────── */
.hint {
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state p    { font-size: 0.9rem; max-width: 320px; margin: 0 auto; }

/* ── Divider ────────────────────────────────────────────────── */
hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

/* ── Scrollbar (webkit) ─────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Code / mono ────────────────────────────────────────────── */
code, .mono {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 1px 5px;
}

/* ══════════════════════════════════════════════════════════════
   Mobile — shared breakpoints
   ══════════════════════════════════════════════════════════════ */

/* Tablet portrait */
@media (max-width: 768px) {
  .topbar { padding: 0 14px; height: 52px; }
  .topbar-nav { gap: 4px; }
  .page-wrap { padding: 18px 14px 32px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-box { padding: 18px 16px; }
}

/* Mobile */
@media (max-width: 480px) {
  body { font-size: 14px; }
  .topbar { height: 48px; padding: 0 12px; }
  .topbar-brand span { display: none; }   /* hide label, keep icon */
  .btn { padding: 6px 11px; font-size: 0.82rem; }
  .btn-sm { padding: 4px 8px; font-size: 0.75rem; }
  .page-wrap { padding: 14px 12px 28px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px 14px; }
  .stat-val { font-size: 1.4rem; }
  .modal-box { padding: 16px 14px; border-radius: var(--radius-md); }
}

/* Small phone */
@media (max-width: 360px) {
  .stat-grid { grid-template-columns: 1fr; }
}
