:root {
  --ink: #17171a;
  --muted: #6f7177;
  --line: #e7e4df;
  --paper: #fffefd;
  --canvas: #f5f3ef;
  --red: #cf1236;
  --red-dark: #a80829;
  --red-soft: #fff0f3;
  --gold: #b58a48;
  --green: #21835a;
  --orange: #b76617;
  --shadow: 0 18px 48px rgba(33, 27, 23, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 5% 0%, rgba(207, 18, 54, 0.07), transparent 32rem),
    radial-gradient(circle at 95% 8%, rgba(181, 138, 72, 0.10), transparent 34rem),
    var(--canvas);
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }

.page-shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

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

.brand-lockup { display: flex; align-items: center; gap: 16px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 15px;
  color: white;
  background: var(--red);
  font: 700 22px/1 Arial, sans-serif;
  letter-spacing: -1px;
  box-shadow: 0 10px 28px rgba(207, 18, 54, 0.24);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
.topbar h1 { margin: 0; font-size: clamp(21px, 2vw, 30px); letter-spacing: -0.04em; }

.service-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  backdrop-filter: blur(10px);
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #a6a6aa; }
.service-status.ready .status-dot { background: #28a36c; box-shadow: 0 0 0 4px rgba(40, 163, 108, .12); }
.service-status.error .status-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(207, 18, 54, .12); }
.service-status.loading .status-dot { animation: pulse 1.2s infinite; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 22px;
  align-items: stretch;
}

.composer-card, .result-card {
  min-width: 0;
  border: 1px solid rgba(226, 221, 215, 0.9);
  border-radius: 25px;
  background: rgba(255, 254, 253, 0.96);
  box-shadow: var(--shadow);
}

.composer-card { padding: 22px; }
.result-card { position: relative; min-height: 760px; padding: 26px; overflow: hidden; }
.result-card::after {
  content: "";
  position: absolute;
  right: -110px;
  top: -110px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(207, 18, 54, .08), transparent 68%);
  pointer-events: none;
}

.product-strip {
  display: grid;
  grid-template-columns: 116px 1fr;
  align-items: center;
  gap: 17px;
  margin-bottom: 25px;
  padding: 10px;
  border: 1px solid #eee9e3;
  border-radius: 18px;
  background: linear-gradient(135deg, #fbf8f4, #fff);
}

.product-strip img { width: 116px; height: 92px; object-fit: cover; border-radius: 13px; }
.product-label { display: block; margin-bottom: 5px; color: var(--red); font-size: 11px; font-weight: 800; letter-spacing: .09em; }
.product-copy h2 { margin-bottom: 6px; font-size: 18px; }
.product-copy p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 10px; }
.section-heading > div { display: flex; align-items: center; gap: 9px; }
.section-heading h3 { margin: 0; font-size: 15px; }
.step-number { color: var(--red); font: 800 11px/1 monospace; }
.text-button { border: 0; color: var(--muted); background: transparent; font-size: 12px; }
.text-button:hover { color: var(--red); }
.limit-note { color: #97979c; font-size: 11px; }

#customerMessage {
  display: block;
  width: 100%;
  min-height: 138px;
  resize: vertical;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  outline: none;
  color: var(--ink);
  background: #fcfbf9;
  line-height: 1.7;
  transition: border-color .2s, box-shadow .2s, background .2s;
}

#customerMessage:focus { border-color: rgba(207,18,54,.45); background: white; box-shadow: 0 0 0 4px rgba(207,18,54,.07); }
#customerMessage::placeholder { color: #a5a4a8; }

.quick-prompts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.quick-prompts button {
  border: 1px solid #ece7e1;
  border-radius: 999px;
  padding: 7px 10px;
  color: #656368;
  background: white;
  font-size: 11px;
}
.quick-prompts button:hover { border-color: #e8adba; color: var(--red); background: var(--red-soft); }

.upload-heading { margin-top: 24px; }
.drop-zone {
  display: grid;
  justify-items: center;
  gap: 7px;
  min-height: 148px;
  padding: 22px;
  border: 1.5px dashed #d9d2ca;
  border-radius: 17px;
  color: var(--muted);
  background: #fbfaf8;
  text-align: center;
  transition: .2s ease;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--red); color: var(--red); background: var(--red-soft); transform: translateY(-1px); }
