:root {
  --bg: #1a1d23;
  --surface: #21252b;
  --surface-2: #282c34;
  --border: #3e4451;
  --text: #abb2bf;
  --text-strong: #e6e6e6;
  --muted: #7f848e;
  --accent: #61afef;
  --accent-hover: #7ec0ff;
  --danger: #e06c75;
  --ok: #98c379;
  --warn: #e5c07b;
  --radius: 8px;
  --sidebar-w: 220px;
  --topbar-h: 52px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text-strong);
  font-weight: 600;
}

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

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

code {
  font-family: var(--mono);
  font-size: 0.875em;
}

.hidden {
  display: none !important;
}

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

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-strong);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1d23;
}

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

.btn-ghost {
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-strong);
}

.btn-danger-ghost {
  border-color: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: rgba(224, 108, 117, 0.12);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-xs {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
}

/* ── Form fields ─────────────────────────────────────────────── */

.field-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-strong);
}

.field-hint {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.field-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-strong);
  font: inherit;
  font-size: 0.875rem;
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(97, 175, 239, 0.2);
}

.field-input-sm {
  width: auto;
  min-width: 10rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.8125rem;
}

.field-textarea {
  resize: vertical;
  min-height: 5rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
}

/* ── App shell ───────────────────────────────────────────────── */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 1rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0.5rem;
  gap: 0.15rem;
}

.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text-strong);
}

.nav-link.active {
  background: rgba(97, 175, 239, 0.15);
  color: var(--accent);
}

.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-company {
  font-size: 0.875rem;
  color: var(--muted);
}

.topbar-company strong {
  color: var(--text-strong);
}

.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow: auto;
}

/* ── Page header ─────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.page-subtitle {
  margin: 0;
  font-size: 0.875rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── Login ───────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-strong);
}

.login-tagline {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-error {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--danger);
  background: rgba(224, 108, 117, 0.12);
  border-radius: var(--radius);
}

.login-api-status {
  margin: 1rem 0 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted);
}

.login-api-status.ok {
  color: var(--ok);
}

.login-api-status.bad {
  color: var(--danger);
}

/* ── Placeholder ─────────────────────────────────────────────── */

.placeholder-page {
  text-align: center;
  padding: 3rem 1rem;
}

.placeholder-page h1 {
  margin-bottom: 0.5rem;
}

/* ── Devices table ───────────────────────────────────────────── */

.devices-error {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--danger);
  background: rgba(224, 108, 117, 0.12);
  border-radius: var(--radius);
}

.devices-loading,
.devices-empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.cell-strong {
  font-weight: 600;
  color: var(--text-strong);
}

.cell-mono {
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.cell-id {
  color: var(--muted);
}

.devices-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.8125rem;
}

.status-summary {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-summary-item {
  color: var(--muted);
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: lowercase;
}

.status-online {
  background: rgba(152, 195, 121, 0.18);
  color: var(--ok);
}

.status-offline {
  background: rgba(224, 108, 117, 0.18);
  color: var(--danger);
}

.status-unknown {
  background: rgba(127, 132, 142, 0.2);
  color: var(--muted);
}

/* ── Inventory ───────────────────────────────────────────────── */

.inv-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  min-height: calc(100vh - var(--topbar-h) - 3rem);
}

@media (max-width: 768px) {
  .inv-layout {
    grid-template-columns: 1fr;
  }
}

.inv-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: calc(100vh - var(--topbar-h) - 3rem);
  overflow: auto;
}

.inv-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.inv-sidebar-title {
  font-weight: 600;
  color: var(--text-strong);
}

.inv-create-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.inv-create-actions {
  display: flex;
  gap: 0.5rem;
}

.inv-create-error {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--danger);
}

.inv-state-msg {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.inv-group-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.inv-group-list li {
  padding: 0.6rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  border: 1px solid transparent;
}

.inv-group-list li:hover {
  background: var(--surface-2);
}

.inv-group-list li.active {
  background: rgba(97, 175, 239, 0.12);
  border-color: rgba(97, 175, 239, 0.35);
}

.inv-group-name {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-strong);
}

.inv-group-desc {
  display: block;
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

.inv-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow: auto;
}

.inv-empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

