:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f9fafc;
  --line: #d9e0ea;
  --line-strong: #b7c2d0;
  --text: #1d2733;
  --muted: #667386;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --good: #12805c;
  --good-soft: #e7f6ef;
  --warn: #b7791f;
  --warn-soft: #fff4db;
  --bad: #bf3a30;
  --bad-soft: #fdeceb;
  --shadow: 0 12px 30px rgba(33, 45, 64, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1520px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 22px;
}

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

.brand-logo-link {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
}

.brand-logo-link:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 3px;
}

.brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 700;
  line-height: 1.18;
}

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

.sync-pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.sync-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9aa6b5;
  box-shadow: 0 0 0 3px rgba(154, 166, 181, 0.14);
}

.sync-pill.ok {
  border-color: #b9dfcd;
  background: var(--good-soft);
  color: var(--good);
}

.sync-pill.ok::before {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(18, 128, 92, 0.14);
}

.sync-pill.warn {
  border-color: #efd08d;
  background: var(--warn-soft);
  color: var(--warn);
}

.sync-pill.warn::before {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(183, 121, 31, 0.16);
}

.ghost-button,
.primary-button {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
}

.language-toggle {
  min-width: 82px;
  padding: 0 12px;
}

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.search-field {
  display: grid;
  gap: 6px;
  width: min(320px, 100%);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.search-field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.search-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.segments {
  display: flex;
  justify-content: flex-start;
  gap: 7px;
  flex-wrap: wrap;
}

.segment {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.segment[data-platform="all"] {
  padding: 0 14px;
}

.segment.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.platform-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  object-fit: contain;
}

.platform-icon.brand-icon {
  display: block;
  border-radius: 0;
}

.table-panel {
  position: relative;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 44px;
  border-bottom: 1px solid var(--line);
  background: #f4f7fb;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

thead button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: inherit;
  font-weight: 750;
}

thead button:hover {
  color: var(--accent);
}

thead button::after {
  content: "▲\A▼";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #9aa6b5;
  font-size: 9px;
  font-weight: 750;
  line-height: 0.78;
  white-space: pre;
}

thead button.sort-asc::after {
  content: "▲";
  color: var(--accent);
  font-size: 12px;
}

thead button.sort-desc::after {
  content: "▼";
  color: var(--accent);
  font-size: 12px;
}

tbody td {
  min-height: 58px;
  padding: 12px;
  border-bottom: 1px solid #edf1f6;
  color: var(--text);
  font-size: 14px;
  vertical-align: middle;
}

tbody tr:hover {
  background: #f7fbff;
}

.service-id-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 750;
  text-align: left;
}

.service-name {
  max-width: 420px;
  line-height: 1.45;
}

mark {
  border-radius: 4px;
  background: #ffed9a;
  color: inherit;
}

.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.pct-cell {
  display: grid;
  gap: 7px;
  min-width: 88px;
}

.pct-cell span {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.meter {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf4;
}

.meter > i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.meter.good > i {
  background: var(--good);
}

.meter.warn > i {
  background: var(--warn);
}

.meter.bad > i {
  background: var(--bad);
}

.quality {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 28px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
}

.quality.stable {
  background: var(--good-soft);
  color: var(--good);
}

.quality.watch {
  background: var(--warn-soft);
  color: var(--warn);
}

.quality.attention {
  background: var(--bad-soft);
  color: var(--bad);
}

.empty-state {
  padding: 46px 16px;
  color: var(--muted);
  text-align: center;
}

.guide-dialog {
  width: min(640px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(20, 33, 48, 0.28);
}

.guide-dialog::backdrop {
  background: rgba(20, 33, 48, 0.42);
}

.guide-dialog form {
  position: relative;
  max-height: min(760px, calc(100vh - 32px));
  overflow-y: auto;
  padding: 24px;
}

.guide-dialog h2 {
  margin: 0 0 12px;
  padding-right: 42px;
  font-size: 22px;
  line-height: 1.35;
  color: var(--text);
}

.guide-section {
  margin-top: 18px;
}

.guide-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--text);
}

.guide-section ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.guide-section li {
  color: var(--muted);
  line-height: 1.7;
}

.guide-section strong {
  color: var(--text);
}

