/* ============================
   楽マジ募集メルマガ ジェネレータ
   Design System & Styles
   ============================ */

:root {
  /* 楽マジブランドカラー（ピンク・暖色系） */
  --primary: #e85d75;
  --primary-light: #ff8fa3;
  --primary-dark: #c2344d;
  --primary-bg: #fff5f7;
  --accent: #ff6b35;
  --accent-light: #ff9966;
  
  /* ニュートラル */
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-hover: #fff0f3;
  --border: #f0e0e4;
  --border-strong: #e0c5cb;
  --text: #2d2327;
  --text-secondary: #6b5860;
  --text-muted: #9e8a90;
  
  /* ステータス */
  --success: #22c55e;
  --warning: #f59e0b;
  
  /* レイアウト */
  --header-h: 64px;
  --sidebar-w: 320px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(45,35,39,0.06);
  --shadow-md: 0 4px 12px rgba(45,35,39,0.08);
  --shadow-lg: 0 8px 30px rgba(45,35,39,0.12);
  --transition: 0.2s ease;
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Noto Sans JP', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.7;
}

/* ========== ヘッダー ========== */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  height: var(--header-h);
  box-shadow: var(--shadow-md);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

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

.logo-icon { font-size: 1.6rem; }

.logo h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.logo-sub {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: 8px;
}

#mode-nav {
  display: flex;
  gap: 6px;
}

.nav-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.85);
  padding: 8px 20px;
  border-radius: 30px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.nav-btn.active {
  background: #fff;
  color: var(--primary-dark);
  font-weight: 700;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}

.nav-icon { font-size: 1rem; }

/* ========== モードパネル ========== */
.mode-panel {
  display: none;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

.mode-panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== アーカイブモード ========== */
.archive-header, .gen-header {
  margin-bottom: 24px;
}

.archive-header h2, .gen-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.archive-desc, .gen-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.archive-container {
  display: flex;
  gap: 20px;
  min-height: calc(100vh - var(--header-h) - 120px);
}

.mail-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: calc(100vh - var(--header-h) - 120px);
  overflow-y: auto;
  padding-right: 4px;
}

/* 年セパレータ（アコーディオン） */
.year-separator {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-dark);
  padding: 10px 10px 6px;
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--primary-light);
  margin-top: 8px;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}

.year-separator:first-child { margin-top: 0; }

.year-separator:hover {
  background: var(--surface-hover);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.year-arrow {
  font-size: 0.65rem;
  display: inline-block;
  transition: transform 0.2s;
}

.year-count {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: auto;
}

.year-group {
  animation: fadeIn 0.2s ease;
}

/* キャンペーンアイテム */
.campaign-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: var(--transition);
}

.campaign-item:hover {
  background: var(--surface-hover);
  border-color: var(--primary-light);
  transform: translateX(3px);
}

.campaign-item.active {
  background: var(--primary-bg);
  border-color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}

.campaign-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.campaign-期 {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
}

.badge {
  font-size: 0.6rem;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.badge-full {
  background: #dcfce7;
  color: #166534;
}

.badge-empty {
  background: #fef3c7;
  color: #92400e;
}

.campaign-name {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
}

.campaign-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.mail-content {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - var(--header-h) - 120px);
}

/* キャンペーン内メール一覧 */
.campaign-mail-list {
  padding: 16px 24px;
}

.campaign-mail-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 10px;
  transition: var(--transition);
}

.campaign-mail-item:hover {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

.cmi-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.cmi-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}

.cmi-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cmi-role {
  font-size: 0.7rem;
  background: var(--bg);
  color: var(--text-secondary);
  padding: 1px 8px;
  border-radius: 10px;
}

.cmi-subject {
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
}

.cmi-toggle {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn-expand {
  font-weight: 600;
}

.cmi-body {
  margin-top: 10px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  line-height: 1.9;
  max-height: 50vh;
  overflow-y: auto;
}

.viewer-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  min-height: 400px;
}

.placeholder-icon { font-size: 3rem; opacity: 0.5; }

