:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --panel: #fbfaf7;
  --ink: #17201c;
  --muted: #65726b;
  --line: #dedbd2;
  --teal: #0d7c72;
  --teal-dark: #075c55;
  --amber: #b06d08;
  --red: #b43b3b;
  --green: #1e7d46;
  --shadow: 0 18px 45px rgba(23, 32, 28, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101614;
  --surface: #1a211f;
  --panel: #121917;
  --ink: #f5f7f3;
  --muted: #a9b5ad;
  --line: #344039;
  --teal: #24a99a;
  --teal-dark: #31c2b2;
  --amber: #e0a529;
  --red: #ff7972;
  --green: #58c783;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

:root[data-theme="auto"] {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #101614;
    --surface: #1a211f;
    --panel: #121917;
    --ink: #f5f7f3;
    --muted: #a9b5ad;
    --line: #344039;
    --teal: #24a99a;
    --teal-dark: #31c2b2;
    --amber: #e0a529;
    --red: #ff7972;
    --green: #58c783;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #1f2a24;
  color: #f9f6ed;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 58px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #f0c15b;
  color: #1f2a24;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.side-title,
.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 750;
}

.sidebar .brand span,
.sidebar .side-title {
  color: #b9c4ba;
}

.nav,
.server-list {
  display: grid;
  gap: 10px;
}

.nav-btn,
.server-pill,
.btn,
.icon-btn {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  font-weight: 760;
}

.nav-btn,
.server-pill {
  width: 100%;
  text-align: left;
  color: #f9f6ed;
  background: rgba(255, 255, 255, 0.08);
  padding: 14px 16px;
}

.nav-btn.active,
.server-pill.active {
  background: #f0c15b;
  color: #1f2a24;
}

.side-section {
  display: grid;
  gap: 12px;
}

.main {
  padding: 28px;
  min-width: 0;
}

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

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

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
}

h2 {
  font-size: 1.4rem;
}

h3 {
  font-size: 1.05rem;
}

.top-actions,
.row-actions,
.dialog-actions,
.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  padding: 0 20px;
  color: var(--ink);
}

.btn.primary {
  background: var(--teal);
  color: white;
}

.btn.primary:hover {
  background: var(--teal-dark);
}

.btn.secondary {
  background: var(--surface);
  border: 1px solid var(--line);
}

.btn.danger {
  background: #fff1ed;
  color: var(--red);
  border: 1px solid #f0c9bf;
}

.icon-btn {
  width: 44px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 1.3rem;
}

.notice {
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.notice.error {
  border-color: #e8aaa0;
  color: var(--red);
}

.hidden {
  display: none !important;
}

.view-root {
  display: grid;
  gap: 18px;
}

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

.metric,
.panel,
.server-card,
.chat-box,
.detail-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 128px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric .value {
  font-size: 2.4rem;
  font-weight: 900;
}

.metric .label {
  color: var(--muted);
  font-weight: 700;
}

.panel {
  padding: 20px;
  display: grid;
  gap: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.server-card {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}

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

.status-dot.attention,
.status-dot.partial {
  background: var(--amber);
}

.status-dot.offline {
  background: var(--red);
}

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

.kv {
  padding: 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  min-height: 68px;
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

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

.dialog {
  width: min(860px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(23, 32, 28, 0.48);
}

.dialog form {
  padding: 22px;
  display: grid;
  gap: 18px;
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 760;
}

input,
textarea,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-shell {
  width: min(440px, 100%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 26px;
  display: grid;
  gap: 18px;
}

.login-brand span {
  color: var(--muted);
}

.login-error {
  color: var(--red);
  font-weight: 760;
}

textarea {
  resize: vertical;
}

.toggles,
.method-grid,
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.toggle,
.method-choice,
.checkbox-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 12px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toggle input,
.method-choice input,
.checkbox-choice input {
  width: 20px;
  height: 20px;
  min-height: 20px;
}

.danger {
  color: var(--red);
}

.field-title {
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 8px;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 16px;
}

.chat-box {
  min-height: 560px;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.messages {
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
}

.message {
  padding: 14px;
  border-radius: 8px;
  max-width: 82%;
  white-space: pre-wrap;
  line-height: 1.45;
}

.message.user {
  justify-self: end;
  background: #e5f3ef;
}

.message.bot {
  background: var(--panel);
  border: 1px solid var(--line);
}

.chat-form {
  padding: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.chat-form textarea {
  min-height: 58px;
}

.audit-list {
  display: grid;
  gap: 8px;
}

.audit-item {
  padding: 10px 12px;
  border-left: 4px solid var(--teal);
  background: var(--panel);
}

.remediation-list {
  display: grid;
  gap: 12px;
}

.remediation-list.compact {
  gap: 10px;
}

.remediation-item {
  border: 1px solid var(--line);
  border-left: 6px solid var(--muted);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.remediation-item.severity-critical {
  border-left-color: var(--red);
}

.remediation-item.severity-warning {
  border-left-color: var(--amber);
}

.remediation-item.severity-info {
  border-left-color: var(--teal);
}

.remediation-item.severity-ok {
  border-left-color: var(--green);
}

.remediation-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.severity-badge {
  min-width: 82px;
  min-height: 32px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 850;
}

.remediation-block {
  display: grid;
  gap: 5px;
}

.remediation-block strong {
  font-size: 0.86rem;
}

.remediation-block p,
.remediation-item p {
  color: var(--muted);
  line-height: 1.45;
}

.step-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 7px;
  color: var(--ink);
}

.empty {
  min-height: 320px;
  display: grid;
  place-items: center;
  text-align: center;
  background: var(--surface);
  border: 1px dashed #c6c1b5;
  border-radius: 8px;
  padding: 24px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-btn {
    text-align: center;
    padding-inline: 8px;
  }

  .side-section {
    display: none;
  }

  .metrics-grid,
  .chat-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panel-head {
    display: grid;
  }

  .top-actions,
  .row-actions {
    width: 100%;
  }

  .btn {
    flex: 1;
  }

  .form-grid,
  .kv-grid {
    grid-template-columns: 1fr;
  }
}
