:root{
  --chat-bg:#f5f7f8;
  --chat-panel:#ffffff;
  --chat-line:#d8dee4;
  --chat-text:#17202a;
  --chat-muted:#64707d;
  --chat-accent:#16845b;
  --chat-accent-soft:#e7f5ee;
  --chat-ai:#eef2ff;
  --chat-staff:#f2f8f5;
  --chat-warn:#fff5dd;
}

body[data-report-mode="concern"]{
  --chat-accent:#b56524;
  --chat-accent-soft:#fff1e5;
}

*{ box-sizing:border-box; }

body[data-page="report_chat"]{
  background:var(--chat-bg);
}

.report-chat-page{
  height:100%;
  color:var(--chat-text);
}

.chat-search-bar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  gap:6px;
  padding:6px 8px;
  border-bottom:1px solid var(--chat-line);
  background:#fff;
}

.chat-search-modes{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  border:1px solid var(--chat-line);
  border-radius:7px;
  overflow:hidden;
  background:#f8fafb;
}

.chat-search-mode{
  appearance:none;
  border:0;
  border-right:1px solid var(--chat-line);
  min-width:42px;
  height:30px;
  padding:0 9px;
  background:transparent;
  color:var(--chat-muted);
  font-size:12px;
  font-weight:700;
  cursor:pointer;
}

.chat-search-mode:last-child{
  border-right:0;
}

.chat-search-mode.is-active{
  background:var(--chat-accent);
  color:#fff;
}

.chat-search-input{
  flex:1 1 auto;
  min-width:0;
  height:32px;
  border:1px solid var(--chat-line);
  border-radius:7px;
  padding:0 10px;
  background:#fff;
  color:var(--chat-text);
  font:inherit;
  font-size:13px;
}

.chat-search-input:focus{
  outline:none;
  border-color:#8bb9a6;
  box-shadow:0 0 0 3px rgba(22,132,91,.12);
}

.chat-search-clear{
  flex:0 0 auto;
  width:32px;
  height:32px;
  border:1px solid var(--chat-line);
  border-radius:7px;
  background:#fff;
  color:var(--chat-muted);
  font-size:18px;
  line-height:1;
  cursor:pointer;
}

.chat-toolbar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:2px 10px 3px;
  border-bottom:1px solid var(--chat-line);
  background:#fff;
}

.chat-title{
  margin:0;
  font-size:16px;
  line-height:1.2;
  font-weight:700;
}

.chat-status{
  margin-left:0;
  font-size:11px;
  color:var(--chat-muted);
  white-space:nowrap;
}

.medical-line-b5{
  flex:0 0 auto;
  max-height:46vh;
  overflow:auto;
  border-bottom:1px solid #d6c58e;
  background:#fffaf0;
}

.medical-line-b5-head{
  position:sticky;
  top:0;
  z-index:2;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:8px 10px;
  border-bottom:1px solid #eadcae;
  background:#fff7df;
}

.medical-line-b5-head > div{
  display:flex;
  align-items:baseline;
  gap:10px;
  min-width:0;
}

.medical-line-b5-head strong{
  color:#72510b;
  font-size:14px;
  white-space:nowrap;
}

.medical-line-b5-head span{
  color:#806f48;
  font-size:11px;
}

.medical-line-b5-head button,
.medical-line-b5-actions button{
  border:1px solid #b18a31;
  border-radius:6px;
  background:#946d17;
  color:#fff;
  font-weight:700;
  cursor:pointer;
}

.medical-line-b5-head button{
  height:30px;
  padding:0 12px;
}

.medical-line-b5-list{
  display:grid;
  gap:8px;
  padding:8px;
}

.medical-line-b5-empty{
  padding:12px;
  color:#806f48;
  text-align:center;
  font-size:12px;
}

.medical-line-b5-card{
  max-width:760px;
  width:100%;
  margin:0 auto;
  padding:9px;
  border:1px solid #dfcf9e;
  border-radius:8px;
  background:#fff;
  box-shadow:0 2px 8px rgba(73,55,14,.08);
}

.medical-line-b5-meta{
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:7px;
  color:#6a6252;
  font-size:11px;
}

.medical-line-b5-meta strong{
  color:#5c430b;
  font-size:13px;
}

.b5-confidence{
  margin-left:auto;
  padding:2px 7px;
  border-radius:999px;
  background:#f0ece2;
  font-weight:700;
}