/* メールビューア */
.mail-view-header {
  background: linear-gradient(135deg, var(--primary-bg) 0%, #fff 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 28px;
}

.mail-view-subject {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

.mail-view-meta {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.mail-view-body {
  padding: 28px;
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.95;
  color: var(--text);
  max-height: calc(100vh - var(--header-h) - 220px);
  overflow-y: auto;
}

.mail-view-actions {
  border-top: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  gap: 8px;
}

/* ========== ジェネレータモード ========== */
.gen-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.gen-form-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin-bottom: 20px;
}

legend {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  padding: 0 10px;
}

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

.form-row label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-row input,
.form-row textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  transition: var(--transition);
  background: var(--bg);
}

.form-row input:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232,93,117,0.12);
  background: #fff;
}

.form-row-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 8px;
}

/* ボタン */
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  border: none;
  padding: 14px 32px;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
  box-shadow: 0 4px 15px rgba(232,93,117,0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(232,93,117,0.4);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 14px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-accent {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.btn-accent:hover {
  background: var(--primary-dark);
}

.btn-copy {
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.btn-copy:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

/* ========== 生成結果 ========== */
.gen-result-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--primary-bg) 0%, #fff 100%);
  border-bottom: 1px solid var(--border);
}

.result-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.result-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 0 8px;
}

.result-tab {
  padding: 12px 18px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.result-tab:hover {
  color: var(--primary);
  background: var(--surface-hover);
}

.result-tab.active {
  color: var(--primary-dark);
  font-weight: 700;
  border-bottom-color: var(--primary);
  background: var(--surface);
}

.result-content {
  padding: 24px;
}

.result-mail {
  display: none;
}

.result-mail.active { display: block; }

.result-mail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.result-mail-subject {
  font-weight: 700;
  color: var(--primary-dark);
}

.result-mail-body {
  white-space: pre-wrap;
  line-height: 1.95;
  font-size: 0.9rem;
  background: var(--bg);
  padding: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 60vh;
  overflow-y: auto;
}

/* ========== トースト ========== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease;
  z-index: 999;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ========== レスポンシブ ========== */
@media (max-width: 900px) {
  .archive-container {
    flex-direction: column;
  }
  .mail-sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 8px;
  }
  .mail-item {
    min-width: 200px;
    flex-shrink: 0;
  }
  .form-row-group {
    grid-template-columns: 1fr;
  }
  .header-inner {
    flex-direction: column;
    height: auto;
    padding: 12px 16px;
    gap: 8px;
  }
  #app-header {
    height: auto;
  }
}

@media (max-width: 600px) {
  .mode-panel { padding: 16px; }
  .gen-form-wrapper { padding: 16px; }
  fieldset { padding: 14px; }
  .mail-view-body { padding: 16px; }
}

/* ジェネレータ: STEP & フィールドセット */
.step-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-dark);
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 8px;
  margin: 24px 0 12px;
}
.step-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.mail-fieldset {
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary-light);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--primary-bg);
  transition: border-color 0.2s;
}
.mail-fieldset:hover {
  border-left-color: var(--primary);
}
.mail-fieldset legend {
  font-weight: 600;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

/* ===== 編集モード・ステータス ===== */
.cmi-status {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  margin-left: auto;
}
.status-draft { background: #f0f0f0; color: #666; }
.status-reviewing { background: #fff3cd; color: #856404; }
.status-approved { background: #d4edda; color: #155724; }

.status-select {
  font-size: 0.78rem;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  margin-left: 4px;
}

.btn-edit {
  background: #fff3cd !important;
  color: #856404 !important;
}
.btn-edit:hover {
  background: #ffeeba !important;
}

.mail-textarea {
  width: 100%;
  min-height: 300px;
  padding: 12px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.88rem;
  line-height: 1.8;
  border: 2px solid var(--primary-light);
  border-radius: 8px;
  background: #fffef7;
  resize: vertical;
  box-sizing: border-box;
}
.mail-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.15);
}

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

.btn-save {
  padding: 8px 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.btn-cancel {
  padding: 8px 20px;
  background: #f0f0f0;
  color: #666;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn-cancel:hover {
  background: #e0e0e0;
}

.cmi-edit {
  margin-top: 8px;
  padding: 12px;
  background: #fffef7;
  border: 1px dashed var(--primary-light);
  border-radius: 8px;
}
