/* k428 - スタンドアロン スタイルシート */

/* ============================================================
   CSS Variables (inunote ベースの配色)
   ============================================================ */
:root {
  --bg: #F4F6F9;
  --card-bg: #FBFCFE;
  --primary: #6B7B8D;
  --primary-hover: #7D8D9E;
  --secondary: #4A5568;
  --heading: #3D4F5F;
  --text: #3A4550;
  --text-light: #8896A4;
  --border: #D8DEE6;
  --border-light: #E2E8F0;
  --white: #ffffff;

  --primary-alpha-10: rgba(107, 123, 141, 0.10);
  --primary-alpha-15: rgba(107, 123, 141, 0.15);
  --primary-alpha-20: rgba(107, 123, 141, 0.20);
  --black-alpha-10: rgba(0, 0, 0, 0.10);
  --black-alpha-50: rgba(0, 0, 0, 0.50);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 50%;
}

/* ============================================================
   リセット & ベース
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Zen Maru Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   認証画面
   ============================================================ */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1000;
}

.auth-container {
  text-align: center;
  padding: 48px 40px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(74, 85, 104, 0.08);
  max-width: 380px;
  width: 90%;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-logo-img {
  width: 56px;
  height: 56px;
  color: #6b7b8d;
}

.auth-container h1 {
  font-size: 1.5rem;
  color: var(--heading);
  margin-bottom: 8px;
}

.auth-container p {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 24px;
}

.google-signin-button {
  display: flex;
  justify-content: center;
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: #dc2626;
  font-size: 0.85rem;
}

/* ============================================================
   ナビゲーションバー
   ============================================================ */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--primary);
  color: var(--white);
  flex-shrink: 0;
  height: 48px;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-icon-img {
  width: 24px;
  height: 24px;
  animation: spin 20s linear infinite;
}


/* ナビバー タブ */
.navbar-tabs {
  display: flex;
  gap: 2px;
  margin-left: 16px;
}

.navbar-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  transition: all 0.2s;
}

.navbar-tab:hover {
  background: rgba(255,255,255,0.25);
}

.navbar-tab.active {
  background: rgba(255,255,255,0.3);
  color: white;
}

.navbar-tab .material-symbols-outlined {
  font-size: 16px;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ヘッダー使用率インジケーター */
.header-usage {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 6px;
  padding-right: 12px;
  border-right: 1px solid rgba(255,255,255,0.2);
}

.header-usage:empty {
  display: none;
}

.header-usage .sys-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-usage .sys-label {
  font-size: 0.55rem;
  font-weight: 500;
  opacity: 0.7;
  letter-spacing: 0.5px;
  min-width: 26px;
}

.header-usage .sys-bar {
  width: 40px;
  height: 3px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}

.header-usage .sys-fill {
  height: 100%;
  border-radius: 2px;
  background: rgba(255,255,255,0.8);
  transition: width 0.6s ease, background 0.6s ease;
}

.header-usage .sys-fill.warn {
  background: #f9e2af;
}

.header-usage .sys-fill.danger {
  background: #f38ba8;
}

.header-usage .sys-error-text {
  font-size: 0.55rem;
  opacity: 0.7;
  color: #f9e2af;
}

.header-usage .sys-value {
  font-size: 0.55rem;
  min-width: 22px;
  text-align: right;
  opacity: 0.8;
  font-family: 'Consolas', 'Monaco', monospace;
}

/* システム統計インジケーター */
.system-stats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 6px;
  padding-right: 12px;
  border-right: 1px solid rgba(255,255,255,0.2);
}

.sys-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sys-label {
  font-size: 0.55rem;
  font-weight: 500;
  opacity: 0.7;
  letter-spacing: 0.5px;
  min-width: 26px;
}

.sys-bar {
  width: 40px;
  height: 3px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}

.sys-fill {
  height: 100%;
  border-radius: 2px;
  background: rgba(255,255,255,0.8);
  transition: width 0.6s ease, background 0.6s ease;
  width: 0%;
}

.sys-fill.warn {
  background: #f9e2af;
}

.sys-fill.danger {
  background: #f38ba8;
}

.sys-value {
  font-size: 0.55rem;
  min-width: 22px;
  text-align: right;
  opacity: 0.8;
  font-family: 'Consolas', 'Monaco', monospace;
}

.navbar-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  border: 2px solid rgba(255,255,255,0.4);
  object-fit: cover;
}

.btn-logout {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--white);
  cursor: pointer;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.25);
}