.b5-confidence.high{ background:#e5f5eb; color:#17663b; }
.b5-confidence.medium{ background:#fff0c9; color:#805800; }
.b5-confidence.low{ background:#fde5e5; color:#9a2f2f; }

.medical-line-b5-source{
  margin-top:7px;
  padding:7px 9px;
  border-left:3px solid #c5ae6c;
  background:#faf7ef;
}

.medical-line-b5-source > span,
.medical-line-b5-field > span{
  display:block;
  margin-bottom:3px;
  color:#756744;
  font-size:10px;
  font-weight:700;
}

.medical-line-b5-source > div{
  white-space:pre-wrap;
  font-size:12px;
  line-height:1.45;
}

.medical-line-b5-field{
  display:block;
  margin-top:7px;
}

.medical-line-b5-field select,
.medical-line-b5-field textarea{
  width:100%;
  border:1px solid #cfc7b5;
  border-radius:6px;
  background:#fff;
  color:var(--chat-text);
  font:inherit;
}

.medical-line-b5-field select{
  height:34px;
  padding:0 8px;
}

.medical-line-b5-field textarea{
  min-height:92px;
  padding:8px;
  resize:vertical;
  line-height:1.5;
}

.medical-line-b5-reason{
  margin-top:6px;
  color:#756f62;
  font-size:11px;
  line-height:1.4;
}

.medical-line-b5-actions{
  display:flex;
  justify-content:flex-end;
  gap:8px;
  margin-top:8px;
}

.medical-line-b5-actions button{
  min-height:34px;
  padding:6px 12px;
}

.medical-line-b5-actions button:disabled{
  opacity:.55;
  cursor:wait;
}

.medical-line-b5-actions button.secondary{
  border-color:#b7ad98;
  background:#fff;
  color:#665f52;
}

.chat-refresh{
  border:1px solid var(--chat-line);
  background:#fff;
  color:var(--chat-text);
  border-radius:6px;
  min-width:36px;
  height:32px;
  font-weight:700;
  cursor:pointer;
}

.chat-list{
  flex:1 1 auto;
  min-height:0;
  overflow:auto;
  padding:10px 8px 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.68), rgba(245,247,248,.86)),
    url("/tools/sakura01.png") center center / cover no-repeat;
}

.chat-empty,
.chat-error{
  margin:20px auto;
  max-width:520px;
  padding:14px;
  border:1px solid var(--chat-line);
  border-radius:8px;
  background:#fff;
  color:var(--chat-muted);
  text-align:center;
}

.report-thread{
  max-width:760px;
  margin:0 auto 12px;
  display:flex;
  justify-content:flex-start;
}

.report-content{
  min-width:0;
  width:min(100%, 620px);
  display:grid;
  grid-template-columns:46px minmax(0, 1fr);
  align-items:start;
  column-gap:2px;
}

.report-speaker{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:2px;
  padding:9px 0 0;
  color:var(--chat-muted);
  font-size:11px;
  line-height:1.25;
  text-align:left;
}

.report-read-count{
  color:inherit;
  font-weight:inherit;
}

.report-thread.own .report-speaker{
  justify-content:flex-start;
}

.report-thread.own{
  justify-content:flex-end;
}

.report-thread.own .report-content{
  grid-template-columns:minmax(0, 1fr) 46px;
}

.report-thread.own .report-content{
  width:min(100%, 620px);
}

.report-thread.own .report-speaker{
  grid-column:2;
  grid-row:1;
  text-align:left;
}

.report-thread.own .report-bubble{
  grid-column:1;
  grid-row:1;
}

.report-thread.own .report-bubble{
  background:#f1fbf5;
  border-color:#bee2cd;
}

.report-bubble{
  min-width:0;
  border:1px solid var(--chat-line);
  border-radius:8px;
  background:var(--chat-panel);
  box-shadow:0 4px 12px rgba(23,32,42,.06);
  overflow:hidden;
  position:relative;
}

.report-head{
  border-radius:8px 8px 0 0;
  overflow:hidden;
}

.report-meta{
  border-radius:0 0 8px 8px;
  overflow:hidden;
}

.report-head{
  display:flex;
  align-items:center;
  gap:6px;
  padding:8px 10px 4px;
}

.resident-name{
  font-size:14px;
  font-weight:700;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.report-body{
  padding:0 10px 8px;
  font-size:14px;
  line-height:1.55;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
}

.report-meta{
  display:flex;
  align-items:center;
  gap:4px;
  padding:6px 10px;
  border-top:1px solid #eef1f3;
  color:var(--chat-muted);
  font-size:12px;
}

.report-action{
  margin:0;
  border:none;
  background:transparent;
  color:var(--chat-muted);
  border-radius:0;
  height:auto;
  padding:0;
  font-size:12px;
  line-height:1.3;
  cursor:pointer;
  text-decoration:none;
  text-underline-offset:2px;
  min-width:0;
}

.report-action-spacer{
  flex:1 1 auto;
}

.report-action-sep{
  color:#c2cbd2;
  padding:0 2px;
}

.report-action.delete{
  color:#9b2d2d;
}

.report-action.has-comments{
  color:#126342;
  font-weight:700;
}

.report-action.ai-link.has-comments{
  color:#4054a8;
}

.report-action:hover{
  color:var(--chat-text);
}

.chat-edit-cancel{
  flex:0 0 auto;
  align-self:center;
  border:1px solid #d7b85b;
  border-radius:6px;
  background:#fff8df;
  color:#735414;
  height:26px;
  padding:0 8px;
  font-size:11px;
  cursor:pointer;
}

.file-strip{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  padding:0 10px 8px;
}

.file-strip .thumb-list{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
}

.file-strip .thumb-item,
.file-thumb-button{
  appearance:none;
  border:0;
  padding:0;
  background:transparent;
  cursor:pointer;
}

.file-thumb{
  width:54px;
  height:54px;
  border:1px solid var(--chat-line);
  border-radius:6px;
  object-fit:cover;
  background:#f8fafb;
}

.file-strip .file-chip{
  appearance:none;
  width:86px;
  min-height:34px;
  border:1px solid var(--chat-line);
  border-radius:6px;
  padding:5px;
  background:#f8fafb;
  font-size:11px;
  color:var(--chat-muted);
  overflow:hidden;
  cursor:pointer;
  text-align:left;
}

.comment-tree{
  margin:0;
  padding:0;
  border-top:1px solid #e4e9ed;
  border-radius:0;
  position:relative;
  background:#fbfcfd;
}

.comment-tree.ai-tree{
  margin:8px 10px 10px;
  border:1px solid #cfddd5;
  border-radius:7px;
  background:#f7faf8;
}

.comment-tree.ai-tree > div{
  padding:6px 10px;
}

.ai-stage-panel{
  display:grid;
  gap:0;
}

.ai-stage-row{
  display:grid;
  grid-template-columns:minmax(0, 1fr) 52px;
  align-items:center;
  gap:12px;
  padding:5px 2px;
  color:#263640;
  font-size:12px;
}

.ai-stage-row + .ai-stage-row{
  border-top:1px solid #e2ebe6;
}

.ai-stage-result{
  text-align:center;
}

.ai-stage-result.is-ok{
  color:#18733f;
}

.ai-stage-result.is-ng{
  color:#b3261e;
}

.ai-stage-result.is-pending{
  color:#76828a;
}

.comment-tree::before{
  content:none;
}

.comment-tree > div{
  width:auto;
  margin:0;
  padding:3px 10px 6px;
  border:0;
  border-radius:0;
  background:transparent;
}

.comment-add-row{
  padding-top:4px;
}

.comment-add{
  border:none;
  background:transparent;
  color:#126342;
  padding:0;
  font-size:12px;
  cursor:pointer;
}

.comment-tree[hidden]{
  display:none;
}

.comment-node{
  position:relative;
  display:flex;
  align-items:baseline;
  gap:10px;
  margin:0;
  padding:2px 0 3px;
  border:none;
  border-radius:0;
  background:transparent;
  border-bottom:none;
}

.comment-node:last-child{
  border-bottom:none;
}

.comment-node + .comment-node{
  margin-top:4px;
  padding-top:8px;
  border-top:1px solid #edf0f2;
}

.comment-node.ai{
  background:transparent;
  border-color:transparent;
}

.comment-node.staff{
  background:transparent;
  border-color:transparent;
}

.comment-node.system{
  background:transparent;
}

.b5-inline-status{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

.b5-inline-status .comment-text{
  min-width:0;
}

.comment-head{
  display:flex;
  align-items:center;
  gap:6px;
  flex:0 0 auto;
  margin:0 0 0 auto;
  color:var(--chat-muted);
  font-size:11px;
  white-space:nowrap;
  justify-content:flex-end;
}

.comment-delete{
  margin-left:0;
  border:none;
  background:transparent;
  color:#9b2d2d;
  padding:0;
  font:inherit;
  cursor:pointer;
  text-decoration:underline;
  text-underline-offset:2px;
}

.comment-author{
  color:var(--chat-text);
  font-weight:700;
}

.comment-type{
  border:1px solid currentColor;
  border-radius:999px;
  padding:1px 6px;
  font-size:10px;
  line-height:1.4;
}

.comment-text{
  flex:1 1 auto;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  font-size:13px;
  line-height:1.45;
  color:var(--chat-text);
  min-width:0;
}

.comment-tree:not(.ai-tree) .comment-text{
  padding-left:1em;
  color:#0b5f3a;
  font-weight:650;
}

.native-comment-node{
  display:block;
  padding:0;
}

.native-comment-node + .native-comment-node{
  margin-top:0;
  padding-top:0;
  border-top:0;
}

.comment-speaker{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:1px;
  color:var(--chat-muted);
  font-size:10px;
  line-height:1;
  padding:5px 0 0;
}

.comment-main{
  min-width:0;
  padding:4px 10px 5px;
  border:1px solid var(--chat-line);
  border-top:0;
  background:var(--chat-panel);
}

.native-comment-node .comment-text{
  padding-left:0;
}

.comment-meta-line{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  min-height:16px;
  margin-top:2px;
  color:var(--chat-muted);
  font-size:10px;
  line-height:1.2;
  text-align:right;
}

.comment-meta-author{
  margin-left:auto;
  white-space:nowrap;
}

.native-comment-node .comment-meta-line .comment-delete{
  display:block;
  margin:0 auto 0 0;
}

.report-content > .comment-tree{
  grid-column:2;
  margin:0;
  padding:0;
  border:0;
  border-radius:0;
  background:transparent;
}

.report-thread.own .report-content > .comment-tree{
  grid-column:1;
}

.report-content > .comment-tree:not(.ai-tree) > div{
  padding:0;
}

.report-content > .comment-tree:not([hidden]) ~ .report-bubble,
.report-content:has(> .comment-tree:not([hidden])) > .report-bubble{
  border-radius:8px 8px 0 0;
}

.report-content > .comment-tree:not(.ai-tree) .native-comment-node:last-child .comment-main{
  border-radius:0 0 8px 8px;
}

.report-content > .comment-tree.ai-tree{
  grid-column:2;
  margin:4px 0 0;
}

.report-thread.own .report-content > .comment-tree.ai-tree{
  grid-column:1;
}

.comment-inline-link{
  display:inline;
  margin:0;
  padding:0;
  border:0;
  background:transparent;
  color:#1565c0;
  font:inherit;
  font-weight:700;
  text-decoration:underline;
  text-underline-offset:2px;
  cursor:pointer;
}

.ai-status{
  cursor:pointer;
  font-weight:700;
}

.ai-status.is-ok{
  color:#18733f;
}

.ai-status.is-ng{
  color:#b3261e;
}

.comment-prn-detail{
  margin-top:6px;
  padding:8px 10px;
  border-left:3px solid #8bb8e8;
  border-radius:4px;
  background:#f3f8fd;
  color:#263640;
  font-weight:400;
  white-space:pre-wrap;
}

.comment-prn-detail[hidden]{
  display:none;
}

.comment-form{
  display:flex;
  gap:6px;
  align-items:flex-end;
  margin:8px 0 2px;
}

.comment-input{
  flex:1 1 auto;
  min-width:0;
  min-height:36px;
  max-height:120px;
  resize:vertical;
  border:1px solid var(--chat-line);
  border-radius:8px;
  padding:8px 10px;
  font:inherit;
  line-height:1.45;
  background:#fff;
}

.comment-send{
  flex:0 0 auto;
  border:none;
  border-radius:8px;
  min-width:54px;
  height:36px;
  padding:0 12px;
  background:var(--chat-accent);
  color:#fff;
  font-weight:700;
  cursor:pointer;
}

.comment-send:disabled{
  opacity:.55;
  cursor:wait;
}

@media (max-width:640px){
  .chat-search-bar{
    gap:5px;
    padding:5px 6px;
  }

  .chat-search-mode{
    min-width:38px;
    padding:0 7px;
  }

  .chat-status{
    display:none;
  }

  .chat-toolbar{
    padding:7px 8px;
  }

  .chat-list{
    background:
      linear-gradient(180deg, rgba(255,255,255,.66), rgba(245,247,248,.84)),
      url("/tools/sakura02.png") center center / cover no-repeat;
  }

  .report-thread{
    max-width:none;
  }

  .report-content{
    width:100%;
    grid-template-columns:40px minmax(0, 1fr);
    column-gap:2px;
  }

  .report-thread.own .report-content{
    grid-template-columns:minmax(0, 1fr) 40px;
  }

  .report-speaker{
    font-size:10px;
  }

  .resident-name{
    font-size:13px;
  }

  .report-body{
    font-size:13px;
  }
}
