:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #101828;
  background: #eef6f5;
  --page: #eef6f5;
  --surface: #ffffff;
  --surface-soft: #f7fbfb;
  --line: #d9e5ea;
  --line-strong: #bfd1da;
  --text: #101828;
  --muted: #667085;
  --accent: #0ea5a4;
  --accent-strong: #0086ad;
  --accent-soft: #dff8f3;
  --success: #10b981;
  --success-soft: #dcfce7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 980px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, rgba(14, 165, 164, 0.12), transparent 34%),
    linear-gradient(180deg, #edf9f7 0%, #f8fbfd 54%, #f2f5f8 100%);
}

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

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent-strong);
  color: #ffffff;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}

button.secondary {
  border-color: #d0dde5;
  background: #ffffff;
  color: #223044;
}

button.danger {
  background: var(--danger);
}

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

.shell {
  width: min(1600px, calc(100vw - 44px));
  margin: 0 auto;
  padding: 18px 0 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 62px;
  border-bottom: 1px solid rgba(180, 199, 210, 0.7);
}

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

.brand-mark,
.site-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #dff8f3;
  color: #047c68;
  font-weight: 900;
}

.brand-mark {
  width: 42px;
  height: 42px;
  background: #102235;
  color: #ffffff;
  font-size: 14px;
}

.brand h1,
.section-heading h2,
.dialog-heading h2 {
  margin: 0;
  color: var(--text);
  line-height: 1.2;
}

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

.brand p,
.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.topbar-actions,
.field-row,
.settings-grid,
.form-footer,
.dialog-actions,
.site-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric-card {
  position: relative;
  min-height: 74px;
  overflow: hidden;
  border: 1px solid rgba(197, 211, 220, 0.8);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 13px 15px;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: #94a3b8;
}

.metric-card.success::before {
  background: var(--success);
}

.metric-card.danger::before {
  background: var(--danger);
}

.metric-card.accent::before {
  background: var(--accent-strong);
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.metric-card strong {
  display: block;
  margin-top: 7px;
  color: #0f172a;
  font-size: 25px;
  line-height: 1;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.board-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 190px auto;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(180, 199, 210, 0.65);
}

.board-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: #39465a;
  font-size: 12px;
  font-weight: 650;
}

label.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  line-height: 1.25;
}

label.toggle input {
  width: auto;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid #c7d3e1;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.14);
}

textarea {
  min-height: 70px;
  resize: vertical;
}

.site-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.site-card {
  min-width: 0;
  border: 1px solid #ccebdc;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  padding: 12px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.site-card.is-error {
  border-color: #fecaca;
}

.site-card.disabled {
  opacity: 0.72;
}

.site-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.site-identity {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.site-icon {
  width: 38px;
  height: 38px;
  font-size: 17px;
}

.site-title-wrap {
  min-width: 0;
}

.site-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.site-title-row h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #0f172a;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-title-wrap p {
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-primary-multiplier {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 850;
}

.site-primary-multiplier.high {
  color: var(--danger);
}

.site-primary-multiplier.mid {
  color: var(--warning);
}

.site-actions {
  justify-content: flex-end;
  gap: 6px;
}

.card-action {
  min-height: 30px;
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 12px;
}

.card-action.secondary {
  background: #ffffff;
}

.card-action.success {
  border-color: #b7ecd3;
  background: var(--success-soft);
  color: #047857;
}

.site-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.site-fact {
  min-width: 0;
}

.site-fact span,
.site-groups-heading span,
.card-group-main span,
.site-card-footer span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.site-fact strong {
  display: block;
  min-width: 0;
  margin-top: 4px;
  overflow: hidden;
  color: #111827;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-fact.tone-success strong {
  color: #047857;
}

.site-fact.tone-error strong {
  color: #b91c1c;
}

.site-groups {
  margin-top: 13px;
}

.site-groups-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.site-groups-heading strong {
  color: #0f172a;
  font-size: 12px;
}

.card-group-list {
  display: grid;
  gap: 7px;
  max-height: 182px;
  overflow-y: auto;
  padding-right: 2px;
}

.card-group-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid #d9efe6;
  border-left-width: 4px;
  border-radius: 8px;
  background: #fbfefd;
  padding: 8px 9px;
}

.card-group-row.selected {
  background: #eefbf7;
}

.card-group-row.tone-low {
  border-left-color: var(--success);
}

.card-group-row.tone-mid {
  border-left-color: var(--warning);
}

.card-group-row.tone-high {
  border-left-color: var(--danger);
}

.card-group-main {
  min-width: 0;
}

.card-group-main strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: #111827;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-group-main span {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multiplier-badge {
  min-width: 76px;
  border-radius: 999px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  text-align: center;
  background: #eef2f7;
  color: #475467;
}

.multiplier-badge.low {
  background: var(--success-soft);
  color: #047857;
}

.multiplier-badge.mid {
  background: var(--warning-soft);
  color: #b45309;
}

.multiplier-badge.high {
  background: var(--danger-soft);
  color: #b91c1c;
}

.multiplier-badge.threshold {
  border: 1px solid #d5dee8;
  background: #ffffff;
  color: #475467;
}

.group-multiplier-values {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.site-card-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e5eef2;
}

.site-card-footer span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading h2 {
  font-size: 16px;
}

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

.email-settings-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.settings-proxy-url {
  grid-column: span 2;
}

.monitor-rules-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-grid label {
  min-width: 0;
}

.settings-grid .toggle {
  align-self: end;
}

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

