:root {
  --bg: #f4efe7;
  --panel: rgba(255, 251, 246, 0.9);
  --ink: #1c1a17;
  --muted: #6e675d;
  --line: rgba(52, 41, 26, 0.12);
  --accent: #b04a29;
  --accent-soft: rgba(176, 74, 41, 0.1);
  --green: #176b51;
  --green-soft: rgba(23, 107, 81, 0.12);
  --red: #992f2f;
  --red-soft: rgba(153, 47, 47, 0.12);
  --amber: #9c6b10;
  --amber-soft: rgba(156, 107, 16, 0.12);
  --radius: 22px;
  --shadow: 0 18px 40px rgba(57, 37, 13, 0.12);
  --mono: "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --surface-soft: rgba(255, 255, 255, 0.74);
  --field-bg: rgba(255, 255, 255, 0.92);
  --code-bg: rgba(255, 255, 255, 0.8);
  --sidebar-bg: rgba(255, 248, 239, 0.78);
  --sidebar-link-bg: rgba(255, 255, 255, 0.78);
  --sidebar-link-border: rgba(52, 41, 26, 0.1);
  --sidebar-link-ink: #1c1a17;
  --sidebar-link-active-bg: rgba(176, 74, 41, 0.16);
  --sidebar-note-bg: rgba(255, 255, 255, 0.82);
  --page-background:
    radial-gradient(circle at top left, rgba(176, 74, 41, 0.16), transparent 26%),
    radial-gradient(circle at bottom right, rgba(23, 107, 81, 0.16), transparent 24%),
    linear-gradient(180deg, #faf7f0 0%, #f3ede4 100%);
}

body[data-theme="black"] {
  --bg: #0e1217;
  --panel: rgba(18, 23, 30, 0.94);
  --ink: #f3f5f8;
  --muted: #aab4c3;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #d06a48;
  --accent-soft: rgba(208, 106, 72, 0.14);
  --green: #8be0bf;
  --green-soft: rgba(91, 181, 148, 0.16);
  --red: #ff9b9b;
  --red-soft: rgba(153, 47, 47, 0.22);
  --amber: #ffd27a;
  --amber-soft: rgba(156, 107, 16, 0.22);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --surface-soft: rgba(255, 255, 255, 0.06);
  --field-bg: rgba(10, 13, 18, 0.88);
  --code-bg: rgba(255, 255, 255, 0.08);
  --sidebar-bg: rgba(8, 11, 16, 0.92);
  --sidebar-link-bg: rgba(255, 255, 255, 0.1);
  --sidebar-link-border: rgba(255, 255, 255, 0.16);
  --sidebar-link-ink: #f7fbff;
  --sidebar-link-active-bg: rgba(255, 255, 255, 0.18);
  --sidebar-note-bg: rgba(255, 255, 255, 0.1);
  --page-background:
    radial-gradient(circle at top left, rgba(208, 106, 72, 0.15), transparent 26%),
    radial-gradient(circle at bottom right, rgba(44, 111, 90, 0.2), transparent 28%),
    linear-gradient(180deg, #121821 0%, #090c10 100%);
}

body[data-theme="gray"] {
  --bg: #dfe3e8;
  --panel: rgba(244, 246, 248, 0.92);
  --ink: #20252b;
  --muted: #5e6772;
  --line: rgba(48, 56, 65, 0.14);
  --accent: #596d86;
  --accent-soft: rgba(89, 109, 134, 0.12);
  --green: #286f57;
  --green-soft: rgba(40, 111, 87, 0.12);
  --red: #9d4141;
  --red-soft: rgba(157, 65, 65, 0.12);
  --amber: #8b681c;
  --amber-soft: rgba(139, 104, 28, 0.14);
  --shadow: 0 18px 40px rgba(70, 79, 88, 0.16);
  --surface-soft: rgba(255, 255, 255, 0.72);
  --field-bg: rgba(255, 255, 255, 0.92);
  --code-bg: rgba(255, 255, 255, 0.82);
  --sidebar-bg: rgba(230, 234, 239, 0.84);
  --sidebar-link-bg: rgba(255, 255, 255, 0.82);
  --sidebar-link-border: rgba(48, 56, 65, 0.12);
  --sidebar-link-ink: #20252b;
  --sidebar-link-active-bg: rgba(89, 109, 134, 0.16);
  --sidebar-note-bg: rgba(255, 255, 255, 0.84);
  --page-background:
    radial-gradient(circle at top left, rgba(89, 109, 134, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(40, 111, 87, 0.12), transparent 22%),
    linear-gradient(180deg, #edf1f5 0%, #d8dde3 100%);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Avenir Next", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--page-background);
}

a { color: inherit; text-decoration: none; }
code {
  font-family: var(--mono);
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 8px;
}

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

.sidebar {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  backdrop-filter: blur(18px);
}

.content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fffaf3;
  background: linear-gradient(135deg, var(--accent), #dd8c42);
  font-weight: 700;
}

.brand-mark img {
  width: 34px;
  height: 34px;
  display: block;
}

.brand h1,
.hero-card h2,
.panel h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

.muted { color: var(--muted); }
.label,
.eyebrow,
.kpi-label {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.nav-link {
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--sidebar-link-bg);
  border: 1px solid var(--sidebar-link-border);
  color: var(--sidebar-link-ink);
  font-weight: 600;
  transition: background 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}

.nav-link:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.28);
}

.nav-link.active {
  background: var(--sidebar-link-active-bg);
  border-color: rgba(255, 255, 255, 0.24);
}

.nav-link-logout {
  background: rgba(153, 47, 47, 0.12);
  border-color: rgba(153, 47, 47, 0.22);
  color: var(--red);
  font-weight: 700;
}

body[data-theme="black"] .nav-link-logout {
  background: rgba(255, 155, 155, 0.16);
  border-color: rgba(255, 155, 155, 0.3);
  color: #ffd1d1;
}

.sidebar-theme {
  margin-bottom: 18px;
}

.theme-switcher {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.theme-btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  cursor: pointer;
  color: var(--ink);
}

.theme-btn.active {
  background: var(--accent-soft);
  border-color: rgba(176, 74, 41, 0.24);
}

.sidebar-note,
.hero-card,
.panel,
.kpi-card,
.icon-card,
.rule-card,
.info-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar-note {
  padding: 14px;
  background: var(--sidebar-note-bg);
}
.hero-card, .panel { padding: 20px; }
.hero-card.narrow { max-width: 620px; }
.hero-subtitle {
  display: inline-block;
  margin-left: 8px;
  font-size: 14px;
  color: var(--muted);
  vertical-align: middle;
}
.qr-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
}
.qr-shell {
  width: 100%;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
}
.qr-shell svg {
  width: 100%;
  max-width: 220px;
  height: auto;
}

.hero-row,
.panel-head,
.filter-actions,
.rule-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.command-box,
.wrap-code {
  display: block;
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  font-family: var(--mono);
  overflow-x: auto;
  word-break: break-all;
}

.compact-card {
  padding: 14px 16px;
  margin-bottom: 14px;
}

.kpi-grid,
.detail-grid,
.filter-grid,
.icon-grid,
.totp-grid,
.metric-history-grid {
  display: grid;
  gap: 14px;
}

.kpi-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filter-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.icon-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.totp-grid { grid-template-columns: minmax(220px, 280px) 1fr; align-items: stretch; }
.metric-history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.activity-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; }