.btn-logout .material-symbols-outlined {
  font-size: 18px;
}

/* ============================================================
   チャットレイアウト
   ============================================================ */
.aichat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

/* ============================================================
   サイドバー（セッション一覧）
   ============================================================ */
.aichat-sidebar {
  width: 260px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-title {
  font-size: 0.85rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-title .material-symbols-outlined {
  font-size: 16px;
}

.btn-new-session {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: background 0.2s;
}

.btn-new-session:hover {
  background: var(--primary-hover);
}

.btn-new-session .material-symbols-outlined {
  font-size: 18px;
}

/* プロバイダー選択 */
.provider-tabs {
  display: flex;
  gap: 4px;
}

.provider-tab {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  text-align: center;
  transition: all 0.2s;
}

.provider-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* セッションリスト */
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.session-item {
  display: flex;
  align-items: center;
  padding: 9px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  position: relative;
  gap: 8px;
  min-width: 0;
}

.session-item:hover {
  background: var(--primary-alpha-10);
}

.session-item.active {
  background: var(--primary-alpha-15);
  border-left-color: var(--primary);
}

.session-item-icon {
  font-size: 14px;
  color: var(--text-light);
  flex-shrink: 0;
}

.session-item-body {
  flex: 1;
  min-width: 0;
}

.session-item-title {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-meta {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 1px;
}

.session-item-delete {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 2px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.session-item:hover .session-item-delete {
  opacity: 1;
}

.session-item-delete:hover {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.1);
}

.session-item-delete .material-symbols-outlined {
  font-size: 16px;
}

.session-item-streaming {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ============================================================
   メインパネル（チャットエリア）
   ============================================================ */
.aichat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* アプリタイトルバー */
.aichat-titlebar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.aichat-titlebar-icon {
  width: 30px;
  height: 30px;
  background: var(--primary-alpha-15);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.aichat-titlebar-icon .material-symbols-outlined {
  font-size: 18px;
  color: var(--primary);
}

.aichat-titlebar-text h2 {
  font-size: 0.95rem;
  color: var(--heading);
}

.aichat-titlebar-text span {
  font-size: 0.75rem;
  color: var(--text-light);
}

.aichat-titlebar-provider {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-light);
}

.provider-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  background: var(--primary-alpha-15);
  color: var(--secondary);
}

/* チャットメッセージエリア */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  gap: 12px;
  padding: 40px;
}

.chat-empty .material-symbols-outlined {
  font-size: 48px;
  opacity: 0.4;
}

.chat-empty p {
  font-size: 0.9rem;
  text-align: center;
}

/* メッセージバブル */
.message {
  display: flex;
  gap: 10px;
  max-width: 90%;
}

.message.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.assistant-message {
  align-self: flex-start;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--primary-alpha-20);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-avatar .material-symbols-outlined {
  font-size: 16px;
  color: var(--secondary);
}

.user-message .message-avatar {
  background: var(--primary);
}

.user-message .message-avatar .material-symbols-outlined {
  color: white;
}

.message-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  line-height: 1.65;
  word-break: break-word;
}

.user-message .message-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.assistant-message .message-bubble {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: var(--radius-sm);
}

/* マークダウンスタイル（アシスタントメッセージ内） */
.assistant-message .message-bubble h1,
.assistant-message .message-bubble h2,
.assistant-message .message-bubble h3 {
  margin: 0.8em 0 0.4em;
  color: var(--heading);
}

.assistant-message .message-bubble p {
  margin: 0.4em 0;
}

.assistant-message .message-bubble p:first-child {
  margin-top: 0;
}

.assistant-message .message-bubble p:last-child {
  margin-bottom: 0;
}

.assistant-message .message-bubble code {
  background: var(--primary-alpha-10);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.85em;
  font-family: 'Consolas', 'Monaco', monospace;
}

.assistant-message .message-bubble pre {
  background: #1e1e2e;
  border-radius: var(--radius-md);
  padding: 12px;
  overflow-x: auto;
  margin: 0.6em 0;
}

.assistant-message .message-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: #cdd6f4;
  font-size: 0.85em;
}

.assistant-message .message-bubble ul,
.assistant-message .message-bubble ol {
  padding-left: 1.4em;
  margin: 0.4em 0;
}

.assistant-message .message-bubble li {
  margin: 0.2em 0;
}

.assistant-message .message-bubble blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 10px;
  margin: 0.6em 0;
  color: var(--text-light);
}

.assistant-message .message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}

