:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #657080;
  --line: #dce1e8;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --warning: #a15c00;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 720;
}

h2 {
  font-size: 18px;
  font-weight: 680;
}

#subline {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
}

input,
select,
button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input,
select {
  min-width: 82px;
  padding: 0 10px;
}

.filter-label input {
  width: min(300px, 42vw);
}

button {
  padding: 0 13px;
  font-weight: 650;
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

button:hover {
  border-color: #aab4c2;
}

#refreshButton,
#toggleLanExclusionButton,
#refreshSuspiciousButton,
#blockSelectedButton,
#blockManualButton,
#refreshBlocksButton,
#refreshPortsButton,
#toggleBlocksButton,
#saveBudgetButton {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

#refreshButton:hover,
#toggleLanExclusionButton:hover,
#refreshSuspiciousButton:hover,
#blockSelectedButton:hover,
#blockManualButton:hover,
#refreshBlocksButton:hover,
#refreshPortsButton:hover,
#toggleBlocksButton:hover,
#saveBudgetButton:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.logout-form {
  margin: 0;
}

main {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 20px 24px 32px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.status-grid article {
  min-height: 102px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.status-grid strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.status-grid small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.table-section {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.suspicious-section,
.blocks-section {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.suspicious-list {
  display: grid;
  gap: 10px;
  padding: 12px 16px 16px;
}

.block-list {
  display: grid;
  gap: 8px;
  padding: 12px 16px 16px;
}

.block-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.block-card strong {
  display: block;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.block-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.budget-bar {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ecf2;
}

.budget-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease, background 180ms ease;
}

.budget-bar span.warning {
  background: #f59e0b;
}

.budget-bar span.critical,
.budget-bar span.protect {
  background: var(--danger);
}

.budget-bar span.unlimited {
  background: #94a3b8;
}

.budget-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.budget-editor input {
  width: 100%;
  min-width: 0;
}

.budget-editor span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.budget-editor button {
  height: 32px;
  padding: 0 10px;
}

.suspicious-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.suspicious-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
}

.suspicious-title strong {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  overflow-wrap: anywhere;
}

.suspicious-card p {
  margin-top: 6px;
  font-size: 14px;
}

.suspicious-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.suspicious-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.severity {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #fff3e0;
  color: var(--warning);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.severity.high {
  background: #fee4e2;
  color: var(--danger);
}

.suspicious-empty {
  height: 76px;
  display: grid;
  place-items: center;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.tab-button {
  border-color: var(--line);
  background: var(--panel);
  color: var(--muted);
}

.tab-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tab-panel {
  display: none;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab-panel.active {
  display: block;
}

.blocks-section.is-collapsed {
  display: none;
}

.table-toolbar {
  justify-content: flex-end;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.section-actions input {
  width: min(300px, 34vw);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.compact-table {
  min-width: 100%;
}

th,
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}

th {
  position: relative;
  color: var(--muted);
  background: #fbfcfd;
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 2;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.resize-handle:hover {
  background: rgba(15, 118, 110, 0.12);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.ip-cell {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.host-cell {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.45;
}

.wrap-cell {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.45;
}

.meta-cell {
  display: grid;
  gap: 3px;
  white-space: normal;
}

.meta-cell strong,
.meta-cell small {
  overflow-wrap: anywhere;
}

.meta-cell strong {
  font-size: 13px;
  font-weight: 680;
}

.meta-cell small {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 720;
}

.badge.ok {
  background: #e8f5ee;
  color: #12663e;
}

.badge.blocked {
  background: #fee4e2;
  color: var(--danger);
}

.row-button {
  min-width: 58px;
  height: 32px;
}

.row-button.danger {
  border-color: #f6b4ae;
  color: var(--danger);
}

.row-button.warn {
  border-color: #f5c16c;
  color: var(--warning);
}

.empty {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.ops-cell {
  vertical-align: middle;
}

.ops-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-check,
.check-head input {
  width: 16px;
  height: 16px;
  min-width: 16px;
  padding: 0;
}

.check-head {
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
  color: inherit;
  font-size: inherit;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #eef2f5;
}

.login-shell {
  width: min(420px, 100%);
  padding: 24px;
}

.login-panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form input {
  width: 100%;
  height: 42px;
}

.login-form button {
  width: 100%;
  height: 42px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.login-form button:hover {
  background: var(--accent-strong);
}

.error-box {
  padding: 10px 12px;
  border: 1px solid #f6b4ae;
  border-radius: 6px;
  background: #fff4f2;
  color: var(--danger);
  font-size: 13px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  main {
    padding: 14px 12px 24px;
  }

  .topbar {
    padding: 14px 12px;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .suspicious-card {
    align-items: stretch;
    flex-direction: column;
  }

  .suspicious-actions {
    justify-content: flex-start;
  }

}
