:root {
  --bg: #eef2f5;
  --bg-soft: #f8fbfc;
  --panel: rgba(255, 255, 255, 0.9);
  --line: rgba(36, 57, 64, 0.14);
  --text: #172126;
  --muted: #60717a;
  --brand: #256f83;
  --brand-deep: #174a5c;
  --good: #1f7a53;
  --warn: #9b6a11;
  --bad: #b04444;
  --shadow: 0 0 12px rgba(23, 33, 38, 0.15);
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: "Aptos", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f8fafb 0%, var(--bg) 100%);
}

code {
  font-family: "Cascadia Code", "Consolas", monospace;
}

.shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 15px 0;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(240, 247, 249, 0.84));
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 5px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brand);
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(24px, 3vw, 28px);
  line-height: 1;
}

.lead {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 12px;
}

.market-pill {
  min-width: 220px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  display: grid;
  gap: 3px;
}

.market-pill.open {
  background: rgba(31, 122, 83, 0.12);
}

.market-pill.closed {
  background: rgba(141, 95, 20, 0.12);
}

.market-pill span,
.market-pill small {
  color: var(--muted);
  font-size: 12px;
}
.market-pill strong {
  font-size: 14px;
}

.flash {
  margin-top: 10px;
  padding: 10px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.flash.success {
  background: rgba(34, 97, 75, 0.12);
}

.flash.error {
  background: rgba(140, 45, 45, 0.12);
}

.quick-nav {
  display: flex;
  gap: 10px;
  /* margin-top: 8px; */
  overflow-x: auto;
  /* padding-bottom: 10px; */
  padding: 10px 0;
  scrollbar-width: none;
}

.quick-nav::-webkit-scrollbar {
  display: none;
}

.quick-nav a {
  flex: 0 0 auto;
  padding: 7px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  font-size: 12px;
  box-shadow: var(--shadow);
}

.stats-grid {
  display: grid;
  gap: 10px;
}
.grid.two {
  display: grid;
  gap: 10px;
}

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

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

.stat,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.stat {
  padding: 8px 10px;
  display: grid;
}

.stat.ok {
  background: linear-gradient(180deg, rgba(31, 122, 83, 0.1), rgba(255, 255, 255, 0.88));
}

.stat.warn {
  background: linear-gradient(180deg, rgba(155, 106, 17, 0.12), rgba(255, 255, 255, 0.88));
}

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

.stat-value {
  font-size: 20px;
}

.panel {
  margin-top: 8px;
  padding: 10px;
}

.panel-head {
  margin-bottom: 6px;
}

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

.panel-head p,
.footer,
.subtle,
.helper,
.provider-popover p {
  color: var(--muted);
  margin: 0;
}

.panel-head p {
  font-size: 13px;
}

.subtle {
  font-size: 12px;
}

.stack-form,
.inline-form {
  display: grid;
  gap: 8px;
}

.stack-form label,
.stack-form .field,
.inline-form {
  align-items: center;
}

.stack-form label,
.stack-form .field {
  display: grid;
  gap: 4px;
}

.stack-form label span,
.field-title {
  color: var(--muted);
  font-size: 13px;
}

.field-title {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-self: start;
}

input,
select,
textarea,
button {
  width: 100%;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid rgba(36, 57, 64, 0.18);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
}

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

button {
  cursor: pointer;
  /* font-weight: 700; */
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #f8fcfd;
  border: none;
  transition: transform 120ms ease, opacity 120ms ease;
  font-size: 13px;
}

button:hover {
  transform: translateY(-1px);
}

button.secondary {
  background: linear-gradient(135deg, #53666f, #34454d);
}

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

button.danger {
  background: linear-gradient(135deg, #b04444, #762626);
}

hr {
  margin: 16px 0;
  border: none;
  border-top: 1px solid var(--line);
}

.top-gap {
  margin-top: 14px;
}

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

.monitor-run-form {
  margin: 0;
}

.helper {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}

.monitor-list {
  display: grid;
  gap: 14px;
}

.monitor-stock {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(248, 251, 252, 0.78);
}

.monitor-stock-head,
.stock-edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.stock-title h3,
.rule-list-head h4 {
  margin: 0;
}

.stock-title h3 {
  font-size: 16px;
}

.stock-title span,
.quote-strip span,
.rule-list-head span {
  color: var(--muted);
}

.stock-title span {
  display: inline-block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
}

.quote-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: flex-end;
}

.quote-strip div {
  min-width: 92px;
}

.quote-strip span:not(.badge) {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

.quote-strip strong {
  white-space: nowrap;
  font-size: 16px;
}

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

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

.monitor-rule {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.5fr) auto;
  gap: 10px;
  align-items: start;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.rule-meta {
  /* display: grid;
  gap: 6px; */
  color: var(--muted);
  font-size: 13px;
}

.rule-meta .badge {
  justify-self: start;
}

.add-rule-form {
  grid-template-columns: 1fr 1fr 1.2fr auto;
  padding: 6px;
  border: 1px dashed rgba(37, 111, 131, 0.28);
  border-radius: var(--radius);
  background: rgba(240, 247, 249, 0.78);
}

.compact-empty {
  padding: 16px;
  text-align: left;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

td {
  word-break: break-word;
  font-size: 12px;
}

.compact {
  grid-template-columns: 1.2fr 1fr auto;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  background: rgba(34, 97, 75, 0.12);
  color: var(--good);
}

.badge.warn {
  background: rgba(141, 95, 20, 0.14);
  color: var(--warn);
}

.badge.muted {
  background: rgba(36, 57, 64, 0.1);
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 8px;
  min-width: 160px;
}

.actions form {
  flex: 1;
}

.empty {
  padding: 28px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  text-align: center;
}

.danger-text {
  color: var(--bad);
}

.popover-trigger,
.popover-close {
  width: 22px;
  min-height: 22px;
  padding: 0;
  border: 1px solid rgba(37, 111, 131, 0.28);
  border-radius: 999px;
  background: rgba(37, 111, 131, 0.1);
  color: var(--brand-deep);
  font-size: 12px;
  line-height: 1;
}

.popover-close {
  margin-left: auto;
  background: rgba(36, 57, 64, 0.08);
  color: var(--muted);
}

.provider-popover {
  width: min(360px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid rgba(36, 57, 64, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 16px 40px rgba(23, 33, 38, 0.18);
}

.provider-popover::backdrop {
  background: rgba(23, 33, 38, 0.08);
}

.provider-popover-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.provider-popover-list {
  display: grid;
  gap: 10px;
}

.provider-popover section {
  display: grid;
  gap: 3px;
}

.provider-popover p {
  font-size: 13px;
  line-height: 1.6;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  font-size: 13px;
}

@media (max-width: 960px) {
  .shell {
    width: min(100%, calc(100% - 20px));
    padding-top: 18px;
  }

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

  .hero {
    padding: 22px 18px;
    gap: 16px;
  }

  .market-pill {
    min-width: 0;
  }

  .panel {
    padding: 10px;
  }

  .monitor-stock-head,
  .stock-edit-row,
  .monitor-rule {
    grid-template-columns: 1fr;
  }

  .quote-strip {
    justify-content: flex-start;
  }

  .compact,
  .rule-form,
  .add-rule-form,
  .settings-actions {
    grid-template-columns: 1fr;
  }

  .actions,
  .footer {
    flex-direction: column;
  }

  .actions {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .table-wrap {
    overflow: visible;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.62);
  }

  td {
    padding: 0;
    border: none;
  }

  td + td {
    margin-top: 12px;
  }

  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
  }

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

  .panel-head h2 {
    font-size: 20px;
  }

  .footer {
    font-size: 12px;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100%, calc(100% - 16px));
  }

  .hero h1 {
    font-size: 30px;
  }

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

  .panel,
  .hero,
  .stat {
    border-radius: var(--radius);
  }

  .quick-nav a {
    padding: 9px 12px;
    font-size: 13px;
  }
}