.empty {
  display: grid;
  place-items: center;
  min-height: 128px;
  border: 1px dashed #cbd6e3;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
}

.board-empty {
  grid-column: 1 / -1;
}

.empty-inline-card {
  display: grid;
  place-items: center;
  min-height: 60px;
  border: 1px dashed #cbd6e3;
  border-radius: 8px;
  background: var(--surface-soft);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: 420px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  padding: 12px 14px;
  box-shadow: 0 16px 35px rgba(15, 23, 42, 0.22);
}

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

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.dialog-backdrop[hidden] {
  display: none;
}

.dialog-panel {
  width: min(720px, calc(100vw - 48px));
  max-height: min(780px, calc(100vh - 48px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.28);
}

.settings-dialog-panel {
  width: min(920px, calc(100vw - 48px));
}

.logs-dialog-panel {
  width: min(1040px, calc(100vw - 48px));
}

.dialog-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 16px;
}

.dialog-heading h2 {
  margin: 3px 0 0;
  font-size: 20px;
}

.eyebrow {
  display: inline-block;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  border-color: #c9d6e4;
  background: #ffffff;
  color: #2f3b4f;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.monitor-form {
  display: grid;
  gap: 12px;
}

.dialog-panel .monitor-form {
  padding: 16px;
}

.settings-form {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.logs-view {
  display: grid;
  gap: 12px;
  padding: 16px;
}

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

.logs-file-path {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logs-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
}

.logs-list {
  display: grid;
  gap: 8px;
  max-height: min(620px, calc(100vh - 210px));
  overflow-y: auto;
  padding-right: 3px;
}

.log-entry {
  border: 1px solid #d6e1ea;
  border-left-width: 4px;
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.log-entry.level-error {
  border-left-color: var(--danger);
}

.log-entry.level-warn {
  border-left-color: var(--warning);
}

.log-entry.level-info {
  border-left-color: var(--accent-strong);
}

.log-entry-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.log-entry-main {
  min-width: 0;
}

.log-entry-main strong {
  display: block;
  overflow: hidden;
  color: #111827;
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-entry-main span {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-level {
  min-width: 58px;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  background: #eef2f7;
  color: #475467;
}

.log-level.error {
  background: var(--danger-soft);
  color: #b91c1c;
}

.log-level.warn {
  background: var(--warning-soft);
  color: #b45309;
}

.log-level.info {
  background: var(--accent-soft);
  color: #047c68;
}

.log-entry-details {
  margin-top: 8px;
}

.log-entry-details summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 750;
}

.log-entry-details pre {
  max-height: 360px;
  overflow: auto;
  margin: 8px 0 0;
  border: 1px solid #d6e1ea;
  border-radius: 8px;
  background: #0f172a;
  color: #e5eef8;
  padding: 10px;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.settings-section {
  display: grid;
  gap: 12px;
}

.monitor-rule-section {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.token-auth-fields {
  display: grid;
  gap: 12px;
  border: 1px solid #d7e5ec;
  border-radius: 8px;
  background: #f8fbfd;
  padding: 12px;
}

.token-auth-fields[hidden] {
  display: none;
}

.settings-section + .settings-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.settings-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.settings-section-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  line-height: 1.2;
}

.settings-section-heading p,
.settings-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.field-row {
  align-items: start;
}

.field-row > label {
  flex: 1;
}

.form-footer {
  justify-content: space-between;
  padding-top: 2px;
}

@media (max-width: 1100px) {
  body {
    min-width: 0;
  }

  .shell {
    width: min(100vw - 20px, 980px);
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-toolbar {
    grid-template-columns: 1fr 190px;
  }

  .board-meta {
    grid-column: 1 / -1;
    text-align: left;
  }

  .site-board {
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar,
  .site-card-header,
  .board-toolbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions,
  .field-row,
  .form-footer,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .site-board {
    grid-template-columns: 1fr;
  }

  .site-actions {
    justify-content: stretch;
  }

  .site-actions .card-action {
    flex: 1;
  }

  .dialog-backdrop {
    padding: 10px;
  }

  .dialog-panel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

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

  .settings-proxy-url {
    grid-column: auto;
  }

  .settings-section-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #eef1f4;
}

.login-screen[hidden] { display: none; }

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: #fff;
  border: 1px solid #d7dce2;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgb(30 41 59 / 12%);
}

.login-brand { margin-bottom: 4px; }
.login-panel label { display: grid; gap: 8px; }
.login-error { margin: 0; color: #b42318; }
.api-client-layout { display: grid; gap: 16px; padding: 20px; }
.api-key-result { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 14px; background: #f0fdf4; border: 1px solid #86efac; border-radius: 6px; }
.api-key-result code { overflow-wrap: anywhere; user-select: all; }
.api-client-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border-bottom: 1px solid #e5e7eb; }
.api-client-row > div { min-width: 0; display: grid; gap: 4px; }
.api-client-row span { color: #667085; overflow-wrap: anywhere; }
.api-client-actions { display: flex; gap: 8px; }
.api-client-sites { margin: 0; padding: 12px; border: 1px solid #d7dce2; border-radius: 6px; }
.api-client-sites[hidden] { display: none; }
.clear-secrets { display: grid; gap: 10px; padding: 12px; border: 1px solid #f0b4b4; border-radius: 6px; }
.clear-secrets[hidden] { display: none; }
.clear-secret-options { display: flex; flex-wrap: wrap; gap: 12px 18px; }

@media (max-width: 720px) {
  .api-key-result { grid-template-columns: 1fr; }
  .api-client-row { align-items: stretch; flex-direction: column; }
}