.guide-def-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.guide-def-list div {
  display: grid;
  grid-template-columns: minmax(96px, 136px) 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.guide-def-list dt {
  color: var(--text);
  font-weight: 800;
}

.guide-def-list dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

@media (max-width: 560px) {
  .guide-dialog form {
    padding: 20px;
  }

  .guide-def-list div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.ai-chat-toggle {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 18;
  min-width: 96px;
  height: 44px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.22);
}

.ai-chat-toggle.onboarding-pulse {
  animation: service-analysis-pulse 1.7s ease-in-out infinite;
}

.ai-chat-tip {
  position: fixed;
  right: 22px;
  bottom: 76px;
  z-index: 19;
  width: min(320px, calc(100% - 44px));
  padding: 12px 14px;
  border: 1px solid #b9c9ea;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
  box-shadow: 0 18px 50px rgba(20, 33, 48, 0.18);
}

.ai-chat-tip::after {
  content: "";
  position: absolute;
  right: 40px;
  bottom: -7px;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  border-right: 1px solid #b9c9ea;
  border-bottom: 1px solid #b9c9ea;
  background: #ffffff;
}

@keyframes service-analysis-pulse {
  0%,
  100% {
    box-shadow: 0 14px 34px rgba(37, 99, 235, 0.22), 0 0 0 0 rgba(37, 99, 235, 0.26);
    transform: translateY(0);
  }

  50% {
    box-shadow: 0 18px 42px rgba(37, 99, 235, 0.3), 0 0 0 8px rgba(37, 99, 235, 0);
    transform: translateY(-2px);
  }
}

.ai-chat-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 18;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(470px, calc(100% - 32px));
  height: min(700px, calc(100vh - 44px));
  overflow: hidden;
  overscroll-behavior: contain;
  border: 1px solid #c8d3e1;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(20, 33, 48, 0.22);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid #dfe6ef;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.ai-chat-header strong,
.ai-chat-header span {
  display: block;
}

.ai-chat-header strong {
  font-size: 17px;
  font-weight: 800;
}

.ai-chat-header span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.ai-chat-header button {
  width: 34px;
  height: 34px;
  border: 1px solid #d8e1ec;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.ai-chat-header button:hover {
  border-color: #c2cedd;
  background: #f3f6fa;
  color: var(--text);
}

.ai-chat-messages {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: #f4f7fb;
  scrollbar-color: #b8c4d4 transparent;
  scrollbar-width: thin;
}

.chat-message {
  max-width: 100%;
  border-radius: 8px;
  padding: 11px 13px;
  line-height: 1.55;
  font-size: 14px;
}

.chat-message p {
  margin: 0;
}

.chat-message.user {
  justify-self: end;
  max-width: 88%;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.18);
}

.chat-message.assistant {
  justify-self: start;
  width: 100%;
  border: 1px solid #dbe3ee;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 8px 22px rgba(20, 33, 48, 0.06);
}

.chat-message.loading {
  color: var(--muted);
}

.ai-rec-card {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #dbe3ee;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: #ffffff;
}

.ai-rec-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-rec-head span,
.ai-rec-head em {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.ai-rec-head strong {
  color: var(--accent);
  font-size: 15px;
}

.ai-rec-card h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.ai-rec-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 11px 0;
}

.ai-rec-stats span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 6px 8px;
  border: 1px solid #dfe6ef;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
}

.ai-rec-stats span:last-child {
  grid-column: 1 / -1;
}

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

.ai-order-list {
  display: grid;
  gap: 0;
  margin: 8px 0 0;
  padding: 0;
  list-style-position: inside;
  border: 1px solid #e3e9f2;
  border-radius: 8px;
  background: #fbfcfe;
  overflow: hidden;
}

.ai-order-list li {
  padding: 8px 10px;
  border-bottom: 1px solid #edf1f6;
}

.ai-order-list li:last-child {
  border-bottom: 0;
}

.ai-order-list span {
  display: block;
  color: var(--text);
  font-size: 12px;
}

.time-highlight {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border: 1px solid #f1c232;
  border-radius: 999px;
  background: #fff2a8;
  color: #7a4b00;
  font-weight: 850;
}

.ai-chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 13px;
  border-top: 1px solid #dfe6ef;
  background: #ffffff;
}

.ai-chat-form textarea {
  width: 100%;
  min-height: 44px;
  max-height: 110px;
  overscroll-behavior: contain;
  resize: vertical;
  padding: 11px 12px;
  border: 1px solid #c8d3e1;
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfe;
  outline: none;
}

.ai-chat-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.ai-chat-form button {
  align-self: end;
  min-width: 76px;
  height: 44px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%) translateY(16px);
  max-width: min(420px, calc(100% - 32px));
  padding: 11px 14px;
  border-radius: 8px;
  background: #1d2733;
  color: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.manual-copy-input {
  position: fixed;
  left: 50%;
  bottom: 74px;
  z-index: 30;
  transform: translateX(-50%);
  width: min(280px, calc(100% - 32px));
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-weight: 750;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (max-width: 1080px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .segments {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 24px, 1520px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .ai-chat-toggle,
  .ai-chat-tip,
  .ai-chat-panel {
    right: 12px;
    bottom: 12px;
  }

  .ai-chat-tip {
    bottom: 66px;
    width: calc(100% - 24px);
  }

  .ai-chat-panel {
    width: calc(100% - 24px);
    height: min(620px, calc(100vh - 24px));
  }
}
