/* ============================================
   Threads Manager - Light Theme Dashboard
   Linear/Vercel Dashboard風クリーンデザイン
   ============================================ */

:root {
  /* 背景 */
  --bg-primary: #F8F9FB;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F3F4F6;
  --bg-sidebar: #FFFFFF;

  /* テキスト */
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;

  /* ボーダー */
  --border: #E5E7EB;
  --border-focus: #6366F1;

  /* アクセント */
  --accent-primary: #6366F1;
  --accent-primary-hover: #4F46E5;
  --accent-primary-light: #EEF2FF;
  --accent-secondary: #8B5CF6;

  /* ステータス */
  --status-success: #10B981;
  --status-success-bg: #ECFDF5;
  --status-warning: #F59E0B;
  --status-warning-bg: #FFFBEB;
  --status-error: #EF4444;
  --status-error-bg: #FEF2F2;
  --status-info: #3B82F6;
  --status-info-bg: #EFF6FF;

  /* その他 */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --sidebar-width: 240px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── リセット ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  text-decoration: none;
  color: inherit;
}

/* ============================================
   レイアウト
   ============================================ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── サイドバー ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.sidebar-logo span {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s ease;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-primary-light);
  color: var(--accent-primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--accent-primary);
  border-radius: 0 3px 3px 0;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── メインコンテンツ ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  max-width: calc(1200px + var(--sidebar-width));
}

.main-content-inner {
  max-width: 1200px;
  margin: 0 auto;
}

/* ── ページヘッダー ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── モバイルヘッダー ── */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 90;
}

.mobile-logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-primary);
}

.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.hamburger:hover {
  background: var(--bg-card-hover);
}

.hamburger svg {
  width: 24px;
  height: 24px;
  color: var(--text-primary);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

/* ============================================
   KPI カード
   ============================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  margin-top: 8px;
}

.trend-up {
  color: var(--status-success);
}

.trend-down {
  color: var(--status-error);
}

/* ── 旧カード互換 ── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.card-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.card-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ============================================
   ファネルKPI
   ============================================ */

.funnel-kpi {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.funnel-stage {
  text-align: center;
  padding: 8px 16px;
  flex: 1;
  min-width: 140px;
}

.funnel-label {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.funnel-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-primary);
  line-height: 1.2;
}

.funnel-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.funnel-arrow {
  font-size: 24px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* ── カードタイトル ── */
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* ── ダッシュボードグリッド（2列）── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

/* ============================================
   セクション
   ============================================ */

.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* ============================================
   テーブル
   ============================================ */

.table-wrapper {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table thead th {
  background: var(--bg-primary);
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.data-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}

.data-table thead th.sortable:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.sort-icon {
  font-size: 10px;
  margin-left: 4px;
  opacity: 0.5;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--accent-primary-light);
}

.data-table td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--text-primary);
}

.loading-cell {
  text-align: center;
  color: var(--text-tertiary);
  padding: 2rem !important;
}

/* ============================================
   ステータスバッジ
   ============================================ */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-pending {
  background: var(--status-warning-bg);
  color: var(--status-warning);
}

.badge-posted {
  background: var(--status-success-bg);
  color: var(--status-success);
}

.badge-failed {
  background: var(--status-error-bg);
  color: var(--status-error);
}

.badge-info {
  background: var(--status-info-bg);
  color: var(--status-info);
}

/* ============================================
   ページネーション
   ============================================ */

.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}

.pagination button {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.pagination button:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
}

.pagination button.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   グラフ
   ============================================ */

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chart-container h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.chart-container canvas {
  max-height: 300px;
}

/* ============================================
   ヒートマップ
   ============================================ */

.heatmap-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow-x: auto;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: 40px repeat(24, 1fr);
  grid-template-rows: 24px repeat(7, 1fr);
  gap: 2px;
}

.heatmap-cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  min-width: 16px;
  min-height: 16px;
  transition: transform 0.1s;
}

.heatmap-cell:hover {
  transform: scale(1.3);
  z-index: 1;
}

