/* --- Base ---------------------------------------------------------------- */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e4e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }
h4 { font-size: 0.85rem; margin: 0.75rem 0 0.25rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.85em; }
.muted { color: var(--muted); }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Topbar -------------------------------------------------------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}
.topbar .brand a { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.topbar nav { display: flex; gap: 1.25rem; flex: 1; }
.topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.topbar .user { display: flex; align-items: center; gap: 1rem; }
.link-button {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 0; font: inherit;
}
.link-button:hover { color: var(--text); }

.container { max-width: 1200px; margin: 1.5rem auto; padding: 0 1.5rem; }
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.page-header h1 { margin: 0; }

/* --- Buttons & forms ----------------------------------------------------- */
.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.btn:hover { background: #f1f3f5; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: white; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: white; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.85em; }

label {
  display: block;
  margin-bottom: 1rem;
  font-weight: 500;
}
label input, label textarea, label select {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  margin-top: 0.25rem;
  background: white;
}
label input:focus, label textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; }

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 600px;
}
.run-form { max-width: none; }
.actions { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.selected-count { color: var(--muted); font-weight: 500; }

/* --- Tables -------------------------------------------------------------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th, .data-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table thead th {
  background: #f9fafb;
  font-weight: 600;
  font-size: 0.85em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbfc; }

/* --- Chips & tags -------------------------------------------------------- */
.filter-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip {
  padding: 0.3rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9em;
}
.chip:hover { background: #f1f3f5; text-decoration: none; }
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.chip .count {
  display: inline-block;
  background: rgba(0,0,0,0.08);
  padding: 0.05em 0.5em;
  border-radius: 999px;
  margin-left: 0.25em;
  font-size: 0.85em;
}
.chip.active .count { background: rgba(255,255,255,0.25); }

.chip-btn {
  padding: 0.25rem 0.6rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85em;
}
.chip-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

.panel-tag {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 500;
  background: #e5e7eb;
  color: #374151;
}
.panel-cpanel { background: #fef3c7; color: #92400e; }
.panel-virtualmin { background: #dbeafe; color: #1e40af; }
.panel-directadmin { background: #dcfce7; color: #166534; }
.panel-enhance { background: #ede9fe; color: #5b21b6; }
.panel-plesk { background: #fce7f3; color: #9f1239; }
.panel-none { background: #f3f4f6; color: #6b7280; }
.panel-unknown { background: #f3f4f6; color: #6b7280; }

.type-tag {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 500;
  margin-right: 0.25em;
}
.type-dedicated { background: #fde68a; color: #78350f; }    /* hardware = warm */
.type-vps       { background: #c7d2fe; color: #312e81; }    /* virt = cool */
.type-container { background: #bbf7d0; color: #14532d; }    /* container = green */
.type-unknown   { background: #f3f4f6; color: #6b7280; }

.status-tag {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 500;
}
.status-pending { background: #f3f4f6; color: #6b7280; }
.status-running { background: #dbeafe; color: #1e40af; }
.status-completed { background: #dcfce7; color: #166534; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-timeout { background: #fef3c7; color: #92400e; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 0.4em;
  vertical-align: middle;
}
.status-dot.ok { background: var(--success); }
.status-dot.warn { background: var(--warn); }
.status-dot.stale { background: var(--muted); }

/* --- Alerts -------------------------------------------------------------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert.ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* --- Login --------------------------------------------------------------- */
.login-card {
  max-width: 360px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.login-card h1 { text-align: center; margin-bottom: 1.5rem; }
.login-card .btn { width: 100%; }
.hint { color: var(--muted); font-size: 0.85em; margin-top: 1rem; }

/* --- Pre / output blocks ------------------------------------------------- */
.copy-block {
  background: #1f2937;
  color: #e5e7eb;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.5;
}
pre.output {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.82em;
  max-height: 400px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
pre.output.stderr { background: #fef2f2; border-color: #fecaca; }
.notes {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  white-space: pre-wrap;
}
.token-box {
  background: #1f2937;
  color: #fbbf24;
  padding: 1rem;
  border-radius: var(--radius);
  word-break: break-all;
  font-size: 0.95em;
}

/* --- KV grid (server detail) -------------------------------------------- */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.kv-grid > div { display: flex; flex-direction: column; }
.kv-grid .k { font-size: 0.75em; text-transform: uppercase; color: var(--muted); letter-spacing: 0.05em; }
.kv-grid .v { font-weight: 500; }

/* --- Run command --------------------------------------------------------- */
.select-section { margin-top: 1rem; }
.select-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.75rem;
}
.select-header h2 { margin: 0; }
.quick-select { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.quick-select span { color: var(--muted); font-size: 0.85em; margin-right: 0.25rem; }

/* --- Job detail expandable rows ----------------------------------------- */
details.exec {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  padding: 0;
}
details.exec summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
details.exec[open] summary { border-bottom: 1px solid var(--border); }
details.exec[open] { padding-bottom: 0.75rem; }
details.exec h4, details.exec pre { margin-left: 1rem; margin-right: 1rem; }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty p { color: var(--muted); }

/* --- Facts ---------------------------------------------------------- */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}
.fact-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.fact-group h3 {
  margin: 0 0 0.6rem;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.fact-group dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(120px, max-content) 1fr;
  gap: 0.4rem 1rem;
}
.fact-group dt {
  color: var(--muted);
  font-weight: 500;
}
.fact-group dd { margin: 0; }

/* Disk usage bar */
.disk-list { list-style: none; padding: 0; margin: 0; }
.disk-list li {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9em;
  margin-bottom: 0.25rem;
}
.bar {
  display: inline-block;
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  background: var(--success);
}
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }

/* Reboot-required badge in the kernel column */
.reboot-badge {
  display: inline-block;
  margin-left: 0.3em;
  color: var(--danger);
  font-weight: bold;
  cursor: help;
}
.small { font-size: 0.85em; }

/* Stacked cell: primary on top, secondary muted below */
td.stacked > div + div { margin-top: 0.15rem; }
td.stacked .small { line-height: 1.2; }
td.nowrap { white-space: nowrap; }

/* Update status light. Used both as a clickable dot in the table
   and as a passive indicator on the detail page. */
.update-light {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.1);
  cursor: help;
  text-decoration: none;
}
a.update-light:hover { box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.update-ok       { background: #16a34a; }                        /* green */
.update-info     { background: #3b82f6; }                        /* blue */
.update-warn     { background: #f59e0b; }                        /* amber */
.update-security { background: #dc2626; box-shadow: 0 0 0 0 rgba(220,38,38,0.5); animation: pulse 2s infinite; }
.update-unknown  { background: #d1d5db; }                        /* grey */

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(220,38,38,0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
  100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
}

/* Per-track breakdown on server detail */
.status-tracks {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
}
.status-tracks .track {
  display: grid;
  grid-template-columns: 24px 90px 1fr;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.status-tracks .track:last-child { border-bottom: none; }
.status-tracks .track-name {
  font-weight: 500;
  text-transform: capitalize;
}
.status-tracks .track-summary { color: var(--muted); }
.status-tracks .track {
  /* override grid to add the actions column */
  grid-template-columns: 24px 90px 1fr auto;
  gap: 0.5rem;
}
.status-tracks .track-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.status-tracks .track-actions form { display: inline; }

/* Bulk actions panel on the dashboard list */
.bulk-actions {
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.bulk-actions summary {
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
  list-style: none;
}
.bulk-actions summary::before { content: "▸  "; }
.bulk-actions[open] summary::before,
.bulk-actions details[open] summary::before { content: "▾  "; }
.bulk-action-row {
  padding: 0 1rem 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
