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

:root {
  --bg:        #0d0f14;
  --surface:   #13161e;
  --surface2:  #1a1e28;
  --border:    #242834;
  --border2:   #2e3345;
  --text:      #e4e8f0;
  --text-muted:#7a8099;
  --green:     #22c55e;
  --green-dim: #16532c;
  --red:       #ef4444;
  --red-dim:   #521818;
  --yellow:    #f59e0b;
  --accent:    #6366f1;
  --accent-dim:#27294d;
  --radius:    8px;
  --radius-lg: 12px;
  --font:      'Inter', system-ui, sans-serif;
  --mono:      'JetBrains Mono', monospace;
  --sidebar-w: 220px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  letter-spacing: -.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  text-decoration: none;
  user-select: none;
}
.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.ffmpeg-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
}

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}
.dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.red   { background: var(--red); }

/* ── Main ──────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 28px 32px;
  gap: 20px;
}

/* ── Page header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.page-sub   { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

/* ── Stats ──────────────────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat {
  flex: 1;
  background: var(--surface);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-n {
  font-size: 24px;
  font-weight: 600;
  font-family: var(--mono);
  line-height: 1;
}
.stat-n.green  { color: var(--green); }
.stat-n.red    { color: var(--red); }
.stat-n.muted  { color: var(--text-muted); }
.stat-l { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }

/* ── Table ──────────────────────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

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

.jobs-table th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.jobs-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
  max-width: 200px;
}

.jobs-table tr:last-child td { border-bottom: none; }
.jobs-table tbody tr:hover { background: rgba(255,255,255,.025); }

.cell-mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-name { font-weight: 500; }

.proxy-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  background: var(--surface2);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--mono);
}
.proxy-tag.active { background: rgba(99,102,241,.15); color: #818cf8; }
.no-proxy { color: var(--text-muted); font-size: 12px; opacity: .5; }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .01em;
}
.badge-idle    { background: var(--surface2); color: var(--text-muted); }
.badge-running { background: var(--green-dim); color: var(--green); }
.badge-stopped { background: var(--surface2); color: var(--text-muted); }
.badge-error   { background: var(--red-dim); color: var(--red); }

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-running .badge-dot {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

/* Action buttons */
.actions {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 0;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: opacity .15s, background .15s, transform .1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { opacity: .88; }

.btn-ghost {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border2);
}
.btn-ghost:hover:not(:disabled) { background: var(--border2); color: var(--text); }

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.2);
}
.btn-danger:hover:not(:disabled) { background: #6b1c1c; }

.btn-success {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(34,197,94,.2);
}
.btn-success:hover:not(:disabled) { background: #1a4d2e; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Modal / Overlay ────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in .15s ease;
}
.overlay[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  animation: slide-up .18s ease;
}

@keyframes slide-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-hd h2 { font-size: 16px; font-weight: 600; }

.modal-ft {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s;
}
.close-btn:hover { color: var(--text); }

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  padding: 20px 24px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field label sup { color: var(--red); }

.field input {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  padding: 8px 11px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus  { border-color: var(--accent); }
.field input::placeholder { color: var(--text-muted); opacity: .6; }
.field input.err    { border-color: var(--red); }

.field small {
  font-size: 11.5px;
  color: var(--text-muted);
  opacity: .7;
}

.separator {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 2px;
}
.separator span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  white-space: nowrap;
}
.separator::before, .separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Logs Drawer ────────────────────────────────────────────────────────── */
.drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(780px, calc(100vw - 60px));
  background: var(--surface);
  border-left: 1px solid var(--border2);
  display: flex;
  flex-direction: column;
  animation: slide-in .2s ease;
}

.overlay#overlay-logs {
  justify-content: flex-end;
  align-items: stretch;
}

@keyframes slide-in {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.drawer-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.drawer-hd h2 { font-size: 15px; font-weight: 600; }
.drawer-sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-family: var(--mono); }

.drawer-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.log-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.log-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 2px 8px;
  border-radius: 4px;
}
.log-badge.idle    { background: var(--surface); color: var(--text-muted); }
.log-badge.running { background: var(--green-dim); color: var(--green); }
.log-badge.stopped { background: var(--surface); color: var(--text-muted); }
.log-badge.error   { background: var(--red-dim); color: var(--red); }

.autoscroll-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.autoscroll-label input { cursor: pointer; accent-color: var(--accent); }

.log-lines-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.log-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 14px 22px;
  background: #080a0f;
}

#log-pre {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: #c8d0e4;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: rgba(34,197,94,.35); color: var(--green); }
.toast.error   { border-color: rgba(239,68,68,.35); color: var(--red); }

/* ── Spinner ────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin .8s linear infinite; display: block; }

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

/* ── Mobile top bar (hidden on desktop) ──────────────────────────────────── */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.mobile-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* ── Mobile job cards (hidden on desktop) ────────────────────────────────── */
.job-cards { display: none; flex-direction: column; gap: 10px; }

.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.job-card-name {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.job-card-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.job-card-label {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  flex-shrink: 0;
  width: 44px;
}

.job-card-val {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.job-card-actions {
  display: flex;
  gap: 8px;
}

.job-card-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 9px 12px;
  font-size: 13px;
}

/* ── Responsive breakpoint ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Layout: stack vertically, no sidebar */
  body { flex-direction: column; overflow: auto; }

  .sidebar { display: none; }

  .mobile-header { display: flex; }

  .main {
    padding: 14px 12px;
    gap: 14px;
    min-height: unset;
    overflow-y: visible;
  }

  /* Page header: tighter on mobile */
  .page-header { flex-wrap: wrap; gap: 10px; }
  .page-title  { font-size: 18px; }

  /* Stats: 2×2 grid on mobile */
  .stats-row { flex-wrap: wrap; }
  .stat { min-width: calc(50% - 1px); }

  /* Hide desktop table, show cards */
  .table-wrap  { display: none; }
  .job-cards   { display: flex; }

  /* Modal: bottom sheet on mobile */
  .overlay {
    align-items: flex-end;
    justify-content: stretch;
  }
  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: slide-up-sheet .22s ease;
  }

  @keyframes slide-up-sheet {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  /* Form: single column */
  .form-grid { grid-template-columns: 1fr; padding: 16px; gap: 12px; }
  .field.full { grid-column: 1; }

  /* Drawer: full screen on mobile */
  .overlay#overlay-logs { justify-content: stretch; align-items: stretch; }
  .drawer {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border2);
    border-radius: 0;
    animation: slide-up-sheet .22s ease;
  }

  /* Drawer header: wrap actions on small screens */
  .drawer-hd { flex-wrap: wrap; padding: 14px 14px 10px; }
  .drawer-actions { gap: 4px; }
  .drawer-actions .btn-sm { padding: 7px 9px; }

  /* Log meta: wrap */
  .log-meta { flex-wrap: wrap; gap: 8px; padding: 8px 14px; }

  /* Toast: full-width bottom bar on mobile */
  .toast {
    left: 12px;
    right: 12px;
    bottom: 16px;
    max-width: none;
  }

  /* Bigger touch targets for all buttons */
  .btn { padding: 9px 16px; font-size: 13.5px; }
  .btn-sm { padding: 7px 10px; font-size: 12.5px; }
}

