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

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #21262d;
  --border:      #30363d;
  --accent:      #0a66c2;
  --accent-hover:#0957a8;
  --success:     #3fb950;
  --warn:        #d29922;
  --danger:      #f85149;
  --text:        #c9d1d9;
  --text-muted:  #8b949e;
  --radius:      6px;
  --shadow:      0 1px 3px rgba(0,0,0,.4);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 16px; font-weight: 600; color: var(--text); }
p { color: var(--text-muted); }

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-weight: 800;
  font-size: 20px;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.logo span { color: var(--text-muted); font-weight: 500; }

.nav-links { display: flex; gap: 4px; }
.nav-links a {
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  transition: color .15s, background .15s;
}
.nav-links a:hover  { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-links a.active { color: var(--text); background: var(--surface-2); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.session-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.session-chip::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.session-chip.ok    { color: var(--success); border-color: #238636; }
.session-chip.ok::before   { background: var(--success); }
.session-chip.warn  { color: var(--warn);    border-color: #9e6a03; }
.session-chip.warn::before { background: var(--warn); }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 0;
  height: calc(100vh - 56px);
}

.sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-panel {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

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

/* ── New Job Form ────────────────────────────────────────────────────────────── */
.new-job-form { padding: 16px; border-bottom: 1px solid var(--border); }
.new-job-form h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.form-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type="text"],
input[type="url"],
input[type="number"],
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10,102,194,.15);
}
input::placeholder { color: var(--text-muted); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--text-muted); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(248,81,73,.1); }

.btn-success { background: #238636; color: #fff; border-color: #238636; }
.btn-success:hover:not(:disabled) { background: #2ea043; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }

/* ── Job List (sidebar) ──────────────────────────────────────────────────────── */
.job-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.job-list { overflow-y: auto; flex: 1; }

.job-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  position: relative;
}
.job-item:hover       { background: var(--surface-2); }
.job-item.active      { background: var(--surface-2); border-left: 2px solid var(--accent); }
.job-item.active:hover { background: var(--surface-2); }

.job-item-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.job-item-label  { font-weight: 500; font-size: 13px; flex: 1; word-break: break-word; }
.job-item-meta   { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--text-muted); }
.job-item-type   { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-state p { margin-top: 6px; font-size: 12px; }

/* Progress bar */
.progress-bar  { height: 2px; background: var(--border); border-radius: 2px; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s ease; }

/* ── Status Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-pending   { background: #1c2d3f; color: #58a6ff; border-color: #1f3e5a; }
.badge-running   { background: #1c2a1e; color: var(--success); border-color: #238636; }
.badge-completed { background: #1c2a1e; color: var(--success); border-color: #238636; }
.badge-failed    { background: #2d1517; color: var(--danger);  border-color: #6e1119; }

/* Pulse animation for running jobs */
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.badge-running { animation: pulse 2s ease-in-out infinite; }

/* ── Main Panel Sections ─────────────────────────────────────────────────────── */
.section-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}
.section-empty svg { opacity: .3; }
.section-empty h3  { font-size: 15px; color: var(--text); }
.section-empty p   { font-size: 13px; max-width: 280px; }

/* ── Job Detail ──────────────────────────────────────────────────────────────── */
.job-detail-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.job-detail-title { flex: 1; }
.job-detail-title h2 { font-size: 15px; word-break: break-all; }
.job-detail-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.job-url { font-size: 11px; color: var(--text-muted); word-break: break-all; margin-top: 4px; }

.job-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }

.download-group { display: flex; gap: 6px; }

/* ── Log Panel ───────────────────────────────────────────────────────────────── */
.log-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.log-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.log-output {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 10px 12px;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}
.log-line-error { color: var(--danger); }
.log-line-warn  { color: var(--warn);   }
.log-line-info  { color: var(--text-muted); }

/* ── Results Table ───────────────────────────────────────────────────────────── */
.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.results-table-wrapper { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:hover td { background: #ffffff04; }
tbody tr:last-child td { border-bottom: none; }

.td-name { font-weight: 500; }
.td-url a { color: var(--accent); font-size: 12px; }
.degree-badge {
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Login Page ──────────────────────────────────────────────────────────────── */
.login-layout {
  max-width: 700px;
  margin: 32px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 20px;
  align-items: center;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 14px 0;
  font-size: 13px;
}
.status-grid .label { color: var(--text-muted); font-size: 12px; }

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

.hint { font-size: 12px; color: var(--text-muted); margin: 8px 0 14px; }

/* ── noVNC iframe ────────────────────────────────────────────────────────────── */
.vnc-frame {
  width: 100%;
  height: 580px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #000;
  display: block;
}
.vnc-unavailable {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.mt-8    { margin-top: 8px; }
.mt-14   { margin-top: 14px; }
.flex    { display: flex; }
.gap-8   { gap: 8px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .form-row { grid-template-columns: 1fr; }
}
