:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-weak: #e8efff;
  --green: #06c755;
  --green-weak: #e6f9ee;
  --red: #dc2626;
  --amber: #b45309;
  --side: #111827;
  --side-text: #cbd5e1;
  --radius: 10px;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* layout */
.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 6px 10px 18px; }
.side a { color: var(--side-text); padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.side a:hover { background: rgba(255,255,255,.06); }
.side a.active { background: rgba(255,255,255,.12); color: #fff; }
.side .spacer { flex: 1; }
.side .me { font-size: 12px; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.1); }
.side .me a { padding: 4px 0; display: inline; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; min-width: 20px; text-align: center; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; margin: 0; }
.content { padding: 20px; flex: 1; min-width: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f9fafb; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
/* 送信の状態（TASK-0005） */
.unresolved-bar { background: #fff4e5; color: #8a4b00; border: 1px solid #f0c27b; border-radius: 6px; padding: 6px 10px; margin-bottom: 6px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.unresolved-bar[hidden] { display: none; }
.uo-item { border-top: 1px solid #eee; padding: 8px 0; }
.send-state[data-state="sending"] { color: #666; }
.send-state[data-state="sent"] { color: #1a7f37; }
.send-state[data-state="failed"], .send-state[data-state="accepted"] { color: #c62828; }
.send-state[data-state="unknown"], .send-state[data-state="in_progress"] { color: #b26a00; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #f2f4f7; }
.pill.lead { background: #eef4ff; color: #3538cd; }
.pill.negotiating { background: #fff6ed; color: #c4320a; }
.pill.customer { background: var(--green-weak); color: #067647; }
.pill.dormant { background: #f2f4f7; color: #475467; }
.pill.lost { background: #fef3f2; color: #b42318; }
.pill.line { background: var(--green-weak); color: #067647; }

/* LINE chat */
.chat { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 60px - 40px); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.conv-col { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.conv-filter { padding: 8px; border-bottom: 1px solid var(--line); }
.conv-list { overflow-y: auto; flex: 1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 6px 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); margin: 0; cursor: pointer; }
.check input { width: auto; }
.conv { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.conv:hover { background: #f9fafb; }
.conv.active { background: var(--accent-weak); }
.conv .body { flex: 1; min-width: 0; }
.conv .name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.conv .last { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: #e4e7ec; object-fit: cover; flex: none; display: grid; place-items: center; color: #475467; font-weight: 700; }
.chat-pane { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; background: #8cabd9; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 8px 12px; border-radius: 16px; background: #fff; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.msg.out { align-self: flex-end; background: #a8f0a0; }
.msg.system { align-self: center; background: rgba(0,0,0,.25); color: #fff; font-size: 12px; padding: 3px 12px; }
.msg-meta { font-size: 10px; color: rgba(0,0,0,.45); margin-top: 2px; }
.msg-row { display: flex; flex-direction: column; }
.msg-row.out { align-items: flex-end; }
.msg-row.system { align-items: center; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-input textarea { min-height: 42px; height: 42px; }

/* chat v2 */
.chat { position: relative; }
.chat.with-panel { grid-template-columns: 300px 1fr 280px; }
.chat-side { display: none; border-left: 1px solid var(--line); overflow-y: auto; background: #fcfcfd; }
.chat.with-panel .chat-side { display: block; }
.side-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.side-sec label:first-child { margin-top: 0; }
/* 担当者の引き継ぎ（TASK-0022） */
.tr-flow { display: flex; align-items: flex-end; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.tr-flow b { display: inline-block; padding: 8px 0; }
.tr-arrow { font-size: 18px; padding-bottom: 8px; color: var(--muted); }
.tr-after { list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; }
.tr-after li { padding: 4px 0 4px 22px; position: relative; }
.tr-after li::before { position: absolute; left: 4px; }
.tr-after .tr-ok::before { content: '✓'; color: #067647; }
.tr-after .tr-warn { color: #b42318; font-weight: 600; }
.tr-after .tr-warn::before { content: '!'; }
.tr-after .tr-muted { color: var(--muted); }
.tr-conflict { background: #fff4e5; color: #8a4b00; border: 1px solid #f0c27b; border-radius: 6px; padding: 8px 10px; margin-top: 8px; font-size: 13px; }
.tr-conflict[hidden] { display: none; }
/* 次の対応の引き継ぎ（TASK-0023） */
.tr-fu { margin-top: 12px; border-top: 1px solid var(--line, #e5e7eb); padding-top: 10px; font-size: 13px; }
.tr-fu-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.tr-fu-list { list-style: none; padding: 0; margin: 6px 0; max-height: 220px; overflow-y: auto; }
.tr-fu-list li { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 5px 0; border-bottom: 1px dashed var(--line, #e5e7eb); }
.tr-fu-list li .check { margin: 0; white-space: nowrap; }
.tr-fu-title { flex: 1; min-width: 8em; font-weight: 600; }
.tr-fu-list li.tr-muted { color: var(--muted); }
.tr-fu-list li.tr-muted .tr-fu-title { font-weight: 400; }
.tr-fu-na { font-size: 12px; white-space: nowrap; }
.tr-fu-list li.tr-fu-changed { background: #fff4e5; }
.tr-fu-limit { margin: 6px 0; padding: 6px 8px; border-radius: 6px; background: #eef4ff; color: #1d3f8a; }
.tr-fu-limit.tr-fu-over { background: #fdecea; color: #b42318; font-weight: 600; }
/* 次の対応・今日の対応（TASK-0014） */
.fu-item { border-top: 1px solid var(--line); padding: 8px 0; }
.fu-list .fu-item:first-child { border-top: 0; }
.fu-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.fu-overdue { color: #b42318; font-weight: 600; }
.fu-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.fu-filters select { width: auto; min-width: 140px; }
.fu-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.fu-tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.fu-tab.on { background: #eef4ff; border-color: #84adff; font-weight: 600; }
.fu-tab.warn .fu-count { background: #fef3f2; color: #b42318; }
.fu-count { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; background: #f2f4f7; font-size: 12px; }
.fu-rows { display: flex; flex-direction: column; }
.fu-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 4px; border-top: 1px solid var(--line); }
.fu-row.overdue { background: #fffbfa; }
.fu-main { min-width: 0; flex: 1; }
.fu-cust { font-size: 13px; }
/* 統合履歴（TASK-0016） */
.tl-item.line.in { border-left-color: #06c755; }
.tl-item.followup { border-left-color: #84adff; }
/* 担当の変更（TASK-0028） */
.tl-item.owner { border-left-color: #7a5af8; }
.tl-owner { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; margin-top: 2px; }
.tl-owner-flow { font-size: 14px; }
.tl-coverage { background: #f4f3ff; border: 1px solid #d9d6fe; border-radius: 6px; padding: 6px 10px; margin: 6px 0; }
.tl-coverage[hidden] { display: none; }
.tl-gaps { margin: 4px 0 0 18px; padding: 0; color: #b42318; }
.tl-gaps-warn { margin-top: 4px; color: #b54708; }
.tl-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.tl-new { background: #eef4ff; border-radius: 6px; padding: 6px 10px; margin-bottom: 8px; font-size: 13px; }
.tl-new[hidden] { display: none; }
@media (max-width: 600px) {
  .fu-row { flex-direction: column; align-items: stretch; }
  .fu-filters select { flex: 1; min-width: 0; }
}
.side-notes { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.conv-filter { display: flex; flex-direction: column; gap: 6px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 5px 0; font-size: 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.conv-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; align-items: center; }
.tag { display: inline-flex; align-items: center; gap: 2px; background: var(--accent-weak); color: #1d4ed8; border-radius: 999px; padding: 1px 8px; font-size: 11px; border: 0; }
.tag button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 12px; }
.tag.ghost { background: #fff; border: 1px dashed #c7d2fe; cursor: pointer; }
.tag-box { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chat-input { flex-direction: column; gap: 6px; }
.chat-tools { display: flex; gap: 6px; align-items: center; }
.chat-row { display: flex; gap: 8px; }
.msg.plain { background: transparent; padding: 0; }
.msg-img { max-width: 260px; max-height: 260px; border-radius: 12px; display: block; }
.sticker { width: 120px; height: auto; display: block; }
.msg audio { width: 240px; max-width: 100%; display: block; }
.transcript { margin-top: 6px; padding: 6px 8px; background: rgba(0,0,0,.05); border-radius: 8px; font-size: 13px; white-space: pre-wrap; }
.msg .btn.sm { margin-top: 6px; }
.tpl-card { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.tpl-card img { width: 100%; max-height: 140px; object-fit: cover; border-radius: 8px; }
.tpl-btn { text-align: center; color: var(--accent); border-top: 1px solid rgba(0,0,0,.1); padding-top: 4px; font-size: 13px; }
.drop-hint { display: none; position: absolute; inset: 0; background: rgba(37,99,235,.12); border: 3px dashed var(--accent); border-radius: var(--radius);
  align-items: center; justify-content: center; font-size: 18px; color: var(--accent); pointer-events: none; z-index: 5; }
.drop-hint.on { display: flex; }
.chat-pane { position: relative; }
.tp-list { max-height: 50vh; overflow-y: auto; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; }
.tp-item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tp-item:hover { background: #f9fafb; }
.act-row { display: grid; grid-template-columns: 130px 1fr 1.4fr; gap: 6px; margin-bottom: 6px; }
.rec-box { margin-top: 8px; }

/* chat v3 */
.msg-line { display: flex; align-items: center; gap: 4px; max-width: 100%; }
.msg-row.out .msg-line { justify-content: flex-end; }
.msg-line .msg { max-width: 70%; }
.msg-act { opacity: 0; border: 0; background: rgba(255,255,255,.8); border-radius: 50%; width: 26px; height: 26px; cursor: pointer; flex: none; }
.msg-row:hover .msg-act { opacity: 1; }
.msg-sender { font-size: 11px; color: rgba(0,0,0,.6); margin: 0 0 2px 4px; }
.quoted { font-size: 12px; color: var(--muted); border-left: 3px solid #cbd5e1; padding: 2px 8px; margin-bottom: 6px; background: rgba(0,0,0,.04); border-radius: 4px; }
.quote-bar { display: flex; align-items: center; gap: 8px; background: var(--accent-weak); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.quote-bar[hidden] { display: none; } /* TASK-0014 で発見：hidden でも表示されていた */
.quote-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar button { border: 0; background: none; cursor: pointer; font-size: 14px; }
.sticker-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.sticker-tabs button { border: 2px solid transparent; background: none; border-radius: 8px; padding: 2px; cursor: pointer; flex: none; }
.sticker-tabs button.on { border-color: var(--accent); }
.sticker-tabs img { width: 40px; height: 40px; object-fit: contain; display: block; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; max-height: 50vh; overflow-y: auto; padding-top: 8px; }
.sticker-grid button { border: 0; background: none; border-radius: 8px; padding: 4px; cursor: pointer; }
.sticker-grid button:hover { background: #f2f4f7; }
.sticker-grid img { width: 76px; height: 76px; object-fit: contain; }
.cs { font-size: 11px; border-radius: 4px; padding: 0 6px; }
.cs.todo { background: #fef3f2; color: #b42318; }
.cs.done { background: var(--green-weak); color: #067647; }
#cs-seg { width: auto; }
#cs-seg button { padding: 4px 10px; }
.resp-sec { border-top: 1px solid var(--line); padding: 10px 0; }
.resp-sec h4 { margin: 0 0 6px; font-size: 14px; }
.kw-row { display: grid; grid-template-columns: auto 1fr 90px 100px; gap: 6px; align-items: start; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 6px; }
.kw-row textarea, .kw-row [data-k="template_id"] { grid-column: 1 / -1; min-height: 50px; }
.kw-row [data-kdel] { grid-column: 1 / -1; justify-self: end; }
.hours { width: auto; background: none; margin: 6px 0; }
.hours td { padding: 3px 6px; border: 0; }
.hours input[type="time"] { width: 110px; padding: 4px 6px; }
.chat-tools { flex-wrap: wrap; }

/* customer detail */
.detail { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 16px; align-items: start; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.tl-item { border-left: 3px solid var(--line); padding: 4px 0 4px 12px; }
.tl-item.call { border-color: var(--accent); }
.tl-item.note { border-color: var(--amber); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

/* softphone */
.phone { display: flex; align-items: center; gap: 8px; }
.phone input { width: 170px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #98a2b3; display: inline-block; }
.dot.on { background: var(--green); }
.dot.err { background: var(--red); }
.call-bar { position: fixed; right: 20px; bottom: 20px; width: 300px; background: var(--side); color: #fff; border-radius: 14px; padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 50; }
.call-bar .who { font-size: 16px; font-weight: 700; }
.call-bar .sub { color: var(--side-text); font-size: 12px; margin: 2px 0 12px; }
.call-bar .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.call-bar .btn { border-color: rgba(255,255,255,.2); background: rgba(255,255,255,.08); color: #fff; }
.call-bar .btn.green { background: var(--green); border-color: var(--green); }
.call-bar .btn.red { background: var(--red); border-color: var(--red); }
.ringing { animation: ring 1s infinite; }
@keyframes ring { 50% { box-shadow: 0 0 0 6px rgba(6,199,85,.35); } }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px; }
.modal h3 { margin: 0 0 6px; }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 340px; box-shadow: 0 6px 20px rgba(0,0,0,.2); cursor: pointer; }
.toast.err { background: var(--red); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.err-text { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }
.code { font-family: ui-monospace, Consolas, monospace; background: #f2f4f7; padding: 6px 8px; border-radius: 6px; display: block; word-break: break-all; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .side .brand, .side .spacer { display: none; }
  .side .me { border: 0; padding: 9px 12px; }
  .grid.two, .detail { grid-template-columns: 1fr; }
  .chat, .chat.with-panel { grid-template-columns: 1fr; height: auto; }
  .chat-side { border-left: 0; border-top: 1px solid var(--line); }
  .act-row { grid-template-columns: 1fr; }
  .conv-list { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-msgs { min-height: 360px; }
  .topbar { flex-wrap: wrap; }
  .phone input { width: 130px; }
  .content { padding: 16px; }
}
