:root {
  color-scheme: light dark;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --text: #1f1f1d;
  --muted: #66645e;
  --line: #ddd9d2;
  --ok: #1f8f55;
  --warn: #a36313;
  --error: #b33c31;
  --shadow: 0 18px 45px rgba(20, 20, 18, .10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121314;
    --panel: #222325;
    --text: #f2f2ee;
    --muted: #b9b8b0;
    --line: #343537;
    --ok: #5bd58b;
    --warn: #f0b452;
    --error: #ff8175;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

main {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 42px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  margin-bottom: 16px;
  padding: 18px 0 14px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
}

.icon {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

h1 {
  font-size: clamp(24px, 2.4vw, 30px);
  line-height: 1;
  margin: 0;
  letter-spacing: 0;
}

.sub {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 16px;
  align-items: start;
}

@media (max-width: 760px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

.scenario-view {
  display: none;
}

.scenario-view.is-active {
  display: block;
  animation: scenario-in .26s cubic-bezier(.2, .8, .2, 1);
}

@keyframes scenario-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 5px;
}

.metric strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.config-section {
  min-height: calc(100vh - 122px);
}

h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

label {
  display: block;
  font-weight: 650;
  font-size: 13px;
  margin: 14px 0 6px;
}

input[type=text],
input[type=number],
input[type=password] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 0 11px;
  font: inherit;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.seg label {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.row:first-child { border-top: 0; }

.value {
  font-weight: 750;
  text-align: right;
}

.ok { color: var(--ok); }
.warn { color: var(--warn); }
.error { color: var(--error); margin-top: 12px; font-size: 13px; }

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.secondary-action {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

#configForm button,
.login-form button,
.password-form button {
  width: 100%;
  margin-top: 16px;
}

.logout {
  margin: 0;
}

.logout button {
  min-height: 38px;
  padding: 0 16px;
}

pre {
  min-height: 240px;
  max-height: 420px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.events-section pre {
  min-height: 260px;
  max-height: calc(100vh - 460px);
}

.users-section {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading p {
  margin: -7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.users-list {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  font-weight: 800;
}

.user-main {
  min-width: 0;
}

.user-main strong,
.user-main span {
  display: block;
}

.user-main span,
.user-meta {
  color: var(--muted);
  font-size: 13px;
}

.user-meta {
  margin-left: auto;
  text-align: right;
}

.password-form {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.password-form h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.form-message {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.form-message.ok {
  color: var(--ok);
}

.form-message.error {
  color: var(--error);
}

@media (max-width: 760px) {
  .app-header {
    padding: 12px 0 10px;
  }

  .header-actions {
    gap: 6px;
  }

  .secondary-action,
  .logout button {
    padding: 0 12px;
  }

  .config-section {
    min-height: auto;
  }

  .events-section pre {
    max-height: 360px;
  }
}

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

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

.login-panel .icon {
  margin-bottom: 14px;
}
