:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #202124;
  --muted: #626a73;
  --line: #d7dde3;
  --accent: #166a5f;
  --accent-strong: #0f4f48;
  --danger: #a5362d;
  --ink: #25272c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Aptos", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a { color: var(--accent-strong); text-decoration: none; }

.shell-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 22px 18px;
  background: var(--ink);
  color: #f5f7fa;
  border-right: 1px solid #000;
}

.shell-main {
  margin-left: 248px;
  padding: 28px;
  max-width: 1320px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}

.breadcrumb a {
  color: var(--accent-strong);
}

.breadcrumb-separator {
  color: #9aa2ab;
}

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

.brand.compact { margin-bottom: 22px; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #d9f06f;
  color: #111;
  font-weight: 800;
  border-radius: 6px;
}

.brand-title { font-size: 17px; font-weight: 800; }
.brand-subtitle { color: #bfc7d1; font-size: 12px; margin-top: 2px; }

.nav {
  display: grid;
  gap: 6px;
}

.nav a, .logout-form button {
  display: block;
  width: 100%;
  padding: 10px 11px;
  color: #f8f0df;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.nav a:hover, .logout-form button:hover {
  border-color: #534d42;
  background: #31343a;
}

.nav a.active {
  border-color: #d9f06f;
  background: #d9f06f;
  color: #111;
  font-weight: 800;
}

.logout-form {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1, h2 { margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 18px; }
p { margin: 6px 0 0; color: var(--muted); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 18px;
}

.metric span { color: var(--muted); display: block; }
.metric strong { display: block; font-size: 34px; margin-top: 8px; }

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

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.on { background: #d7f4db; color: #155a24; }
.badge.off { background: #f2d8d4; color: var(--danger); }

.level-badge {
  display: inline-flex;
  min-width: 58px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.level-info { background: #dceaf8; color: #18517b; }
.level-warning, .level-warn { background: #fff0c2; color: #8a5600; }
.level-error, .level-critical { background: #f7d8d5; color: #9a241c; }
.level-debug { background: #e7e9ee; color: #47515d; }

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

button, .button-link {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  line-height: 1;
}

button.primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.text-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.icon-button {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

select:not([multiple]) {
  height: 38px;
  padding-top: 7px;
  padding-bottom: 7px;
}

select[multiple] {
  min-height: 148px;
}

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

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

.form-row-full { grid-column: 1 / -1; }

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(420px, 100%);
}

.inline-form input {
  min-width: 220px;
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 8px 18px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  color: var(--text);
  font-size: 14px;
}

.check-row input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.config-layout {
  display: grid;
  gap: 18px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
  background: var(--bg);
}

.sticky-actions .primary {
  width: auto;
  min-width: 132px;
}

.notice {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #a9d7b2;
  background: #e6f7e8;
  color: #155a24;
  border-radius: 6px;
}

.toast {
  position: fixed;
  top: 22px;
  right: 26px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 14px;
  border: 1px solid #a9d7b2;
  background: #e6f7e8;
  color: #155a24;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgb(20 35 48 / 14%);
}

.empty-state {
  text-align: center;
  color: var(--muted);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

.pagination-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.pagination-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  align-items: center;
}

.pagination-actions .button-link {
  min-width: 72px;
  white-space: nowrap;
}

.button-link.disabled {
  color: var(--muted);
  background: #f1f3f5;
  cursor: not-allowed;
}

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

.login-panel {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  display: grid;
  gap: 16px;
}

.alert {
  background: #ffe6df;
  color: var(--danger);
  border: 1px solid #e4afa5;
  padding: 10px;
  border-radius: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(21 24 28 / 42%);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(420px, 100%);
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgb(0 0 0 / 24%);
}

.confirm-dialog p {
  margin-top: 10px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.modal-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.modal-form .primary {
  width: auto;
}

.back-to-top {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 25;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgb(20 35 48 / 18%);
}

.back-to-top[hidden] {
  display: none;
}

.details-dialog {
  width: min(820px, calc(100vw - 32px));
  max-height: min(78vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgb(0 0 0 / 24%);
}

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

.details-dialog pre {
  margin: 0;
  padding: 18px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #2d333a;
  font: 13px/1.55 "Cascadia Mono", Consolas, monospace;
}

.log-table {
  table-layout: fixed;
}

.log-table th:nth-child(1), .log-table td:nth-child(1) { width: 172px; }
.log-table th:nth-child(2), .log-table td:nth-child(2) { width: 92px; }
.log-table th:nth-child(3), .log-table td:nth-child(3) { width: 34%; }

.log-cell {
  display: grid;
  gap: 7px;
  align-items: start;
}

.log-preview {
  display: -webkit-box;
  max-height: 42px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.5;
}

.log-time {
  white-space: nowrap;
}

code {
  white-space: pre-wrap;
  word-break: break-word;
  color: #424a52;
}

@media (max-width: 820px) {
  .shell-sidebar {
    position: static;
    width: auto;
  }

  .shell-main {
    margin-left: 0;
    padding: 18px;
  }

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

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .inline-form {
    grid-template-columns: 1fr;
    align-items: stretch;
    width: 100%;
  }

  .inline-form input {
    min-width: 0;
  }

  .back-to-top {
    right: 16px;
    bottom: 16px;
  }
}
