:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9dee5;
  --line-strong: #b9c2cc;
  --text: #17212b;
  --muted: #657281;
  --blue: #1267b1;
  --blue-dark: #0c4f8a;
  --green: #167a48;
  --red: #b3261e;
  --yellow: #fbf2ce;
  --thead: #eef2f6;
  --thead-text: #324252;
  --stat-bg: #f9fafb;
  --toast-bg: #15202b;
  --shadow: rgba(0, 0, 0, 0.18);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161c;
  --panel: #1b222b;
  --line: #303946;
  --line-strong: #465364;
  --text: #edf2f7;
  --muted: #a0acba;
  --blue: #5ea8ff;
  --blue-dark: #2f82df;
  --green: #4fc084;
  --red: #ff746d;
  --yellow: #342d19;
  --thead: #232c36;
  --thead-text: #d6dee8;
  --stat-bg: #151b22;
  --toast-bg: #f1f5f9;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
}

button:hover {
  border-color: var(--blue);
}

button.primary,
.add-form button {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

button.primary:hover,
.add-form button:hover {
  background: var(--blue-dark);
}

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

button:disabled {
  cursor: default;
  opacity: 0.55;
}

input {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: var(--panel);
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar > div:first-child {
  min-width: 0;
}

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

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

h3 {
  font-size: 15px;
  line-height: 1.3;
}

.meta,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 100vw;
}

.left-pane,
.right-pane {
  min-width: 0;
}

.add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 8px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

.monitor-list {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.monitor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
}

.monitor.selected {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.monitor-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.monitor-title > div {
  min-width: 0;
  max-width: 100%;
}

.monitor-title button {
  min-height: 28px;
  flex: 0 0 auto;
  padding: 0 8px;
}

.monitor-url {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: var(--stat-bg);
  min-width: 0;
}

.stat b {
  display: block;
  font-size: 18px;
}

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

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.switch input {
  min-height: 0;
}

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

.status-error {
  color: var(--red);
}

.status-run {
  color: var(--blue);
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 280px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--thead);
  color: var(--thead-text);
  font-size: 13px;
}

td {
  font-size: 14px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.load-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
}

.load-link:hover {
  text-decoration: underline;
}

.events-head {
  margin-top: 18px;
}

.events {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.event {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  padding: 10px;
}

.event.unread {
  background: var(--yellow);
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 20;
}

.toast {
  width: min(380px, calc(100vw - 32px));
  background: var(--toast-bg);
  color: var(--bg);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 24px var(--shadow);
}

@media (max-width: 960px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

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

  .table-wrap {
    max-height: none;
  }
}
