:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --ink: #111827;
  --ink-soft: #344054;
  --muted: #667085;
  --line: #d7dde6;
  --line-soft: #ebeff5;
  --sidebar: #ffffff;
  --accent: #2457c5;
  --accent-soft: #eef4ff;
  --error: #b42318;
  --error-soft: #fff1f0;
  --warn: #a15c07;
  --warn-soft: #fff7e6;
  --ok: #0f766e;
  --ok-soft: #ecfdf3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 10px 28px rgba(16, 24, 40, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
button, input, select { font: inherit; }
button, .button-link {
  min-height: 36px;
  border: 1px solid #b9c3d3;
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 1px 1px rgba(16, 24, 40, 0.03);
}
button:hover, .button-link:hover { border-color: #8ea0bb; background: #f9fbff; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(36, 87, 197, 0.18);
  outline-offset: 2px;
}
button.danger { color: var(--error); border-color: #e7b5af; background: #fffafa; }
button.danger:hover { background: var(--error-soft); }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand {
  padding: 2px 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: grid;
  gap: 2px;
}
.brand strong { font-size: 24px; letter-spacing: 0; line-height: 1; }
.brand span { color: var(--muted); font-size: 12px; }
.sidebar nav { display: grid; gap: 3px; }
.nav-section {
  color: #98a2b3;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 16px 10px 5px;
}
.nav-section:first-child { padding-top: 0; }
.sidebar a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  min-height: 36px;
}
.sidebar a:hover { background: #f6f8fb; border-color: var(--line-soft); }
.sidebar a.active {
  background: var(--accent-soft);
  color: #173b88;
  border-color: #c7d7fe;
  font-weight: 650;
}
.logout {
  margin-top: auto;
  display: grid;
  gap: 9px;
  color: var(--muted);
  padding: 14px 10px 0;
  border-top: 1px solid var(--line-soft);
}
.logout span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.logout button { width: 100%; }

.shell {
  margin-left: 252px;
  min-height: 100vh;
  padding: 24px 30px 36px;
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.topbar h1 { margin: 3px 0 0; font-size: 28px; line-height: 1.15; font-weight: 720; letter-spacing: 0; }
.crumb, .muted { color: var(--muted); font-size: 13px; }
.crumb { font-weight: 600; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.server-switcher label { min-width: 190px; }

.filters {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(210px, 2fr) repeat(6, minmax(112px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #c7d0dd;
  border-radius: 7px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
}
input::placeholder { color: #98a2b3; }

.service-strip { display: flex; flex-wrap: wrap; gap: 9px; margin: 2px 0 16px; }
.service-pill {
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: 0 1px 1px rgba(16, 24, 40, 0.03);
}
.service-pill:hover { border-color: #9aa8bc; }
.service-pill span { color: var(--muted); margin-left: 6px; }

.log-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
.log-table, .details-panel, .audit-table, .service-list, .service-detail, .settings-panel, .firewall-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-head {
  display: grid;
  grid-template-columns: 128px 168px 224px 104px minmax(0, 1fr);
  gap: 12px;
  padding: 11px 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}
.log-row {
  display: grid;
  grid-template-columns: 128px 168px 224px 104px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
}
.log-row:hover, .log-row:focus { background: #f8fbff; outline: none; }
.log-row:focus { box-shadow: inset 3px 0 0 var(--accent); }
.log-row time, .source, .server-name { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-name { color: var(--ink-soft); font-weight: 650; }
.log-row code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 12.5px;
  line-height: 1.45;
  color: #1f2937;
}
.badge {
  width: fit-content;
  min-width: 70px;
  text-align: center;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 650;
  border: 1px solid #d7dde8;
  color: #475467;
  background: #f8fafc;
}
.sev-emergency .badge, .sev-alert .badge, .sev-critical .badge, .sev-error .badge { color: var(--error); border-color: #f0b8b3; background: var(--error-soft); }
.sev-warning .badge { color: var(--warn); border-color: #f1cd8f; background: var(--warn-soft); }
.sev-notice .badge { color: #475467; background: #f8fafc; }
.status-grid { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; font-size: 13px; }
dt { color: var(--muted); font-weight: 650; }
dd { margin: 0; overflow-wrap: anywhere; }
pre {
  background: #111827;
  color: #f3f4f6;
  padding: 13px;
  border-radius: 7px;
  overflow: auto;
  white-space: pre-wrap;
}
.details-panel { padding: 16px; align-self: start; position: sticky; top: 18px; overflow: visible; }
.details-panel h2 { margin: 0 0 12px; font-size: 16px; }
.details-panel p { margin: 0 0 10px; }
.empty {
  padding: 24px;
  color: var(--muted);
  background: linear-gradient(#fff, #fff);
}
.alert { border-radius: 7px; padding: 10px 12px; margin-bottom: 12px; }
.alert.error { color: var(--error); background: var(--error-soft); border: 1px solid #e7b5af; }

.service-page { display: grid; grid-template-columns: 390px minmax(0, 1fr); gap: 16px; }
.service-list { overflow: auto; max-height: calc(100vh - 112px); }
.service-list a {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
}
.service-list a:hover { background: #f8fbff; }
.service-list a.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.service-list span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-list em { font-style: normal; font-size: 12px; font-weight: 650; color: var(--muted); }
.state-active { color: var(--ok) !important; }
.state-failed, .state-inactive { color: var(--error) !important; }
.service-detail { padding: 18px; }
.service-detail h2 { margin: 0 0 14px; font-size: 20px; }
.service-detail h3 { margin: 22px 0 10px; font-size: 14px; color: var(--ink-soft); }
.actions { display: flex; gap: 9px; margin: 16px 0 22px; flex-wrap: wrap; }
.mini-log { display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.mini-log span { color: var(--muted); font-size: 12px; }
.mini-log code { font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

.audit-table .table-head, .audit-row { grid-template-columns: 178px 120px 154px 190px 90px minmax(0, 1fr); }
.audit-row {
  display: grid;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}

.auth-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.auth-panel {
  width: min(430px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 30px;
  display: grid;
  gap: 15px;
  box-shadow: var(--shadow);
}
.auth-panel h1 { margin: 0; font-size: 28px; }
.auth-panel p { margin: 0 0 4px; color: var(--muted); }
.auth-panel button { background: var(--accent); color: #fff; border-color: var(--accent); }
.settings-panel { max-width: 540px; padding: 18px; }
.settings-panel form { display: grid; gap: 14px; }

.firewall-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; }
.firewall-main, .firewall-side { display: grid; gap: 16px; align-content: start; }
.firewall-panel { padding: 16px; overflow: visible; }
.firewall-panel h2 { margin: 0 0 13px; font-size: 16px; }
.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.inline-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.inline-actions form { display: flex; gap: 8px; align-items: center; }
.firewall-rule-head, .firewall-rule, .firewall-rule-edit {
  display: grid;
  grid-template-columns: 52px minmax(120px, 1fr) 112px minmax(120px, 1fr) 92px;
  gap: 12px;
  align-items: center;
}
.firewall-rule-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.firewall-rule { padding: 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.firewall-rule-edit {
  grid-column: 1 / 5;
  grid-template-columns: 52px minmax(120px, 1fr) 112px minmax(120px, 1fr);
  width: 100%;
  min-height: 44px;
  padding: 10px 0;
  border: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  text-align: left;
  justify-content: stretch;
}
.firewall-rule-edit:hover, .firewall-rule-edit:focus { background: #f8fbff; }
.firewall-rule form { justify-self: end; }
.firewall-rule code, .firewall-rule-edit code { overflow-wrap: anywhere; }
.firewall-rule strong, .firewall-rule-edit strong { color: var(--ink-soft); font-size: 12px; }
.stack-form { display: grid; gap: 12px; }
.firewall-edit-modal { width: min(760px, calc(100vw - 48px)); }
.rule-current {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.rule-current span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rule-current code { overflow-wrap: anywhere; }
.firewall-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.full-span { grid-column: 1 / -1; }

.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(17, 24, 39, 0.48);
  display: grid;
  place-items: center;
  padding: 28px;
}
.modal-backdrop[hidden] { display: none; }
.log-modal {
  width: min(1120px, calc(100vw - 48px));
  max-height: calc(100vh - 56px);
  background: #fff;
  color: var(--ink);
  border: 1px solid #c8d0dd;
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(16, 24, 40, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.log-modal header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 10px 10px 0 0;
}
.log-modal h2, .log-modal h3 { margin: 0; }
.log-modal h2 { font-size: 20px; }
.log-modal h3 {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.icon-button { white-space: nowrap; }
.modal-body { overflow: auto; padding: 18px 20px 20px; display: grid; gap: 17px; }
.modal-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.message-block {
  background: #f8fafc;
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.58;
  max-height: 34vh;
  overflow: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.modal-actions { display: flex; gap: 8px; margin-top: 9px; }
.modal-fields { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 8px 14px; font-size: 13px; }
.modal-fields dd { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; white-space: pre-wrap; }
.modal-badge.sev-emergency,
.modal-badge.sev-alert,
.modal-badge.sev-critical,
.modal-badge.sev-error { color: var(--error); border-color: #f0b8b3; background: var(--error-soft); }
.modal-badge.sev-warning { color: var(--warn); border-color: #f1cd8f; background: var(--warn-soft); }

@media (max-width: 1180px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .log-layout, .service-page, .firewall-layout { grid-template-columns: 1fr; }
  .details-panel { position: static; }
}

@media (max-width: 820px) {
  .sidebar { position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-section { grid-column: 1 / -1; }
  .logout { margin-top: 8px; }
  .shell { margin-left: 0; padding: 18px; }
  .table-head { display: none; }
  .log-row { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .modal-backdrop { padding: 10px; }
  .log-modal { width: calc(100vw - 20px); max-height: calc(100vh - 20px); }
  .modal-fields { grid-template-columns: 1fr; }
  .panel-title, .inline-actions, .inline-actions form { display: grid; justify-content: stretch; }
  .firewall-rule-head { display: none; }
  .firewall-rule, .firewall-rule-edit { grid-template-columns: 1fr; }
  .firewall-rule-edit { grid-column: auto; }
  .firewall-rule form { justify-self: stretch; }
  .firewall-edit-form { grid-template-columns: 1fr; }
  .audit-row { grid-template-columns: 1fr; }
}
