:root {
  --bg: #101112;
  --panel: #181a1b;
  --panel-2: #202324;
  --line: #313536;
  --text: #f0f2ef;
  --muted: #a6ada8;
  --green: #38c172;
  --amber: #d9a441;
  --red: #e45656;
  --cyan: #49b6c8;
  --button: #2a2e30;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

a { color: inherit; text-decoration: none; }

button, .button {
  border: 1px solid var(--line);
  background: var(--button);
  color: var(--text);
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover, .button:hover { border-color: var(--cyan); }
.primary { background: var(--cyan); color: #071012; border-color: var(--cyan); font-weight: 700; }
.danger { background: #3a2020; border-color: #5a2b2b; color: #ffd3d3; }
.full { width: 100%; }

.topbar {
  height: 62px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 22px;
  background: #141617;
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand { font-weight: 800; font-size: 18px; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.topbar nav a { padding: 9px 11px; border-radius: 6px; color: var(--muted); }
.topbar nav a.active, .topbar nav a:hover { background: var(--panel-2); color: var(--text); }
.logout { margin: 0; }

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 24px auto 48px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 28px; }
h2 { margin-bottom: 0; font-size: 18px; }
p, small { color: var(--muted); }

.panel, .stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel { padding: 18px; margin-bottom: 18px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat { padding: 16px; }
.stat span { color: var(--muted); display: block; margin-bottom: 8px; }
.stat strong { font-size: 30px; }
.stat.ok strong { color: var(--green); }
.stat.off strong { color: var(--muted); }
.stat.bad strong { color: var(--red); }

.quick-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.quick-item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 6px;
}

.quick-item:hover { border-color: var(--line); }
.dot { width: 10px; height: 10px; border-radius: 99px; display: inline-block; }
.badge { padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.ok { background: rgba(56, 193, 114, .16); color: var(--green); }
.warn { background: rgba(217, 164, 65, .16); color: var(--amber); }
.stuck { background: rgba(217, 164, 65, .16); color: var(--amber); }
.bad, .error { background: rgba(228, 86, 86, .16); color: var(--red); }
.off { background: rgba(166, 173, 168, .16); color: var(--muted); }

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}
.flash.ok { border-color: rgba(56, 193, 114, .35); }

.system-alert {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(217, 164, 65, .45);
  background: rgba(217, 164, 65, .12);
  color: var(--text);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.system-alert strong { color: var(--amber); }
.system-alert span { color: var(--text); }
.system-alert code {
  display: block;
  overflow-x: auto;
  background: #0c0d0d;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  color: #d7ddd9;
}

table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 10px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td small { display: block; margin-top: 4px; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }
.actions-cell form, .actions-row form { display: inline-flex; gap: 6px; flex-wrap: wrap; margin: 0; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label { display: grid; gap: 7px; color: var(--muted); font-weight: 600; }
input, textarea, select {
  width: 100%;
  background: #0f1010;
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 40px;
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
}
textarea { resize: vertical; min-height: 98px; }
select { appearance: auto; }
input:focus, textarea:focus, select:focus { outline: 1px solid var(--cyan); border-color: var(--cyan); }
.wide { grid-column: 1 / -1; }
.switch { min-height: 40px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.switch input { width: auto; min-height: auto; }
.input-action { display: flex; gap: 6px; }
.input-action input { flex: 1; }
.form-actions { display: flex; gap: 8px; }

.profile-picker {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 14px;
  align-items: start;
}

.profile-descriptions {
  display: grid;
  gap: 8px;
}

.profile-description {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 10px;
}

.profile-description.active {
  border-color: var(--cyan);
}

.profile-description strong,
.profile-description span,
.profile-description small {
  display: block;
}

.profile-description strong {
  color: var(--text);
  margin-bottom: 5px;
}

.profile-description span {
  color: var(--muted);
  font-weight: 500;
}

.profile-description small {
  margin-top: 5px;
}

.details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.details div, .details label { background: var(--panel-2); border-radius: 6px; padding: 12px; overflow-wrap: anywhere; }
.details span { display: block; color: var(--muted); margin-bottom: 6px; }
.details strong { font-weight: 600; }

.log-view {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  background: #0c0d0d;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  color: #d7ddd9;
}

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

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
}
.login-box form { display: grid; gap: 14px; }

@media (max-width: 820px) {
  .topbar { height: auto; align-items: stretch; flex-direction: column; padding: 14px; gap: 10px; }
  .topbar nav { flex-wrap: wrap; }
  .page-head { align-items: stretch; flex-direction: column; }
  .stats, .form-grid, .details, .profile-picker { grid-template-columns: 1fr; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 760px; }
}