.assistant-message .message-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85em;
  margin: 0.6em 0;
}

.assistant-message .message-bubble th,
.assistant-message .message-bubble td {
  border: 1px solid var(--border);
  padding: 5px 8px;
}

.assistant-message .message-bubble th {
  background: var(--primary-alpha-10);
}

/* ツール使用インジケーター */
.tool-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: var(--text-light);
  margin: 2px 0;
}

.tool-indicator .material-symbols-outlined {
  font-size: 14px;
}

/* ストリーミング中のカーソル */
.streaming-cursor::after {
  content: '\25CC';
  animation: blink 1s step-end infinite;
  color: var(--primary);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* チャット入力エリア */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
  border-color: var(--primary);
}

.chat-input {
  flex: 1;
  border: none;
  background: none;
  resize: none;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}

.chat-input::placeholder {
  color: var(--text-light);
}

.chat-send-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.chat-send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.chat-send-btn .material-symbols-outlined {
  font-size: 18px;
}

/* 送信中のストップボタン */
.chat-stop-btn {
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: var(--radius-md);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-stop-btn:hover {
  background: #c0392b;
}

.chat-stop-btn .material-symbols-outlined {
  font-size: 18px;
}

/* セッション未選択時の空状態 */
.no-session-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  gap: 16px;
  padding: 40px;
}

.no-session-placeholder .material-symbols-outlined {
  font-size: 56px;
  opacity: 0.3;
}

.no-session-placeholder h3 {
  font-size: 1rem;
  color: var(--text-light);
}

/* ============================================================
   ローディング状態
   ============================================================ */
.thinking-indicator {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  align-items: center;
}

.thinking-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: thinking 1.2s ease-in-out infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   モバイル対応
   ============================================================ */
@media (max-width: 768px) {
  .aichat-sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    height: 100vh;
    z-index: 100;
    transition: left 0.25s ease;
    box-shadow: 2px 0 8px var(--black-alpha-10);
  }

  .aichat-sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--black-alpha-50);
    z-index: 99;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .system-stats {
    display: none;
  }

  .header-usage {
    display: none;
  }
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 4px;
}

.mobile-menu-btn .material-symbols-outlined {
  font-size: 22px;
}

/* ============================================================
   使用率ゲージパネル
   ============================================================ */
.usage-panel {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.usage-panel:empty {
  display: none;
}

.usage-section-title {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.usage-section-title .material-symbols-outlined {
  font-size: 13px;
}

.usage-gauge {
  margin-bottom: 6px;
}

.usage-gauge:last-child {
  margin-bottom: 0;
}

.usage-gauge-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.usage-gauge-label {
  font-size: 0.72rem;
  color: var(--text-light);
}

.usage-gauge-value {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text);
}

.usage-gauge-bar {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.usage-gauge-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  background: var(--primary);
}

.usage-gauge-fill.warn {
  background: #e67e22;
}

.usage-gauge-fill.danger {
  background: #e74c3c;
}

.usage-gauge-reset {
  font-size: 0.65rem;
  color: var(--text-light);
  margin-top: 2px;
}

.usage-section + .usage-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.usage-stat {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-light);
  margin-bottom: 2px;
}

.usage-stat-value {
  color: var(--text);
  font-weight: 500;
}

/* ============================================================
   ターミナルビュー
   ============================================================ */
.terminal-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.terminal-container {
  flex: 1;
  display: flex;
  min-height: 0;
}

.terminal-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.terminal-pane + .terminal-pane {
  border-left: 1px solid var(--border);
}

.terminal-pane-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #181825;
  color: #bac2de;
  font-size: 0.72rem;
  font-family: 'Consolas', 'Monaco', monospace;
  flex-shrink: 0;
  border-bottom: 1px solid #313244;
}

.terminal-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.terminal-status.connected {
  background: #a6e3a1;
}

.terminal-status.disconnected {
  background: #f38ba8;
}

.terminal-pane-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #1e1e2e;
}

.terminal-pane-body .xterm {
  height: 100%;
  padding: 4px;
}

/* ターミナル モバイル対応 */
@media (max-width: 768px) {
  .terminal-container {
    flex-direction: column;
  }

  .terminal-pane + .terminal-pane {
    border-left: none;
    border-top: 1px solid #313244;
  }

  .navbar-tabs {
    margin-left: 8px;
    gap: 1px;
  }

  .navbar-tab {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .navbar-tab .material-symbols-outlined {
    font-size: 14px;
  }
}
