/* =============================================
   共通設定 / 変数定義
   ============================================= */
:root {
  --color-bg-light: #f4f4f4;
  --color-bg-sidebar: #ffffff5b;
  --color-bg-card: #ffffff;
  --color-input-bg: #fff;
  
  --color-accent: #ffcc00;
  --color-text-main: #1a1a1a;
  --color-text-sub: #888888;
  --color-border: #d1d1d1;
  
  --color-msg-system-bg: #ffffff;
  --color-msg-system-text: #333;
  --color-msg-user-bg: #1a1a1b;
  --color-msg-user-text: #ffffff;
  
  --font-main: "Inter", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  --font-mono: "Roboto Mono", monospace;

  --sidebar-width: 60px;
  --mobile-nav-height: 56px;
}

[data-theme="dark"] {
  --color-bg-light: #0f0f10;
  --color-bg-sidebar: #1a1a1b80;
  --color-bg-card: #18181b;
  --color-input-bg: #27272a;
  
  --color-text-main: #e4e4e7;
  --color-text-sub: #a1a1aa;
  --color-border: #3f3f46;
  
  --color-msg-system-bg: #27272a;
  --color-msg-system-text: #e4e4e7;
  --color-accent: #facc15;
}

/* =============================================
   Base
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  background-color: var(--color-bg-light);
  color: var(--color-text-main);
  font-family: var(--font-main);
  margin: 0;
  overflow: hidden;
  height: 100vh;
  height: 100dvh; /* iOS Safari対応 */
  display: flex;
  flex-direction: column;
  position: relative;
}

/* =============================================
   背景の装飾
   ============================================= */
.bg-decorator {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(circle, #000 0.5px, transparent 0.5px);
  background-size: 40px 40px;
  opacity: 0.1;
}

.bg-silhouette {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 40vh; height: 80vh;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.05), transparent);
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  z-index: 0;
  pointer-events: none;
}

/* =============================================
   レイアウト構造
   ============================================= */
.ui-container {
  padding: 20px 40px 60px 40px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
  margin-left: var(--sidebar-width);
}

.ui-container.hidden { display: none; }

/* =============================================
   サイドバー (デスクトップ)
   ============================================= */
.main-sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 60px 0;
  z-index: 1000;
}

.sidebar-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.setting-btn {
  width: 40px; height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--color-text-main);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
  border-radius: 8px;
}

.setting-btn:hover {
  background: var(--color-border);
  transform: translateY(-2px);
}

.setting-btn svg { width: 20px; height: 20px; opacity: 0.7; }

/* Tooltip */
.tooltip-panel {
  position: absolute;
  left: 30px; top: 50%;
  transform: translateY(-50%);
  background: #000; color: #fff;
  padding: 4px 10px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  border-radius: 2px;
}

.tooltip-panel::before {
  content: '';
  position: absolute;
  left: -4px; top: 50%;
  transform: translateY(-50%);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-right: 4px solid #000;
}

.setting-btn:hover .tooltip-panel {
  opacity: 1;
  transform: translateY(-50%) translateX(5px);
}

/* =============================================
   モバイル ボトムナビゲーション
   ============================================= */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0;
  width: 100%;
  height: var(--mobile-nav-height);
  background: var(--color-bg-card);
  border-top: 1px solid var(--color-border);
  z-index: 2000;
  justify-content: space-around;
  align-items: center;
  padding: 4px 0;
  padding-bottom: env(safe-area-inset-bottom, 4px);
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--color-text-sub);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 0.6rem;
  font-family: var(--font-main);
  transition: color 0.2s;
}

.mobile-nav-btn:hover,
.mobile-nav-btn:active {
  color: var(--color-accent);
}

.mobile-nav-btn svg {
  width: 20px; height: 20px;
}

/* =============================================
   チャットインターフェース
   ============================================= */
.chat-wrapper {
  flex-grow: 1;
  display: flex;
  margin: 20px 0;
  overflow: hidden;
  position: relative;
  z-index: 10;
}

/* 左: 補助ステータス */
.left-side {
  width: 260px;
  min-width: 180px;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 20px;
  flex-shrink: 0;
}

/* リサイザー */
.resizer {
  width: 12px;
  cursor: col-resize;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.2s;
  user-select: none;
  position: relative;
  z-index: 20;
  margin: 0 10px;
}

.resizer:hover, .resizer.dragging {
  background: rgba(0, 243, 255, 0.1);
}

