:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f8faf8;
  --border: #d8ddd9;
  --text: #1e2723;
  --muted: #69756f;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --success: #177245;
  --warning: #9a6700;
  --shadow: 0 1px 2px rgba(20, 35, 28, 0.06), 0 8px 24px rgba(20, 35, 28, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.shell {
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: #202522;
  color: #f4f5f3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  font-size: 17px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}

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

.side-link {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: #d5ddd8;
  text-decoration: none;
}

.side-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.side-meta {
  margin-top: auto;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  color: #b8c5bf;
  font-size: 13px;
}

.main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 32px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0 0 5px;
  font-size: 26px;
  line-height: 1.2;
}

.subline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

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

.stat {
  display: flex;
  min-height: 76px;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.stat strong {
  font-size: 24px;
  line-height: 1;
}

.panel {
  margin-bottom: 18px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

.rule-form {
  display: grid;
  gap: 18px;
}

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

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.field input,
.field select,
.search input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #c9d1cc;
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
}

.field input:focus,
.field select:focus,
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.domain-input {
  display: flex;
  min-height: 42px;
  border: 1px solid #c9d1cc;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.domain-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.domain-input input {
  min-width: 0;
  flex: 1 1 auto;
  border: 0;
  box-shadow: none;
}

.domain-input input:focus {
  border: 0;
  box-shadow: none;
}

.domain-suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-left: 1px solid #dce2de;
  background: #f1f4f2;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.field input::placeholder,
.search input::placeholder {
  color: #97a29c;
}

.form-options {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.check input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

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

.button.primary:hover {
  background: var(--accent-strong);
}

.button.ghost {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button.ghost:hover {
  background: var(--surface-2);
}

.button.small {
  min-height: 30px;
  padding: 6px 10px;
  font-size: 13px;
}

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

.button.danger:hover {
  background: #fdeae8;
}

.search {
  width: min(280px, 100%);
}

.search input {
  min-height: 38px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid #e7ebe8;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

td {
  white-space: nowrap;
}

td:first-child {
  font-weight: 600;
}

td:nth-child(2) {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.on {
  background: #e4f3eb;
  color: var(--success);
}

.status-pill.off {
  background: #f0f1f0;
  color: var(--muted);
}

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

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

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 48px));
  padding: 12px 16px;
  border-radius: 8px;
  background: #202522;
  color: #fff;
  box-shadow: 0 12px 32px rgba(20, 35, 28, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
  }

  .side-nav {
    display: flex;
    gap: 4px;
  }

  .side-link {
    padding: 8px 10px;
  }

  .side-meta {
    display: none;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 20px 16px 40px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 22px;
  }

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

  .stat {
    min-height: 64px;
    padding: 12px 14px;
  }

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

  .panel {
    padding: 16px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }
}
