:root {
  --ink: #18212a;
  --muted: #667585;
  --line: #dbe3ea;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --blue: #1f5f9f;
  --blue-dark: #174879;
  --green: #237f66;
  --amber: #9a6500;
  --red: #b33535;
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  padding: 9px 14px;
  cursor: pointer;
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border-radius: 6px;
  background: #e8eef3;
  color: var(--ink);
  padding: 9px 14px;
  text-decoration: none;
}

.button-link:hover {
  background: #dbe5ed;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.secondary {
  background: #e8eef3;
  color: var(--ink);
}

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

button.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  background: #edf2f6;
  color: var(--ink);
  font-size: 22px;
}

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

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.section-head h3,
.section-head p {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
}

.brand p,
.eyebrow,
.side-note,
.panel-head span,
.section-head p,
label span {
  color: var(--muted);
  font-size: 13px;
}

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

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--ink);
  padding: 11px 12px;
}

.nav-item:hover,
.nav-item.active {
  background: #eaf1f7;
  color: var(--blue-dark);
}

.side-note {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafb;
}

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

.topbar,
.section-head,
.panel-head,
.toolbar,
.actions,
.row-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h2 {
  font-size: 28px;
}

.actions,
.toolbar,
.row-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.monitor-status {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto auto;
  gap: 20px;
  align-items: center;
  padding: 18px;
  margin-bottom: 16px;
  border: 1px solid #e8c8c8;
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  background: #fffafa;
}

.monitor-status h3,
.monitor-status p {
  margin: 8px 0 0;
}

.monitor-status p,
.notice span {
  color: var(--muted);
  font-size: 13px;
}

.monitor-status-meta {
  display: grid;
  gap: 4px;
  min-width: 150px;
}

.monitor-status-meta span {
  color: var(--muted);
  font-size: 12px;
}

.monitor-status-meta strong {
  font-size: 28px;
}

.notice {
  display: grid;
  gap: 5px;
  padding: 13px 15px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.notice.warning {
  border-color: #ead39f;
  background: #fffaf0;
}

.source-error {
  margin-top: 8px;
  padding: 8px;
  border-radius: 6px;
  background: #fff0f0;
  color: var(--red);
  font-size: 12px;
  overflow-wrap: anywhere;
}

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

.metric,
.panel,
.card,
.source-card,
.grid-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.metric {
  display: grid;
  gap: 12px;
  padding: 18px;
}

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

.metric strong {
  font-size: 32px;
}

.split {
  display: grid;
  grid-template-columns: minmax(300px, 1.2fr) minmax(260px, 0.8fr);
  gap: 16px;
}

.panel {
  padding: 18px;
  min-height: 280px;
}

.panel-head,
.section-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar input {
  max-width: 360px;
}

.toolbar select {
  max-width: 210px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

.policy-grid,
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.card,
.source-card,
.grid-card {
  padding: 16px;
}

.card h4,
.source-card h4,
.grid-card h4 {
  margin: 0 0 8px;
  font-size: 17px;
}

.meta-row,
.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 12px;
  background: #edf2f6;
  color: #425364;
  white-space: nowrap;
}

.badge.ok {
  background: #dff1ea;
  color: var(--green);
}

.badge.warn {
  background: #fff1d9;
  color: var(--amber);
}

.badge.bad {
  background: #f7dede;
  color: var(--red);
}

.subtext {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

.list,
.breakdown {
  display: grid;
  gap: 10px;
}

.list-item,
.breakdown-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.list-item strong,
.breakdown-item strong {
  display: block;
  margin-bottom: 5px;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: #e7edf3;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--green);
}

.briefing {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 18px;
  white-space: pre-wrap;
  line-height: 1.7;
}

dialog {
  width: min(920px, calc(100vw - 30px));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 33, 43, 0.28);
  padding: 0;
}

dialog::backdrop {
  background: rgba(16, 28, 39, 0.48);
}

.modal-form {
  padding: 20px;
}

.modal-form.small {
  width: min(480px, calc(100vw - 30px));
}

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

.modal-head {
  margin-bottom: 16px;
}

.modal-head h3 {
  margin: 0;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.form-grid label,
.modal-form.small label {
  display: grid;
  gap: 6px;
}

.wide {
  grid-column: 1 / -1;
}

.empty {
  padding: 22px;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 220px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s ease;
  pointer-events: none;
}

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

@media (max-width: 980px) {
  .app-shell,
  .split,
  .metrics,
  .monitor-status,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .toolbar input,
  .toolbar select,
  .toolbar button {
    max-width: none;
    width: 100%;
  }
}
