* { box-sizing: border-box; }

:root {
  --bg: #10131a;
  --panel: #1a1f2b;
  --panel-2: #232a3a;
  --border: #2e3748;
  --text: #e6eaf2;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent-hover: #6ba1ff;
  --green: #34c77b;
  --red: #e05252;
  --yellow: #e0b34f;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
code { font-family: Consolas, "Cascadia Mono", monospace; }

.nav {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.nav-links { display: flex; align-items: center; gap: 14px; }
.nav-user { color: var(--muted); }

.wrap { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }

.agents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(640px, 1fr)); gap: 18px; }
.agent-card { display: flex; flex-direction: row; gap: 14px; align-items: stretch; }
.agent-main { display: flex; flex-direction: column; gap: 10px; flex: 1 1 55%; min-width: 280px; }
.agent-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.agent-head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }

@media (max-width: 700px) {
  .agent-card { flex-direction: column; }
}

.state-meta { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.cycles { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.status-run { color: var(--green); font-weight: 600; }
.status-stop { color: var(--muted); }

.agent-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

.agent-remote { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
.remote-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ss-int { color: var(--muted); font-size: 13px; }
.ss-int input { width: 56px; }
.key-pad { display: flex; gap: 6px; flex-wrap: wrap; }
.key-btn { min-width: 44px; font-weight: 600; }

.log { margin-top: 4px; }
.log summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.log-body {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12.5px;
  color: #b9c2d4;
}

/* Панель последнего скриншота: всегда видна, занимает всё свободное место справа */
.shot-panel {
  flex: 1 1 45%;
  min-width: 240px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  overflow: hidden;
}
.shot-img {
  max-width: 100%;
  max-height: 480px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
}
.shot-meta { text-align: center; }
.shot-empty { min-height: 160px; text-align: center; gap: 4px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-online { background: rgba(52, 199, 123, .15); color: var(--green); }
.badge-offline { background: rgba(224, 82, 82, .15); color: var(--red); }

.btn {
  display: inline-block;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-text { color: var(--red); }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; }
.inline-form { display: inline; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.alert-error { background: rgba(224, 82, 82, .12); border: 1px solid var(--red); color: #ffb4b4; }
.alert-warning { background: rgba(224, 179, 79, .12); border: 1px solid var(--yellow); color: #ffd98a; }

.auth-wrap { max-width: 380px; margin: 80px auto; padding: 0 20px; }
.auth-card { display: flex; flex-direction: column; gap: 4px; }
.auth-card h1 { margin: 0 0 8px; font-size: 22px; }

.token-card { border: 1px solid var(--accent); }
.token-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.token {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  overflow-wrap: anywhere;
  flex: 1;
  user-select: all;
}

/* Настройки агента (форма по схеме) */
.settings summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.cfg-form { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.cfg-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 14px;
}
.cfg-section legend {
  color: var(--muted);
  font-size: 13px;
  padding: 0 6px;
}
.cfg-section label { margin: 0; font-size: 13px; }
.cfg-section input[type="number"], .cfg-section input[type="text"], .cfg-section select {
  padding: 6px 9px;
  font-size: 13px;
  width: 100%;
}
.cfg-section textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 6px 9px;
  font-size: 12.5px;
  font-family: Consolas, "Cascadia Mono", monospace;
  width: 100%;
}
.cfg-check { display: flex; align-items: center; gap: 8px; color: var(--text) !important; }
.cfg-check input { width: auto; }
.cfg-status { margin-top: 8px; }
.cfg-error { color: var(--red); }
.cfg-hint { margin-left: 4px; }
.cfg-preview summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.cfg-json {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
  color: #b9c2d4;
}