/* Otto After-Sales Self-Service Reply Assistance System v2
 * Layout: 4-column detail view per user's Excel design
 *   Col1 (green): Conversation + Chinese translations
 *   Col2-top (pink): Order/complaint info summary
 *   Col2-bottom (light blue): Handling suggestion input
 *   Col3 (right): Generated German reply + Chinese translation
 */
:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --border: #d8dce3;
  --text: #1a1a2e;
  --muted: #5c6370;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --chip-nm: #7c3aed;
  --chip-na: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
  --radius: 10px;
  --col-conv-bg: #e8f5e9;       /* light green — conversation */
  --col-info-bg: #fce4ec;       /* pink — complaint info */
  --col-input-bg: #e0f7fa;      /* light cyan — input */
  --col-reply-bg: #e8eaf6;      /* light blue-purple — reply output */
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.topbar .src { font-size: 12px; color: var(--muted); }
.store-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.store-select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 13px; max-width: 220px; cursor: pointer;
}
.store-select:focus { border-color: var(--accent); outline: none; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color:#fff; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Layout ---- */
.layout { display: grid; grid-template-columns: 1fr; height: calc(100vh - 57px); }
.listview { display: flex; flex-direction: column; height: 100%; }
.detailview { display: none; height: 100%; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.toolbar .search {
  flex: 1; min-width: 200px; max-width: 340px;
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background:#fff;
}
.toolbar .search input { border: none; outline: none; flex: 1; font-size: 13px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background:#fff; border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 12.5px; color: var(--muted);
}
.chip.active { background: var(--accent); color:#fff; border-color: var(--accent); }
.chip.nm.active { background: var(--chip-nm); border-color: var(--chip-nm); }
.chip.na.active { background: var(--chip-na); border-color: var(--chip-na); }
select.sortsel { padding: 6px 10px; border:1px solid var(--border); border-radius:8px; background:#fff; font-size:13px; }

/* ---- Table ---- */
.tablewrap { flex: 1; overflow: auto; padding: 0 20px 20px; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.grid th, table.grid td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.grid th { background: #fafbfc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--accent-soft); }
table.grid td.idcell { font-variant-numeric: tabular-nums; color: var(--muted); }
table.grid td.ordercell { font-weight: 600; color: var(--accent); }
.urg { font-variant-numeric: tabular-nums; font-weight: 600; }
.urg.hot { color: var(--danger); }
.urg.mid { color: var(--warn); }
.urg.cool { color: var(--ok); }
.thema { display: inline-block; padding: 2px 9px; border-radius: 6px; background:#eef1f5; font-size: 12px; }
.statuspill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.statuspill.nm { background: #f3efff; color: var(--chip-nm); }
.statuspill.na { background: var(--accent-soft); color: var(--chip-na); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ================================
   DETAIL VIEW — 4-COLUMN LAYOUT
   ================================ */
.detailview {
  display: none;
  grid-template-columns: 50% 25% 25%;
  gap: 0;
  overflow: hidden;
}
.detailview.open { display: grid; }

/* ---- Column 1: Conversation (green) ---- */
.col-conv {
  background: var(--col-conv-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px;
}
.col-title {
  font-size: 14px; font-weight: 700; margin: 8px 0 10px;
  color: var(--text);
}
.backbtn { margin-bottom: 4px; }

.thread { display: flex; flex-direction: column; gap: 10px; }

.msg {
  border-radius: 10px; padding: 10px 12px;
  box-shadow: var(--shadow); border: 1px solid rgba(0,0,0,.06);
}
.msg .meta {
  font-size: 11.5px; color: var(--muted); margin-bottom: 5px;
  display: flex; gap: 8px; align-items: center;
}
.msg .who { font-weight: 700; }
.msg .body {
  white-space: pre-wrap; line-height: 1.55; font-size: 13px;
}
.msg .translation {
  margin-top: 6px; padding: 6px 10px;
  background: rgba(255,255,255,.75); border-radius: 6px;
  font-size: 12.5px; line-height: 1.55; color: #333;
  border-left: 3px solid #4caf50;
}
.msg .tl-label {
  font-size: 11px; font-weight: 700; color: #2e7d32;
  margin-bottom: 2px;
}

.msg.customer { background: #fff; align-self: flex-start; max-width: 100%; }
.msg.agent { background: #e3f2fd; border-color: #bbdefb; align-self: flex-end; max-width: 100%; }
.msg.agent .translation { border-left-color: #1976d2; }
.msg.agent .tl-label { color: #1565c0; }

/* ---- Column 2: Info (pink) + Input (cyan) ---- */
.col-mid {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

/* Info panel — pink */
.info-panel {
  background: var(--col-info-bg);
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.info-title {
  font-size: 14px; font-weight: 700; margin: 0 0 10px;
  color: #880e4f;
}
.info-grid { display: flex; flex-direction: column; gap: 3px; }
.info-row {
  display: flex; gap: 4px; font-size: 12.5px; line-height: 1.6;
}
.info-row.full { flex-direction: column; }
.info-row .ik {
  color: #ad1457; font-weight: 600; flex-shrink: 0;
  min-width: 95px;
}
.info-row .iv {
  color: var(--text); word-break: break-word;
}

/* Suggestion input panel — cyan */
.suggest-input-panel {
  background: var(--col-input-bg);
  padding: 14px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.si-label {
  font-size: 13px; font-weight: 700; color: #00695c; margin-bottom: 6px;
  display: block;
}
.si-textarea {
  flex: 1; min-height: 140px; resize: vertical;
  border: 2px solid #80deea; border-radius: 8px;
  padding: 10px 12px; font-family: inherit; font-size: 13px;
  line-height: 1.55; outline: none; background: #fff;
}
.si-textarea:focus { border-color: #00acc1; }
.si-generate {
  margin-top: 10px; align-self: flex-start;
  padding: 9px 18px; font-size: 13.5px; font-weight: 600;
}

/* ---- Column 3: Reply output (blue-purple) ---- */
.col-reply {
  background: var(--col-reply-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px 16px;
}
.reply-output {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; min-height: 160px;
  white-space: pre-wrap; line-height: 1.65; font-size: 13.5px;
  overflow: auto;
}
.reply-placeholder {
  color: var(--muted); text-align: center; padding: 40px 20px;
  font-style: italic;
}
.reply-actions {
  display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap;
}
.char-count { font-size: 12px; color: var(--muted); margin-left: auto; }

.note {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: #fff8e1; border: 1px solid #ffe082; color: #795548; font-size: 12px; line-height: 1.5;
}
.note strong { color: #e65100; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50;
}
.toast.show { opacity: 1; }

.empty { padding: 60px; text-align: center; color: var(--muted); }

/* ================================
   AI 对话助手抽屉（右侧滑出）
   ================================ */
.assist-mask {
  position: fixed; inset: 0; background: rgba(20,24,33,.32);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 40;
}
.assist-mask.show { opacity: 1; pointer-events: auto; }

.assist-drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 400px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,.10);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease; z-index: 45;
}
.assist-drawer.open { transform: translateX(0); }

.assist-head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.assist-head strong { font-size: 14.5px; }
.assist-sub { font-size: 11.5px; color: var(--muted); flex: 1; }
.assist-close {
  border: none; background: transparent; font-size: 16px; cursor: pointer;
  color: var(--muted); padding: 2px 6px; border-radius: 6px;
}
.assist-close:hover { background: #f0f2f5; color: var(--text); }

.assist-msgs {
  flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px;
  background: #f7f8fa;
}
.assist-hint {
  font-size: 12px; color: var(--muted); line-height: 1.6;
  background: #fff; border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px;
}

.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }
.bubble {
  max-width: 86%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.msg-row.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg-row.bot .bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 3px; }

/* 助手返回的最终德语回复卡片 */
.reply-card {
  margin-top: 8px; border: 1px solid #c5d8ff; border-radius: 10px; overflow: hidden; background: #fff;
}
.reply-card .rc-head {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  background: #eef3ff; font-size: 12px; font-weight: 700; color: #1d4ed8;
}
.reply-card .rc-body { padding: 10px 12px; font-size: 13px; white-space: pre-wrap; line-height: 1.6; }
.reply-card .rc-cn { padding: 0 12px 8px; font-size: 12px; color: #444; white-space: pre-wrap; line-height: 1.55; }
.reply-card .rc-actions { padding: 8px 12px 10px; display: flex; gap: 8px; }

.assist-input {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--panel);
}
.assist-input textarea {
  flex: 1; resize: none; height: 46px; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-family: inherit; font-size: 13px; line-height: 1.5; outline: none;
}
.assist-input textarea:focus { border-color: var(--accent); }
.assist-input .btn { align-self: flex-end; }

/* ================================
   同步邮件弹窗
   ================================ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,24,33,.4);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
}
.modal-mask.show { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(.96);
  width: 420px; max-width: 92vw; background: var(--panel); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.22); z-index: 61;
  opacity: 0; pointer-events: none; transition: .2s; overflow: hidden;
}
.modal.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.modal-head {
  display: flex; align-items: center; gap: 8px; padding: 14px 18px;
  border-bottom: 1px solid var(--border); background: #fafbfc;
}
.modal-head strong { font-size: 15px; flex: 1; }
.modal-close {
  border: none; background: transparent; font-size: 16px; cursor: pointer;
  color: var(--muted); padding: 2px 6px; border-radius: 6px;
}
.modal-close:hover { background: #f0f2f5; color: var(--text); }
.modal-body { padding: 18px; }
.sync-step { display: flex; flex-direction: column; gap: 10px; }
.sync-step.hidden { display: none; }
.sync-tip { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin: 0 0 4px; }
.sync-label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.sync-input {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
  font-size: 14px; outline: none; background: #fff; width: 100%;
}
.sync-input:focus { border-color: var(--accent); }
.sync-err { color: var(--danger); font-size: 12px; min-height: 14px; }
.sync-go { align-self: flex-start; padding: 9px 20px; font-weight: 600; margin-top: 4px; }
.progress-bar {
  height: 10px; background: #eef1f5; border-radius: 999px; overflow: hidden; margin-top: 6px;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--accent); border-radius: 999px;
  transition: width .4s ease;
}

/* ───────── 访问密码门 ───────── */
.auth-gate {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}
.auth-gate.hidden { display: none; }
.auth-card {
  width: 340px; max-width: 90vw; padding: 36px 30px;
  background: #fff; border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  text-align: center;
}
.auth-logo { font-size: 46px; line-height: 1; }
.auth-title { margin: 12px 0 4px; font-size: 22px; color: #1a1a2e; }
.auth-sub { margin: 0 0 22px; color: #5c6370; font-size: 14px; }
.auth-input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid #d8dce3; border-radius: 10px; outline: none;
  box-sizing: border-box;
}
.auth-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.auth-go { width: 100%; margin-top: 14px; padding: 12px; font-size: 15px; }
.auth-err { color: #dc2626; font-size: 13px; min-height: 18px; margin-top: 10px; }
.auth-foot { margin-top: 16px; font-size: 11px; color: #9aa1ac; }
