:root {
  color-scheme: light;
  --bg: #F7F8FA;
  --card: #FFFFFF;
  --card-alt: #F1F3F6;
  --ink: #111827;
  --muted: #6B7280;
  --line: #E5E7EB;
  --primary: #1A56DB;
  --primary-hover: #1447B8;
  --green: #15803D;
  --green-bg: #ECFDF3;
  --yellow: #B45309;
  --yellow-bg: #FFFBEB;
  --red: #B91C1C;
  --red-bg: #FEF2F2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  line-height: 1.5;
}

button, input { font: inherit; }

.num, .mono {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  word-break: break-all;
}

.app-shell {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 14px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
}

.muted {
  color: var(--muted);
  margin: 0;
  font-size: 13px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-wrap {
  min-height: 82vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 24px 20px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--primary);
  margin-bottom: 10px;
}

.brand-dot, .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
  display: inline-block;
  flex-shrink: 0;
}

.status-dot[data-level="green"] { background: var(--green); }
.status-dot[data-level="yellow"] { background: var(--yellow); }
.status-dot[data-level="red"] { background: var(--red); }

.auth-title {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.3;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field input, .search-row input, .inline-form input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #FFFFFF;
  color: var(--ink);
  font-weight: 400;
}

.field input:focus, .search-row input:focus, .inline-form input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--card);
  color: var(--ink);
  border-color: var(--line);
}

.btn-secondary:hover:not(:disabled) { background: var(--card-alt); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: #FECACA;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  min-height: 40px;
  padding: 0 10px;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--ink);
  background: var(--card-alt);
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-block { width: 100%; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-brand {
  font-weight: 700;
  font-size: 16px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  background: var(--card-alt);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.tab-btn {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 6px;
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--red);
  color: #FFFFFF;
}

.tab-btn.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

.status-msg {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: var(--card);
  border: 1px solid var(--line);
}

.status-msg[data-kind="error"] {
  background: var(--red-bg);
  color: var(--red);
  border-color: #FECACA;
}

.status-msg[data-kind="success"] {
  background: var(--green-bg);
  color: var(--green);
  border-color: #BBF7D0;
}

.panel-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.banner[data-level="green"] { border-left: 4px solid var(--green); }
.banner[data-level="yellow"] { border-left: 4px solid var(--yellow); }
.banner[data-level="red"] { border-left: 4px solid var(--red); }

.banner-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 220px;
}

.banner-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--card-alt);
  color: var(--ink);
}

.badge[data-level="green"] { background: var(--green-bg); color: var(--green); }
.badge[data-level="yellow"] { background: var(--yellow-bg); color: var(--yellow); }
.badge[data-level="red"] { background: var(--red-bg); color: var(--red); }

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

.metric-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.metric-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.metric-value {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}

.metric-sub {
  font-size: 12px;
  color: var(--muted);
  word-break: break-word;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--card-alt);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}

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

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

.timeline-list, .user-list, .orders-list, .digest-box, .support-list, .source-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timeline-item, .user-row, .order-row, .digest-row, .support-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #FFFFFF;
  min-width: 0;
}

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

.funnel-step {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.funnel-step strong {
  font-size: 18px;
  line-height: 1.2;
}

.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}

.detail-block {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.attachment-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attachment-card img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--line);
  cursor: pointer;
}

select.inline-select {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #FFFFFF;
  color: var(--ink);
  font: inherit;
  flex: 1 1 160px;
}

.timeline-head, .user-head, .order-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.timeline-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.hero-card {
  border-color: #BFDBFE;
  background: linear-gradient(180deg, #F8FAFF 0%, #FFFFFF 100%);
}

.pill-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pill-label {
  font-size: 13px;
  font-weight: 600;
}

.pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.pill-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
}

.result-card {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--card-alt);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.result-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.copy-preview {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: #FFFFFF;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.user-actions {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inline-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  padding: 10px;
  border-radius: 10px;
}

.inline-form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form-row input[type="number"] {
  width: 110px;
}

.inline-form-row input[type="text"] {
  flex: 1 1 150px;
  min-width: 0;
}

@media (min-width: 768px) {
  .app-shell { padding: 24px 24px 56px; }
  .metrics-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .funnel-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .result-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .attachment-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
