/* PentestGPT Control Panel V2 — mobile-first. Base rules target the single
   column / bottom-tab-bar / card-table mobile layout; one @media block at
   the bottom layers on the desktop rail + real-table layout. This file is
   entirely independent of portal/styles.css (V1) by design. */

:root {
  --bg: #070f18;
  --panel: #0e1b28;
  --panel-2: #122334;
  --border: rgba(148, 187, 209, 0.16);
  --text: #e7eef7;
  --muted: #93a8bd;
  --accent: #7cf0c9;
  --accent-strong: #36d0a0;
  --web: #6fb8ff;
  --da: #f2b774;
  --danger: #ff7b72;
  --warn: #f4c95d;
  --radius: 12px;
  --shell-header-h: 56px;
  --shell-nav-h: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0 0 4px 0;
  font-weight: 600;
}

p {
  margin: 0 0 8px 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

/* ---------------------------------------------------------------- login */

.v2-login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.v2-login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.v2-login-sub {
  color: var(--muted);
  margin-bottom: 16px;
}

.v2-login-error {
  color: var(--danger);
  font-size: 13px;
}

.v2-login-submit {
  margin-top: 12px;
  width: 100%;
}

.v2-login-classic-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

/* ------------------------------------------------------------ app shell */

.v2-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.v2-topbar {
  height: var(--shell-header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}

.v2-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.v2-brand-mark {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #06120d;
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.v2-beta-chip {
  font-size: 10px;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

.v2-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.v2-session-user {
  color: var(--muted);
  font-size: 13px;
  display: none;
}

/* infra-health banner in the top bar */
.v2-status-banner {
  display: none;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.v2-status-seg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.v2-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--muted);
}

.v2-status-dot-online {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(124, 240, 201, 0.6);
}

.v2-status-dot-offline {
  background: var(--danger);
}

.v2-status-dot-unknown {
  background: var(--muted);
}

.v2-main {
  flex: 1 1 auto;
  padding: 16px 14px calc(var(--shell-nav-h) + 24px) 14px;
  overflow-x: hidden;
}

.v2-view {
  max-width: 1100px;
  margin: 0 auto;
}

/* mobile nav = fixed bottom tab bar */
.v2-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--shell-nav-h);
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.v2-nav-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 2px;
}

.v2-nav-item.active {
  color: var(--accent);
}

.v2-nav-icon svg {
  display: block;
  width: 20px;
  height: 20px;
}

.v2-nav-label {
  font-size: 10px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- forms */

.v2-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.v2-field input,
.v2-field select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
}

.v2-field-checkbox {
  flex-direction: row;
  align-items: center;
}

.v2-field-checkbox input {
  width: auto;
}

.primary-button-v2,
.ghost-button-v2,
.danger-button-v2 {
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid transparent;
}

.primary-button-v2 {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #06120d;
}

.primary-button-v2:disabled {
  opacity: 0.6;
  cursor: default;
}

.ghost-button-v2 {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.danger-button-v2 {
  background: rgba(255, 123, 114, 0.16);
  border-color: rgba(255, 123, 114, 0.4);
  color: var(--danger);
}

.icon-inline svg {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
}

.v2-error {
  color: var(--danger);
  font-size: 13px;
}

.v2-warning {
  color: var(--warn);
  font-size: 13px;
}

.v2-muted {
  color: var(--muted);
}

.v2-loading {
  color: var(--muted);
  padding: 20px 0;
}

/* --------------------------------------------------------- section head */

.v2-section-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.v2-track-pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 10px;
}

.v2-track-pill-web {
  background: rgba(111, 184, 255, 0.16);
  color: var(--web);
}

.v2-track-pill-da {
  background: rgba(242, 183, 116, 0.18);
  color: var(--da);
}

.v2-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.v2-launch-wrap {
  margin-bottom: 18px;
}

.v2-launch-form-host {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.v2-launch-form {
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------- dashboard */

.v2-dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.v2-stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.v2-stat-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.v2-stat-value {
  font-size: 28px;
  font-weight: 700;
  margin: 2px 0;
}

.v2-stat-sub {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.v2-launch-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.v2-launch-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  color: var(--text);
}

.v2-launch-card-icon svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
  margin-bottom: 8px;
}

.v2-launch-card h3 {
  margin-bottom: 4px;
}

.v2-launch-card p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

/* -------------------------------------------------------- table / cards */

.v2-table-host {
  margin-top: 4px;
}

/* ------------------------------------------------ device-grouped history */

.v2-device-group {
  margin-bottom: 14px;
}

.v2-device-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}

.v2-device-group-count {
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-radius: 999px;
  padding: 2px 10px;
}

.v2-device-group-body.hidden {
  display: none;
}

.v2-table {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.v2-row-head {
  display: none;
}

.v2-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.v2-row-expandable {
  cursor: pointer;
}

.v2-cell {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.v2-cell::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex: 0 0 auto;
}

.v2-cell-actions {
  justify-content: flex-end;
  gap: 6px;
}

.v2-cell-actions::before {
  content: none;
}

.v2-empty {
  color: var(--muted);
  padding: 20px 4px;
  text-align: center;
}

.icon-button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-button svg {
  width: 16px;
  height: 16px;
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-button-danger {
  color: var(--danger);
  border-color: rgba(255, 123, 114, 0.35);
}

.icon-button-inline {
  text-decoration: none;
}

.v2-expand {
  margin: -4px 0 4px 0;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.v2-children-summary {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.v2-child-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.v2-child-row:first-of-type {
  border-top: none;
}

.v2-child-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Clickable aggregate child (DA phase / Juice Shop child) — opens that
   phase's own transcript. Per-phase action icons sit at the row's right. */
.v2-child-row-clickable { cursor: pointer; border-radius: 6px; }
.v2-child-row-clickable:hover { background: rgba(127, 179, 255, 0.08); }
.v2-child-actions { display: inline-flex; gap: 4px; flex: 0 0 auto; }
.v2-child-actions .icon-button { width: 26px; height: 26px; border-radius: 6px; }
.v2-child-actions .icon-button svg { width: 14px; height: 14px; }
.v2-detail-actions { display: flex; gap: 8px; margin: 0 0 0.6rem; flex-wrap: wrap; }

.v2-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.v2-chip {
  font-size: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.v2-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  border-radius: 999px;
  padding: 3px 9px;
}

.v2-status-queued {
  background: rgba(147, 168, 189, 0.18);
  color: var(--muted);
}

.v2-status-running {
  background: rgba(111, 184, 255, 0.18);
  color: var(--web);
}

.v2-status-success {
  background: rgba(124, 240, 201, 0.16);
  color: var(--accent);
}

.v2-status-failed {
  background: rgba(255, 123, 114, 0.16);
  color: var(--danger);
}

.v2-status-warn {
  background: rgba(244, 201, 93, 0.16);
  color: var(--warn);
}

.v2-status-unknown {
  background: rgba(147, 168, 189, 0.12);
  color: var(--muted);
}

/* ---------------------------------------------------------------- modal */

.v2-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 14, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.v2-modal {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.v2-modal-title {
  margin-bottom: 12px;
}

.v2-modal-form {
  display: flex;
  flex-direction: column;
}

.v2-modal-error {
  color: var(--danger);
  font-size: 13px;
}

.v2-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.v2-detail-pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  max-height: 320px;
  overflow-y: auto;
}

/* ---------------------------------------------------------------- toast */

#v2-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--shell-nav-h) + 16px);
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid rgba(124, 240, 201, 0.3);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

#v2-toast.v2-toast-error {
  border-color: rgba(255, 123, 114, 0.35);
  color: var(--danger);
}

#v2-toast.v2-toast-hidden {
  display: none;
}

/* ---------------------------------------------------- desktop breakpoint */

@media (min-width: 721px) {
  .v2-app {
    flex-direction: row;
  }

  .v2-topbar {
    position: fixed;
    top: 0;
    left: 220px;
    right: 0;
  }

  .v2-session-user {
    display: inline;
  }

  .v2-status-banner {
    display: inline-flex;
  }

  .v2-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 220px;
    height: 100vh;
    flex-direction: column;
    justify-content: flex-start;
    border-top: none;
    border-right: 1px solid var(--border);
    padding-top: var(--shell-header-h);
  }

  .v2-nav-item {
    /* KEY: reset the mobile bottom-tab `flex: 1 1 0` — otherwise each item
       stretches to fill the 100vh column and the links spread far apart.
       0 0 auto keeps them their natural height, grouped tightly at the top. */
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 9px 14px;
    margin: 1px 8px;
    border-radius: 8px;
  }

  .v2-nav-item:hover {
    background: rgba(127, 179, 255, 0.07);
    color: var(--text);
  }

  .v2-nav-item.active {
    background: rgba(127, 179, 255, 0.10);
  }

  .v2-nav-label {
    font-size: 13px;
  }

  .v2-main {
    margin-left: 220px;
    padding: calc(var(--shell-header-h) + 20px) 28px 28px 28px;
    max-width: none;
  }

  .v2-dashboard-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .v2-launch-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* real table layout, via CSS Grid rather than display:table — a plain
     block .v2-expand panel between two .v2-row grids stays full-width and
     stays anchored directly under its own row, which the CSS table/
     table-row/table-caption model cannot do per-row. */
  .v2-table {
    display: block;
    width: 100%;
  }

  .v2-row-head,
  .v2-row {
    display: grid;
    grid-template-columns: repeat(var(--v2-cols, 4), minmax(0, 1fr)) var(--v2-actions-w, 8.5rem);
    column-gap: 10px;
    align-items: center;
  }

  .v2-row-head {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0 12px 6px 12px;
  }

  .v2-row {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    margin-bottom: 8px;
  }

  .v2-cell {
    padding: 11px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .v2-cell::before {
    content: none;
  }

  .v2-cell-actions {
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    overflow: visible;
    white-space: normal;
  }

  .v2-expand {
    margin: -4px 0 8px 0;
  }
}

/* Effort slider (launch form) */
.v2-field .v2-effort-slider {
  width: 100%;
  accent-color: var(--v2-accent, #34d399);
  margin: 0.35rem 0 0.15rem;
}
.v2-field .v2-effort-value {
  font-size: 0.82rem;
  opacity: 0.8;
}

/* ===== App Testing (SAST/DAST) ===== */
.v2-track-appsec { background: #6d28d9; color: #fff; }
.v2-view-sub { opacity: 0.78; margin: -0.25rem 0 1rem; max-width: 60ch; font-size: 0.92rem; }
.v2-toolbar { margin-bottom: 0.75rem; }
.v2-btn-icon { display: inline-flex; vertical-align: middle; margin-right: 0.35rem; }
.v2-btn-icon svg { width: 16px; height: 16px; }
.v2-radio-row { display: flex; gap: 1.25rem; align-items: center; padding: 0.25rem 0; }
.v2-radio-row label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.field-hint-v2 { display: block; font-size: 0.78rem; opacity: 0.65; margin-top: 0.25rem; }

/* Cold-start indicator: shown next to a pre-execution status while an Azure
   worker spins up from zero, so a ~1-3 min wait doesn't read as "stuck". */
.v2-status-coldstart { display: flex; flex-direction: column; gap: 0.25rem; align-items: flex-start; }
.v2-coldstart-hint { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; opacity: 0.75; font-style: italic; }
.v2-coldstart-dot { width: 8px; height: 8px; border-radius: 50%; background: #e0a63b; flex: 0 0 auto; animation: v2-coldstart-pulse 1.1s ease-in-out infinite; }
@keyframes v2-coldstart-pulse { 0%, 100% { opacity: 0.35; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1.15); } }

/* Near-realtime run transcript / live-terminal view in the run detail modal. */
.v2-detail-meta { font-size: 0.85rem; opacity: 0.8; margin: 0 0 0.5rem; }
.v2-live-terminal { max-height: 55vh; overflow-y: auto; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.78rem; line-height: 1.45; }

.v2-sev-chips { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }
.v2-sev-chip { font-size: 0.72rem; font-weight: 600; padding: 0.1rem 0.4rem; border-radius: 999px; color: #fff; }
.v2-sev-chip.sev-critical { background: #b91c1c; }
.v2-sev-chip.sev-high { background: #ea580c; }
.v2-sev-chip.sev-medium { background: #ca8a04; }
.v2-sev-chip.sev-low { background: #2563eb; }

.v2-progress-cell { display: flex; flex-direction: column; gap: 0.2rem; min-width: 120px; }
.v2-progress { height: 6px; border-radius: 999px; background: rgba(128,128,128,0.25); overflow: hidden; }
.v2-progress-fill { height: 100%; background: var(--v2-accent, #34d399); transition: width 0.4s; }
.v2-progress-label { font-size: 0.74rem; opacity: 0.72; }

.v2-detail .v2-findings { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.6rem; max-height: 55vh; overflow-y: auto; }
.v2-finding { border-left: 3px solid #888; padding: 0.5rem 0.75rem; border-radius: 4px; background: rgba(128,128,128,0.08); }
.v2-finding.sev-critical { border-left-color: #b91c1c; }
.v2-finding.sev-high { border-left-color: #ea580c; }
.v2-finding.sev-medium { border-left-color: #ca8a04; }
.v2-finding.sev-low { border-left-color: #2563eb; }
.v2-finding-head { font-weight: 600; }
.v2-finding-loc { font-family: monospace; font-size: 0.8rem; opacity: 0.75; margin: 0.15rem 0; }
.v2-finding-body { font-size: 0.88rem; margin-top: 0.25rem; }
.v2-finding-fix { font-size: 0.88rem; margin-top: 0.25rem; opacity: 0.9; }
.v2-muted { opacity: 0.6; }

/* ===== Workers & Relays sub-tabs ===== */
.v2-subtabs { display: flex; gap: 0.25rem; border-bottom: 1px solid rgba(128,128,128,0.25); margin: 0.5rem 0 1rem; }
.v2-subtab {
  background: none; border: none; padding: 0.55rem 1rem; cursor: pointer;
  font-size: 0.92rem; color: inherit; opacity: 0.65;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.v2-subtab:hover { opacity: 0.9; }
.v2-subtab.is-active { opacity: 1; font-weight: 600; border-bottom-color: var(--v2-accent, #34d399); }
.v2-tab-content { min-height: 4rem; }
.v2-modal-title { margin: 0 0 0.5rem; font-size: 1.05rem; }
