:root {
  --accent: #065f46; --accent2: #10b981; --bg: #f4faf7; --card: #ffffff;
  --text: #1c2b27; --muted: #6b7c78; --border: #dbe8e2; --bubble-user: #10b981; --bubble-ai: #eef6f2;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif; background: var(--bg); color: var(--text); }

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

/* サイドバー */
.sidebar {
  width: 260px; flex-shrink: 0; background: #0b3b30; color: #eafff6;
  display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top) + 10px) 10px 10px;
  transition: transform .2s ease; z-index: 30;
}
.sidebar-head { display: flex; gap: 8px; margin-bottom: 10px; }
.btn-new {
  flex: 1; padding: 10px 12px; border: 1px solid rgba(255,255,255,.25); border-radius: 10px;
  background: rgba(255,255,255,.08); color: #eafff6; font-weight: 700; font-size: .92rem; cursor: pointer; text-align: left;
}
.help-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.08); color: #eafff6; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: .87rem; color: #cdeee1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: rgba(255,255,255,.08); }
.conv-item.is-active { background: rgba(255,255,255,.16); color: #fff; }
.conv-item .conv-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-item .btn-delete { background: none; border: none; color: #cdeee1; opacity: .6; cursor: pointer; font-size: .85rem; padding: 2px 4px; }
.conv-item .btn-delete:hover { opacity: 1; }
.conv-empty { color: #8fb3a7; font-size: .82rem; padding: 10px; }

.sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }

/* メイン */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-header {
  display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  border-bottom: 1px solid var(--border); background: var(--card); flex-shrink: 0;
}
.icon-btn { border: none; background: transparent; font-size: 1.25rem; cursor: pointer; color: var(--accent); display: none; }
.conv-title { font-weight: 700; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-badge { flex-shrink: 0; font-size: .74rem; font-weight: 700; color: var(--accent); background: #dcf7ea; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.empty-state { margin: auto; text-align: center; color: var(--muted); max-width: 380px; font-size: .92rem; line-height: 1.6; }

.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: .95rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--bubble-user); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bubble-ai); color: var(--text); border-bottom-left-radius: 4px; }
.msg.pending { opacity: .6; }
.msg-sources { margin-top: 8px; font-size: .78rem; opacity: .75; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--card); flex-shrink: 0;
}
.input {
  flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 18px;
  font-size: .95rem; font-family: inherit; line-height: 1.5; background: var(--bg); color: var(--text);
}
.input:focus { outline: none; border-color: var(--accent2); }
.btn-send {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--accent);
  color: #fff; font-size: 1.1rem; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.btn-send:disabled { opacity: .5; cursor: default; }

/* ヘルプ */
.help-panel { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.help-panel[hidden] { display: none; }
.help-card { background: #fff; border-radius: 14px; padding: 20px; max-width: 420px; max-height: 80vh; overflow-y: auto; color: var(--text); }
.help-card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.help-card ul { margin: 0 0 16px; padding-left: 18px; }
.help-card li { margin-bottom: 8px; font-size: .9rem; line-height: 1.5; }
.btn { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-size: .9rem; font-family: inherit; }
.btn-primary { background: var(--accent); color: #fff; border: none; font-weight: 700; }

/* 設定パネル */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field select, .field input[type="password"] {
  width: 100%; padding: 10px 11px; font-size: .95rem; border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; color: var(--text); background: #fff;
}
.field select:focus, .field input[type="password"]:focus { outline: none; border-color: var(--accent2); }
.help-card p.small { font-size: .8rem; line-height: 1.5; margin: 4px 0 16px; }
#settings-panel .btn { margin-right: 8px; margin-bottom: 8px; }

/* モバイル */
@media (max-width: 760px) {
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-scrim.is-open { display: block; }
  .icon-btn { display: inline-block; }
  .msg { max-width: 88%; }
}
