:root {
  --paper: #f6f3ea;
  --surface: #fffdf7;
  --surface-soft: #f0eadf;
  --surface-strong: #e6ded0;
  --ink: #18211f;
  --muted: #65736f;
  --faint: #8a9691;
  --line: #ddd4c5;
  --line-strong: #c9bda8;
  --teal: #0f766e;
  --teal-dark: #0a5f59;
  --blue: #254c7a;
  --gold: #a86f18;
  --red: #b24037;
  --plum: #70445f;
  --ok: #12715f;
  --warn: #aa7418;
  --danger: #a63d35;
  --shadow: 0 18px 46px rgba(45, 37, 24, 0.13);
  --radius: 8px;
  --font: "Noto Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(24, 33, 31, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 33, 31, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--teal) 72%, white);
  outline-offset: 2px;
}

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

input,
select,
textarea {
  width: 100%;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 82px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 16%, transparent);
}

svg {
  width: 17px;
  height: 17px;
  flex: none;
}

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

.sidebar {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, var(--surface-soft));
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #fff;
  background: var(--teal);
  font-size: 21px;
  font-weight: 800;
}

.brand-title {
  font-size: 15px;
  font-weight: 900;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-block {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.case-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.case-item {
  width: 100%;
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  margin-bottom: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.case-item:hover,
.case-item.active {
  border-color: color-mix(in srgb, var(--teal) 35%, var(--line));
  background: color-mix(in srgb, var(--teal) 8%, var(--surface));
}

.case-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

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

.case-stage {
  align-self: start;
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 10%, var(--surface));
  font-size: 11px;
  font-weight: 800;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--line);
}

.main {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px);
}

.page-title {
  min-width: 0;
}

.page-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
}

.page-title span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.action-row,
.download-row,
.tabbar,
.segmented {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.content {
  flex: 1;
  min-height: 0;
  padding: 20px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, var(--surface-soft));
  box-shadow: 0 10px 28px rgba(45, 37, 24, 0.07);
}

.panel-head {
  min-height: 54px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 15px;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.panel-body {
  padding: 15px;
}

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

.form-grid label {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.form-grid label.wide {
  grid-column: 1 / -1;
}

.form-grid span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.btn,
.icon-btn,
.case-item,
.tab,
.metric,
.chip {
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.12s ease, box-shadow 0.16s ease;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 13px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: #fff;
}

.btn:active:not(:disabled),
.icon-btn:active:not(:disabled),
.tab:active {
  transform: translateY(1px);
}

.btn.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--teal) 20%, transparent);
}

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

.btn.warn {
  border-color: color-mix(in srgb, var(--gold) 48%, var(--line));
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 8%, var(--surface));
}

.btn.full {
  width: 100%;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  color: var(--teal);
  border-color: color-mix(in srgb, var(--teal) 42%, var(--line));
  background: #fff;
}

.tabbar {
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.tab.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  min-height: 86px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric:hover {
  border-color: color-mix(in srgb, var(--teal) 35%, var(--line));
}

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

.metric strong {
  display: block;
  margin-top: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 22px;
}

.metric small {
  display: block;
  margin-top: 3px;
  color: var(--faint);
}

.diagnosis-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
}

.indicator-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
}

.indicator-table th,
.indicator-table td {
  padding: 9px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.indicator-table th {
  color: var(--ink);
  background: var(--surface-soft);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.status.ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 10%, var(--surface));
}

.status.warning {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 13%, var(--surface));
}

.report-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.report-cover {
  min-height: 162px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  padding: 22px;
  color: #fff;
  background: var(--teal);
}

.report-cover h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.report-cover p {
  margin: 9px 0 0;
  opacity: 0.9;
  line-height: 1.7;
}

.report-badge {
  align-self: start;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: var(--radius);
  padding: 10px 12px;
  text-align: right;
  background: rgba(255, 255, 255, 0.12);
}

.report-badge strong,
.report-badge span {
  display: block;
  white-space: nowrap;
}

.report-badge span {
  margin-top: 3px;
  opacity: 0.76;
  font-size: 12px;
}

.markdown {
  padding: 22px 26px 30px;
  line-height: 1.76;
}

.markdown h1,
.markdown h2,
.markdown h3 {
  margin: 18px 0 9px;
  line-height: 1.35;
  letter-spacing: 0;
}

.markdown h1 {
  margin-top: 0;
  font-size: 22px;
}

.markdown h2 {
  padding-left: 10px;
  border-left: 3px solid var(--teal);
  font-size: 17px;
}

.markdown h3 {
  font-size: 15px;
}

.markdown p {
  margin: 8px 0;
  color: var(--muted);
}

.markdown strong {
  color: var(--ink);
}

.markdown ul,
.markdown ol {
  margin: 8px 0;
  padding-left: 22px;
  color: var(--muted);
}

.markdown li {
  margin: 4px 0;
}

.markdown blockquote {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  background: color-mix(in srgb, var(--gold) 8%, var(--surface));
  color: var(--ink);
}

.markdown table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

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

.markdown th {
  background: var(--surface-soft);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.empty-state {
  min-height: 230px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  text-align: center;
  padding: 24px;
}

.empty-state strong {
  display: block;
  font-size: 17px;
}

.empty-state p {
  max-width: 46ch;
  margin: 8px auto 0;
  color: var(--muted);
  line-height: 1.7;
}

.note-list {
  display: grid;
  gap: 9px;
}

.note-item {
  border-left: 3px solid var(--teal);
  padding: 8px 10px;
  background: color-mix(in srgb, var(--teal) 6%, var(--surface));
  color: var(--muted);
  line-height: 1.6;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  border-radius: var(--radius);
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.loading {
  position: relative;
  overflow: hidden;
}

.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: sweep 1.1s infinite;
}

@keyframes sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .case-list {
    display: flex;
    overflow-x: auto;
    padding: 10px 14px;
  }

  .case-item {
    min-width: 220px;
  }

  .sidebar-footer {
    display: none;
  }
}

@media (max-width: 980px) {
  .workspace-grid,
  .diagnosis-layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 700px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 12px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .btn {
    flex: 1 1 138px;
  }

  .content {
    padding: 12px;
  }

  .form-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .report-cover {
    grid-template-columns: 1fr;
  }

  .report-cover {
    padding: 18px;
  }

  .report-cover h1 {
    font-size: 22px;
  }

  .report-badge {
    text-align: left;
  }

  .markdown {
    padding: 18px 14px 26px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .tabbar,
  .download-row,
  .toast {
    display: none !important;
  }

  .app-shell,
  .main,
  .content {
    display: block;
    padding: 0;
    min-height: auto;
  }

  .panel,
  .report-shell {
    border: 0;
    box-shadow: none;
  }

  .report-cover {
    color: #111;
    background: #fff;
    border-bottom: 2px solid #111;
  }
}
