/* ── Issue tracking (Profile → Issues) ─────────────────────────────────────────────────────────────
   A support desk grafted onto the ClaimGuard ledger design system: same paper, same pills, same type
   scale — but the ticket page reads as a conversation. Bubbles are sided by WHO IS READING, not by
   role: the operator sees their own replies on the right and the reporter sees theirs there, so both
   sides read the same thread as "my chat". Tokens come from app.css; nothing here redefines a colour. */

/* ── Account section tabs (Profile ⇄ Issues) ────────────────────────────────────────────────────── */
.acct-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.acct-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .14s ease, border-color .14s ease;
}
.acct-tab svg { width: 15px; height: 15px; }
.acct-tab:hover { color: var(--ink-2); }
.acct-tab.on { color: var(--brand); border-bottom-color: var(--brand); }
.acct-badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--risk); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* Sidebar badge. The nav sits on --ink, so this is the one place the risk colour is used as a
   solid fill rather than a tinted background. margin-left:auto pushes it to the nav item's edge. */
.nav-badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--risk); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ── List: toolbar, grouping, rows ──────────────────────────────────────────────────────────────── */
.issue-toolbar {
  display: flex; gap: 14px; align-items: center; justify-content: space-between;
  flex-wrap: wrap; margin-bottom: 14px;
}
.issue-search { display: flex; gap: 8px; align-items: center; }
.issue-search input {
  font-family: var(--font-ui); font-size: 13px; padding: 7px 12px; min-width: 240px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
}
.issue-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ok-bg); }
.issue-search .btn { padding: 6px 13px; font-size: 12.5px; border-radius: 999px; }
.issue-search .btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* The "Unread" chip. Tinted rather than solid so it reads as urgent without competing with the
   selected-chip state (.chip.on is solid ink); when it IS selected, ink wins as usual. */
.chip.alert { color: var(--risk); background: var(--risk-bg); border-color: var(--risk-line); }
.chip.alert:hover { border-color: var(--risk); }
.chip.alert.on { background: var(--risk); color: #fff; border-color: var(--risk); }

.issue-group { margin-bottom: 16px; }
.issue-group .card-head h3 { display: flex; align-items: center; gap: 8px; }

.issue-table td { vertical-align: top; }
.issue-table .issue-title { font-weight: 500; color: var(--ink); }
.issue-table .is-unread .issue-title { font-weight: 700; }
.issue-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted); margin-top: 3px;
}
/* .tag is mono by default (fiscal codes); these are words, so borrow the UI face. */
.tag.subtle { font-family: var(--font-ui); letter-spacing: 0; }
/* Reply/attachment counts. Inline SVG rather than emoji — Inter has no emoji glyphs. */
.meta-icon { display: inline-flex; align-items: center; gap: 4px; }
.meta-icon svg { width: 12px; height: 12px; }

.unread-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--risk); box-shadow: 0 0 0 3px var(--risk-bg);
}

.empty-state {
  text-align: center; padding: 44px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty-state .empty-mark { width: 34px; height: 34px; color: var(--line); }
.empty-state p { margin: 0 0 8px; }

/* ── Ticket page shell: thread left, controls right ─────────────────────────────────────────────── */
.issue-layout {
  display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
  gap: 20px; align-items: start;
}
.issue-head { align-items: flex-start; }
.issue-head-pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.issue-side { display: flex; flex-direction: column; gap: 20px; }

/* Status explainer — colour-matched to the pill it describes, so the state is legible at a glance
   even before the words are read. */
.issue-banner {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 14px 18px; margin-bottom: 20px;
  font-size: 13.5px; line-height: 1.55;
}
.issue-banner .ib-mark { width: 4px; align-self: stretch; border-radius: 2px; background: var(--muted); flex: 0 0 auto; }
.issue-banner b { display: block; margin-bottom: 2px; }
.issue-banner.k-ok      { background: var(--ok-bg);      border-color: var(--ok-line); }
.issue-banner.k-ok      .ib-mark { background: var(--ok); }
.issue-banner.k-warn    { background: var(--warn-bg);    border-color: var(--warn-line); }
.issue-banner.k-warn    .ib-mark { background: var(--warn); }
.issue-banner.k-risk    { background: var(--risk-bg);    border-color: var(--risk-line); }
.issue-banner.k-risk    .ib-mark { background: var(--risk); }
.issue-banner.k-pending { background: var(--pending-bg); border-color: var(--pending-line); }
.issue-banner.k-pending .ib-mark { background: var(--pending); }

/* ── The conversation ───────────────────────────────────────────────────────────────────────────── */
.thread {
  display: flex; flex-direction: column; gap: 16px;
  padding: 20px 22px; max-height: 60vh; overflow-y: auto;
  background: var(--surface);
}
.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 86%; }
.msg.me { flex-direction: row-reverse; align-self: flex-end; }
.avatar-sm {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--pending-bg); color: var(--pending); border: 1px solid var(--pending-line);
}
.msg.staff .avatar-sm { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.bubble {
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px;
  background: var(--surface-2); min-width: 0;
}
.msg.me .bubble { background: var(--ok-bg); border-color: var(--ok-line); }
.msg-meta {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted); margin-bottom: 4px;
}
.msg-meta b { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
.msg-body:empty { display: none; }
.msg-status { margin-top: 7px; font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* A status change with nothing to say: a labelled rule across the thread, not an empty bubble. */
.status-rule { display: flex; align-items: center; gap: 9px; font-size: 11.5px; padding: 2px 0; }
.status-rule::before, .status-rule::after { content: ""; height: 1px; background: var(--line-2); flex: 1; }
.status-rule::before { flex: 0 0 12px; }

/* Where the reader's attention should land: everything below arrived since they last opened this. */
.new-rule {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; color: var(--risk); text-transform: uppercase; letter-spacing: .1em; font-weight: 700;
}
.new-rule::before, .new-rule::after { content: ""; height: 1px; background: var(--risk-line); flex: 1; }

/* ── Attachments inside a bubble ────────────────────────────────────────────────────────────────── */
.att-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 9px; }
.att-img img {
  width: 84px; height: 84px; object-fit: cover; display: block;
  border-radius: 8px; border: 1px solid var(--line);
}
.att-img:hover img { border-color: var(--brand); }
.att-file {
  display: inline-flex; align-items: center; gap: 7px; max-width: 220px;
  padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  font-size: 12.5px; color: var(--ink-2);
}
.att-file:hover { border-color: var(--brand); }
.att-file svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--muted); }
.att-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file small { color: var(--muted); flex: 0 0 auto; }

