/* ========================================
   クリニック顧客管理システム - 共通スタイル
   ======================================== */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #e0f2fe;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --sidebar-width: 240px;
  --header-height: 64px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  --font: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
}

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

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

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

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

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

.sidebar-logo .logo-text span {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--gray-400);
  margin-top: 1px;
}

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

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--gray-500);
  text-transform: uppercase;
  padding: 16px 18px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: var(--gray-400);
  font-size: 13.5px;
  transition: all 0.15s;
  border-radius: 0;
  position: relative;
}

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

.nav-item.active {
  color: #fff;
  background: rgba(37,99,235,0.25);
}

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

.nav-item .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

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

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.user-avatar.role-admin { background: var(--danger); }
.user-avatar.role-doctor { background: var(--primary); }
.user-avatar.role-staff { background: var(--success); }

.user-details { flex: 1; overflow: hidden; }
.user-name { font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--gray-400); }

.logout-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--danger); }

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

/* ========== トップヘッダー ========== */
.top-header {
  height: var(--header-height);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-800);
  flex: 1;
}

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

.header-date {
  font-size: 12.5px;
  color: var(--gray-500);
  background: var(--gray-100);
  padding: 6px 12px;
  border-radius: 20px;
}

/* ========== コンテンツエリア ========== */
.content-area {
  padding: 24px;
  flex: 1;
}

/* ========== カード ========== */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  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: 15px;
  font-weight: 700;
  color: var(--gray-800);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

/* ========== ボタン ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37,99,235,0.3); }

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover { background: #15803d; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm {
  padding: 5px 11px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius);
  background: none;
  border: none;
  color: var(--gray-500);
  font-size: 15px;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--gray-100); color: var(--gray-700); }
.btn-icon.danger:hover { background: var(--danger-light); color: var(--danger); }

/* ========== フォーム ========== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger);
  margin-left: 3px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--gray-800);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-control::placeholder { color: var(--gray-400); }

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

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

.form-hint {
  font-size: 11.5px;
  color: var(--gray-400);
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

/* ========== テーブル ========== */
.table-wrapper {
  overflow-x: auto;
}

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

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--gray-50);
  border-bottom: 1.5px solid var(--gray-200);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--gray-50); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .clickable { cursor: pointer; }

/* ========== バッジ ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  gap: 4px;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-secondary { background: var(--gray-100); color: var(--gray-600); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ========== 検索バー ========== */
.search-bar {
  position: relative;
}

.search-bar .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 14px;
  pointer-events: none;
}

.search-bar input {
  padding-left: 34px;
}

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

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(16px);
  transition: transform 0.2s;
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal-lg { max-width: 860px; }
.modal-sm { max-width: 440px; }

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--gray-400);
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--gray-700); }

.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ========== 統計カード ========== */
.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-content { flex: 1; }
.stat-label { font-size: 12px; color: var(--gray-500); font-weight: 500; margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--gray-900); line-height: 1; }
.stat-sub { font-size: 11.5px; color: var(--gray-400); margin-top: 5px; }

/* ========== ページネーション ========== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--gray-100);
}

.pagination-info {
  font-size: 12.5px;
  color: var(--gray-500);
}

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

.page-btn {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--gray-200);
  background: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--gray-600);
  font-weight: 600;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ========== アラート ========== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #86efac; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: var(--info-light); color: #075985; border: 1px solid #7dd3fc; }

/* ========== ローディング ========== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

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

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

/* ========== トースト ========== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--gray-800);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.25s ease;
}

.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }
.toast.toast-warning { background: var(--warning); }

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

/* ========== 詳細表示 ========== */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.detail-item {}
.detail-label { font-size: 11.5px; font-weight: 600; color: var(--gray-500); margin-bottom: 3px; }
.detail-value { font-size: 13.5px; color: var(--gray-800); }

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

.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tab-btn.active {
  color: var(--primary);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}

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

/* ========== エンプティステート ========== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ========== 確認ダイアログ ========== */
.confirm-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 16px;
}

/* ========== スクロールバー ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ========== レスポンシブ ========== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}
