/* ----------------------------------------------------
   カラーパレット & デザイン変数
   ---------------------------------------------------- */
:root {
  --bg-main: #f4f1ea;
  --bg-card: #fbf9f5;
  --bg-sidebar: #eae5db;
  --bg-chat: #f7f4ed;

  --text-main: #1f2022;
  --text-muted: #6e6d6a;
  --text-light: #fbf9f5;

  --accent-dark: #2b2c2e;
  --accent-dark-hover: #3d3e41;

  --bubble-user: #2b2c2e;
  --bubble-user-text: #fbf9f5;
  --bubble-ai: #ffffff;
  --bubble-ai-text: #1f2022;

  --border-color: #e2dcd3;
  --border-focus: #1f2022;

  --status-ready-bg: #e2eadf;
  --status-ready-text: #2d4229;

  --font-family: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg-main: #121315;
  --bg-card: #1a1b1e;
  --bg-sidebar: #161719;
  --bg-chat: #141517;

  --text-main: #e3e2de;
  --text-muted: #9e9d98;
  --text-light: #1f2022;

  --accent-dark: #e3e2de;
  --accent-dark-hover: #ffffff;

  --bubble-user: #2d3036;
  --bubble-user-text: #e3e2de;
  --bubble-ai: #212328;
  --bubble-ai-text: #e3e2de;

  --border-color: #2b2d32;
  --border-focus: #e3e2de;

  --status-ready-bg: #1d2b1c;
  --status-ready-text: #92c38d;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  /* モバイルブラウザのアドレスバー対応 */
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s, color 0.25s;
}

.app-layout {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  background: var(--bg-card);
  position: relative;
}

/* モバイルサイドバー用背景オーバーレイ */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ----------------------------------------------------
   左側：サイドバー
   ---------------------------------------------------- */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.25s;
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-main);
}

.brand-icon {
  width: 20px;
  height: 20px;
}

.new-chat-btn {
  width: 100%;
  padding: 10px 14px;
  background: var(--accent-dark);
  color: var(--text-light);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
  min-height: 44px;
  /* タップサイズ最適化 */
}

.new-chat-btn:hover {
  background: var(--accent-dark-hover);
}

.new-chat-btn svg {
  width: 16px;
  height: 16px;
}

.sidebar-menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-main);
  font-size: 0.88rem;
  transition: background 0.2s;
  position: relative;
  min-height: 40px;
}

.session-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .session-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.session-item.active {
  background: rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

[data-theme="dark"] .session-item.active {
  background: rgba(255, 255, 255, 0.1);
}

.delete-session-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: none;
  align-items: center;
  justify-content: center;
}

.delete-session-btn:hover {
  color: #ef4444;
  background: rgba(0, 0, 0, 0.06);
}

.session-item:hover .delete-session-btn,
.session-item.active .delete-session-btn {
  display: flex;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

/* ----------------------------------------------------
   右側：メインエリア ＆ ドラッグドロップ
   ---------------------------------------------------- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-card);
  position: relative;
  transition: background-color 0.25s;
}

.drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(31, 32, 34, 0.85);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.drop-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.drop-message {
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 1rem;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  padding: 30px;
  border-radius: var(--radius-lg);
  text-align: center;
}

.drop-message svg {
  width: 40px;
  height: 40px;
}

.chat-header {
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.25s, border-color 0.25s;
  min-height: 56px;
}

.header-title-area {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-header h2 {
  font-size: 0.98rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn-text {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-family);
  transition: all 0.2s;
  min-height: 36px;
}

.icon-btn-text:hover {
  background: var(--bg-sidebar);
}

.icon-btn-text svg {
  width: 14px;
  height: 14px;
}

.theme-toggle-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  min-width: 36px;
  min-height: 36px;
}

.theme-toggle-btn:hover {
  background: var(--bg-sidebar);
}

.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d97706;
}

.status-bar.ready .status-indicator {
  background: #4d7c0f;
}

[data-theme="dark"] .status-bar.ready .status-indicator {
  background: #84cc16;
}

.speed-metrics {
  font-family: 'Inter', monospace;
  font-weight: 500;
  background: rgba(0, 0, 0, 0.04);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
}

[data-theme="dark"] .speed-metrics {
  background: rgba(255, 255, 255, 0.08);
}

/* チャットログ */
.chat-box {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-chat);
  transition: background-color 0.25s;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 90%;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.assistant {
  align-self: flex-start;
}

.message-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  margin-top: 2px;
}