.resizer::after {
  content: '';
  width: 2px; height: 40px;
  background: var(--color-border);
  border-radius: 1px;
  box-shadow: 0 0 5px var(--color-accent);
}

/* 中央: メインチャットログ */
.chat-view {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  backdrop-filter: blur(8px);
  position: relative;
  min-width: 0;
}

.chat-log {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.chat-log::-webkit-scrollbar { width: 4px; }
.chat-log::-webkit-scrollbar-thumb { background: #ccc; }

/* =============================================
   メッセージ
   ============================================= */
.msg {
  max-width: 85%;
  width: fit-content;
  padding: 12px 16px;
  font-size: 0.85rem;
  line-height: 1.6;
  position: relative;
  word-wrap: break-word;
  border-radius: 2px;
}

.msg.system {
  align-self: flex-start;
  background: var(--color-msg-system-bg);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  color: var(--color-msg-system-text);
}

.msg.user {
  align-self: flex-end;
  background: var(--color-msg-user-bg);
  color: var(--color-msg-user-text);
  border-right: 4px solid var(--color-accent);
}

.msg-info {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  color: var(--color-text-sub);
  margin-bottom: 8px;
  display: block;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  padding-bottom: 4px;
}

.msg .content {
  white-space: pre-wrap;
  word-break: break-word;
  display: block;
}

/* Markdown in messages */
.msg .content p { margin: 0 0 10px 0; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content ul, .msg .content ol { padding-left: 20px; margin: 10px 0; }
.msg .content li { margin-bottom: 5px; }
.msg .content code {
  font-family: var(--font-mono);
  background: rgba(0,0,0,0.1);
  padding: 2px 4px;
  border-radius: 3px;
}
.msg .content pre {
  background: #1a1a1a; color: #d1d1d1;
  padding: 12px; border-radius: 5px;
  overflow-x: auto; margin: 10px 0;
}
.msg .content strong { color: var(--color-accent); }
.msg strong { color: #3b82f6; }

/* =============================================
   入力欄
   ============================================= */
.input-bar-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;
  border-top: 1px solid var(--color-border);
  background-color: var(--color-bg-light);
}

.input-bar {
  padding: 15px 20px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background-color: var(--color-bg-light);
}

.input-bar textarea {
  flex-grow: 1;
  background: var(--color-input-bg);
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
  padding: 10px 12px;
  font-family: var(--font-mono);
  outline: none;
  resize: none;
  height: 40px;
  min-height: 40px;
  max-height: 150px;
  overflow-y: auto;
  line-height: 1.4;
  box-sizing: border-box;
  font-size: 16px; /* iOSでズーム防止 */
}

.input-bar button#sendBtn {
  background: var(--color-text-main);
  color: var(--color-bg-light);
  border: none;
  height: 40px;
  padding: 0 25px;
  font-weight: 900;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.input-bar button#sendBtn:hover { opacity: 0.8; }

.input-bar .icon-btn {
  background: transparent;
  color: var(--color-text-main);
  border: 1px solid transparent;
  padding: 0;
  width: 40px; height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

.input-bar .icon-btn:hover {
  background: rgba(128, 128, 128, 0.1);
}

.input-bar .icon-btn.active {
  color: var(--color-accent);
  background: rgba(255, 204, 0, 0.1);
}

.icon-btn.recording {
  color: #ef4444;
  animation: pulse 1.5s infinite;
}

/* Image Preview */
.image-preview {
  display: flex;
  position: absolute;
  bottom: 100%;
  left: 20px;
  padding-bottom: 10px;
  z-index: 10;
}

.image-preview.hidden { display: none; }

.image-preview img {
  height: 120px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.image-preview .remove-image {
  position: absolute;
  top: -8px; right: -8px;
  background: #ff5555;
  color: white;
  width: 24px; height: 24px;
  text-align: center;
  line-height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* =============================================
   Loading / Status
   ============================================= */
.loading-dots {
  font-family: monospace;
  font-size: 0.7rem;
  color: #3b82f6;
  animation: pulse 1.5s infinite;
  margin-top: 5px;
}

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

.hidden { display: none !important; }

/* =============================================
   ステータスパネル (左側)
   ============================================= */
.status-item {
  display: flex;
  align-items: flex-start;
  gap: 15px;
}

.status-indicator {
  padding: 2px 8px;
  background: #000;
  color: var(--color-accent);
  font-size: 0.6rem;
  font-weight: bold;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.status-content {
  display: flex;
  flex-direction: column;
}

.status-label {
  font-size: 0.6rem;
  color: var(--color-text-sub);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.status-value {
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.05em;
}

/* Source Panel */
.source-panel { margin-top: 20px; }

.source-panel-header {
  font-size: 0.7rem;
  font-weight: bold;
  margin-bottom: 10px;
  color: var(--color-text-main);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 5px;
}

.source-panel-content {
  font-size: 0.65rem;
  color: var(--color-text-sub);
  line-height: 1.6;
  overflow-y: auto;
  max-height: 40vh;
}

.source-card {
  margin-bottom: 12px;
  padding: 10px;
  border-left: 3px solid #3b82f6;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-left-width: 3px;
  border-left-color: #3b82f6;
  border-radius: 0 6px 6px 0;
}

.source-card-title {
  font-weight: bold;
  font-size: 0.9rem;
  color: #3b82f6;
  margin-bottom: 4px;
}

.source-card-snippet {
  font-size: 0.8rem;
  color: var(--color-text-sub);
  line-height: 1.4;
}

.source-empty {
  color: var(--color-text-sub);
  font-style: italic;
}

/* Notice Box */
.notice-box {
  margin-top: auto;
  padding: 15px;
  border: 1px dashed var(--color-border);
  font-size: 0.6rem;
  color: var(--color-text-sub);
}

/* =============================================
   ヘッダー / フッター
   ============================================= */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 10px;
  gap: 10px;
}

.bottom-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.connection-status {
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  opacity: 0.6;
  white-space: nowrap;
}

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #22c55e;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.menu-icon { font-size: 1.2rem; }

/* =============================================
   設定画面
   ============================================= */
.close-btn {
  background: var(--color-text-main);
  color: var(--color-bg-light);
  border: none;
  padding: 5px 15px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}

.settings-content {
  margin-top: 40px;
  max-width: 600px;
  overflow-y: auto;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 900;
  border-bottom: 2px solid var(--color-text-main);
  padding-bottom: 5px;
  margin-bottom: 20px;
  letter-spacing: 0.1em;
}

.config-grid {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.config-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-item label {
  font-size: 0.65rem;
  font-weight: bold;
  color: var(--color-text-sub);
  font-family: var(--font-mono);
}

.config-item select, 
.config-item input[type="password"],
.config-item input[type="text"] {
  background: var(--color-input-bg);
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 16px; /* iOSズーム防止 */
  outline: none;
}

.config-item select option {
  background: var(--color-bg-card);
  color: var(--color-text-main);
}

.config-item input[type="range"] {
  width: 100%;
  accent-color: var(--color-text-main);
}

.config-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.save-btn {
  margin-top: 30px;
  background: var(--color-accent);
  color: #000;
  border: none;
  padding: 12px 20px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 900;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s;
}

.save-btn:hover {
  background: var(--color-text-main);
  color: var(--color-bg-light);
}

.save-btn:active { transform: scale(0.98); }
.save-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* =============================================
   設定プリセット
   ============================================= */
.preset-section {
  margin-top: 40px;
  border-top: 1px solid var(--color-border);
  padding-top: 25px;
}

.preset-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 15px;
}

.preset-name-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-light);
  color: var(--color-text-main);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.preset-name-input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.preset-save-btn {
  margin-top: 0 !important;
  white-space: nowrap;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-empty {
  color: var(--color-text-dim);
  font-size: 0.8rem;
  padding: 12px 0;
}

.preset-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-light);
  transition: border-color 0.2s;
}

.preset-card:hover {
  border-color: var(--color-accent);
}

.preset-card-info {
  flex: 1;
  min-width: 0;
}

.preset-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-card-detail {
  font-size: 0.75rem;
  color: var(--color-text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.preset-card-actions {
  display: flex;
  gap: 8px;
  margin-left: 12px;
  flex-shrink: 0;
}

.preset-load-btn {
  padding: 5px 14px;
  border: 1px solid var(--color-accent);
  border-radius: 5px;
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  transition: all 0.15s;
}

.preset-load-btn:hover {
  background: var(--color-accent);
  color: var(--color-bg-main);
}

.preset-delete-btn {
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  background: transparent;
  color: var(--color-text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.15s;
}

.preset-delete-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* =============================================
   履歴ダッシュボード
   ============================================= */
.dashboard-controls {
  margin-top: 40px;
  display: flex;
  gap: 15px;
  align-items: center;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 15px; top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
}

.search-input {
  width: 100%;
  padding: 12px 12px 12px 45px;
  background: var(--color-input-bg);
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: var(--font-main);
  box-sizing: border-box;
  outline: none;
  font-size: 16px;
}

.icon-btn-outline {
  padding: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  color: var(--color-text-main);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.select-outline {
  padding: 10px 15px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  color: var(--color-text-main);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--color-bg-card);
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  transition: all 0.2s;
}

.action-btn-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--color-text-main);
  color: var(--color-bg-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  transition: all 0.2s;
}

.action-btn-danger {
  width: auto;
  background: #ef4444;
  border: none;
  color: #fff;
}
.action-btn-danger:hover { background: #dc2626; }

.dashboard-content {
  margin-top: 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.empty-state {
  text-align: center;
  color: var(--color-text-sub);
  margin-top: 100px;
}

.empty-state-icon {
  margin: 0 auto 20px;
  opacity: 0.3;
}

.empty-state-title {
  font-size: 1.2rem;
  color: var(--color-text-main);
  margin-bottom: 5px;
}

.session-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  width: 100%;
}

/* Session Card */
.session-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.session-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(0,0,0,0.05);
  border-color: var(--color-accent);
}

.session-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--color-border);
  transition: background 0.2s;
}

.session-card:hover::before { background: var(--color-accent); }

.session-card-title {
  font-size: 1rem;
  font-weight: bold;
  color: var(--color-text-main);
  padding-right: 33px;
}

.session-card-meta {
  font-size: 0.75rem;
  color: var(--color-text-sub);
  font-family: var(--font-mono);
  display: flex;
  justify-content: space-between;
}

.session-card-preview {
  font-size: 0.85rem;
  color: var(--color-text-sub);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.session-delete-btn {
  position: absolute;
  top: 10px; right: 10px;
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.2s;
  color: #666;
}

.session-card:hover .session-delete-btn { opacity: 1; }

.session-delete-btn:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* History Details Panel */
.history-details-panel {
  overflow-y: auto;
  max-height: 60vh;
  padding: 20px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
}

.btn-row {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 15px;
  flex-wrap: wrap;
}

/* =============================================
   Response Actions (Restore)
   ============================================= */
.response-actions {
  margin-top: 12px;
  padding: 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.short-response-warning {
  color: #f59e0b;
  font-size: 0.8rem;
}

.restore-btn {
  background: transparent;
  color: var(--color-text-sub);
  border: 1px solid transparent;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  transition: all 0.2s;
}

.restore-btn:hover {
  background: rgba(0,0,0,0.05);
  color: var(--color-text-main);
}

/* =============================================
   Modal
   ============================================= */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--color-bg-card);
  padding: 24px;
  border-radius: 8px;
  width: 400px;
  max-width: 90%;
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal h3 { margin-top: 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.btn-primary {
  background: var(--color-accent);
  color: #000;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-main);
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-primary:hover, .btn-secondary:hover { opacity: 0.8; }

/* =============================================
   Utility
   ============================================= */
.crosshair {
  position: absolute;
  width: 20px; height: 20px;
  color: var(--color-text-main);
  z-index: 20;
  opacity: 0.5;
  pointer-events: none;
}
.crosshair::before, .crosshair::after {
  content: '';
  position: absolute;
  background: currentColor;
}
.crosshair::before { width: 100%; height: 1px; top: 10px; left: 0; }
.crosshair::after { height: 100%; width: 1px; left: 10px; top: 0; }
.crosshair-tl { top: 10%; left: 10%; }
.crosshair-tr { top: 10%; right: 10%; }
.crosshair-bl { bottom: 10%; left: 10%; }
.crosshair-br { bottom: 10%; right: 10%; }

/* Typography */
.text-title-lg { font-size: 1.7rem; letter-spacing: 0.05em; }
.text-title-md { font-size: 1.1rem; }
.text-subtitle { font-size: 0.8rem; color: var(--color-text-sub); margin-top: 5px; }
.text-small { font-size: 0.9rem; }
.text-xs { font-size: 0.7rem; }
.text-xxs { font-size: 0.6rem; }
.text-mono { font-family: var(--font-mono); }
.text-bold { font-weight: bold; }
.text-muted { color: var(--color-text-sub); }
.text-center { text-align: center; }

.badge {
  background: #000; color: #fff;
  padding: 2px 5px;
  font-size: 0.6rem;
}

.brand-main {
  font-weight: 900;
  position: relative;
  color: var(--color-text-main);
  line-height: 1.1;
  margin: 0;
}

.version-label {
  position: absolute;
  bottom: 10px; left: 10px;
  font-size: 0.6rem;
  color: var(--color-text-sub);
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  z-index: 1;
}

.w-auto { width: auto; }

/* =============================================
   RESPONSIVE: Tablet (< 1024px)
   ============================================= */
@media (max-width: 1024px) {
  .left-side {
    width: 200px;
    min-width: 150px;
  }

  .dashboard-controls {
    gap: 10px;
  }

  .action-btn, .action-btn-primary {
    padding: 8px 12px;
    font-size: 0.7rem;
  }
}

/* =============================================
   RESPONSIVE: Mobile (< 768px)
   ============================================= */
@media (max-width: 768px) {
  /* サイドバーを非表示、ボトムナビを表示 */
  .main-sidebar { display: none; }
  .mobile-nav { display: flex; }

  .ui-container {
    margin-left: 0;
    padding: 12px 12px calc(var(--mobile-nav-height) + 12px) 12px;
  }

  /* ヘッダー調整 */
  .top-header {
    flex-wrap: wrap;
  }

  .brand-main.text-title-md { font-size: 1.1rem; }
  .brand-main.text-title-lg { font-size: 1.5rem; }
  .connection-status { font-size: 0.55rem; }

  /* 左サイドパネルを非表示 */
  .left-side { display: none; }
  .resizer { display: none; }

  /* チャットを全幅に */
  .chat-wrapper {
    margin: 10px 0;
  }

  .chat-view {
    border-radius: 8px;
  }

  .chat-log {
    padding: 12px;
  }

  .msg {
    max-width: 95%;
    font-size: 0.8rem;
    padding: 10px 12px;
  }

  /* 入力欄調整 */
  .input-bar {
    padding: 10px;
    gap: 6px;
  }

  .input-bar .icon-btn {
    width: 36px; height: 36px;
  }

  .input-bar button#sendBtn {
    padding: 0 16px;
    height: 36px;
    font-size: 0.8rem;
  }

  /* 設定画面 */
  .settings-content {
    margin-top: 20px;
    max-width: 100%;
  }

  /* ダッシュボード */
  .dashboard-controls {
    margin-top: 20px;
  }

  .search-box { min-width: 100%; }

  .session-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* 装飾を非表示 */
  .crosshair { display: none; }
  .bg-silhouette { display: none; }
  .bg-decorator { opacity: 0.05; }
  .version-label { display: none; }
  .bottom-status { display: none; }

  /* 履歴詳細 */
  .history-details-panel {
    max-height: 50vh;
    padding: 12px;
  }

  .btn-row {
    flex-direction: column;
  }

  .btn-row .save-btn {
    width: 100%;
  }

  /* ダッシュボードのボタンをモバイル用に */
  .select-outline { font-size: 0.7rem; padding: 8px 10px; }
  .action-btn, .action-btn-primary {
    padding: 8px 12px;
    font-size: 0.7rem;
    flex: 1;
    justify-content: center;
  }

  .preset-controls {
    flex-direction: column;
  }

  .preset-controls .preset-save-btn {
    width: 100%;
  }
}

/* =============================================
   RESPONSIVE: Small phone (< 400px)
   ============================================= */
@media (max-width: 400px) {
  .ui-container {
    padding: 8px 8px calc(var(--mobile-nav-height) + 8px) 8px;
  }

  .brand-main.text-title-md { font-size: 0.95rem; }
  .badge { display: none; }

  .input-bar {
    padding: 8px;
    gap: 4px;
  }

  /* モバイルでは音声/画像/位置情報ボタンをコンパクトに */
  .input-bar .icon-btn {
    width: 32px; height: 32px;
  }

  .input-bar .icon-btn svg {
    width: 16px; height: 16px;
  }

  .msg {
    max-width: 100%;
    font-size: 0.75rem;
  }
}

/* =============================================
   PWA: iOS standalone mode
   ============================================= */
@media (display-mode: standalone) {
  .mobile-nav {
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }

  .ui-container {
    padding-top: env(safe-area-inset-top, 20px);
  }
}