.kpi-card,
.icon-card,
.chart-card { padding: 16px; }

.kpi-card strong,
.icon-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.metric-value-compact {
  font-size: 18px !important;
  line-height: 1.35;
  word-break: break-word;
}

.icon-title {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.icon-badge {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  font-size: 22px;
  background: var(--accent-soft);
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

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

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(52, 41, 26, 0.14);
  background: var(--field-bg);
  color: var(--ink);
}

textarea { resize: vertical; }

.primary-btn,
.ghost-btn,
.inline-link,
.range-chip {
  padding: 11px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.copy-btn {
  font-weight: 700;
  border-color: rgba(176, 74, 41, 0.22);
}

body[data-theme="black"] .copy-btn {
  background: rgba(255, 255, 255, 0.92);
  color: #10141a;
  border-color: rgba(255, 255, 255, 0.94);
}

body[data-theme="black"] .ghost-btn,
body[data-theme="black"] .inline-link,
body[data-theme="black"] .range-chip,
body[data-theme="black"] .theme-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #f5f8fb;
  border-color: rgba(255, 255, 255, 0.18);
}

.primary-btn {
  border: 0;
  color: #fffaf3;
  background: linear-gradient(135deg, var(--accent), #d7773f);
}

.range-chip.active,
.status-chip.online {
  background: var(--green-soft);
  color: var(--green);
}

.status-chip.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-chip.offline,
.status-chip.critical {
  background: var(--red-soft);
  color: var(--red);
}

.status-chip {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.server-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table tbody tr {
  background: transparent;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.hot-cell { color: var(--red); font-weight: 700; }
.warm-cell { color: var(--amber); font-weight: 700; }
.empty-cell { color: var(--muted); text-align: center; }
.alert-row-critical {
  background: rgba(153, 47, 47, 0.1) !important;
}

.alert-row-warning {
  background: rgba(156, 107, 16, 0.08) !important;
}

.alert-row-resolved {
  background: rgba(23, 107, 81, 0.08) !important;
}

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

.detail-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line);
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.timeline-item.open { border-color: rgba(153, 47, 47, 0.22); }
.timeline-item.resolved { border-color: rgba(23, 107, 81, 0.22); }
.timeline-item.critical.open {
  background: rgba(153, 47, 47, 0.14);
  border-color: rgba(153, 47, 47, 0.3);
}

.timeline-item.resolved {
  background: rgba(23, 107, 81, 0.1);
}

.timeline-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
}

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

.rule-card { padding: 16px; }
.rule-meta { margin: 10px 0; color: var(--muted); }

.check-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

.flash {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(153, 47, 47, 0.16);
}

.flash.error {
  background: var(--red-soft);
  color: var(--red);
}

.flash.success {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(23, 107, 81, 0.2);
}

.top-gap { margin-top: 12px; }

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form select,
.inline-form input {
  min-width: 120px;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.expand-row-actions {
  display: flex;
  justify-content: center;
}

.danger-btn {
  border-color: rgba(153, 47, 47, 0.28);
  color: var(--red);
}

.container-picker {
  display: grid;
  gap: 10px;
}

.container-picker.is-disabled {
  opacity: 0.56;
}

.container-choice {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.container-choice input {
  width: auto;
}

.container-choice small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.log-details summary {
  list-style: none;
}

.log-details summary::-webkit-details-marker {
  display: none;
}

.log-box {
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
}

.compact-log {
  margin: 0;
  max-height: 200px;
}

.log-modal {
  width: min(960px, calc(100vw - 48px));
  border: 0;
  padding: 0;
  background: transparent;
}

.log-modal::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
}

.log-modal-shell {
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.log-box-modal {
  min-height: 420px;
  max-height: 70vh;
}

.metric-chart {
  min-height: 170px;
}

.metric-chart-svg {
  width: 100%;
  height: 140px;
  display: block;
}

.metric-axis {
  stroke: var(--line);
  stroke-width: 1;
}

.metric-line {
  fill: none;
  stroke: var(--metric-line);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.metric-dot {
  fill: var(--metric-line);
}

.metric-point {
  fill: var(--metric-line);
}

.metric-hit {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
}

.metric-tooltip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.4;
  max-width: 280px;
}

.metric-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.metric-chart-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

.metric-chart-caption {
  font-size: 12px;
  margin-top: 4px;
}

body[data-theme="black"] .data-table tbody tr:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}

body[data-theme="black"] .data-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

body[data-theme="black"] .timeline-item {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

body[data-theme="black"] .alert-row-critical {
  background: rgba(255, 104, 104, 0.16) !important;
}

body[data-theme="black"] .alert-row-warning {
  background: rgba(255, 205, 118, 0.1) !important;
}

body[data-theme="black"] .alert-row-resolved {
  background: rgba(89, 181, 148, 0.12) !important;
}

body[data-theme="black"] .data-table th,
body[data-theme="black"] .data-table td {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

body[data-theme="black"] .log-box {
  background: rgba(0, 0, 0, 0.32);
  color: #f5f8fb;
  border-color: rgba(255, 255, 255, 0.14);
}

body[data-theme="black"] .container-choice {
  background: rgba(255, 255, 255, 0.06);
}

body[data-theme="black"] .danger-btn {
  background: rgba(255, 155, 155, 0.12);
  color: #ffd1d1;
  border-color: rgba(255, 155, 155, 0.24);
}

body[data-theme="black"] .metric-tooltip {
  background: rgba(12, 15, 20, 0.96);
  color: #f5f8fb;
  border-color: rgba(255, 255, 255, 0.16);
}

@media (max-width: 1200px) {
  .shell,
  .kpi-grid,
  .detail-grid,
  .filter-grid,
  .icon-grid,
  .totp-grid,
  .activity-filter-grid {
    grid-template-columns: 1fr;
  }

  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
}
