* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 15px;
  background: #F5F7FA;
  color: #333;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ログインダイアログ */
#login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#login-overlay.hidden { display: none; }

#login-dialog {
  background: #fff;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  width: 90%;
  max-width: 360px;
  text-align: center;
}

#login-dialog h2 {
  margin-bottom: 20px;
  font-size: 18px;
  color: #1565C0;
}

#password-input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
}

#password-input:focus {
  border-color: #1565C0;
}

#login-btn {
  width: 100%;
  padding: 12px;
  background: #1565C0;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}

#login-btn:hover { background: #0D47A1; }

#login-error {
  color: #e53935;
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ヘッダー */
#header {
  background: #1565C0;
  color: #fff;
  padding: 14px 20px;
  text-align: center;
}

#header h1 {
  font-size: 17px;
  font-weight: 600;
}

/* タブ */
#tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  font-family: inherit;
}

.tab.active {
  color: #1565C0;
  border-bottom-color: #1565C0;
  font-weight: 600;
}

.tab:hover { color: #333; }

/* タブコンテンツ */
.tab-content {
  display: none;
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.tab-content.active { display: block; }

/* 統計カード */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.stat-label {
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #1565C0;
}

/* コスト情報セクション */
.cost-section {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-bottom: 24px;
}

.cost-section h2 {
  font-size: 16px;
  margin-bottom: 12px;
  color: #333;
}

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

.cost-card {
  text-align: center;
  padding: 12px 8px;
  background: #F5F7FA;
  border-radius: 8px;
}

.cost-label {
  font-size: 11px;
  color: #888;
  margin-bottom: 4px;
}

.cost-value {
  font-size: 20px;
  font-weight: 700;
  color: #E65100;
}

.cost-value-small {
  font-size: 16px;
}

/* 設定セクション */
.settings-section {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.settings-section h2 {
  font-size: 16px;
  margin-bottom: 16px;
  color: #333;
}

.setting-row {
  margin-bottom: 16px;
}

.setting-row > label {
  display: block;
  font-size: 13px;
  color: #666;
  margin-bottom: 6px;
  font-weight: 600;
}

.setting-row select,
.setting-row textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.setting-row select:focus,
.setting-row textarea:focus {
  border-color: #1565C0;
}

/* トグルスイッチ */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-label {
  font-size: 14px;
  font-weight: 600;
}

.toggle-switch {
  position: relative;
  width: 50px;
  height: 26px;
  display: inline-block;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #4CAF50;
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #FF9800;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

/* ミニトグル（カテゴリ用） */
.toggle-mini {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
}

.toggle-mini input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-mini-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 20px;
  transition: background 0.3s;
}

.toggle-mini-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-mini input:checked + .toggle-mini-slider {
  background: #4CAF50;
}

.toggle-mini input:checked + .toggle-mini-slider::before {
  transform: translateX(16px);
}

/* ボタン */
.btn-primary {
  background: #1565C0;
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary:hover { background: #0D47A1; }

.btn-secondary {
  background: #f5f5f5;
  color: #666;
  border: 1px solid #ddd;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.btn-secondary:hover { background: #eee; }

.btn-danger {
  background: #fff;
  color: #e53935;
  border: 1px solid #e53935;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.btn-danger:hover { background: #FFEBEE; }

.btn-sm {
  padding: 6px 16px;
  font-size: 13px;
}

.feedback {
  font-size: 13px;
  color: #4CAF50;
  margin-left: 12px;
}

.error-text {
  color: #e53935;
  font-size: 13px;
  margin-top: 8px;
}

/* ========================================
   プロンプト管理 (Phase 3)
   ======================================== */

.prompt-section {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.prompt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.prompt-header h2 {
  font-size: 16px;
}

.prompt-stats {
  font-size: 13px;
  color: #666;
}

.prompt-actions-top {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* アコーディオン */
.accordion-item {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-item.accordion-negative {
  border-color: #FFCDD2;
}

.accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #FAFAFA;
  cursor: pointer;
  user-select: none;
}

.accordion-negative .accordion-header {
  background: #FFF5F5;
}

.accordion-arrow {
  font-size: 12px;
  color: #999;
  flex-shrink: 0;
  width: 16px;
}

.accordion-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.accordion-negative .accordion-title {
  color: #C62828;
}

.accordion-chars {
  font-size: 12px;
  color: #999;
}

.accordion-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.badge-enabled {
  background: #E8F5E9;
  color: #2E7D32;
}

.badge-disabled {
  background: #F5F5F5;
  color: #999;
}

.lock-icon {
  font-size: 14px;
}

.accordion-body {
  display: none;
  padding: 16px;
  border-top: 1px solid #e0e0e0;
}

.accordion-negative .accordion-body {
  border-top-color: #FFCDD2;
  background: #FFFAFA;
}

.accordion-item.open .accordion-body {
  display: block;
}

.accordion-desc {
  font-size: 12px;
  color: #888;
  margin-bottom: 10px;
}

.cat-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  min-height: 150px;
}

.cat-textarea:focus {
  border-color: #1565C0;
}

.accordion-negative .cat-textarea:focus {
  border-color: #C62828;
}

.accordion-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* ========================================
   モーダル
   ======================================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-large {
  max-width: 700px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
  font-size: 16px;
  color: #333;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #999;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: #333;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: #666;
  margin-bottom: 4px;
  font-weight: 600;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: #1565C0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* プレビュー */
.preview-stats {
  font-size: 13px;
  color: #666;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #F5F7FA;
  border-radius: 6px;
}

.preview-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.7;
  padding: 16px;
  background: #FAFAFA;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  max-height: 50vh;
  overflow-y: auto;
  font-family: inherit;
}

/* ========================================
   チャットログ
   ======================================== */

.logs-section {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.logs-section h2 {
  font-size: 16px;
  margin-bottom: 12px;
}

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

.logs-controls label {
  font-size: 13px;
  color: #666;
  font-weight: 600;
}

.logs-controls select {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

/* ログエントリ */
.log-entry {
  border-bottom: 1px solid #f0f0f0;
  padding: 14px 0;
}

.log-entry:last-child { border-bottom: none; }

.log-meta {
  font-size: 12px;
  color: #999;
  margin-bottom: 8px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.log-meta .responder-ai {
  color: #1565C0;
  font-weight: 600;
}

.log-meta .responder-human {
  color: #FF9800;
  font-weight: 600;
}

.log-tokens {
  color: #E65100;
  font-size: 11px;
  font-weight: 500;
}

.log-bubble {
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.log-bubble.user-msg {
  background: #E3F2FD;
  margin-left: 20%;
  text-align: right;
}

.log-bubble.ai-msg {
  background: #F5F5F5;
  margin-right: 20%;
}

.log-bubble-label {
  font-size: 11px;
  color: #999;
  margin-bottom: 2px;
}

.log-bubble-label.user-label { text-align: right; margin-left: 20%; }
.log-bubble-label.ai-label { margin-right: 20%; }

/* レスポンシブ */
@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .cost-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stat-value { font-size: 22px; }

  .tab-content { padding: 14px; }

  .prompt-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .accordion-header {
    padding: 10px 12px;
    flex-wrap: wrap;
  }

  .accordion-header-right {
    margin-left: 24px;
  }

  .log-bubble.user-msg { margin-left: 10%; }
  .log-bubble.ai-msg { margin-right: 10%; }
  .log-bubble-label.user-label { margin-left: 10%; }
  .log-bubble-label.ai-label { margin-right: 10%; }
}
