:root {
  --bg: #e9eff5;
  --bg-accent: linear-gradient(155deg, #e9eff5 0%, #dfe8f1 48%, #e5edf4 100%);
  --bg-grid: rgba(28, 58, 84, 0.05);
  --ink: #12293d;
  --muted: #4b6074;
  --line: #cbd9e6;
  --panel: #ffffff;
  --primary: #0f4f7d;
  --primary-strong: #0b3f66;
  --good: #1d8762;
  --warn: #b67400;
  --bad: #b24438;
  --shadow: 0 12px 30px rgba(8, 26, 44, 0.1);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  font-family: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft Yahei", sans-serif;
  color: var(--ink);
  background: var(--bg-accent);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--bg-grid) 1px, transparent 1px), linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 36px 36px;
  opacity: 0.25;
  pointer-events: none;
  z-index: -1;
}

.layout {
  width: min(1120px, calc(100vw - 28px));
  margin: clamp(14px, 3.4vw, 28px) auto clamp(20px, 5vw, 40px);
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  display: grid;
  gap: 18px;
}

.hero {
  background: linear-gradient(135deg, var(--primary-strong), #1b5f8d 68%);
  color: #f8fbff;
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.hero::after {
  content: "";
  display: block;
  margin-top: 16px;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(1.5rem, 2.8vw, 2.2rem);
}

.hero p {
  margin: 0;
  line-height: 1.55;
  opacity: 0.94;
}

.ai-disclaimer {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(10, 27, 42, 0.2);
  color: rgba(248, 251, 255, 0.95);
  font-size: 0.88rem;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: var(--shadow);
}

.view-section {
  display: grid;
  gap: 18px;
}

.view-section[hidden] {
  display: none !important;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  position: sticky;
  top: 8px;
  z-index: 20;
  backdrop-filter: blur(4px);
  background: rgba(255, 255, 255, 0.95);
}

.top-nav-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px 10px 5px 6px;
  background: #f5f9fd;
  flex-shrink: 0;
}

.brand-logo {
  width: 30px;
  height: 30px;
  display: block;
}

.brand-text {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.top-nav-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-btn {
  background: #edf3f8;
  color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.top-nav-menu .nav-btn,
.nav-logout {
  min-height: 40px;
}

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

.nav-logout {
  background: #fff2ef;
  border-color: #e8b6b0;
  color: var(--bad);
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.login-brand-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

form {
  display: grid;
  gap: 14px;
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #4f6476 50%), linear-gradient(135deg, #4f6476 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 3px), calc(100% - 10px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

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

button {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

#generate-btn {
  background: var(--primary);
  color: #fff;
}

#requirement-generate-btn {
  background: #e8f4ff;
  color: #0f5f92;
  border: 1px solid #c4dbef;
}

#print-btn {
  background: #eaf1f7;
  color: var(--ink);
}

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

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel .ai-disclaimer {
  margin: 8px 0 0;
  border: 1px solid #d7e3ee;
  background: #f4f8fc;
  color: #3d5569;
}

.report-disclaimer {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed #c8d8e6;
  background: #f8fbfe;
  color: #4b6074;
  font-size: 0.88rem;
}

.generation-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
  font-weight: 600;
}

.generation-progress[hidden] {
  display: none !important;
}

.generation-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #bfd3e4;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.score-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #f9fcff;
}

.score-card .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.score-card .value {
  font-size: 1.2rem;
  font-weight: 700;
}

.risk-opportunity {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

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

.stream-head h3 {
  margin: 0;
}

.stream-compact {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f9ff;
  padding: 8px 10px;
}

#stream-inline-text {
  display: inline-block;
  min-width: 100%;
  white-space: nowrap;
  color: #2d5778;
  animation: streamSlide 14s linear infinite;
}

.stream-detail {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
  padding: 10px;
}

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

.stream-feed {
  display: grid;
  gap: 8px;
  min-height: 100px;
  max-height: 360px;
  overflow: auto;
}

.stream-bubble {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  line-height: 1.5;
  font-size: 0.92rem;
  white-space: pre-wrap;
}

.stream-bubble-system {
  background: #eef5fc;
  color: #2f5878;
}

.stream-bubble-status {
  background: #e9f6ef;
  color: #21684a;
}

.stream-bubble-thinking {
  background: #f7fbff;
  color: #1f3f57;
  border-left: 3px solid #6ca6d1;
}

.price-table-wrap {
  overflow-x: auto;
}

.price-chart-wrap {
  position: relative;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}

#product-price-chart {
  width: 100%;
  height: 340px;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.chart-tip {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.price-chart-tooltip {
  position: absolute;
  min-width: 190px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(14, 38, 63, 0.14);
  padding: 8px 10px;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--ink);
  pointer-events: none;
  z-index: 4;
}

.price-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  margin-top: 8px;
}

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

.price-table th {
  background: #f2f7fb;
  color: var(--muted);
  font-weight: 600;
}

.risk-rule-details {
  margin-top: 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fbfdff;
}

.risk-rule-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.92rem;
}

.report h3 {
  margin-top: 20px;
}

ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

li {
  margin-bottom: 8px;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

@media (max-width: 1080px) {
  .layout {
    width: min(1120px, calc(100vw - 24px));
  }
}

@media (max-width: 860px) {
  .layout {
    gap: 14px;
  }

  .top-nav {
    top: 6px;
  }

  .grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .stream-feed {
    max-height: 320px;
  }
}

@media (max-width: 700px) {
  .layout {
    width: calc(100vw - 16px);
    margin-top: 16px;
  }

  .panel,
  .hero {
    padding: 16px;
  }

  .hero h1 {
    font-size: 1.45rem;
  }

  #product-price-chart {
    height: 300px;
  }

  .top-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .top-nav-main {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .brand-link {
    width: 100%;
    justify-content: center;
  }

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

  .top-nav-menu .nav-btn {
    width: 100%;
  }

  .nav-logout {
    width: 100%;
  }

  .actions {
    flex-direction: column;
  }

  .actions button {
    width: 100%;
  }

  .score-cards,
  .risk-opportunity {
    grid-template-columns: 1fr;
  }

  .stream-feed {
    max-height: 280px;
  }
}

@media (max-width: 480px) {
  .top-nav-menu {
    grid-template-columns: 1fr;
  }

  .price-table th,
  .price-table td {
    padding: 7px 8px;
    font-size: 0.86rem;
  }
}

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

  .no-print {
    display: none !important;
  }

  .layout {
    width: 100%;
    margin: 0;
    gap: 0;
  }

  .panel {
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding: 0;
  }

  .report article,
  .report header {
    page-break-inside: avoid;
    margin-bottom: 12px;
  }
}
