:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --text: #202327;
  --muted: #69707a;
  --line: #d9dee5;
  --primary: #1c6b5a;
  --primary-hover: #155647;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok-bg: #eef8f4;
  --warn-bg: #fff7e6;
  --sidebar: #182722;
  --sidebar-line: #30413b;
  --sidebar-text: #f3f7f5;
  --sidebar-muted: #aebdb8;
}

* {
  box-sizing: border-box;
}

.form-username-context {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-line);
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 18px 12px 14px;
}

.brand,
.sidebar-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  padding: 2px 6px 18px;
}

.brand-mark {
  width: 38px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #4e665e;
  border-radius: 6px;
  background: #22352f;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand strong,
.brand small,
.sidebar-status strong,
.sidebar-status small {
  display: block;
}

.brand small,
.sidebar-status small {
  margin-top: 2px;
  color: var(--sidebar-muted);
  font-size: 11px;
}

.main-nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-color: transparent;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  padding: 8px 10px;
}

.nav-item:hover {
  border-color: #3b5048;
  background: #22352f;
  color: var(--sidebar-text);
}

.nav-item.active {
  border-color: #4a7164;
  background: #29483e;
  color: #fff;
}

.nav-item kbd {
  min-width: 20px;
  border: 1px solid #4a5d56;
  border-radius: 4px;
  color: var(--sidebar-muted);
  padding: 1px 5px;
  font: inherit;
  font-size: 10px;
  text-align: center;
}

.sidebar-status {
  margin-top: auto;
  border-top: 1px solid var(--sidebar-line);
  padding: 14px 6px 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #71817b;
}

.sidebar-status.running .status-dot {
  background: #55c69c;
  box-shadow: 0 0 0 3px rgba(85, 198, 156, 0.14);
}

.workspace {
  min-width: 0;
}

.page-heading {
  min-height: 70px;
  display: flex;
  align-items: center;
  padding: 12px 20px;
}

.eyebrow {
  color: var(--primary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.page-description,
.section-description {
  margin-top: 3px;
  color: var(--muted);
}

.page-content {
  width: min(100%, 1500px);
  margin: 0 auto;
  padding: 16px;
}

.page-section:not(.active) {
  display: none;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 20px;
}

.login-card p,
.login-message {
  color: var(--muted);
}

.login-message {
  min-height: 20px;
}

.panel,
.row {
  border: 1px solid var(--line);
  background: var(--surface);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.35;
}

h2 {
  font-size: 15px;
  line-height: 1.4;
}

.section-title span,
.meta,
.events {
  color: var(--muted);
}

.row-actions,
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.catalog-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 10px;
  cursor: pointer;
}

.file-button:hover {
  border-color: #aeb7c2;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.section-title-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.runtime-status {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 13px;
  line-height: 1.35;
}

.runtime-status.running {
  border-color: #bdded2;
  background: var(--ok-bg);
  color: var(--primary);
}

.runtime-status.waiting {
  border-color: #f0d48d;
  background: var(--warn-bg);
  color: #8a5a00;
}

.polling-info {
  flex: 0 1 auto;
  min-width: 0;
  min-height: 24px;
  display: flex;
  justify-content: flex-start;
  gap: 8px;
}

.polling-info .polling-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
  color: var(--muted);
  padding: 2px 9px;
  line-height: 1.35;
}

.polling-info.running .polling-tag {
  border-color: #bdded2;
  background: var(--ok-bg);
  color: var(--primary);
}

.polling-info.waiting .polling-tag {
  border-color: #f0d48d;
  background: var(--warn-bg);
  color: #8a5a00;
}

.panel {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
}

.content-panel:first-child,
.page-section > .panel:first-child,
.inventory-grid > .panel {
  margin-top: 0;
}

.control-panel {
  margin-top: 0;
}

.control-panel > .section-title {
  justify-content: flex-start;
}

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

.monitor-grid,
.inventory-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.28fr);
  gap: 12px;
}

.node-strip-panel {
  padding: 9px 12px;
}

.runtime-flow-panel {
  display: grid;
  gap: 9px;
}

.runtime-flow-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
}

.runtime-flow-row.account-flow-row {
  grid-template-columns: 68px auto minmax(0, 1fr);
}

.runtime-flow-row.exit-flow-row {
  grid-template-columns: 68px auto minmax(0, 1fr);
}

.account-mode-field {
  display: flex;
  gap: 5px;
}

.daily-dispatch-field {
  display: flex;
  gap: 5px;
}

.radio-option.compact {
  min-height: 27px;
  padding: 3px 7px;
  font-size: 12px;
}

