:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #162033;
  --muted: #6a7280;
  --line: #dfe4ec;
  --primary: #1f7a5f;
  --primary-dark: #155a46;
  --danger: #c23838;
  --warn: #a66b00;
  --ok: #16815e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  background: #101827;
  color: white;
  padding: 22px 18px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 4px 0 0;
  color: #a9b4c4;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  color: #d6dce7;
  background: transparent;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: #1d293c;
  color: white;
}

.main {
  min-width: 0;
  padding: 24px;
}

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

.topbar h2 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.session-box {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

label {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  background: white;
}

input.inline-input {
  width: 160px;
  margin-top: 0;
}

input.table-search {
  margin: 0 0 10px;
  padding: 8px 10px;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: white;
  background: var(--primary);
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

button.secondary {
  background: #2e5f88;
}

button.secondary:hover {
  background: #234866;
}

button.ghost {
  border: 1px solid var(--line);
  color: var(--text);
  background: white;
}

button.ghost.danger {
  border-color: #efcaca;
  color: var(--danger);
}

button.ghost.danger:hover {
  background: var(--danger);
  color: white;
}

button.mini {
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}

.actions,
.upload-box {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.message {
  margin-top: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.muted {
  color: var(--muted);
  line-height: 1.7;
}

.muted.compact {
  margin: 4px 0 0;
  line-height: 1.5;
}

.hidden {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

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

.stat-card .value {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 760;
}

.summary-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pill {
  border-radius: 999px;
  padding: 6px 10px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 13px;
}

.pill.ok {
  color: var(--ok);
  background: #e7f6ef;
}

.pill.warn {
  color: var(--warn);
  background: #fff4d9;
}

.pill.error {
  color: var(--danger);
  background: #fde7e7;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.small {
  max-height: 360px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #4a5567;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

td.empty-row {
  color: var(--muted);
  text-align: center;
}

.status-ok {
  color: var(--ok);
  font-weight: 700;
}

.status-warning {
  color: var(--warn);
  font-weight: 700;
}

.status-error {
  color: var(--danger);
  font-weight: 700;
}

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

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

.rule-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.rule-status-panel {
  position: sticky;
  top: 0;
  z-index: 3;
}

.rule-section {
  display: grid;
  gap: 16px;
}

.rule-table-block h4 {
  margin: 0 0 10px;
  font-size: 16px;
}

.rule-form.editing-form {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 122, 95, 0.12);
}

.rule-form h4 {
  margin: 0 0 10px;
  font-size: 15px;
}

.rule-form button {
  margin-top: 10px;
}

code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef2f6;
}

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

  .sidebar {
    position: static;
  }

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

  .rule-form.wide {
    grid-column: span 1;
  }

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