:root {
  --bg-base: #090d16;
  --bg-elevated: rgba(17, 24, 39, 0.78);
  --bg-card: rgba(20, 29, 47, 0.86);
  --bg-soft: rgba(30, 41, 59, 0.65);
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(129, 140, 248, 0.45);
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --accent: #6366f1;
  --accent-2: #06b6d4;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
  --success: #10b981;
  --danger: #f43f5e;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 12% 10%, rgba(99, 102, 241, 0.22), transparent 38%),
    radial-gradient(circle at 88% 15%, rgba(6, 182, 212, 0.18), transparent 40%),
    radial-gradient(circle at 50% 95%, rgba(139, 92, 246, 0.14), transparent 45%),
    var(--bg-base);
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ヘッダー */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 22px;
  background: var(--bg-elevated);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--accent-grad);
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-sub);
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-strong);
  font-size: 0.82rem;
  color: #cbd5e1;
}

.model-pill strong {
  color: #67e8f9;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

.tab-switch {
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}

/* タブパネル */
.tab-panel {
  display: none;
  flex: 1;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* チャットカード */
.chat-card {
  flex: 1;
  min-height: 640px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
}

.chat-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-chip {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-chip.soft {
  background: rgba(99, 102, 241, 0.14);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.3);
}

.summary-banner {
  margin: 14px 20px 0;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.11);
  border: 1px solid rgba(129, 140, 248, 0.32);
}

.summary-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: #a5b4fc;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.summary-banner p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: #e2e8f0;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 480px;
  padding: 36px 20px;
}

.empty-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  font-size: 24px;
  color: #a5b4fc;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-sub);
}

.message {
  display: flex;
  gap: 12px;
  max-width: 82%;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.message.assistant .avatar {
  background: var(--accent-grad);
  color: #fff;
}

.message.user .avatar {
  background: #334155;
  color: #f8fafc;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bubble {
  padding: 13px 16px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 0.94rem;
  word-break: break-word;
}

.message.assistant .bubble {
  background: rgba(30, 41, 59, 0.88);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.message.user .bubble {
  background: var(--accent-grad);
  color: #fff;
  border-top-right-radius: 4px;
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.28);
}

.bubble pre {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.75);
  overflow-x: auto;
  font-size: 0.83rem;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
}

.meta {
  font-size: 0.72rem;
  color: var(--text-sub);
  padding: 0 4px;
}

.message.user .meta {
  text-align: right;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 22px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.chat-composer {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-main);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.5;
  outline: none;
}

.chat-composer textarea:focus {
  border-color: var(--accent);
}

.chat-footer {
  display: flex;
  justify-content: space-between;
  padding: 8px 20px 12px;
  font-size: 0.76rem;
  color: var(--text-sub);
  background: rgba(15, 23, 42, 0.65);
}

/* RAGデータ管理画面 */
.rag-layout {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 20px;
  align-items: start;
}

.rag-editor-card,
.rag-list-card {
  background: var(--bg-card);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card-header h2,
.rag-list-header h2 {
  margin: 0 0 6px;
  font-size: 1.08rem;
}

.card-header p {
  margin: 0 0 18px;
  font-size: 0.84rem;
  color: var(--text-sub);
}

.faq-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
}

.form-group input,
.form-group textarea,
.search-input {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.75);
  color: var(--text-main);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.search-input:focus {
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.json-io-box {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.json-io-box h3 {
  margin: 0 0 6px;
  font-size: 0.92rem;
}

.hint-text {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--text-sub);
  line-height: 1.5;
}

.json-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.rag-list-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.count-badge {
  display: inline-block;
  font-size: 0.76rem;
  color: #67e8f9;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.28);
  padding: 3px 10px;
  border-radius: 999px;
}

.search-input {
  max-width: 250px;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 620px;
  overflow-y: auto;
  padding-right: 4px;
}

.faq-card {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  transition: border-color 0.2s ease;
}

.faq-card:hover {
  border-color: var(--border-strong);
}

.faq-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.faq-cat {
  font-size: 0.74rem;
  font-weight: 700;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.16);
  padding: 3px 9px;
  border-radius: 6px;
}

.faq-actions {
  display: flex;
  gap: 6px;
}

.faq-q {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: #f8fafc;
}

.faq-a {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.6;
  color: #cbd5e1;
}

.faq-empty {
  padding: 32px;
  text-align: center;
  color: var(--text-sub);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

/* ボタン共通 */
button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #fff;
  background: var(--accent-grad);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.3);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #e0e7ff;
  background: rgba(99, 102, 241, 0.2);
}

.btn-ghost {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
  background: rgba(30, 41, 59, 0.65);
}

.btn-danger {
  border: 1px solid rgba(244, 63, 94, 0.35);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fda4af;
  background: rgba(244, 63, 94, 0.14);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.78rem;
}

.hidden {
  display: none !important;
}

/* トースト通知 */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-strong);
  color: #f8fafc;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(244, 63, 94, 0.6);
  color: #fecdd3;
}

@media (max-width: 920px) {
  .rag-layout {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 94%;
  }
}