.avatar svg {
  width: 14px;
  height: 14px;
}

.message.user .avatar {
  background: var(--accent-dark);
  color: var(--text-light);
  border: none;
}

.message.assistant .avatar {
  background: var(--bg-card);
  color: var(--text-main);
}

.content {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  line-height: 1.55;
  font-size: 0.9rem;
  word-break: break-word;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
}

.message.user .content {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-top-right-radius: 2px;
}

.message.assistant .content {
  background: var(--bubble-ai);
  color: var(--bubble-ai-text);
  border: 1px solid var(--border-color);
  border-top-left-radius: 2px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  padding: 0 4px;
}

.message.user .message-meta {
  justify-content: flex-end;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  opacity: 0.85;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.72rem;
  font-family: var(--font-family);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  opacity: 0.85;
}

.action-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

[data-theme="dark"] .action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.action-btn svg {
  width: 12px;
  height: 12px;
}

/* Markdown スタイル */
.content h1,
.content h2,
.content h3 {
  margin-top: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}

.content h1 {
  font-size: 1.1rem;
}

.content h2 {
  font-size: 1.0rem;
}

.content h3 {
  font-size: 0.92rem;
}

.content p {
  margin-bottom: 6px;
}

.content p:last-child {
  margin-bottom: 0;
}

.content ul,
.content ol {
  margin-left: 16px;
  margin-bottom: 6px;
}

.content code:not(pre code) {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85em;
}

[data-theme="dark"] .content code:not(pre code) {
  background: rgba(255, 255, 255, 0.1);
}

.content pre {
  margin: 10px 0;
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.content pre code.hljs {
  padding: 12px;
  font-size: 0.82em;
  font-family: 'Consolas', 'Monaco', monospace;
  line-height: 1.45;
}

/* ----------------------------------------------------
   入力フォーム ＆ ファイルバッジ
   ---------------------------------------------------- */
.chat-form {
  padding: 12px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  transition: background-color 0.25s, border-color 0.25s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-badge-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-main);
  max-width: 100%;
}

[data-theme="dark"] .file-badge {
  background: rgba(255, 255, 255, 0.08);
}

.file-badge span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-badge svg {
  width: 13px;
  height: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.remove-badge-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 2px;
  line-height: 1;
}

.remove-badge-btn:hover {
  color: #ef4444;
}

.input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-chat);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  transition: border-color 0.2s, background-color 0.25s;
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
}

.model-select-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  align-self: flex-start;
  max-width: 100%;
}

.model-select-icon {
  width: 13px;
  height: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.model-select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.78rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  padding-right: 4px;
}

.model-select option {
  background: var(--bg-card);
  color: var(--text-main);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.icon-btn-action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  min-width: 36px;
  min-height: 36px;
}

.icon-btn-action:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

[data-theme="dark"] .icon-btn-action:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn-action svg {
  width: 18px;
  height: 18px;
}

textarea {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  max-height: 100px;
  line-height: 1.4;
  padding: 6px 0;
}

textarea::placeholder {
  color: var(--text-muted);
}

button[type="submit"] {
  padding: 8px 14px;
  background: var(--accent-dark);
  color: var(--text-light);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s;
  flex-shrink: 0;
  min-height: 36px;
}

button[type="submit"] svg {
  width: 14px;
  height: 14px;
}

button[type="submit"]:hover:not(:disabled) {
  background: var(--accent-dark-hover);
}

button[type="submit"].stop-btn {
  background: #991b1b;
  color: #ffffff;
}

button[type="submit"].stop-btn:hover:not(:disabled) {
  background: #7f1d1d;
}

button:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ----------------------------------------------------
   レスポンシブ（スマホ・タブレット表示）
   ---------------------------------------------------- */
.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: flex;
  }

  .btn-text-desktop {
    display: none;
    /* スマホではアイコンのみでコンパクト表示 */
  }

  .icon-btn {
    background: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
  }

  .icon-btn svg {
    width: 20px;
    height: 20px;
  }

  .chat-box {
    padding: 12px;
  }

  .message {
    max-width: 95%;
  }

  .chat-form {
    padding: 10px 12px;
  }
}