:root {
  --ink: #17231f;
  --muted: #66736e;
  --line: #dfe6e2;
  --paper: #ffffff;
  --canvas: #f3f6f4;
  --green: #0f6b4f;
  --green-dark: #084b37;
  --mint: #dff4ea;
  --yellow: #ffd43b;
  --amber: #956100;
  --rose: #b3364a;
  --shadow: 0 18px 60px rgba(25, 46, 38, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: #10271f; color: white; padding: 28px 18px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--yellow); color: #1f2b27; font-weight: 900; font-size: 21px; transform: rotate(-3deg); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .02em; }
.brand small { color: #9bb3aa; margin-top: 4px; font-size: 11px; }
nav { display: grid; gap: 7px; }
.nav-item { border: 0; color: #b9cbc4; background: transparent; padding: 12px 14px; border-radius: 11px; text-align: left; font-weight: 650; display: flex; justify-content: space-between; }
.nav-item:hover { background: rgba(255,255,255,.06); color: white; }
.nav-item.active { background: #21483a; color: white; }
.nav-item span { min-width: 22px; border-radius: 20px; background: var(--yellow); color: #23302b; padding: 1px 6px; text-align: center; font-size: 11px; }
.sidebar-foot { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.12); display: grid; gap: 7px; }
.sidebar-foot label { color: #9bb3aa; font-size: 11px; }
.sidebar-foot input { width: 100%; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); color: white; }

main { padding: 40px clamp(24px, 4vw, 64px) 70px; max-width: 1500px; width: 100%; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.eyebrow { color: var(--green); text-transform: uppercase; letter-spacing: .14em; font-size: 10px; font-weight: 800; margin: 0 0 7px; }
h1 { font-size: clamp(27px, 3vw, 40px); letter-spacing: -.04em; margin: 0; }
h2 { font-size: 18px; letter-spacing: -.02em; margin: 0; }
p { color: var(--muted); }
.mode-pill { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 99px; padding: 9px 13px; box-shadow: 0 5px 25px rgba(0,0,0,.03); font-size: 12px; }
.mode-pill span { width: 9px; height: 9px; border-radius: 50%; background: #f0a400; box-shadow: 0 0 0 4px #fff1c7; }
.mode-pill.auto span { background: #1b9b69; box-shadow: 0 0 0 4px #d9f3e8; }

.view { display: none; }
.view.active { display: block; animation: reveal .18s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(4px); } }
.notice { padding: 17px 20px; border-radius: 13px; display: flex; gap: 12px; align-items: baseline; margin-bottom: 20px; }
.notice.safety { background: #fff4c6; border: 1px solid #f0dc82; }
.notice strong { flex: 0 0 auto; color: #664a00; }
.notice span { color: #685f45; font-size: 13px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.metric, .panel { background: var(--paper); border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--shadow); }
.metric { padding: 20px; min-height: 146px; display: flex; flex-direction: column; }
.metric > span { font-size: 12px; color: var(--muted); }
.metric strong { margin: 12px 0 auto; font-size: 38px; letter-spacing: -.05em; }
.metric small { color: #87928e; }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, .8fr); gap: 15px; margin-top: 15px; }
.panel { padding: 22px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.panel-title p { margin: 5px 0 0; font-size: 12px; }
.audit-list { display: grid; gap: 7px; }
.audit-item { display: grid; grid-template-columns: 120px 135px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid #edf1ef; font-size: 12px; }
.audit-item time, .audit-item span { color: var(--muted); }
.steps { margin: 0; padding-left: 24px; display: grid; gap: 17px; }

button { border: 0; border-radius: 10px; padding: 10px 15px; font-weight: 700; transition: .15s ease; }
button:hover { transform: translateY(-1px); }
.primary { background: var(--green); color: white; box-shadow: 0 8px 22px rgba(15,107,79,.2); }
.primary:hover { background: var(--green-dark); }
.secondary { background: #e8efeb; color: #284138; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.danger { background: #f8e2e6; color: var(--rose); }
.small { padding: 7px 10px; font-size: 11px; }
.link-button { padding: 0; background: transparent; color: var(--green); text-align: left; }
.icon-button { background: transparent; font-size: 25px; color: var(--muted); padding: 2px 9px; }

.toolbar { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.toolbar p { margin: 0; font-size: 13px; }
.button-row, .filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.filter.active { color: white; background: var(--green); border-color: var(--green); }
.inbox-layout { display: grid; grid-template-columns: minmax(260px, .72fr) minmax(480px, 1.5fr); gap: 14px; min-height: 610px; }
.conversation-list, .job-detail { background: white; border: 1px solid var(--line); border-radius: 17px; overflow: hidden; }
.conversation-card { padding: 16px; border: 0; border-bottom: 1px solid #edf1ef; background: white; width: 100%; text-align: left; border-radius: 0; }
.conversation-card:hover, .conversation-card.active { transform: none; background: #f1f7f4; }
.conversation-card .row { display: flex; justify-content: space-between; gap: 10px; }
.conversation-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-card p { margin: 9px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.state-badge, .risk-badge { border-radius: 99px; padding: 4px 8px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.state-waiting_review { background: #fff1bd; color: #6c4b00; }
.state-approved { background: #dbefe7; color: #0d664a; }
.state-sent { background: #e5e9ec; color: #4d5c64; }
.state-queued, .state-processing { background: #e4edff; color: #345a99; }
.state-rejected, .state-failed, .state-cancelled { background: #f8e2e6; color: #943248; }
.job-detail { padding: 25px; }
.empty-state { min-height: 300px; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-state p { font-size: 13px; }
.empty-state.compact { min-height: 320px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.detail-head h2 { font-size: 22px; }
.detail-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.detail-meta span { color: var(--muted); font-size: 11px; }
.chat-log { display: grid; gap: 10px; padding: 22px 0; max-height: 250px; overflow-y: auto; }
.bubble { max-width: 78%; padding: 11px 13px; border-radius: 13px; font-size: 13px; line-height: 1.55; }
.bubble.inbound { background: #edf1ef; justify-self: start; border-bottom-left-radius: 4px; }
.bubble.outbound { background: var(--mint); justify-self: end; border-bottom-right-radius: 4px; }
.decision-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 17px; }
.decision-box div { background: #f6f8f7; border-radius: 10px; padding: 10px; }
.decision-box small, .decision-box strong { display: block; }
.decision-box small { color: var(--muted); margin-bottom: 5px; }
.generation-detail { margin: -5px 0 17px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 12px; }
.generation-detail p { margin: 5px 0 0; color: var(--ink); overflow-wrap: anywhere; }
.generation-detail ul { margin: 8px 0 0; padding-left: 18px; color: var(--danger); }
.draft-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.job-detail textarea { width: 100%; min-height: 120px; }
.review-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 12px; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.product-card { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.product-card .head { display: flex; justify-content: space-between; gap: 12px; }
.product-card h3 { margin: 0; font-size: 17px; }
.product-card .id { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; margin-top: 6px; }
.product-card .price { display: flex; gap: 20px; margin: 18px 0; }
.product-card .price span { display: block; font-size: 11px; color: var(--muted); }
.product-card .price strong { display: block; margin-top: 3px; font-size: 19px; }
.product-card .facts { min-height: 45px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.product-card footer { margin-top: 15px; display: flex; justify-content: space-between; align-items: center; }

.simulator-layout { display: grid; grid-template-columns: minmax(360px, .8fr) minmax(420px, 1.15fr); gap: 16px; }
.form-panel { display: grid; gap: 13px; }
label { display: grid; gap: 6px; color: #51615b; font-size: 12px; font-weight: 650; }
input, textarea, select { border: 1px solid #ccd7d2; border-radius: 9px; padding: 10px 11px; color: var(--ink); background: white; outline: none; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(15,107,79,.1); }
.result-message { background: #edf1ef; border-radius: 12px; padding: 14px; margin-bottom: 16px; }
.result-reply { border-left: 4px solid var(--green); background: var(--mint); padding: 17px; border-radius: 3px 12px 12px 3px; line-height: 1.65; }

dialog { border: 0; border-radius: 20px; padding: 0; width: min(780px, calc(100vw - 30px)); max-height: calc(100vh - 30px); overflow: auto; box-shadow: 0 25px 100px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(10,30,23,.55); backdrop-filter: blur(3px); }
dialog form { padding: 25px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.dialog-head p { margin: 5px 0 0; font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .full { grid-column: 1 / -1; }
.specification-section { border: 1px solid #d9e3de; border-radius: 13px; padding: 15px; background: #f8faf9; }
.specification-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 13px; }
.specification-head strong { color: var(--ink); font-size: 14px; }
.specification-head p, .advanced-facts p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.specification-head span { flex: none; border-radius: 999px; padding: 5px 9px; color: var(--green); background: var(--mint); font-size: 11px; font-weight: 700; }
.specification-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.advanced-facts { border: 1px dashed #ccd7d2; border-radius: 11px; padding: 12px 14px; }
.advanced-facts summary { color: #51615b; cursor: pointer; font-size: 12px; font-weight: 700; }
.advanced-facts textarea { box-sizing: border-box; display: block; margin: 10px 0; width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.empty { color: var(--muted); padding: 30px; text-align: center; }
#toast { position: fixed; right: 25px; bottom: 25px; max-width: 360px; border-radius: 12px; padding: 13px 16px; color: white; background: #19352b; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: #8f2d40; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand div, .nav-item:not(.active)::after, .sidebar-foot { display: none; }
  .nav-item { font-size: 0; justify-content: center; padding: 14px 4px; }
  .nav-item::before { content: attr(data-view); font-size: 10px; text-transform: uppercase; }
  .nav-item span { display: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid, .simulator-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px; flex-direction: row; align-items: center; gap: 10px; overflow-x: auto; }
  .brand { padding: 0; }
  .brand-mark { width: 36px; height: 36px; }
  nav { display: flex; }
  .nav-item { width: 64px; }
  main { padding: 24px 15px 50px; }
  .topbar { align-items: flex-start; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .inbox-layout { grid-template-columns: 1fr; }
  .conversation-list { max-height: 300px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .specification-grid { grid-template-columns: 1fr 1fr; }
  .notice { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 480px) {
  .specification-grid { grid-template-columns: 1fr; }
  .specification-head { align-items: flex-start; flex-direction: column; }
}
