:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1c2330; --muted: #6b7280;
  --line: #e2e5ea; --brand: #1f4e8c; --brand-dk: #16386a;
  --ok: #1d8a4c; --warn: #b8860b; --danger: #c0392b;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar { background: var(--brand-dk); color: #fff; padding: 0 20px;
  display: flex; align-items: center; gap: 22px; height: 52px; }
header.topbar .logo { font-weight: 700; font-size: 15px; }
header.topbar nav { display: flex; gap: 16px; flex: 1; }
header.topbar nav a { color: #cdd9ea; font-weight: 500; }
header.topbar nav a:hover, header.topbar nav a.active { color: #fff; text-decoration: none; }
header.topbar .who { color: #aebfd6; font-size: 13px; }

main { max-width: 1080px; margin: 24px auto; padding: 0 20px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 22px 0 10px; color: var(--brand-dk);
  border-bottom: 2px solid var(--line); padding-bottom: 5px; }
.sub { color: var(--muted); margin: 0 0 18px; }

.panel { background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 18px 20px; margin-bottom: 16px; }

.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.cards.cards6 { grid-template-columns: repeat(6, 1fr); }
.card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px; text-align: center; }
.card .n { font-size: 26px; font-weight: 700; }
.card .l { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.card.alert .n { color: var(--danger); }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
  font-size: 13px; vertical-align: top; }
th { background: #eef1f5; color: var(--brand-dk); font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafbfc; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; }
.tag.new { background: #e3edf9; color: var(--brand); }
.tag.inv { background: #fff3d6; color: var(--warn); }
.tag.res { background: #e0f2e6; color: var(--ok); }
.tag.safety { background: #fbe2de; color: var(--danger); }
.tag.repeat { background: #fbe2de; color: var(--danger); }
.tag.age { background: #eef1f5; color: var(--muted); }
.tag.sat-good { background: #e0f2e6; color: var(--ok); }
.tag.sat-mid { background: #fff3d6; color: var(--warn); }
.tag.sat-low { background: #fbe2de; color: var(--danger); }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-bottom: 14px; }
.filter-bar input[type=text], .filter-bar select { width: auto; min-width: 130px; }
th a { color: var(--brand-dk); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--muted); font-weight: 500; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

label { display: block; font-weight: 600; font-size: 12px; margin: 12px 0 3px;
  color: var(--brand-dk); }
input[type=text], input[type=password], input[type=date], input[type=time],
select, textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 6px; font: inherit; background: #fff; }
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 18px; }

button, .btn { display: inline-block; background: var(--brand); color: #fff;
  border: 0; padding: 9px 18px; border-radius: 6px; font: inherit;
  font-weight: 600; cursor: pointer; margin-top: 14px; }
button:hover, .btn:hover { background: var(--brand-dk); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--brand); }

.banner { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-weight: 500; }
.banner.ok { background: #e0f2e6; color: var(--ok); }
.banner.warn { background: #fff3d6; color: var(--warn); }
.banner.err { background: #fbe2de; color: var(--danger); }

.login-wrap { max-width: 340px; margin: 80px auto; }
.muted { color: var(--muted); }
pre.report { background: #fbfbfc; border: 1px solid var(--line); border-radius: 6px;
  padding: 14px; white-space: pre-wrap; font: 13px/1.6 ui-monospace, monospace; }
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 4px 14px; }
.kv dt { font-weight: 600; color: var(--brand-dk); }
.kv dd { margin: 0; }

/* Image attachments */
input[type=file] { display: block; margin: 4px 0 2px; font: inherit; }

.thumbs { display: flex; flex-wrap: wrap; gap: 12px; }
.thumb { position: relative; display: flex; flex-direction: column; align-items: center;
  width: 132px; border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  background: #fbfbfc; }
.thumb.primary { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.thumb-link { display: block; position: relative; }
.thumb img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px;
  background: #eef1f5; transition: filter .12s; }
.thumb-link:hover img { filter: brightness(.92); }
.cover-badge { position: absolute; top: 4px; left: 4px; background: var(--brand);
  color: #fff; font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 4px; }
.chip { margin-top: 5px; font-size: 10px; font-weight: 600; color: var(--brand-dk);
  background: #eef2f8; border-radius: 10px; padding: 1px 8px; }
.thumb-cap { margin-top: 4px; font-size: 12px; color: var(--ink); max-width: 120px;
  text-align: center; word-break: break-word; }
.thumb-name { margin-top: 3px; font-size: 11px; color: var(--muted); max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-edit { margin-top: 6px; width: 120px; font-size: 12px; }
.thumb-edit summary { cursor: pointer; color: var(--brand); }
.thumb-edit input[type=text], .thumb-edit select { font-size: 12px; padding: 4px 6px; margin-top: 4px; }
.thumb-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.thumb-actions form { margin: 0; }

/* Non-image attachments (PDF documents) */
.file-card { padding: 6px 0; font-size: 13px; }
.file-icon { display: inline-block; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 4px; padding: 1px 6px;
  margin-right: 4px; letter-spacing: .04em; }

/* Drag-and-drop upload zone */
.dropzone-target { border: 2px dashed var(--line); border-radius: 8px; padding: 18px;
  text-align: center; cursor: pointer; background: #fcfcfd; }
.dropzone-target.dragover { border-color: var(--brand); background: #eef4fb; }
.progress { height: 18px; background: #eef1f5; border-radius: 9px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; width: 0; background: var(--brand); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center; transition: width .15s; }

/* List / dashboard mini-thumbnails */
.photo-cell { width: 56px; }
.photo-cell a { position: relative; display: inline-block; }
.mini-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 5px;
  border: 1px solid var(--line); vertical-align: middle; background: #eef1f5; }
.count-badge { position: absolute; top: -6px; right: -6px; background: var(--brand-dk);
  color: #fff; font-size: 10px; font-weight: 600; border-radius: 8px; padding: 0 5px; }

/* Notifications bell + panel */
.notif-wrap { position: relative; }
#notif-bell { color: #cdd9ea; font-size: 17px; text-decoration: none; position: relative; }
#notif-bell:hover { color: #fff; }
.notif-badge { position: absolute; top: -7px; right: -10px; background: var(--danger);
  color: #fff; font-size: 10px; font-weight: 700; border-radius: 9px; padding: 1px 5px; }
.notif-panel { position: absolute; right: -10px; top: 34px; width: 360px; max-height: 70vh;
  overflow-y: auto; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 10px 30px rgba(10,12,16,.22); z-index: 800; }
.notif-head { display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
  color: var(--brand-dk); font-size: 13px; }
.linklike { background: none; border: 0; color: var(--brand); cursor: pointer;
  font: inherit; font-size: 12px; padding: 0; margin: 0; }
.linklike:hover { text-decoration: underline; background: none; }
#notif-list { list-style: none; margin: 0; padding: 0; }
.notif-item a { display: block; padding: 9px 14px; border-bottom: 1px solid var(--line);
  color: var(--ink); text-decoration: none; }
.notif-item a:hover { background: #f6f8fb; }
.notif-item.unread a { background: #eef4fb; }
.notif-item.unread a:hover { background: #e3edf9; }
.notif-title { display: block; font-weight: 600; font-size: 13px; }
.notif-body { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.notif-when { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.notif-empty { padding: 14px; display: block; }
.notif-foot { padding: 9px 14px; border-top: 1px solid var(--line); font-size: 12px; }

/* Watch bar on the complaint detail page */
.watch-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.btn-watch { padding: 4px 12px; font-size: 12px; margin: 0; }
.btn-watch.sm { font-size: 11px; padding: 3px 9px; }
.btn-watch.watching { background: var(--brand); color: #fff; }

/* Typeahead combobox */
.ta-wrap { position: relative; }
.ta-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
  margin: 2px 0 0; padding: 4px; list-style: none; background: #fff;
  border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 6px 18px rgba(20,30,50,.12); max-height: 260px; overflow-y: auto; }
.ta-list li { padding: 6px 9px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.ta-list li:hover, .ta-list li.active { background: #eef4fb; color: var(--brand-dk); }

/* Related panel (similar / duplicate / repeat hits) */
.related-panel { border-left: 4px solid var(--warn); }
.related-row { display: block; width: 100%; text-align: left; background: #fbfbfc;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
  margin: 0 0 6px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); }
.related-row:hover { background: #eef4fb; }
.related-row strong { color: var(--brand); }
.related-row.kind-possible_duplicate { border-left: 4px solid var(--danger); }
.related-row.kind-similar { border-left: 4px solid var(--warn); }
.related-row.kind-repeat { border-left: 4px solid var(--brand); }
.related-snippet { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

/* Peek drawer (read-only complaint preview) */
.peek-backdrop { position: fixed; inset: 0; background: rgba(10,12,16,.45); z-index: 900; }
.peek-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line); z-index: 950;
  padding: 20px 22px; overflow-y: auto; box-shadow: -8px 0 30px rgba(10,12,16,.18); }
.peek-close { position: absolute; top: 10px; right: 12px; background: none;
  border: 0; font-size: 24px; color: var(--muted); cursor: pointer; padding: 4px 8px; margin: 0; }
.peek-close:hover { color: var(--ink); background: none; }
.peek-kv { grid-template-columns: 120px 1fr; }
.peek-h3 { font-size: 13px; margin: 14px 0 4px; color: var(--brand-dk); }
.peek-details { margin: 0; font-size: 13px; white-space: pre-wrap; }

/* Team discussion thread (v1.5) */
.thread { margin-bottom: 14px; }
.comment { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  margin-bottom: 8px; background: #fbfbfc; }
.comment.mine { background: #eef4fb; border-color: #d6e3f3; }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 12px;
  margin-bottom: 5px; }
.comment-body { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.chip.role-cs { background: #e3edf9; color: var(--brand); }
.chip.role-factory { background: #fff3d6; color: var(--warn); }
.chip.role-admin { background: #e0f2e6; color: var(--ok); }
.chip.role-management { background: #eef2f8; color: var(--brand-dk); }

/* Stored reports */
.report-grid { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 14px; }
.report-grid svg.chart { background: #fbfbfc; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; }
.report-table { width: auto; min-width: 320px; margin: 10px 0; }
.report-body h2 { margin-top: 18px; }
.report-body h3 { font-size: 14px; color: var(--brand-dk); margin: 14px 0 6px; }
.report-body ul { margin: 6px 0 10px 20px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(10,12,16,.88); z-index: 1000;
  align-items: center; justify-content: center; }
.lb-figure { margin: 0; max-width: 90vw; max-height: 90vh; text-align: center; }
.lb-img { max-width: 90vw; max-height: 82vh; border-radius: 6px; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
.lb-cap { color: #e7ebf2; margin-top: 10px; font-size: 14px; }
.lb-btn { position: absolute; background: rgba(255,255,255,.12); color: #fff; border: 0;
  font-size: 28px; line-height: 1; cursor: pointer; border-radius: 8px; padding: 6px 14px; }
.lb-btn:hover { background: rgba(255,255,255,.25); }
.lb-close { top: 18px; right: 22px; }
.lb-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 18px; top: 50%; transform: translateY(-50%); }

/* ===== v1.6: mail thread + AI panel ===== */
.mail-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.chip.danger { background: #fde8e8; color: #b42318; border-color: #f5c2c0; }
.ai-panel .ai-output {
  margin-top: 10px; padding: 12px 14px; background: var(--panel-alt, #f6f8fa);
  border: 1px solid var(--border, #d8dee4); border-radius: 8px;
  white-space: pre-wrap; font-size: 14px; line-height: 1.5;
}
.ai-thread { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ai-msg {
  max-width: 85%; padding: 8px 12px; border-radius: 10px;
  white-space: pre-wrap; font-size: 14px; line-height: 1.5;
  border: 1px solid var(--border, #d8dee4);
}
.ai-msg.user { align-self: flex-end; background: var(--accent-soft, #eef4ff); }
.ai-msg.assistant { align-self: flex-start; background: var(--panel-alt, #f6f8fa); }
.ai-msg.pending { opacity: .6; font-style: italic; }
.ai-msg-actions { display: block; margin-top: 6px; }
.ai-msg-actions .linklike { margin-right: 10px; font-size: 12px; }
.ai-panel form { margin-top: 10px; }

/* ===== v1.7: autofill chips, mentions, read-only values ===== */
.autofill-chip {
  display: inline-block; margin: 6px 0 0; padding: 3px 10px; font-size: 12px;
  background: #eef8ee; color: #1a7f37; border: 1px solid #bfe5c8;
  border-radius: 999px;
}
.autofill-chip .linklike { margin-left: 4px; color: inherit; }
/* v1.9 (C1/H6): suggestion chip — shown under a field that already holds a
   DIFFERENT value; clicking the value applies it (never auto-overwrites). Amber
   to read as a *proposal* distinct from the green "auto-filled" confirmation. */
.autofill-suggest {
  display: inline-flex; align-items: center; gap: 2px; margin: 5px 0 0;
  padding: 3px 8px 3px 10px; font-size: 12px; background: #fff7e6;
  color: #8a5a00; border: 1px solid #f0d49a; border-radius: 999px;
}
.autofill-suggest .as-label { color: #9a7330; }
.autofill-suggest .as-apply { color: #8a5a00; font-weight: 600; }
.autofill-suggest .as-dismiss { color: #b08a45; font-size: 14px; line-height: 1; }
/* v1.9 (B): disambiguation chooser when an LLM extraction matches >1 entity. */
.entity-picker {
  margin: 6px 0 0; border: 1px solid var(--border, #d8dee4); border-radius: 8px;
  background: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.10); max-width: 520px;
  overflow: hidden;
}
.entity-picker .ep-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--brand-dk);
  background: #f3f6fb; border-bottom: 1px solid var(--line);
}
.entity-picker .ep-dismiss { color: var(--muted); font-size: 15px; line-height: 1; }
.entity-picker .ep-row {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  margin: 0; padding: 7px 10px; font: inherit; font-size: 13px; color: var(--ink);
  cursor: pointer; border-bottom: 1px solid var(--line);
}
.entity-picker .ep-row:last-child { border-bottom: 0; }
.entity-picker .ep-row:hover, .entity-picker .ep-row:focus {
  background: var(--accent-soft, #eef4ff); outline: none;
}
.mention {
  background: #eef4ff; color: #1f4fa3; border-radius: 4px; padding: 0 3px;
  font-weight: 600;
}
.ro-value { display: inline-block; padding: 6px 0; font-weight: 600; }
/* v1.10: save-as-new-product panel + the picker's action rows. */
.new-product-panel { margin: 8px 0 4px; padding: 10px 12px; border: 1px dashed var(--line);
  border-radius: 6px; background: #fbfdff; }
.new-product-panel [data-new-product-confirm] { margin-left: 8px; }
.ep-row.ep-action { font-weight: 600; border-top: 1px solid var(--line); }
/* v1.9 (E): read-only Factory Notes display (appended via "Add Factory Notes"). */
.ro-notes { white-space: pre-wrap; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: #f7f9fc; min-height: 38px; max-height: 220px;
  overflow-y: auto; font-size: 13px; color: var(--ink); }
[data-mention-list] { position: relative; }
[data-mention-list] .ta-item {
  padding: 6px 10px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--border, #e3e8ee);
}
[data-mention-list] .ta-item.active,
[data-mention-list] .ta-item:hover { background: var(--accent-soft, #eef4ff); }
div[data-mention-list]:not([hidden]) {
  border: 1px solid var(--border, #d8dee4); border-radius: 8px;
  background: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.08);
  max-width: 360px; margin-top: -6px;
}

/* v1.8 (item 13): field-help info button + tooltip */
.fieldhelp { display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin: 0 0 0 4px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: #eef1f6; color: var(--brand-dk);
  font: 600 10px/1 sans-serif; cursor: help; vertical-align: middle; }
.fieldhelp:hover, .fieldhelp:focus { background: var(--brand); color: #fff; outline: none; }
.fieldhelp-tip { position: absolute; z-index: 60; max-width: 320px; padding: 8px 10px;
  background: var(--ink); color: #fff; border-radius: 6px; font-size: 12px;
  line-height: 1.45; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
[data-draft-status] { font-size: 12px; color: var(--ok); }

/* v1.8 (D12): first-login guided tour overlay */
.tour-backdrop { position: fixed; inset: 0; background: rgba(10,16,26,.45); z-index: 90; }
.tour-popover { position: absolute; z-index: 91; width: 320px; max-width: 90vw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px; box-shadow: 0 8px 26px rgba(0,0,0,.28); }
.tour-popover h3 { margin: 0 0 6px; font-size: 15px; color: var(--brand-dk); }
.tour-popover p { margin: 0 0 12px; font-size: 13px; }
.tour-actions { display: flex; gap: 8px; justify-content: flex-end; }
.tour-highlight { position: relative; z-index: 92; outline: 3px solid var(--brand);
  outline-offset: 2px; border-radius: 4px; }
