:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #dbe3ef;
  --brand: #0f172a;
  --accent: #16a34a;
  --warn: #dc2626;
  --amber: #b45309;
  --soft: #eef6f1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
input {
  font: inherit;
}

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

.app {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--brand);
  color: white;
  padding: 14px 16px 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

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

.icon-btn {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  padding: 6px;
}

.subline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: #cbd5e1;
  font-size: 12px;
}

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

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-width: 0;
}

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

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  line-height: 1;
}

.tabs {
  position: sticky;
  top: 64px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 12px;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(8px);
}

.tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
}

.tab.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.content {
  padding: 0 12px 24px;
}

.section {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.section h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.notice,
.error,
.loading {
  margin-top: 12px;
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.notice {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.error {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.loading {
  border: 1px solid #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.loading.full {
  margin: 40vh 16px 0;
  text-align: center;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  min-height: 38px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: white;
  padding: 0 12px;
}

.btn.secondary {
  background: white;
  color: var(--brand);
}

.btn.danger {
  border-color: var(--warn);
  background: var(--warn);
}

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  line-height: 1.5;
}

.input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.manual-monitor-panel {
  padding-bottom: 10px;
}

.manual-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 8px;
}

.search-btn {
  padding: 0 8px;
}

.manual-results {
  display: grid;
  margin-top: 10px;
}

.manual-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  gap: 10px;
  border-top: 1px solid var(--line);
}

.manual-result-main {
  min-width: 0;
}

.manual-result-main strong,
.manual-result-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manual-result-main strong {
  display: block;
  font-size: 14px;
}

.manual-result-main span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.icon-action {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 22px;
  line-height: 1;
}

.strategy-input {
  min-height: 110px;
}

.login-panel {
  margin-top: 20vh;
}

.spaced {
  margin-top: 12px;
}

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

.stock-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.stock-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

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

.code {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok {
  background: var(--soft);
  color: #166534;
}

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

.badge.bad {
  background: #fef2f2;
  color: var(--warn);
}

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

.field {
  border-top: 1px solid #eef2f7;
  padding-top: 8px;
}

.field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.field strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
}

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

.timeline-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #eef2f7;
}

.timeline-item:first-child {
  border-top: 0;
}

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

.empty {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.chart-detail h2 { margin-top: 14px; }
.kline-canvas { display: block; width: 100%; height: 320px; margin-top: 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.stock-card[data-stock-code] { cursor: pointer; }

@media (min-width: 760px) {
  .app {
    max-width: 780px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: var(--bg);
  }
}
