/* ベース設定 */
:root {
  --bg-body: #050816;
  --bg-panel: rgba(15, 23, 42, 0.9);
  --bg-panel-soft: rgba(15, 23, 42, 0.7);
  --border-subtle: rgba(148, 163, 184, 0.25);
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --accent-strong: #0ea5e9;
  --text-main: #e5e7eb;
  --text-sub: #9ca3af;
  --text-muted: #6b7280;
  --danger: #f97373;
  --shadow-soft: 0 22px 45px rgba(15, 23, 42, 0.65);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-pill: 999px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at top, #0f172a 0, #020617 55%, #000 100%);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

/* アプリ全体レイアウト */
.app {
  display: flex;
  flex-direction: row;
  max-width: 1200px;
  height: 100vh;
  margin: 0 auto;
  padding: 16px;
  gap: 16px;
}

/* サイドバー */
.sidebar {
  flex: 0 0 320px;
  background: var(--bg-panel-soft);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 18px;
  backdrop-filter: blur(20px);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.logo-circle {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, #38bdf8, #0f172a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #0b1120;
  font-size: 18px;
}

.app-title {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.03em;
}

.app-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-sub);
}

.sidebar-section {
  font-size: 13px;
}

.section-title {
  font-size: 13px;
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.section-text {
  margin: 0;
  line-height: 1.5;
  color: var(--text-main);
}

.section-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-main);
  line-height: 1.6;
}

.section-list li + li {
  margin-top: 4px;
}

/* Analytics の円グラフを小さめにする */
.analytics-pie {
  max-width: 260px;
  max-height: 260px;
  margin: 0 auto 16px;
}

/* ステータス */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.25);
}

.status-note {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-sub);
}

/* チャットエリア全体 */
.chat {
  flex: 1 1 auto;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
}

/* チャットヘッダ */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 4px 4px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.3);
}

.chat-title {
  margin: 0;
  font-size: 18px;
}

.chat-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-sub);
}

.chat-header-badge {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  font-size: 11px;
  font-weight: 500;
  color: #0b1120;
  white-space: nowrap;
}

/* ログ欄 */
.chat-log {
  flex: 1 1 auto;
  margin-top: 10px;
  padding: 10px 4px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* スクロールバー */
.chat-log::-webkit-scrollbar {
  width: 8px;
}

.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 999px;
}

/* メッセージ */
.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
}

.message-avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  background: radial-gradient(circle at 30% 30%, #38bdf8, #020617);
  color: #e5e7eb;
}

.message--user .message-avatar {
  background: radial-gradient(circle at 30% 30%, #22c55e, #022c22);
}

.message-body {
  flex: 1 1 auto;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 18px;
  padding: 8px 11px 9px;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.message--user .message-body {
  background: rgba(22, 101, 52, 0.16);
  border-color: rgba(74, 222, 128, 0.35);
}

.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 11px;
  margin-bottom: 3px;
}

.message-role {
  color: var(--text-sub);
}

.message-time {
  color: var(--text-muted);
}

.message-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-main);
  word-wrap: break-word;
}

/* 入力エリア */
.chat-input-area {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.35);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.textarea-wrapper {
  position: relative;
  background: rgba(15, 23, 42, 0.95);
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 6px 10px;
}

.textarea-wrapper:focus-within {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25);
}

#user-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-size: 14px;
  color: var(--text-main);
  line-height: 1.5;
}

#user-input::placeholder {
  color: var(--text-muted);
}

/* 入力フッター */
.chat-input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-hint {
  padding-left: 2px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.operator-requests-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.operator-request-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 12px;
  width: 320px;
  font-size: 13px;
}

.operator-request-header {
  font-size: 14px;
  margin-bottom: 4px;
}

.operator-request-message {
  margin-top: 4px;
  padding: 4px 6px;
  background: #f5f5f5;
  border-radius: 4px;
  max-height: 60px;
  overflow: hidden;
}

.operator-request-actions {
  margin-top: 8px;
  text-align: right;
}


/* 送信ボタン */
.send-button {
  border: none;
  outline: none;
  border-radius: var(--radius-pill);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  color: #0b1120;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease, box-shadow 0.08s ease,
    opacity 0.08s ease;
  box-shadow: 0 12px 25px rgba(8, 47, 73, 0.6);
  margin-bottom: 10px;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 15px 30px rgba(8, 47, 73, 0.7);
}

.send-button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 8px 16px rgba(8, 47, 73, 0.5);
}

