:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
a,
textarea {
  font: inherit;
}

button,
.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--accent-dark);
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary:hover {
  background: #f3f4f6;
}

.danger {
  background: var(--danger);
}

.danger:hover {
  background: var(--danger-dark);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

input {
  height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 420px;
  padding: 14px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

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

.hidden {
  display: none !important;
}

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

.login-panel {
  width: min(100%, 380px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.login-panel h1 {
  margin: 16px 0 4px;
  font-size: 28px;
}

.login-panel p {
  color: var(--muted);
}

.login-panel label {
  display: block;
  margin: 22px 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel button {
  width: 100%;
  margin-top: 14px;
}

.error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.app {
  width: min(100% - 32px, 1180px);
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.limit-note {
  width: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.client-actions,
.create-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.status-card {
  display: flex;
  gap: 10px;
  align-items: start;
  min-width: 0;
  padding: 14px;
}

.status-card p {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
}

.status-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--muted);
  flex: 0 0 auto;
}

.dot.ok {
  background: var(--success);
}

.dot.bad {
  background: var(--danger);
}

.panel {
  overflow: hidden;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 20px;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.create-form input {
  width: 180px;
}

.clients {
  display: grid;
}

.peers {
  display: grid;
}

.requests,
.backups,
.audit {
  display: grid;
}

.peer-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 180px) minmax(170px, 220px);
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.peer-row:last-child {
  border-bottom: 0;
}

.peer-row h3 {
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.peer-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.peer-row.stale {
  background: #fff7ed;
}

.peer-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.peer-row strong {
  font-size: 14px;
}

.empty {
  margin: 0;
  padding: 24px 16px;
  color: var(--muted);
}

.client-card {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) auto;
  gap: 16px;
  align-items: center;
  border-width: 0 0 1px;
  border-radius: 0;
  padding: 16px;
}

.client-card:last-child {
  border-bottom: 0;
}

.request-row,
.backup-row,
.audit-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.request-row:last-child,
.backup-row:last-child,
.audit-row:last-child {
  border-bottom: 0;
}

.request-row h3,
.backup-row h3 {
  margin: 0 0 4px;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.request-row p,
.backup-row p,
.audit-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.audit-row code {
  max-width: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #f9fafb;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-main {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: center;
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #eef4ff;
  color: var(--accent);
  font-weight: 800;
}

.client-title {
  min-width: 0;
}

.client-title h3 {
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.client-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.client-meta label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(92vw, 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(17, 24, 39, 0.46);
}

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

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
}

dialog textarea {
  border: 0;
  border-radius: 0;
}

.qr-box {
  display: grid;
  place-items: center;
  padding: 18px;
  background: #fff;
}

.qr-box img {
  width: min(74vw, 420px);
  height: auto;
  image-rendering: pixelated;
}

@media (max-width: 900px) {
  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .create-form input {
    width: 100%;
  }

  .create-form button,
  .topbar-actions button {
    flex: 1;
  }

  .client-card {
    grid-template-columns: 1fr;
  }

  .request-row,
  .backup-row,
  .audit-row {
    grid-template-columns: 1fr;
  }

  .peer-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

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

  .client-actions > * {
    flex: 1 1 130px;
  }
}