.heatmap-label {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.heatmap-label-col {
  justify-content: center;
}

/* ============================================
   投稿カレンダー
   ============================================ */

.calendar-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-day-header {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding: 8px 0;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  gap: 4px;
  padding: 4px;
  transition: background 0.15s;
}

.calendar-day:hover {
  background: var(--bg-card-hover);
}

.calendar-day.today {
  background: var(--accent-primary-light);
  font-weight: 600;
}

.calendar-day.other-month {
  color: var(--text-tertiary);
}

.calendar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-primary);
}

.calendar-dot.posted {
  background: var(--status-success);
}

.calendar-dot.pending {
  background: var(--status-warning);
}

/* ============================================
   フォーム
   ============================================ */

.post-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

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

textarea,
input[type="datetime-local"],
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: vertical;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.form-message {
  font-size: 13px;
}

.form-message.success {
  color: var(--status-success);
}

.form-message.error {
  color: var(--status-error);
}

/* ============================================
   ボタン
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  font-family: var(--font);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
}

.btn-danger {
  background: transparent;
  color: var(--status-error);
  border: 1px solid var(--status-error);
  padding: 6px 12px;
  font-size: 13px;
}

.btn-danger:hover {
  background: var(--status-error-bg);
}

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

/* ============================================
   ベスト投稿
   ============================================ */

.best-posts {
  display: grid;
  gap: 12px;
}

.best-post-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.best-post-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.best-post-rank {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-primary);
  min-width: 2rem;
  text-align: center;
  line-height: 1;
}

.best-post-content {
  flex: 1;
}

.best-post-text {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.5;
}

.best-post-stats {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.best-post-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================
   アクション推奨カード
   ============================================ */

.action-card {
  background: var(--accent-primary-light);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent-primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.action-card-icon {
  width: 24px;
  height: 24px;
  color: var(--accent-primary);
  flex-shrink: 0;
  margin-top: 2px;
}

.action-card-text {
  flex: 1;
}

.action-card-text h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.action-card-text p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ============================================
   トースト通知
   ============================================ */

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 400px;
  animation: slideIn 0.3s ease;
}

.toast.toast-success {
  border-left: 4px solid var(--status-success);
}

.toast.toast-error {
  border-left: 4px solid var(--status-error);
}

.toast.toast-warning {
  border-left: 4px solid var(--status-warning);
}

.toast.toast-info {
  border-left: 4px solid var(--status-info);
}

.toast-message {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 16px;
  padding: 4px;
}

.toast.fade-out {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ============================================
   フッター
   ============================================ */

.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-tertiary);
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}

/* ============================================
   ユーティリティ
   ============================================ */

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

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.text-sm {
  font-size: 13px;
}

.text-xs {
  font-size: 12px;
}

.text-muted {
  color: var(--text-secondary);
}

.text-tertiary {
  color: var(--text-tertiary);
}

.text-accent {
  color: var(--accent-primary);
}

.font-bold {
  font-weight: 700;
}

.font-semibold {
  font-weight: 600;
}

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }

.hidden {
  display: none !important;
}

/* ============================================
   レスポンシブ
   ============================================ */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .mobile-header {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header h1 {
    font-size: 20px;
  }

  .kpi-grid,
  .summary-cards {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
  }

  .kpi-card,
  .card {
    padding: 16px;
  }

  .kpi-value,
  .card-value {
    font-size: 24px;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .funnel-kpi {
    flex-direction: column;
    gap: 4px;
  }

  .funnel-arrow {
    transform: rotate(90deg);
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .data-table {
    font-size: 13px;
  }

  .data-table td,
  .data-table thead th {
    padding: 8px 12px;
  }

  .calendar-grid {
    gap: 2px;
  }

  .heatmap-grid {
    grid-template-columns: 30px repeat(24, 1fr);
  }
}

@media (max-width: 480px) {
  .kpi-grid,
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .best-post-item {
    flex-direction: column;
    gap: 8px;
  }

  .best-post-rank {
    text-align: left;
  }

  .toast {
    min-width: auto;
    max-width: calc(100vw - 32px);
  }
}
