:root {
  --navy: #17233c;
  --blue: #1677ff;
  --blue-soft: #eaf3ff;
  --green: #0aa66f;
  --green-soft: #e9f9f3;
  --orange: #e78318;
  --red: #dd3f4e;
  --red-soft: #fff0f1;
  --ink: #202b40;
  --muted: #738096;
  --line: #e3e8f0;
  --panel: #ffffff;
  --surface: #f5f7fb;
  --shadow: 0 10px 30px rgba(27, 44, 75, .08);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: var(--ink); background: var(--surface); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
.hidden { display: none !important; }
.eyebrow { color: #8090a8; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.primary { border-color: var(--blue) !important; color: #fff !important; background: var(--blue) !important; }

.auth-screen { display: grid; place-items: center; min-height: 100%; padding: 30px; background: radial-gradient(circle at 15% 10%, #deecff 0, transparent 34%), linear-gradient(145deg, #f6f9fd, #eef3fa); }
.auth-card { display: grid; gap: 14px; width: min(430px, 100%); padding: 36px; border: 1px solid #dfe6ef; border-radius: 20px; background: #fff; box-shadow: 0 24px 70px rgba(31, 52, 88, .14); }
.auth-card h1 { margin: 0; font-size: 28px; }
.auth-card p { margin: 0; color: var(--muted); }
.auth-card label, .password-form label { display: grid; gap: 7px; color: #48576f; font-size: 12px; font-weight: 700; }
.auth-card input, .password-form input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid #cad4e1; border-radius: 9px; outline: none; }
.auth-card input:focus, .password-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22, 119, 255, .1); }
.auth-card button { height: 44px; border: 0; border-radius: 9px; font-weight: 800; }
.form-error { min-height: 18px; color: var(--red) !important; font-size: 12px; }

.app { display: grid; grid-template: 68px minmax(0, 1fr) / 178px 340px minmax(0, 1fr); width: 100%; height: 100%; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 20px; min-width: 0; padding: 0 18px; border-bottom: 1px solid var(--line); background: #fff; }
.product-title { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.product-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; color: #fff; background: linear-gradient(145deg, #1677ff, #0959c7); box-shadow: 0 6px 16px rgba(22,119,255,.25); font-weight: 900; }
.product-title h1 { margin: 0; font-size: 17px; }
.product-title p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; min-width: 0; }
.header-actions button, .conversation-actions button, .composer-heading button, .composer-footer button { min-height: 34px; padding: 0 11px; border: 1px solid #d6deea; border-radius: 8px; color: #42536b; background: #fff; font-size: 12px; }
.header-actions span { overflow: hidden; max-width: 160px; color: #58677f; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.queue-sidebar { min-height: 0; overflow: auto; padding: 16px 12px; border-right: 1px solid var(--line); background: #f8faff; }
.queue-sidebar > strong { display: block; margin: 18px 8px 7px; color: #7b879a; font-size: 11px; }
.queue-sidebar nav { display: grid; gap: 3px; }
.queue-sidebar nav button { width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; color: #536178; background: transparent; text-align: left; font-size: 12px; }
.queue-sidebar nav button:hover { background: #eef3fa; }
.queue-sidebar nav button.active { color: #0e61ce; background: #e7f1ff; font-weight: 800; }
.queue-overview { padding: 13px; border: 1px solid #dbe6f5; border-radius: 12px; background: #fff; box-shadow: 0 4px 14px rgba(32,55,91,.05); }
.queue-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.queue-metrics div { display: grid; gap: 2px; }
.queue-metrics strong { font-size: 22px; }
.queue-metrics span { color: var(--muted); font-size: 10px; }

.inbox-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); background: #fff; }
.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.toolbar > div { grid-column: 1 / -1; }
.toolbar h2 { margin: 3px 0 0; font-size: 17px; }
.toolbar input, .toolbar select { min-width: 0; height: 36px; padding: 0 10px; border: 1px solid #d8e0ea; border-radius: 8px; outline: none; background: #f8fafc; font-size: 12px; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--blue); background: #fff; }
.store-filter-label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.store-filter-label span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.store-filter-label select { width: 132px; }
.system-alerts { display: grid; gap: 5px; padding: 10px 14px; color: #9b4f0b; background: #fff5e9; font-size: 11px; }
.conversation-list { min-height: 0; overflow: auto; }
.conversation { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; width: 100%; padding: 13px 12px; border: 0; border-bottom: 1px solid #edf0f5; background: #fff; text-align: left; }
.conversation:hover { background: #f7faff; }
.conversation.active { background: #edf5ff; box-shadow: inset 3px 0 var(--blue); }
.conversation.needs-reply::after { position: absolute; top: 13px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); content: ""; }
.avatar, .customer-avatar, .message-avatar { display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #7aa9e8, #3d78ca); font-weight: 800; }
.avatar { width: 40px; height: 40px; font-size: 14px; }
.conversation-copy { display: block; min-width: 0; }
.conversation-title { display: flex; align-items: center; gap: 6px; }
.conversation-title strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-title em { margin-left: auto; color: #748197; font-size: 9px; font-style: normal; white-space: nowrap; }
.store-line { display: block; overflow: hidden; margin-top: 3px; color: #2e73c8; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.conversation p { overflow: hidden; margin: 5px 0; color: #657289; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.conversation time { align-self: center; color: #98a2b2; font-size: 9px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag, .role-pill { display: inline-flex; align-items: center; min-height: 20px; padding: 2px 7px; border-radius: 999px; color: #1b6cb7; background: #e8f4ff; font-size: 9px; }
.tag.after { color: #8055b7; background: #f1eafd; }
.tag.status { color: #31765c; background: #e8f8f0; }
.tag.marked { color: #b36b00; background: #fff2d8; }
.tag.risk { color: #bf3441; background: #ffeaed; }

.details { min-width: 0; min-height: 0; overflow: hidden; background: var(--surface); }
.empty { display: grid; place-items: center; align-content: center; gap: 7px; min-height: 180px; height: 100%; color: #8a96a8; text-align: center; }
.empty strong { color: #56637a; }
.service-workspace { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; background: #fff; }
.conversation-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 16px; border-bottom: 1px solid var(--line); background: #fff; }
.customer-heading { display: flex; align-items: center; gap: 10px; min-width: 0; }
.customer-avatar { width: 42px; height: 42px; overflow: hidden; font-size: 15px; }
.customer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.customer-heading > div:last-child { min-width: 0; }
.customer-heading h2 { overflow: hidden; margin: 3px 0 0; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.customer-heading p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.store-badge { display: inline-block; overflow: hidden; max-width: 320px; color: #176bca; font-size: 10px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.conversation-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.conversation-actions .mark-button.active { color: #a86100; border-color: #f1c878; background: #fff6df; }
.conversation-actions .claim-button.owned { color: #087b57; border-color: #9bd9c4; background: #eaf9f4; opacity: 1; }
.risk-banner { padding: 8px 16px; color: #a12b37; border-bottom: 1px solid #f4cdd1; background: var(--red-soft); font-size: 11px; font-weight: 700; }
.workspace-body { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(280px, 340px); flex: 1; min-height: 0; }
.chat-column { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); background: #f5f7fa; }
.chat-context-strip { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); background: #fff; }
.chat-context-strip span { overflow: hidden; color: #536078; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.chat-context-strip strong { margin-right: 6px; color: #8691a2; }
.message-thread { display: flex; flex: 1; flex-direction: column; gap: 12px; min-height: 180px; overflow: auto; padding: 18px 20px; scroll-behavior: smooth; }
.history-message { display: flex; align-items: flex-start; gap: 7px; max-width: 82%; }
.history-message.agent { align-self: flex-end; flex-direction: row-reverse; }
.history-message.system { align-self: center; max-width: 92%; }
.message-avatar { width: 28px; height: 28px; margin-top: 4px; font-size: 10px; }
.history-message.agent .message-avatar { background: linear-gradient(145deg, #5cb992, #24825e); }
.history-message.system .message-avatar { background: #9ba5b3; }
.message-bubble { min-width: 0; padding: 9px 11px; border: 1px solid #e4e8ef; border-radius: 4px 13px 13px 13px; background: #fff; box-shadow: 0 2px 7px rgba(30,48,79,.04); }
.history-message.agent .message-bubble { border-color: #cfe2fb; border-radius: 13px 4px 13px 13px; background: #eaf3ff; }
.history-message.system .message-bubble { color: #657289; border: 0; border-radius: 8px; background: #e9edf2; }
.message-bubble small { color: #8b96a8; font-size: 9px; }
.message-bubble p { margin: 4px 0 0; color: #263249; font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.history-empty, .context-empty { padding: 14px; color: #8995a7; font-size: 11px; text-align: center; }

.reply-composer { position: relative; z-index: 2; flex: 0 0 auto; padding: 11px 14px 12px; border-top: 1px solid #dfe4ec; background: #fff; box-shadow: 0 -8px 24px rgba(33,49,75,.04); }
.composer-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.composer-heading > div:first-child { display: grid; gap: 2px; }
.composer-heading strong { font-size: 13px; }
.composer-heading span { color: #7c8799; font-size: 9px; }
.composer-heading > div:last-child { display: flex; gap: 5px; }
.suggestions { display: flex; gap: 7px; margin: 8px 0; overflow-x: auto; }
.suggestion-card { display: grid; flex: 0 0 230px; gap: 4px; padding: 8px 9px; border: 1px solid #dbe3ee; border-radius: 9px; background: #f8faff; text-align: left; }
.suggestion-card:hover { border-color: #91bdf3; background: #f0f7ff; }
.suggestion-card small { color: #2874c9; font-size: 9px; font-weight: 800; }
.suggestion-card span { overflow: hidden; color: #45546b; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-card em { color: #8793a5; font-size: 8px; font-style: normal; }
.suggestion-empty { padding: 7px 0; color: #8b96a8; font-size: 10px; }
.reply-editor { display: block; width: 100%; min-height: 82px; max-height: 160px; padding: 11px; resize: vertical; border: 1px solid #cdd6e3; border-radius: 9px; outline: none; font-size: 12px; line-height: 1.55; }
.reply-editor:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22,119,255,.08); }
.reply-editor:disabled { background: #f2f4f7; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.composer-footer > div { display: flex; gap: 6px; }
.send-safety { color: #7e899b; font-size: 9px; }
.send-status { margin-top: 8px; color: #708096; font-size: 10px; }
.send-status summary, .order-history summary { cursor: pointer; font-weight: 700; }
.reply-task-history { display: grid; gap: 6px; max-height: 150px; overflow: auto; margin-top: 7px; }
.reply-task { padding: 7px 9px; border-left: 3px solid #e5a23b; border-radius: 6px; background: #f8f9fb; }
.reply-task.sent { border-color: var(--green); }
.reply-task.failed { border-color: var(--red); }
.reply-task div { display: flex; justify-content: space-between; }
.reply-task p { margin: 3px 0 0; color: #4b5870; }
.reply-task em { color: var(--red); font-style: normal; }

.customer-panel { min-width: 0; min-height: 0; overflow: auto; padding: 12px; background: #f7f9fc; }
.side-card { margin-bottom: 10px; padding: 12px; border: 1px solid #e2e7ef; border-radius: 11px; background: #fff; box-shadow: 0 3px 12px rgba(31,48,77,.04); }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-title strong { font-size: 12px; }
.section-title span { color: #8190a4; font-size: 9px; text-align: right; }
.identity-card dl { display: grid; gap: 7px; margin: 0; }
.identity-card dl div { display: grid; grid-template-columns: 70px minmax(0,1fr); gap: 8px; }
.identity-card dt { color: #8591a3; font-size: 10px; }
.identity-card dd { overflow: hidden; margin: 0; color: #34435a; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.summary-grid div { display: grid; gap: 3px; padding: 8px; border-radius: 8px; background: #f5f7fa; }
.summary-grid span { color: #8691a3; font-size: 9px; }
.summary-grid strong { overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.order-history { margin-top: 9px; color: #54637a; font-size: 10px; }
.order-row { display: grid; gap: 3px; margin-top: 6px; padding: 8px; border-radius: 7px; background: #f6f8fb; }
.order-row small { color: #8390a2; }
.product-card p { margin: 0; color: #4f5c72; font-size: 10px; line-height: 1.5; }
.product-card a { display: inline-block; margin-top: 7px; color: var(--blue); font-size: 10px; }
.customer-fields { display: grid; gap: 8px; }
.customer-fields label { display: grid; gap: 4px; color: #6e7a8f; font-size: 9px; font-weight: 700; }
.customer-fields input, .customer-fields select, .customer-fields textarea, .transfer-card input, .transfer-card select { width: 100%; min-width: 0; padding: 7px 8px; border: 1px solid #d9e0e9; border-radius: 7px; outline: none; background: #fff; font-size: 10px; }
.customer-fields .mark-check { display: flex; align-items: center; gap: 5px; }
.customer-fields .mark-check input { width: auto; }
.customer-fields button, .transfer-card button { min-height: 34px; border: 1px solid #cfd8e4; border-radius: 7px; color: #36536f; background: #f5f8fb; font-size: 10px; }
.transfer-card { display: grid; gap: 7px; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 26px; max-width: min(520px, 88vw); padding: 12px 18px; transform: translateX(-50%); border-radius: 10px; color: #fff; background: rgba(24, 36, 59, .94); box-shadow: var(--shadow); font-size: 12px; }

.modal { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(18, 28, 47, .52); }
.modal-card { width: min(1180px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border-radius: 16px; background: #fff; box-shadow: 0 28px 80px rgba(12,23,42,.28); }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.modal-heading h2, .modal-heading h3 { margin: 3px 0 0; }
.modal-heading > button { border: 0; background: transparent; font-size: 22px; }
.user-form { display: grid; grid-template-columns: 1fr 1fr 1fr .7fr auto; gap: 8px; margin-top: 18px; }
.user-form input, .user-form select, .rule-form input, .rule-form select, .rule-form textarea { min-width: 0; padding: 8px 10px; border: 1px solid #d6deea; border-radius: 8px; }
.user-form button, .rule-form button { border: 0; border-radius: 8px; }
.permission-help { color: var(--muted); font-size: 11px; }
.permission-list, .rule-list, .knowledge-list, .learning-list, .audit-list { display: grid; gap: 8px; margin-top: 12px; }
.permission-row { display: grid; grid-template-columns: 150px 100px 1fr auto; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; }
.permission-row strong small { display: block; color: var(--muted); }
.disabled-user { opacity: .58; background: #f3f4f6; }
.store-checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.store-checks label { font-size: 11px; }
.permission-actions { display: flex; gap: 5px; }
.permission-actions button, .rule-row button, .knowledge-row button, .learning-row button { padding: 6px 9px; border: 1px solid #ccd6e2; border-radius: 7px; color: #486078; background: #f6f8fb; }
.ai-admin, .rule-admin, .knowledge-admin, .audit-admin { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.ai-status { display: grid; grid-template-columns: 130px 1fr; gap: 5px 12px; margin-top: 12px; padding: 12px; border: 1px solid #ead9b8; border-radius: 9px; color: #755a27; background: #fffaf0; }
.ai-status.ready { border-color: #a8ddcd; color: #087c56; background: #effbf7; }
.ai-status small { grid-column: 1 / -1; color: var(--muted); }
.rule-form { display: grid; grid-template-columns: 1fr .7fr 1.5fr; gap: 8px; margin: 14px 0 8px; }
.rule-form textarea { grid-column: 1 / -1; resize: vertical; }
.rule-form label { display: flex; align-items: center; gap: 6px; color: #556176; font-size: 12px; }
.rule-form button { justify-self: end; padding: 9px 16px; }
.rule-row, .knowledge-row { display: grid; grid-template-columns: 150px 80px 1fr auto; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; }
.rule-row p, .knowledge-row p, .learning-row p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.rule-flags { display: flex; gap: 5px; }
.learning-heading { display: flex; justify-content: space-between; margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); }
.learning-row { display: grid; grid-template-columns: 1fr 1fr 180px auto; gap: 10px; align-items: center; padding: 11px; border: 1px solid #e4d6b9; border-radius: 9px; background: #fffaf0; }
.learning-row input, .learning-row select { width: 100%; padding: 7px 8px; border: 1px solid #ddcfb2; border-radius: 7px; }
.learning-actions { display: flex; gap: 5px; margin-top: 5px; }
.audit-row { display: grid; grid-template-columns: 140px 150px 1fr 120px; gap: 10px; padding: 9px 11px; border-radius: 8px; background: #f6f8fb; color: #46536a; font-size: 11px; }
.audit-row code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: inherit; }
.password-card { width: min(500px, 100%); }
.password-form { display: grid; gap: 12px; margin-top: 18px; }
.password-form button { height: 42px; border: 0; border-radius: 8px; }

@media (max-width: 1280px) {
  .app { grid-template-columns: 160px 310px minmax(0, 1fr); }
  .workspace-body { grid-template-columns: minmax(350px, 1fr) 280px; }
  .conversation-actions button { padding: 0 8px; }
  .store-badge { max-width: 220px; }
}

@media (max-width: 1040px) {
  .app { grid-template-columns: 290px minmax(0, 1fr); }
  .queue-sidebar { display: none; }
  .inbox-panel { grid-column: 1; }
  .details { grid-column: 2; }
  .workspace-body { grid-template-columns: minmax(360px, 1fr) 260px; }
  .header-actions button:nth-of-type(2), .header-actions button:nth-of-type(3) { display: none; }
}

@media (max-width: 760px) {
  html, body { overflow: auto; }
  .app { display: block; height: auto; min-height: 100%; }
  .topbar { position: sticky; top: 0; z-index: 10; height: 58px; }
  .product-title p, .header-actions > span, .header-actions button:not(#logout) { display: none; }
  .inbox-panel { height: 42vh; border-bottom: 1px solid var(--line); }
  .details { height: auto; min-height: 58vh; overflow: visible; }
  .service-workspace { height: auto; }
  .conversation-header { align-items: flex-start; }
  .conversation-actions { flex-wrap: wrap; }
  .workspace-body { display: block; }
  .chat-column { min-height: 72vh; border-right: 0; }
  .message-thread { min-height: 300px; max-height: 52vh; }
  .customer-panel { overflow: visible; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar > div { grid-column: 1 / -1; }
  .store-filter-label select { width: 100%; }
  .user-form, .rule-form, .permission-row, .rule-row, .knowledge-row, .learning-row, .audit-row { grid-template-columns: 1fr; }
}