.drop-zone strong { color: var(--ink); font-size: 14px; }
.drop-zone span:last-child { font-size: 11px; }
.upload-icon { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 12px; color: var(--red); background: white; box-shadow: 0 5px 16px rgba(40, 33, 28, .08); }
.upload-icon svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.image-previews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-top: 10px; }
.preview-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #eee; }
.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-item button { position: absolute; top: 5px; right: 5px; display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%; color: white; background: rgba(20,20,23,.72); }
.preview-item button:hover { background: var(--red); }

.privacy-note { display: flex; align-items: flex-start; gap: 9px; margin: 13px 0 16px; color: #7c797d; font-size: 11px; line-height: 1.55; }
.privacy-note svg { flex: 0 0 auto; width: 18px; fill: none; stroke: var(--green); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.primary-button, .local-button {
  position: relative;
  width: 100%;
  min-height: 61px;
  border: 0;
  border-radius: 15px;
  padding: 10px 12px 18px;
  font-weight: 800;
  letter-spacing: .02em;
  transition: transform .2s, box-shadow .2s, opacity .2s;
}
.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  box-shadow: 0 13px 28px rgba(207, 18, 54, .24);
}
.local-button { color: #27262a; background: #eeeae5; box-shadow: 0 8px 20px rgba(33,27,23,.08); }
.primary-button:hover, .local-button:hover { transform: translateY(-1px); }
.primary-button:hover { box-shadow: 0 16px 32px rgba(207,18,54,.3); }
.local-button:hover { background: #e5dfd8; box-shadow: 0 12px 24px rgba(33,27,23,.12); }
.primary-button:disabled, .local-button:disabled { cursor: wait; opacity: .58; transform: none; }
.primary-button small, .local-button small { position: absolute; left: 0; right: 0; bottom: 7px; font-size: 9px; font-weight: 500; opacity: .72; }
.button-loading { display: none; align-items: center; justify-content: center; gap: 10px; }
.button-loading i { width: 16px; height: 16px; border: 2px solid rgba(120,115,112,.35); border-top-color: currentColor; border-radius: 50%; animation: spin .75s linear infinite; }
.primary-button.loading .button-label, .local-button.loading .button-label { display: none; }
.primary-button.loading .button-loading, .local-button.loading .button-loading { display: flex; }
.form-error { min-height: 18px; margin: 10px 2px 0; color: var(--red); font-size: 12px; }

.empty-state { position: relative; z-index: 1; display: grid; place-items: center; align-content: center; min-height: 700px; text-align: center; }
.empty-orbit { display: grid; place-items: center; width: 110px; height: 110px; margin-bottom: 24px; border: 1px solid #eadde0; border-radius: 50%; background: radial-gradient(circle, #fff, #fff3f5); box-shadow: 0 0 0 18px rgba(207,18,54,.025), 0 0 0 36px rgba(207,18,54,.018); }
.empty-orbit span { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 17px; color: white; background: var(--red); font-weight: 900; }
.empty-state h2 { margin-bottom: 10px; font-size: 24px; letter-spacing: -.03em; }
.empty-state > p { max-width: 440px; color: var(--muted); line-height: 1.7; }
.safety-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.safety-pills span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: #77747a; background: white; font-size: 11px; }

.hidden { display: none !important; }
.result-content { position: relative; z-index: 1; }
.result-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.result-header h2 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.risk-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.risk-badge { padding: 6px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.risk-badge.low { color: var(--green); background: #eaf8f1; }
.risk-badge.medium { color: var(--orange); background: #fff3e5; }
.risk-badge.high { color: var(--red); background: var(--red-soft); }
.confidence { color: #99979b; font-size: 10px; }

.analysis-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.analysis-box { min-width: 0; min-height: 108px; margin: 0; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: #fbfaf8; }
.analysis-label { display: block; margin-bottom: 8px; color: #8b888d; font-size: 10px; font-weight: 800; letter-spacing: .09em; }
.analysis-box p { margin: 0; color: #4c4a4f; font-size: 12px; line-height: 1.65; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list span { padding: 6px 8px; border-radius: 7px; color: #76552d; background: #f4eadb; font-size: 10px; }

.human-alert { display: flex; gap: 11px; margin: 0 0 18px; padding: 13px 14px; border: 1px solid #f2c9d1; border-radius: 14px; background: var(--red-soft); }
.alert-icon { display: grid; place-items: center; flex: 0 0 auto; width: 25px; height: 25px; border-radius: 50%; color: white; background: var(--red); font-weight: 900; }
.human-alert strong { color: var(--red-dark); font-size: 12px; }
.human-alert p { margin: 3px 0 0; color: #82545e; font-size: 11px; line-height: 1.55; }

.reply-tabs { display: flex; gap: 4px; width: fit-content; margin-bottom: 10px; padding: 4px; border-radius: 12px; background: #f2efeb; }
.reply-tab { border: 0; border-radius: 9px; padding: 8px 12px; color: #77757a; background: transparent; font-size: 11px; font-weight: 700; }
.reply-tab.active { color: var(--ink); background: white; box-shadow: 0 3px 10px rgba(30,25,20,.08); }

.reply-panel { border: 1px solid #dfd9d3; border-radius: 17px; overflow: hidden; background: white; }
#replyEditor { display: block; width: 100%; min-height: 190px; resize: vertical; padding: 17px; border: 0; outline: none; color: #2a292c; background: white; font-size: 14px; line-height: 1.8; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 17px; border-top: 1px solid #eee9e4; color: #99969a; font-size: 10px; }
.reply-actions button { display: inline-flex; align-items: center; gap: 7px; border: 0; border-radius: 10px; padding: 9px 13px; color: white; background: var(--ink); font-size: 11px; font-weight: 750; }
.reply-actions button:hover { background: var(--red); }
.reply-actions svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.follow-up { margin-top: 18px; padding: 15px 17px; border-radius: 15px; background: #f8f6f3; }
.follow-up ul { margin: 0; padding-left: 18px; color: #5c595e; font-size: 11px; line-height: 1.8; }
.follow-up li::marker { color: var(--red); }
.model-meta { margin: 13px 2px 0; color: #aaa7ab; font-size: 9px; text-align: right; }

.knowledge-section { display: grid; grid-template-columns: 0.72fr 1.28fr; gap: 40px; margin-top: 22px; padding: 28px; border: 1px solid rgba(226,221,215,.85); border-radius: 25px; background: rgba(255,254,253,.78); }
.knowledge-intro h2 { margin-bottom: 10px; font-size: 25px; letter-spacing: -.04em; }
.knowledge-intro > p:last-child { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.75; }
.knowledge-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.knowledge-card { min-width: 0; padding: 13px; border: 1px solid #e8e3dd; border-radius: 14px; background: white; }
.knowledge-card .knowledge-status { display: block; width: 7px; height: 7px; margin-bottom: 10px; border-radius: 50%; background: var(--green); }
.knowledge-card.cautious .knowledge-status { background: var(--orange); }
.knowledge-card.disabled .knowledge-status { background: var(--red); }
.knowledge-card h3 { margin-bottom: 5px; font-size: 12px; }
.knowledge-card p { margin: 0; color: #8a878c; font-size: 10px; line-height: 1.55; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 10; transform: translate(-50%, 20px); padding: 11px 16px; border-radius: 12px; color: white; background: rgba(22,22,25,.92); box-shadow: 0 10px 30px rgba(0,0,0,.18); opacity: 0; pointer-events: none; transition: .25s ease; font-size: 12px; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.topbar-link { border: 0; color: #6e6a70; background: transparent; font-size: 11px; font-weight: 750; text-decoration: none; cursor: pointer; }
.topbar-link:hover { color: var(--red); }
.current-user { padding-left: 10px; border-left: 1px solid var(--line); color: var(--ink); font-size: 11px; font-weight: 800; }
.button-link { padding: 0; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; background: linear-gradient(145deg, #f7f3ee, #fff); }
.auth-card { width: min(100%, 410px); padding: 34px; border: 1px solid var(--line); border-radius: 26px; background: white; box-shadow: 0 24px 70px rgba(50,35,20,.10); }
.auth-card h1 { margin: 15px 0 8px; font-size: 30px; }
.auth-subtitle { margin: 0 0 24px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.auth-card form, .user-form { display: grid; gap: 14px; }
.auth-card label, .user-form label { display: grid; gap: 7px; color: #555158; font-size: 11px; font-weight: 750; }
.auth-card input, .user-form input, .user-form select { width: 100%; border: 1px solid #ddd6cf; border-radius: 11px; padding: 12px; outline: none; background: white; font: inherit; }
.auth-card input:focus, .user-form input:focus, .user-form select:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; padding: 11px 16px; font-size: 11px; font-weight: 800; text-decoration: none; cursor: pointer; }
.primary-button { border: 0; color: white; background: var(--red); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: white; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 11px; }

.admin-shell { width: min(1100px, calc(100% - 32px)); margin: 35px auto 70px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.admin-header h1 { margin: 4px 0 0; font-size: 30px; }
.admin-card { margin-bottom: 18px; padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: white; }
.admin-card h2 { margin: 0 0 18px; font-size: 18px; }
.user-form { grid-template-columns: 1fr 1fr 1.3fr .8fr auto; align-items: end; }
.user-list { display: grid; gap: 9px; }
.user-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 18px; padding: 14px; border: 1px solid #eee8e2; border-radius: 13px; }
.user-row strong, .user-row span { display: block; }
.user-row > div > span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.account-state { padding: 5px 9px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.account-state.active { color: var(--green); background: #eaf8f1; }
.account-state.disabled { color: #777; background: #eee; }
.user-actions { display: flex; gap: 7px; }
.record-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.record-heading h2 { margin-bottom: 5px; }
.record-heading p, .empty-records { margin: 0; color: var(--muted); font-size: 11px; }
.conversation-list { display: grid; gap: 10px; max-height: 680px; overflow: auto; }
.conversation-row { display: grid; gap: 10px; padding: 15px; border: 1px solid #eee8e2; border-radius: 14px; background: #fcfbf9; }
.conversation-meta { display: flex; justify-content: space-between; gap: 12px; color: #969197; font-size: 10px; }
.conversation-meta strong { color: var(--ink); }
.conversation-content { display: grid; grid-template-columns: 44px 1fr; gap: 8px; font-size: 12px; line-height: 1.65; }
.conversation-content b { color: var(--red); }
.conversation-content p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.conversation-content.reply { padding-top: 9px; border-top: 1px dashed #e5ded7; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .result-card { min-height: 650px; }
  .empty-state { min-height: 590px; }
  .knowledge-section { grid-template-columns: 1fr; gap: 20px; }
  .user-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .page-shell { width: min(100% - 20px, 1440px); padding-top: 15px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { max-width: 150px; }
  .brand-mark { width: 48px; height: 48px; border-radius: 12px; font-size: 18px; }
  .topbar h1 { font-size: 18px; }
  .service-status { position: absolute; top: 78px; right: 10px; padding: 7px 10px; font-size: 10px; }
  .composer-card, .result-card, .knowledge-section { border-radius: 20px; }
  .composer-card, .result-card { padding: 16px; }
  .product-strip { grid-template-columns: 84px 1fr; margin-top: 22px; }
  .product-strip img { width: 84px; height: 78px; }
  .analysis-grid { grid-template-columns: 1fr; }
  .image-previews { grid-template-columns: repeat(3, 1fr); }
  .knowledge-section { padding: 20px; }
  .knowledge-cards { grid-template-columns: repeat(2, 1fr); }
  .result-header { flex-direction: column; }
  .risk-wrap { align-items: flex-start; }
  .reply-tabs { width: 100%; }
  .reply-tab { flex: 1; padding-inline: 6px; }
  .action-buttons { grid-template-columns: 1fr; }
  .user-form { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr; }
  .user-actions { flex-wrap: wrap; }
}