.inv-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.inv-detail-name {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.inv-detail-desc {
  margin: 0;
  font-size: 0.875rem;
}

.inv-add-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.inv-add-row select {
  flex: 1;
  min-width: 12rem;
}

.inv-member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.inv-member-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.inv-member-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.inv-member-name {
  font-size: 0.875rem;
}

.inv-member-meta {
  font-size: 0.75rem;
}

.inv-member-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ── Enrollment ──────────────────────────────────────────────── */

.enrollment-page .page-header {
  text-align: center;
  justify-content: center;
}

.enrollment-page .page-header > div {
  text-align: center;
}

.enrollment-card {
  max-width: 520px;
  margin: 0 auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.enrollment-section {
  margin-bottom: 1rem;
}

.enrollment-section-inline {
  margin-top: 0.5rem;
}

.enrollment-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.enrollment-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.enrollment-error {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--danger);
  background: rgba(224, 108, 117, 0.12);
  border-radius: var(--radius);
}

.enrollment-success {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--ok);
  background: rgba(152, 195, 121, 0.12);
  border-radius: var(--radius);
}

.os-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.os-switch-btn {
  padding: 0.4rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.os-switch-btn:hover {
  background: var(--surface-2);
}

.os-switch-btn.active {
  background: var(--accent);
  color: #1a1d23;
  font-weight: 600;
}

/* ── Templates ───────────────────────────────────────────────── */

.templates-page {
  max-width: 760px;
  margin: 0 auto;
}

.templates-page .page-header {
  text-align: center;
  justify-content: center;
}

.templates-page .page-header > div {
  text-align: center;
}

.tpl-upload-card,
.tpl-list-section {
  width: 100%;
}

.tpl-section-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.tpl-upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.tpl-upload-hint {
  margin: 0 0 0.5rem;
}

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

.tpl-file-label {
  cursor: pointer;
  margin: 0;
}

.tpl-file-name {
  font-size: 0.875rem;
}

.tpl-yaml-input {
  font-family: var(--mono);
  font-size: 0.8125rem;
  resize: vertical;
  min-height: 10rem;
}

.tpl-error {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--danger);
  background: rgba(224, 108, 117, 0.12);
  border-radius: var(--radius);
}

.tpl-success {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--ok);
  background: rgba(152, 195, 121, 0.12);
  border-radius: var(--radius);
}

.tpl-list-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tpl-state-msg {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.tpl-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tpl-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.tpl-item-expanded {
  border-color: var(--accent);
}

.tpl-item-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
}

.tpl-item-open:hover .tpl-item-name {
  color: var(--accent);
}

.tpl-item-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-strong);
}

.tpl-item-desc {
  font-size: 0.8125rem;
}

.tpl-item-meta {
  font-size: 0.75rem;
}

.tpl-item-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.tpl-detail {
  flex-basis: 100%;
  width: 100%;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tpl-detail-meta {
  margin: 0;
  font-size: 0.875rem;
}

.tpl-detail-content {
  min-height: 12rem;
}

/* ── Sandbox ─────────────────────────────────────────────────── */

.sandbox-page .page-header {
  margin-bottom: 1.25rem;
}

.sandbox-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  align-items: start;
  min-height: calc(100vh - var(--topbar-h) - 7rem);
}

@media (max-width: 900px) {
  .sandbox-layout {
    grid-template-columns: 1fr;
  }
}

.sandbox-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-height: 12rem;
}

.sandbox-panel-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-strong);
}

.sandbox-panel-hint {
  margin: 0;
  font-size: 0.875rem;
}

.sandbox-runner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sandbox-runner-header .sandbox-panel-title {
  margin: 0;
}

.sandbox-runner-loading {
  font-size: 0.75rem;
}

.sandbox-runner-loading.hidden {
  display: none;
}

.sandbox-runner-error {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--danger);
  background: rgba(224, 108, 117, 0.12);
  border-radius: var(--radius);
}

.sandbox-runner-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sandbox-runner-company {
  margin: 0;
  font-size: 0.8125rem;
}

.sandbox-runner-company strong {
  color: var(--text-strong);
}

.runner-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  width: fit-content;
}

.runner-tag-count {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1;
}

.runner-tag-free {
  background: rgba(152, 195, 121, 0.18);
  color: var(--ok);
  border: 1px solid rgba(152, 195, 121, 0.35);
}

.runner-tag-busy {
  background: rgba(224, 108, 117, 0.18);
  color: var(--danger);
  border: 1px solid rgba(224, 108, 117, 0.35);
}

.runner-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0;
}

.runner-stat {
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
}

.runner-stat dt {
  margin: 0 0 0.2rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.runner-stat dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-strong);
}

/* ── Jobs Plays (reuses sandbox layout) ─────────────────────────── */

.jobs-plays-auto-toggle {
  margin: 0;
  font-size: 0.75rem;
}

.jobs-plays-auto-on {
  color: var(--success, #98c379);
}

.jobs-plays-auto-off {
  color: var(--muted);
}
