/* =============================================
   すまいファースト CRM - メインスタイル
   ============================================= */

:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #3730a3;
  --secondary: #0ea5e9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --pink: #ec4899;

  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #1e1b4b;
  --bg-sidebar-active: #312e81;

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-light: #f8fafc;

  --border: #e2e8f0;
  --border-focus: #6366f1;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.15);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;

  --sidebar-width: 240px;
  --topbar-height: 60px;
}

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

html, body {
  height: 100%;
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

/* =============================================
   レイアウト
   ============================================= */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* サイドバー */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo .logo-title {
  font-size: 15px;
  font-weight: 700;
  color: #c7d2fe;
  line-height: 1.3;
}
.sidebar-logo .logo-sub {
  font-size: 11px;
  color: #818cf8;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: #6366f1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 16px 4px;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 2px 8px;
  color: #a5b4fc;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}
.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.nav-item.active {
  background: var(--bg-sidebar-active);
  color: #fff;
}
.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 15px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px;
  color: #6366f1;
}

/* メインコンテンツ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* トップバー */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.topbar-spacer { flex: 1; }
.topbar-badge {
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

/* ページコンテンツ */
.page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.page {
  display: none;
}
.page.active {
  display: block;
}

/* =============================================
   カード・セクション
   ============================================= */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  border: 1px solid var(--border);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* =============================================
   ダッシュボード KPIカード
   ============================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.kpi-card.kpi-sales::before    { background: linear-gradient(90deg, #10b981, #34d399); }
.kpi-card.kpi-progress::before { background: linear-gradient(90deg, #4f46e5, #818cf8); }
.kpi-card.kpi-echo::before     { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.kpi-card.kpi-review::before   { background: linear-gradient(90deg, #0ea5e9, #38bdf8); }

.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}
.kpi-value .kpi-unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 2px;
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* =============================================
   パイプライン
   ============================================= */
.pipeline-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.pipeline-stage {
  flex: 1;
  min-width: 100px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.pipeline-stage:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.pipeline-stage.ps-echo    { border-top: 3px solid #f59e0b; }
.pipeline-stage.ps-before  { border-top: 3px solid #8b5cf6; }
.pipeline-stage.ps-guided  { border-top: 3px solid #0ea5e9; }
.pipeline-stage.ps-review  { border-top: 3px solid #f97316; }
.pipeline-stage.ps-contract{ border-top: 3px solid #10b981; }

.pipeline-count {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
}
.pipeline-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 600;
}
.ps-echo    .pipeline-count { color: #f59e0b; }
.ps-before  .pipeline-count { color: #8b5cf6; }
.ps-guided  .pipeline-count { color: #0ea5e9; }
.ps-review  .pipeline-count { color: #f97316; }
.ps-contract .pipeline-count { color: #10b981; }

/* =============================================
   顧客テーブル
   ============================================= */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
}
.filter-chip:hover, .filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

thead th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }

/* =============================================
   バッジ・ステージ
   ============================================= */
.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.stage-echo     { background: #fef3c7; color: #92400e; }
.stage-before   { background: #ede9fe; color: #5b21b6; }
.stage-guided   { background: #e0f2fe; color: #0369a1; }
.stage-review   { background: #ffedd5; color: #9a3412; }
.stage-contract { background: #d1fae5; color: #065f46; }

.rank-badge {
  display: inline-block;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  line-height: 22px;
}
.rank-A { background: #fef9c3; color: #854d0e; border: 1.5px solid #fbbf24; }
.rank-B { background: #dbeafe; color: #1e40af; border: 1.5px solid #60a5fa; }
.rank-C { background: #f1f5f9; color: #475569; border: 1.5px solid #cbd5e1; }

/* 取込元アイコン */
.source-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}
.source-slack   { background: #7c3aed; color: #fff; border-radius: 4px; }
.source-gmail   { background: #ef4444; color: #fff; border-radius: 50%; }
.source-sheet   { background: #16a34a; color: #fff; border-radius: 4px; font-size: 11px; }
.source-manual  { background: transparent; }

/* =============================================
   スコアバー
   ============================================= */
.score-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}
.score-track {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
  min-width: 50px;
}
.score-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.score-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 24px;
}

/* =============================================
   ボタン
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }

/* =============================================
   フォーム
   ============================================= */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-primary);
  background: #fff;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.form-control.error { border-color: var(--danger); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

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

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* =============================================
   モーダル
   ============================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.25s;
}
.modal-overlay.open .modal {
  transform: translateY(0);
}
.modal.modal-lg { max-width: 800px; }
.modal.modal-sm { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
}
.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.modal-close:hover { background: var(--danger); color: #fff; }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* =============================================
   トースト通知
   ============================================= */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideInRight 0.3s ease;
  max-width: 340px;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-warning { background: var(--warning); }
.toast.toast-info    { background: var(--primary); }

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

/* =============================================
   売上管理
   ============================================= */
.sales-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.sales-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.sales-item-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.sales-item-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}

/* =============================================
   取込ページ
   ============================================= */
.import-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.import-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.import-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.import-icon.slack  { background: #ede9fe; color: #7c3aed; }
.import-icon.gmail  { background: #fee2e2; color: #ef4444; }
.import-icon.sheet  { background: #dcfce7; color: #16a34a; }

.import-title {
  font-size: 15px;
  font-weight: 700;
}
.import-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.import-log {
  background: #0f172a;
  color: #a5f3fc;
  border-radius: var(--radius);
  padding: 14px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 12px;
}
.import-log .log-ok    { color: #86efac; }
.import-log .log-warn  { color: #fde047; }
.import-log .log-error { color: #fca5a5; }
.import-log .log-info  { color: #a5f3fc; }

/* =============================================
   詳細表示
   ============================================= */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
}
.detail-item {}
.detail-item-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}
.detail-item-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* タイムライン */
.timeline {
  list-style: none;
  padding-left: 0;
}
.timeline-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 28px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item:last-child::before { display: none; }
.timeline-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.timeline-content {
  flex: 1;
}
.timeline-title {
  font-size: 13px;
  font-weight: 600;
}
.timeline-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* =============================================
   検索バー
   ============================================= */
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 300px;
}
.search-wrap i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
}
.search-input {
  padding-left: 32px !important;
}

/* =============================================
   空状態
   ============================================= */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
}
.empty-state p {
  font-size: 13.5px;
}

/* =============================================
   ページネーション
   ============================================= */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 16px;
}
.page-btn {
  min-width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.page-btn:hover  { background: var(--bg); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* =============================================
   スピナー
   ============================================= */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   レスポンシブ
   ============================================= */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-primary);
  padding: 4px;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: flex;
    align-items: center;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid.col3 {
    grid-template-columns: 1fr;
  }
  .page-content {
    padding: 16px;
  }
  .pipeline-bar {
    gap: 8px;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

/* =============================================
   ユーティリティ
   ============================================= */
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2         { gap: 8px; }
.gap-3         { gap: 12px; }
.mt-2          { margin-top: 8px; }
.mt-4          { margin-top: 16px; }
.mb-4          { margin-bottom: 16px; }
.text-sm       { font-size: 12px; }
.text-muted    { color: var(--text-muted); }
.font-bold     { font-weight: 700; }
.text-right    { text-align: right; }
.text-center   { text-align: center; }
.text-success  { color: var(--success); }
.text-danger   { color: var(--danger); }
.text-warning  { color: var(--warning); }
.w-full        { width: 100%; }
.hidden        { display: none !important; }

/* ハンバーガーオーバーレイ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}
.sidebar-overlay.open { display: block; }
