/* ============================================
   HomeFit CRM - 管理画面スタイル
   ============================================ */

:root {
  /* ブランドカラー */
  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --primary-light: #EFF6FF;
  --primary-bg: #DBEAFE;

  /* ステータスカラー */
  --success: #10B981;
  --success-light: #D1FAE5;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --info: #6366F1;
  --info-light: #E0E7FF;

  /* グレースケール */
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  /* レイアウト */
  --sidebar-width: 240px;
  --sidebar-collapsed: 60px;
  --header-height: 0px;

  /* フォント */
  --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.875rem;
  --font-size-lg: 1rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;

  /* 影 */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

  /* 角丸 */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* リセット */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--gray-800);
  background: var(--gray-50);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

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

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

/* サイドバー */
.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width 0.2s ease;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-footer { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 12px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

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

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

.logo-text {
  font-weight: 600;
  font-size: var(--font-size-base);
  white-space: nowrap;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--gray-400);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.sidebar-toggle:hover { color: white; background: rgba(255,255,255,0.1); }

.sidebar-nav {
  list-style: none;
  padding: 8px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--gray-400);
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: all 0.15s;
}
.nav-link:hover { color: white; background: rgba(255,255,255,0.08); }
.nav-link.active { color: white; background: var(--primary); }
.nav-link svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-email {
  font-size: var(--font-size-xs);
  color: var(--gray-400);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

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

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed);
}

.page-content {
  padding: 24px;
  max-width: 1400px;
}

/* ============================================
   ページヘッダー
   ============================================ */

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

.page-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--gray-900);
}

.page-subtitle {
  font-size: var(--font-size-sm);
  color: var(--gray-500);
  margin-top: 2px;
}

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

.card {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--gray-800);
}

.card-body {
  padding: 20px;
}

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

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

.kpi-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}

.kpi-label {
  font-size: var(--font-size-sm);
  color: var(--gray-500);
  font-weight: 500;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--gray-900);
}

.kpi-sub {
  font-size: var(--font-size-xs);
  color: var(--gray-400);
  margin-top: 4px;
}

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

.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.data-table th:hover { color: var(--gray-900); }
.data-table th .sort-icon { margin-left: 4px; opacity: 0.3; }
.data-table th.sorted .sort-icon { opacity: 1; color: var(--primary); }

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--gray-50); }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--primary-light); }

/* ============================================
   バッジ（ステータス表示）
   ============================================ */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  line-height: 1.6;
}

.badge-blue { background: var(--primary-bg); color: var(--primary); }
.badge-green { background: var(--success-light); color: #065F46; }
.badge-yellow { background: var(--warning-light); color: #92400E; }
.badge-red { background: var(--danger-light); color: #991B1B; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: var(--info-light); color: #4338CA; }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-secondary { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; color: white; }

.btn-sm { padding: 4px 10px; font-size: var(--font-size-xs); }
.btn-icon { padding: 6px; }

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

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

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  color: var(--gray-800);
  background: white;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-textarea { min-height: 80px; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* ============================================
   フィルターバー
   ============================================ */

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

.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  min-width: 160px;
}

.search-input {
  position: relative;
}

.search-input input {
  padding-left: 36px;
}

.search-input svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
}

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

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: var(--font-size-sm);
  color: var(--gray-500);
}

.pagination-buttons {
  display: flex;
  gap: 4px;
}

.pagination-btn {
  padding: 6px 12px;
  border: 1px solid var(--gray-300);
  background: white;
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  color: var(--gray-700);
}
.pagination-btn:hover:not(:disabled) { background: var(--gray-50); }
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ============================================
   カンバン
   ============================================ */

.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
}

.kanban-column {
  min-width: 280px;
  max-width: 320px;
  flex-shrink: 0;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 12px;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  margin-bottom: 8px;
}

.kanban-column-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--gray-700);
}

.kanban-count {
  background: var(--gray-300);
  color: var(--gray-700);
  font-size: var(--font-size-xs);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}

.kanban-card {
  background: white;
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.kanban-card:hover {
  box-shadow: var(--shadow-md);
}

.kanban-card-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.kanban-card-sub {
  font-size: var(--font-size-xs);
  color: var(--gray-500);
}

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

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--gray-400);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
}

/* ============================================
   トースト
   ============================================ */

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

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  animation: slideIn 0.3s ease;
  min-width: 250px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--primary); color: white; }

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

/* ============================================
   ディテール（詳細画面）
   ============================================ */

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.detail-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
}

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

.detail-section {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  padding: 20px;
}

.detail-section-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-100);
}

.detail-field {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--gray-50);
}

.detail-field:last-child { border-bottom: none; }

.detail-field-label {
  font-size: var(--font-size-sm);
  color: var(--gray-500);
  font-weight: 500;
  min-width: 120px;
}

.detail-field-value {
  font-size: var(--font-size-sm);
  color: var(--gray-800);
  text-align: right;
  word-break: break-all;
}

/* ============================================
   タブ
   ============================================ */

.tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 20px;
}

.tab {
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--gray-500);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============================================
   空状態
   ============================================ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state svg { margin-bottom: 12px; }
.empty-state p { font-size: var(--font-size-sm); }

/* ============================================
   ローディング
   ============================================ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--gray-400);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 戻るリンク */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-sm);
  color: var(--gray-500);
  margin-bottom: 16px;
}
.back-link:hover { color: var(--primary); }

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

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .main-content { margin-left: 0; }

  .page-content { padding: 16px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .form-input,
  .filter-bar .form-select { width: 100%; min-width: unset; }

  .kanban-board { padding: 0; }
  .kanban-column { min-width: 260px; }

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

  /* モバイルメニューボタン */
  .mobile-menu-btn {
    display: block;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 101;
    background: var(--gray-900);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 8px;
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none; }
}

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

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.text-muted { color: var(--gray-500); }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