.runtime-flow-row + .runtime-flow-row {
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.runtime-flow-label {
  padding-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.runtime-node-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 1px 0;
}

.runtime-node-tag {
  min-height: 27px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f8faf9;
  color: var(--muted);
  padding: 3px 9px;
  font-size: 12px;
  line-height: 1.35;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.runtime-node-tag.current {
  border-color: var(--primary);
  background: var(--ok-bg);
  color: var(--primary);
  font-weight: 600;
}

.account-node-tag.selected {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.account-node-tag:disabled {
  cursor: not-allowed;
}

.runtime-account-strip .runtime-node-tag.throttled {
  border-color: #edcf84;
  background: var(--warn-bg);
  color: #805400;
}

.runtime-account-strip .runtime-node-tag.error {
  border-color: #efb0ab;
  background: var(--danger-bg);
  color: var(--danger);
}

.runtime-node-tag.dynamic,
.runtime-node-tag.replacement {
  border-color: #edcf84;
  background: var(--warn-bg);
  color: #805400;
}

.runtime-node-tag.dynamic.current,
.runtime-node-tag.replacement.current {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.runtime-node-tag.cooldown,
.runtime-node-tag.unavailable {
  border-color: #efb0ab;
  background: var(--danger-bg);
  color: var(--danger);
}

.node-status-marker {
  border-radius: 3px;
  background: var(--danger);
  color: #fff;
  padding: 1px 4px;
  font-size: 10px;
  font-weight: 700;
}

.inventory-grid {
  grid-template-columns: minmax(330px, 0.82fr) minmax(0, 1.18fr);
  align-items: start;
}

.monitor-snapshot-panel,
.events-panel {
  min-height: 360px;
}

.rule-catalog-list {
  display: grid;
  gap: 10px;
}

.catalog-rule {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.catalog-rule-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.catalog-rule-header h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.catalog-rule-header p {
  margin-top: 3px;
  color: var(--muted);
}

.catalog-rule-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 12px 0 0;
}

.catalog-rule-meta div {
  min-width: 0;
}

.catalog-rule-meta dt {
  color: var(--muted);
  font-size: 12px;
}

.catalog-rule-meta dd {
  overflow-wrap: anywhere;
  margin: 3px 0 0;
}

.catalog-rule-data {
  margin-top: 12px;
  color: var(--muted);
}

.catalog-rule-data summary,
.catalog-rule-json summary {
  cursor: pointer;
}

.catalog-rule-records {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.catalog-rule-record {
  border-left: 2px solid #bdded2;
  background: #f8faf9;
  padding: 10px;
}

.catalog-rule-json {
  margin-top: 10px;
}

.catalog-rule-json pre {
  overflow: auto;
  max-height: 260px;
  margin: 8px 0 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f8faf9;
  color: var(--text);
  padding: 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.summary-value {
  display: block;
  margin: 4px 0;
  color: var(--primary);
  font-size: 22px;
  line-height: 1.3;
}

.summary-rules {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.summary-rules span {
  overflow: hidden;
  border-left: 2px solid #bdded2;
  color: var(--muted);
  padding-left: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  color: var(--muted);
  padding: 12px 0;
}

.text-button {
  min-height: auto;
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 2px;
}

.account-form {
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
}

.notify-panel {
  position: sticky;
  top: 16px;
}

.notification-form {
  gap: 16px;
}

.notification-channel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 7px;
  background: #fafbfb;
  padding: 14px;
}

.notification-channel-refurb {
  border-left-color: var(--primary);
}

.notification-channel-operations {
  border-left-color: #c58a1d;
}

.notification-channel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.notification-channel-header h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
}

.notification-channel-header p {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.55;
}

.notification-channel-tag {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  padding: 3px 7px;
  font-size: 11px;
  line-height: 1.4;
}

.notification-channel textarea {
  min-height: 92px;
  line-height: 1.55;
}

.notification-channel-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.notification-channel-actions button {
  min-width: 112px;
  white-space: nowrap;
}

.notification-form-footer {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.notification-form-footer .primary {
  width: 100%;
}

.notification-form-footer .meta {
  line-height: 1.6;
}

.control-grid,
.grid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.control-grid.locked label,
.control-grid.locked fieldset,
.control-grid.locked .time-range-field {
  opacity: 0.62;
}

.runtime-actions {
  display: grid;
  grid-column: span 2;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

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

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
  color: var(--muted);
}

.mode-field {
  display: grid;
  gap: 5px;
}

.mode-options {
  display: flex;
  min-height: 32px;
  gap: 6px;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 9px;
}

.time-range-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.time-range-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}

.time-range-inputs span {
  color: var(--muted);
}

.scheduled-sniping-field {
  grid-column: span 4;
  display: grid;
  gap: 5px;
}

.scheduled-sniping-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.weekday-options {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.weekday-options label {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  color: var(--text);
}

.weekday-options input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.scheduled-time-range {
  width: min(100%, 250px);
}

.mode-runtime-settings {
  grid-column: span 2;
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-runtime-settings > .mode-field,
.mode-runtime-settings > .time-range-field,
.control-grid > .scheduled-sniping-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-runtime-settings > .mode-field .mode-options,
.mode-runtime-settings > .time-range-field .time-range-inputs,
.control-grid > .scheduled-sniping-field .scheduled-sniping-controls {
  flex: 1 1 auto;
}

.mode-runtime-settings > .time-range-field > span,
.control-grid > .scheduled-sniping-field > span {
  white-space: nowrap;
}

.mode-runtime-settings > .mode-field .mode-options {
  flex: 0 0 auto;
}

.mode-runtime-settings > .time-range-field .time-range-inputs {
  flex: 0 0 300px;
}

.mode-runtime-settings > .time-range-field .time-range-inputs input {
  min-width: 0;
}

.control-grid > .scheduled-sniping-field {
  grid-column: span 2;
}

.control-grid > .scheduled-sniping-field .scheduled-sniping-controls {
  flex-wrap: nowrap;
}

.control-grid > .scheduled-sniping-field .scheduled-time-range {
  flex: 0 0 210px;
  width: 210px;
}

.title-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-weight: 400;
}

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

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

textarea {
  resize: vertical;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.inline-check input,
.title-check input {
  width: auto;
  min-height: auto;
}

.radio-option input {
  width: auto;
  min-height: auto;
}

button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 10px;
  cursor: pointer;
}

button:hover {
  border-color: #aeb7c2;
}

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

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

button.danger {
  border-color: #f1b4af;
  background: var(--danger-bg);
  color: var(--danger);
}

button.danger.solid {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.rows,
.rules,
.events {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.events-panel .events {
  max-height: calc(100vh - 300px);
  overflow: auto;
  padding-right: 4px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border-radius: 6px;
}

.title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: #edf1f5;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 12px;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--primary);
}

.badge.warn {
  background: var(--warn-bg);
  color: #8a5a00;
}

.import-box {
  margin-top: 12px;
}

.rule-group {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
}

.snapshot-rule-sections {
  display: grid;
  gap: 14px;
}

.snapshot-rule-section + .snapshot-rule-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.snapshot-rule-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.rule-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.event {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) 68px;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(20, 26, 33, 0.12);
  padding: 10px 12px;
  color: var(--text);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

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

#lastEventText {
  margin-left: auto;
}

@media (max-width: 1000px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-line);
    padding: 8px 12px;
  }

  .brand {
    padding: 0;
  }

  .brand small,
  .sidebar-status {
    display: none;
  }

  .main-nav {
    display: flex;
    justify-content: flex-end;
    overflow-x: auto;
  }

  .nav-item {
    width: auto;
    flex: 0 0 auto;
  }

  .page-heading {
    min-height: 68px;
    padding: 10px 14px;
  }

  .page-content {
    padding: 12px;
  }

  .layout,
  .monitor-grid,
  .inventory-grid,
  .control-grid,
  .grid-form,
  .account-form {
    grid-template-columns: 1fr;
  }

  .runtime-actions {
    grid-column: auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-grid > .scheduled-sniping-field {
    grid-column: auto;
    flex-wrap: wrap;
  }

  .mode-runtime-settings {
    grid-column: auto;
    flex-wrap: wrap;
  }

  .control-grid > .scheduled-sniping-field .scheduled-sniping-controls {
    flex-wrap: wrap;
  }

  .runtime-flow-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .runtime-flow-row.account-flow-row {
    grid-template-columns: 1fr;
  }

  .runtime-flow-label {
    padding-top: 0;
  }

  .notify-panel {
    position: static;
  }

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

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

  .brand {
    display: none;
  }

  .main-nav {
    justify-content: flex-start;
    gap: 2px;
    overflow-x: hidden;
  }

  .nav-item {
    padding: 6px 7px;
    font-size: 12px;
  }

  .nav-item kbd {
    display: none;
  }

  .page-heading {
    min-height: 62px;
  }

  .snapshot-panel > .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .notification-channel-actions {
    grid-template-columns: 1fr;
  }

  .notification-channel-actions button {
    width: 100%;
  }

  .catalog-rule-header {
    align-items: stretch;
    flex-direction: column;
  }

  .catalog-rule-meta {
    grid-template-columns: 1fr;
  }
}
