:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --ink: #17202f;
  --muted: #647084;
  --line: #d9e1ea;
  --line-strong: #b8c3cf;
  --side: #111827;
  --side-soft: #1f2937;
  --teal: #0f766e;
  --blue: #2563eb;
  --amber: #b45309;
  --rose: #be123c;
  --green: #15803d;
  --shadow: 0 14px 34px rgba(20, 28, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.45;
}

button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 14px;
  background: var(--side);
  color: #e5e7eb;
  overflow-y: auto;
}

.brand {
  padding: 4px 6px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { margin-top: 2px; color: #9ca3af; }

.tool-nav {
  display: grid;
  gap: 8px;
  flex: 1;
  padding-top: 16px;
}

.nav-group {
  margin: 14px 8px 2px;
  color: #9ca3af;
  font-size: 12px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #e5e7eb;
  text-align: left;
}

.nav-item:hover { background: var(--side-soft); }

.nav-item.active {
  background: #e6f4f1;
  color: #0f3f3a;
  border-color: #b9ded8;
  font-weight: 700;
}

.sidebar-footer {
  margin-top: 24px;
  padding: 14px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-footer p {
  margin: 0;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.sidebar-footer p + p {
  margin-top: 6px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

#tool-desc {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
}

.export-btn, .file-button {
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  padding: 10px 14px;
  font-weight: 700;
}

.export-btn:disabled {
  cursor: not-allowed;
  background: #a7b5c3;
}

.upload-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 112px;
  margin-bottom: 14px;
  padding: 22px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.upload-panel.dragging {
  border-color: var(--teal);
  background: #eef8f6;
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-copy strong, .upload-copy span {
  display: block;
}

.upload-copy span {
  margin-top: 6px;
  color: var(--muted);
}

.file-meta {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 14px;
}

.result-area {
  min-height: 380px;
}

.empty-state, .error-state {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 300px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.empty-state strong, .error-state strong {
  color: var(--ink);
  font-size: 18px;
}

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

.guide-panel header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.guide-panel h2 {
  margin: 0;
  font-size: 22px;
}

.guide-path {
  display: grid;
  gap: 6px;
  margin: 16px 20px;
  padding: 14px 16px;
  border: 1px solid #c8e5df;
  border-radius: 8px;
  background: #eef8f6;
}

.guide-path strong {
  color: #0f514b;
}

.guide-path span {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.guide-steps {
  display: grid;
  gap: 16px;
  padding: 0 20px 20px;
}

.guide-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.guide-step-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.guide-step-title span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.guide-step img {
  display: block;
  width: 100%;
  height: auto;
  background: #f8fafc;
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.pill.warning {
  border-color: #f3c780;
  background: #fff7e8;
  color: #8a4b05;
}

.cards-grid, .dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.dashboard-grid {
  grid-template-columns: repeat(2, minmax(360px, 1fr));
}

.result-card, .chart-card, .stat-card, .data-table-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.item-result-section {
  grid-column: 1 / -1;
}

.result-card header, .chart-card header, .data-table-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.result-card h2, .chart-card h2, .data-table-card h2 {
  margin: 0;
  font-size: 17px;
}

.chart-card header span {
  max-width: 50%;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.count-badge {
  min-width: 36px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e9f5f2;
  color: #0f514b;
  text-align: center;
  font-weight: 800;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #4b5563;
  font-weight: 800;
}

td:first-child {
  min-width: 160px;
  font-weight: 700;
  color: var(--ink);
  white-space: normal;
  overflow-wrap: anywhere;
}

.muted-row {
  padding: 18px;
  color: var(--muted);
}

.result-item-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.result-item-card {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.result-item-id,
.metric {
  display: grid;
  gap: 4px;
  align-content: center;
}

.result-item-id {
  padding-right: 12px;
  border-right: 1px solid var(--line);
}

.result-item-id span,
.metric span {
  color: var(--muted);
  font-size: 12px;
}

.result-item-id strong {
  color: var(--ink);
  font-size: 16px;
  overflow-wrap: anywhere;
}

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

.metric {
  min-height: 52px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e6edf4;
}

.metric strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card {
  padding: 16px;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

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

.bar-list {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.chart-table {
  min-width: 0;
}

.chart-table th,
.chart-table td {
  white-space: normal;
}

.chart-table td:first-child {
  min-width: 160px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(100px, 1.2fr) minmax(120px, 2fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 28px;
}

.bar-label {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.bar-track {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: #e5eaf0;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), #4f46e5);
}

.bar-value {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.data-table-card {
  margin-top: 14px;
}

.crm-frame-panel {
  min-height: calc(100vh - 150px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.crm-frame-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.crm-frame-toolbar a {
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  padding: 8px 12px;
  text-decoration: none;
  font-weight: 700;
}

.crm-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 198px);
  min-height: 760px;
  border: 0;
}

.doc-panel {
  display: grid;
  gap: 14px;
}

.doc-intro,
.doc-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.doc-intro {
  padding: 18px 20px;
}

.doc-intro p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.doc-section header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.doc-section h2 {
  margin: 0;
  font-size: 20px;
}

.doc-body {
  display: grid;
  gap: 16px;
  padding: 16px 18px 18px;
}

.doc-group {
  display: grid;
  gap: 8px;
}

.doc-group h3 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
}

.doc-lines {
  display: grid;
  gap: 6px;
}

.doc-lines p {
  margin: 0;
  color: var(--ink);
  line-height: 1.65;
  white-space: pre-wrap;
}

.doc-lines p.doc-note {
  color: var(--muted);
}

.donut-wrap {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 22px;
  align-items: center;
  padding: 22px 26px;
}

.donut {
  position: relative;
  display: grid;
  place-items: center;
  width: 168px;
  aspect-ratio: 1;
  border-radius: 999px;
  background: conic-gradient(var(--teal) var(--value), #e5eaf0 0);
}

.donut::before {
  content: "";
  position: absolute;
  width: 108px;
  aspect-ratio: 1;
  border-radius: inherit;
  background: #fff;
}

.donut strong {
  position: relative;
  font-size: 26px;
}

.donut-legend {
  display: grid;
  gap: 14px;
}

.donut-legend-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-weight: 700;
}

.donut-legend-row span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.donut-legend-row i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--teal);
}

.donut-legend-row + .donut-legend-row i {
  background: #a8b4c2;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #17202f;
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .workspace { padding: 18px; }
  .page-header, .upload-panel {
    grid-template-columns: 1fr;
    flex-direction: column;
  }
  .bar-row {
    grid-template-columns: 1fr;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .result-item-card {
    grid-template-columns: 1fr;
  }
  .result-metrics {
    grid-template-columns: repeat(auto-fit, minmax(94px, 1fr));
  }
  .donut-wrap {
    grid-template-columns: 1fr;
  }
  .result-item-id {
    padding-right: 0;
    padding-bottom: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