.send-button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ローディングインジケータ */
.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.loading-indicator .dot {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  animation: bounce 1s infinite alternate;
}

.loading-indicator .dot:nth-child(2) {
  animation-delay: 0.15s;
}

.loading-indicator .dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  from {
    transform: translateY(0);
    opacity: 0.5;
  }
  to {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* レスポンシブ対応 */
@media (max-width: 900px) {
  .app {
    flex-direction: column;
    height: 100vh;
    padding: 8px;
  }

  .sidebar {
    flex: 0 0 auto;
    padding: 14px 14px 12px;
    gap: 12px;
  }

  .chat {
    padding: 14px 12px 10px;
  }

  .chat-header {
    flex-direction: column;
  }

  .chat-header-badge {
    align-self: flex-start;
  }
}

@media (max-width: 520px) {
  .sidebar {
    display: none; /* 必要ならここをコメントアウトしてモバイルでも表示可 */
  }

  .app {
    max-width: 100%;
  }
}


/* ===== Admin UI 用 ===== */

.admin-main {
  /* chat と同じだが、少しだけ余裕を持たせる */
}

.admin-nav {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.admin-nav-item {
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-sub);
  border: 1px solid transparent;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
}

.admin-nav-item:hover {
  border-color: rgba(148, 163, 184, 0.5);
  color: var(--text-main);
}

.admin-nav-item--active {
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  color: #0b1120;
  border-color: transparent;
}

.admin-view {
  margin-top: 12px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-view--hidden {
  display: none;
}

.admin-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.admin-card {
  background: rgba(15, 23, 42, 0.9);
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 10px 12px;
}

.admin-card-title {
  margin: 0 0 4px;
  font-size: 14px;
}

.admin-card-text {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-sub);
}

.admin-metric {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 13px;
}

.admin-metric-label {
  color: var(--text-sub);
}

.admin-metric-value {
  font-weight: 600;
}

.admin-meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.admin-file-list {
  list-style: none;
  padding-left: 0;
  margin: 4px 0 0;
  max-height: 180px;
  overflow-y: auto;
  font-size: 12px;
}

.admin-file-item {
  padding: 2px 0;
  border-bottom: 1px solid rgba(30, 64, 175, 0.2);
}

.admin-file-item--empty {
  color: var(--text-muted);
  border-bottom: none;
}

/* ログテーブル */

.admin-logs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-logs-table-wrapper {
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.4);
  overflow: hidden;
  background: rgba(15, 23, 42, 0.9);
}

.admin-logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.admin-logs-table th,
.admin-logs-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(30, 64, 175, 0.25);
  text-align: left;
  vertical-align: top;
}

.admin-logs-table th {
  background: rgba(15, 23, 42, 0.95);
  position: sticky;
  top: 0;
  z-index: 1;
}

.admin-logs-empty {
  text-align: center;
  color: var(--text-muted);
}

.admin-log-output {
  margin-top: 8px;
  padding: 8px;
  background: rgba(15, 23, 42, 0.95);
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.4);
  font-size: 11px;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.admin-reload-button {
  padding-inline: 12px;
  font-size: 12px;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-end-button {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: transparent;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-sub);
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
}

.chat-end-button:hover {
  background: rgba(30, 64, 175, 0.6);
  color: #e5e7eb;
  border-color: rgba(191, 219, 254, 0.8);
}

.admin-conversation-detail {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.9);
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.admin-conversation-body {
  margin-top: 8px;
  max-height: 260px;
  overflow-y: auto;
  border-radius: var(--radius-md);
  border: 1px solid rgba(30, 64, 175, 0.35);
  background: rgba(15, 23, 42, 0.95);
  padding: 8px 10px;
  font-size: 12px;
}

.admin-conversation-message {
  margin-bottom: 6px;
}

.admin-conversation-message strong {
  font-size: 11px;
  color: var(--text-sub);
}

.admin-conversation-message-user strong {
  color: #38bdf8;
}

.admin-conversation-message-bot strong {
  color: #a5b4fc;
}

.admin-conversation-message-text {
  margin-left: 8px;
  white-space: pre-wrap;
}

.admin-logs-header-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* エクスポートボタンは普通のボタンでOK */

.admin-export-button {
  font-size: 12px;
  padding-inline: 10px;
}

/* 削除ボタンは少し「危険っぽく」 */

.admin-clear-button {
  font-size: 12px;
  padding-inline: 10px;
  border-color: rgba(248, 113, 113, 0.8);
  color: #fecaca;
}

.admin-clear-button:hover {
  background: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 1);
  color: #fee2e2;
}