/* ── Composer ───────────────────────────────────────────────────────────────────────────────────── */
.composer { border-top: 1px solid var(--line-2); padding: 14px 22px 16px; display: flex; flex-direction: column; gap: 10px; }
/* app.css styles .field input/select but not textarea — cover every textarea this feature uses. */
.composer textarea, .field textarea, .status-form textarea, .verdict-card textarea {
  font-family: var(--font-ui); font-size: 14px; padding: 10px 12px; width: 100%; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); resize: vertical;
}
.composer textarea:focus, .field textarea:focus, .status-form textarea:focus, .verdict-card textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ok-bg);
}
.composer-foot { display: flex; align-items: center; gap: 10px; }
.attach-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  padding: 7px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.attach-btn:hover { border-color: var(--ink-2); }
.attach-btn svg { width: 14px; height: 14px; }
.attach-btn input[type=file] { display: none; }
.attach-names {
  font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px;
}
.composer-closed { border-top: 1px solid var(--line-2); padding: 16px 22px; font-size: 13px; }

/* ── Operator controls + sidebar cards ──────────────────────────────────────────────────────────── */
.status-form { display: flex; flex-direction: column; gap: 12px; }
.triage-form { border-top: 1px solid var(--line-2); padding-top: 12px; }
.triage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.verdict-card { border-color: var(--ok-line); }

.detail-list { display: flex; flex-direction: column; gap: 9px; font-size: 13px; }
.detail-list > div { display: flex; justify-content: space-between; gap: 14px; }
.detail-list > div > span:last-child { text-align: right; }

.timeline { display: flex; flex-direction: column; gap: 14px; font-size: 12.5px; }
.tl-item { display: flex; gap: 10px; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; background: var(--muted); }
.tl-dot.k-ok      { background: var(--ok); }
.tl-dot.k-warn    { background: var(--warn); }
.tl-dot.k-risk    { background: var(--risk); }
.tl-dot.k-pending { background: var(--pending); }
.tl-when { font-size: 11px; margin-top: 2px; }

/* ── Category picker on the report form ─────────────────────────────────────────────────────────── */
.cat-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.cat-opt { position: relative; }
/* The radio stays in the layout (not display:none) so it keeps keyboard focus and arrow-key group
   navigation; it is the paired <label for> that is actually clicked and painted. */
.cat-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.cat-opt > label {
  display: block; cursor: pointer; font-weight: 400;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .14s ease, background .14s ease;
}
.cat-opt > label b { display: block; font-size: 13.5px; color: var(--ink-2); }
.cat-opt > label small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.cat-opt > label:hover { border-color: var(--ink-2); }
.cat-opt input:checked + label { border-color: var(--brand); background: var(--ok-bg); box-shadow: 0 0 0 1px var(--brand); }
.cat-opt input:focus-visible + label { box-shadow: 0 0 0 3px var(--ok-bg); }

@media (max-width: 1080px) {
  .issue-layout { grid-template-columns: 1fr; }
  .msg { max-width: 100%; }
  .issue-search input { min-width: 0; flex: 1; }
}

/* ── Issues ⇄ Document issues: the two lists ─────────────────────────────────────────────────────
   Sits above the bucket filters, so the page reads "which list" then "which slice of it". */
.issue-kinds { margin-bottom: 14px; }
.issue-kinds .chip { font-weight: 500; }
.issue-kinds .chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
/* A bare dot, not a number: the count is already on the tab you're not looking at. */
.issue-kinds .dot {
    width: 6px; height: 6px; border-radius: 50%; background: var(--risk);
    display: inline-block; margin-left: 5px; vertical-align: middle;
}

/* ── The documents panel on a system-generated batch ticket ────────────────────────────────────── */
.doc-issues { margin-bottom: 16px; }
.doc-issues .card-head .hint { font-size: 12.5px; }
.doc-issues td { vertical-align: top; }
.doc-issues .tag.subtle + .tag.subtle { margin-left: 4px; }
.doc-issues form { margin-left: 6px; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 999px; }

/* ── Batch grouping on the invoice ledger ───────────────────────────────────────────────────────
   A band rather than a nested table: keeps one set of column widths down the whole page. */
.ledger tr.batch-head td {
    background: var(--line-1, #f6f7f8); font-weight: 600; font-size: 12.5px;
    padding-top: 9px; padding-bottom: 9px; border-top: 1px solid var(--line);
}
.ledger tr.batch-head .muted { font-weight: 400; margin-left: 6px; }
.ledger tr.batch-head .pill { margin-left: 8px; }

/* Filename in the documents panel opens the PDF — make it read as a link without shouting. */
.doc-issues .doc-link { color: var(--brand); text-decoration: none; }
.doc-issues .doc-link:hover { text-decoration: underline; }
