:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687480;
  --line: #d9e0e7;
  --accent: #0b6bcb;
  --ok: #147d3f;
  --warn: #966500;
  --bad: #b42318;
}

* { box-sizing: border-box; }

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

button, input {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  min-height: 36px;
  padding: 0 14px;
  cursor: pointer;
}

button.secondary {
  background: white;
  color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

code {
  background: #eef2f6;
  border-radius: 4px;
  padding: 1px 5px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: white;
  border-bottom: 1px solid var(--line);
}

.topbar strong {
  margin-right: 12px;
}

.layout {
  width: min(1180px, calc(100vw - 28px));
  margin: 18px auto 40px;
  display: grid;
  gap: 16px;
}

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1, h2, h3, p {
  margin-top: 0;
}

h2 { font-size: 18px; }
h3 { font-size: 15px; }

.status-grid, .operation-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.status-grid > div, .operation-grid article {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  min-width: 0;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 4px;
}

.status-heading {
  display: flex;
  align-items: center;
  gap: 9px;
}

.section-head h2 {
  margin-bottom: 0;
}

.status-indicator {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  flex: 0 0 16px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: #9aa6b2;
  box-shadow: 0 0 0 1px #8693a0;
}

.status-indicator[data-state="ok"] {
  background: var(--ok);
  box-shadow: 0 0 0 1px #0d6330;
}

.status-indicator[data-state="warn"] {
  background: #d69e00;
  box-shadow: 0 0 0 1px var(--warn);
}

.status-indicator[data-state="bad"] {
  background: #d92d20;
  box-shadow: 0 0 0 1px var(--bad);
}

.status-indicator:hover {
  box-shadow: 0 0 0 3px #dce3e9;
}

.status-indicator:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.status-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 40px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(23, 32, 42, 0.2);
}

.status-dialog::backdrop {
  background: rgba(23, 32, 42, 0.42);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h3 {
  margin: 0;
}

.dialog-close {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.dialog-close:hover {
  background: #eef2f6;
  color: var(--text);
}

.status-details {
  max-height: calc(100vh - 120px);
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.empty-state {
  display: grid;
  gap: 4px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: 18px;
}

.empty-state strong { color: var(--text); }

.empty-state[data-state="running"] {
  border-color: var(--accent);
}

.empty-state[data-state="ok"] {
  border-color: var(--ok);
}

.empty-state[data-state="bad"] {
  border-color: var(--bad);
}

.task-output {
  max-height: 420px;
  margin: 8px 0 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9fb;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.lan-dialog {
  width: min(980px, calc(100vw - 32px));
}

.lan-dialog-body {
  display: grid;
  gap: 18px;
  padding: 16px;
}

.lan-tabs, .lan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lan-tab[aria-selected="true"] {
  background: var(--accent);
  color: white;
}

.lan-scenario, .lan-results {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.lan-scenario h3, .lan-results h3 {
  margin-bottom: 6px;
}

.lan-field {
  display: grid;
  gap: 5px;
  max-width: 320px;
  margin-bottom: 12px;
  color: var(--muted);
}

.lan-field input {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: white;
}

.lan-table-wrap {
  margin-top: 10px;
  overflow: auto;
}

.lan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.lan-table th, .lan-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.lan-table td:nth-child(3) {
  white-space: normal;
  min-width: 130px;
}

.lan-target-actions {
  display: flex;
  gap: 6px;
}

.lan-target-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.relay-dialog {
  width: min(820px, calc(100vw - 32px));
}

.relay-dialog-body {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.relay-create, .relay-active {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.relay-fields, .relay-modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.relay-fields .lan-field {
  max-width: none;
}

.relay-modes {
  margin-bottom: 12px;
}

.relay-modes > label {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.relay-modes span, .relay-modes small {
  display: block;
}

.relay-modes small {
  margin-top: 2px;
  color: var(--muted);
}

.relay-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.relay-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.relay-item a, .relay-item span {
  display: block;
  overflow-wrap: anywhere;
}

.relay-item-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 620px) {
  .relay-fields, .relay-modes {
    grid-template-columns: 1fr;
  }
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
}

.login-panel form {
  display: grid;
  gap: 12px;
}

.login-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.login-panel input {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 10px;
}

.alert {
  border-radius: 6px;
  padding: 10px 12px;
  margin: 12px 0;
}

.alert.error {
  border: 1px solid #f0b8b2;
  background: #fff7f6;
  color: var(--bad);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 880px) {
  .status-grid, .operation-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-grid, .operation-grid {
    grid-template-columns: 1fr;
  }
}
