:root {
  --accent: #0B8B9C;
  --accent-soft: rgba(11, 139, 156, .10);
  --ink: #16191C;
  --ink-2: #16202A;
  --muted: #6B7785;
  --faint: #8B9097;
  --line: #ECEFF1;
  --field: #F7F9FA;
  --field-line: #E2E8EC;
  --side: #FBFCFC;
  --danger: #C0392B;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Maru Gothic ProN", "Hiragino Sans",
    "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #fff; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
[hidden] { display: none !important; }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* ---- サイドバー ---- */
.side {
  width: 260px; flex: 0 0 260px; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side-top {
  display: flex; align-items: center; height: 58px; padding: 0 16px;
  border-bottom: 1px solid var(--line); flex: 0 0 58px;
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: .2px; }
.icon-btn {
  margin-left: auto; width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.icon-btn.dark { background: var(--ink); color: #fff; }
.search {
  margin: 12px 14px 6px; height: 38px; border-radius: 9px; background: #F0F2F3;
  display: flex; align-items: center; gap: 9px; padding: 0 12px; color: #9AA0A6;
}
.search input { border: 0; background: transparent; outline: none; flex: 1; min-width: 0; font-size: 13px; }
.people { flex: 0 1 auto; overflow-y: auto; padding: 6px 8px; min-height: 0; }
.person-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent;
  padding: 8px 8px; border-radius: 10px; text-align: left;
}
.person-item:hover { background: #F0F3F4; }
.person-item[aria-current="true"] { background: var(--accent-soft); }
.person-item .meta { min-width: 0; flex: 1; }
.person-item b { display: block; font-size: 14px; font-weight: 700; }
.person-item small {
  display: block; font-size: 11.5px; color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.avatar {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; background: #DDEFF1; color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
}
.avatar.dark { background: var(--ink); }
.side-hint { margin: 24px 20px 0; font-size: 12px; color: var(--faint); line-height: 1.6; text-align: center; }
.side-me {
  display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 16px; flex: 0 0 54px; margin-top: auto;
  border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left;
}
.side-me-text b { display: block; font-size: 14px; }
.side-me-text small { display: block; font-size: 11.5px; color: var(--faint); }
.scrim { display: none; }

/* ---- メイン ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 16px;
  border-bottom: 1px solid var(--line); flex: 0 0 58px;
}
.topbar .menu, .brand-m { display: none; }
.topbar-title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-ghost {
  border: 1px solid #D5DDE2; background: #fff; border-radius: 9px; padding: 6px 14px;
  font-size: 13.5px; font-weight: 700; white-space: nowrap;
}
.btn-primary {
  border: 0; background: var(--accent); color: #fff; border-radius: 9px; padding: 8px 22px; font-weight: 800;
}
.btn-danger { border: 0; background: transparent; color: var(--danger); font-size: 13px; padding: 6px 4px; }

.view { flex: 1; min-height: 0; }
.home { overflow-y: auto; }
.hero { max-width: 620px; margin: 0 auto; padding: 68px 24px 40px; }
.hero h1 {
  margin: 0; font-size: 27px; font-weight: 900; color: var(--ink-2); letter-spacing: -.5px;
  line-height: 1.3; text-align: center;
}
.hero .sub { margin: 12px 0 0; font-size: 15px; color: var(--muted); line-height: 1.6; text-align: center; }
.hero .t { color: var(--accent); font-weight: 800; }

.field-name {
  margin-top: 22px; display: flex; align-items: center; gap: 7px; height: 50px; padding: 0 16px;
  border-radius: 16px; background: var(--field); border: 1.3px solid var(--field-line);
}
.field-name input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 15px; }
.field-big {
  margin-top: 14px; padding: 10px 16px; border-radius: 18px; background: var(--field);
  border: 1.4px solid var(--field-line);
}
.field-big textarea {
  width: 100%; border: 0; background: transparent; outline: none; resize: vertical;
  font-size: 15px; line-height: 1.6; min-height: 96px;
}
.field-name:focus-within, .field-big:focus-within { border-color: var(--accent); }

.depth { display: flex; gap: 8px; margin-top: 12px; justify-content: center; }
.depth label { position: relative; }
.depth input { position: absolute; opacity: 0; pointer-events: none; }
.depth span {
  display: inline-block; padding: 6px 16px; border-radius: 999px; border: 1px solid #D5DDE2;
  font-size: 13px; color: var(--muted); background: #fff;
}
.depth input:checked + span { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.depth input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.depth.small { margin-top: 0; justify-content: flex-start; }
.depth.small span { padding: 4px 12px; font-size: 12px; }

.send {
  margin-top: 14px; width: 100%; height: 54px; border-radius: 27px; background: var(--accent);
  border: 0; color: #fff; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 9px;
}
.send:disabled { opacity: .55; cursor: default; }
.send.small { margin-top: 0; width: auto; height: 40px; padding: 0 20px; font-size: 14px; border-radius: 20px; }
.send.stop { background: var(--ink); }

.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; justify-content: center; }
.examples button, .chips button {
  border: 1px solid var(--field-line); background: #fff; border-radius: 999px; padding: 6px 12px;
  font-size: 12.5px; color: var(--ink-2);
}
.examples button:hover, .chips button:hover { border-color: var(--accent); color: var(--accent); }
.notice { margin-top: 28px; font-size: 11.5px; color: var(--faint); line-height: 1.7; text-align: center; }

/* ---- スレッド ---- */
.thread { display: flex; flex-direction: column; }
.thread-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px 0; max-width: 820px; width: 100%; margin: 0 auto;
}
.person-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.person-name { font-weight: 800; font-size: 16px; }
.person-rel { font-size: 12px; color: var(--faint); }
.tabs {
  display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--line);
  max-width: 820px; width: 100%; margin: 0 auto; overflow-x: auto;
}
.tabs button {
  border: 0; background: transparent; padding: 8px 12px; font-size: 13.5px; color: var(--muted);
  border-bottom: 2.5px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 800; }

.messages { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
.messages > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.msg-user { display: flex; justify-content: flex-end; margin-top: 18px; }
.msg-user .bubble {
  max-width: 85%; background: var(--accent); color: #fff; border-radius: 16px 16px 4px 16px;
  padding: 10px 14px; font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}
.msg-user .kind { display: block; font-size: 11px; opacity: .8; margin-bottom: 2px; }
.msg-ai { margin-top: 14px; }
.card {
  border: 1px solid var(--line); border-radius: 16px; padding: 6px 20px 14px; background: #fff;
  box-shadow: 0 1px 2px rgba(22, 32, 42, .04);
}
.card-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.card-actions button {
  border: 1px solid #D5DDE2; background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 12px; color: var(--muted);
}
.thinking { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 13px; padding: 14px 0 6px; }
.dots span {
  display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: .15s; }
.dots span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.error { color: var(--danger); font-size: 13.5px; padding: 12px 0; }
.partial { margin-top: 8px; font-size: 12px; color: #9A6B00; }
.card-actions.orphan { justify-content: flex-end; align-items: center; }
.orphan-note { font-size: 12px; color: var(--faint); }
.empty-thread { text-align: center; color: var(--faint); font-size: 13px; padding: 40px 0; line-height: 1.8; white-space: pre-line; }

/* Markdown */
.md { font-size: 14.5px; line-height: 1.85; color: var(--ink-2); word-break: break-word; }
.md h2 { font-size: 17px; margin: 18px 0 6px; }
.md h3 { font-size: 15px; margin: 14px 0 4px; }
.md h4 { font-size: 14.5px; margin: 12px 0 4px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 1.4em; }
.md li { margin: 2px 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md strong { color: var(--ink); }
.md code { background: #F0F3F4; padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.md blockquote {
  position: relative; margin: 8px 0; padding: 10px 14px; background: #F2F7F8; border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
}
.md blockquote p { margin: 0; }
.md blockquote .quote-copy {
  display: block; margin: 6px 0 0 auto; border: 1px solid #D5DDE2; background: #fff; border-radius: 7px;
  padding: 2px 8px; font-size: 11.5px; color: var(--muted);
}
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--field); }

.composer {
  border-top: 1px solid var(--line); padding: 10px 20px calc(12px + env(safe-area-inset-bottom));
  background: #fff;
}
.composer > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.composer textarea {
  display: block; width: 100%; border: 1.3px solid var(--field-line); background: var(--field);
  border-radius: 14px; padding: 10px 12px; outline: none; resize: none; font-size: 14.5px; line-height: 1.6;
}
.composer textarea:focus { border-color: var(--accent); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.relation-ask { margin-bottom: 10px; }
.relation-ask-title { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.guide-cta { display: flex; justify-content: center; }

/* ---- ダイアログ ---- */
.dlg {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px); overflow-y: auto; box-shadow: 0 20px 60px rgba(22, 32, 42, .25);
}
.dlg::backdrop { background: rgba(22, 32, 42, .45); }
.dlg form { padding: 22px 22px 16px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg-lead { margin: 6px 0 14px; font-size: 12.5px; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 700; }
.grid .span2 { grid-column: span 2; }
.grid input, .grid select, .grid textarea {
  border: 1px solid #D9DFE4; background: var(--field); border-radius: 9px; padding: 8px 10px;
  font-size: 14px; font-weight: 400; outline: none; resize: vertical; width: 100%;
}
.grid input:focus, .grid select:focus, .grid textarea:focus { border-color: var(--accent); }
details { margin-top: 14px; }
summary { cursor: pointer; font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 10px; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- スマホ ---- */
@media (max-width: 959px) {
  .side {
    position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: 4px 0 24px rgba(0, 0, 0, .12);
  }
  .side.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(22, 32, 42, .35); z-index: 20; }
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar .menu { display: flex; margin-left: 0; }
  .brand-m { display: flex; }
  .topbar-title { display: none; }
  .topbar .btn-ghost { margin-left: auto; font-size: 12.5px; padding: 5px 10px; }
  .hero { padding: 40px 18px 32px; }
  .hero h1 { font-size: 23px; }
  .thread-head { padding: 10px 14px 0; }
  .thread-head .btn-ghost { font-size: 12px; padding: 5px 10px; }
  .tabs { padding: 6px 10px 0; }
  .messages { padding: 12px 14px 20px; }
  .card { padding: 4px 14px 12px; }
  .composer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .relation-ask .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .relation-ask .chips button { flex: 0 0 auto; }
  .grid { grid-template-columns: 1fr; }
  .grid .span2 { grid-column: auto; }
}
