/* ========== リセット・ベース ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif; background: #F5F4F0; color: #1A1916; line-height: 1.5; position: relative; }
a { color: #185FA5; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== レイアウト ========== */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 200px; background: #fff; border-right: 0.5px solid #E0DDD5; padding: 16px 0; flex-shrink: 0; position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; }
.main-content { flex: 1; margin-left: 200px; padding: 24px; min-height: 100vh; }

/* ========== サイドバー ========== */
.sidebar-logo { padding: 0 16px 14px; border-bottom: 0.5px solid #E0DDD5; margin-bottom: 8px; }
.logo-text { font-size: 15px; font-weight: 600; color: #1A1916; }
.logo-sub { font-size: 11px; color: #7A7975; margin-top: 2px; }
.nav-section { padding: 6px 0; }
.nav-label { font-size: 10px; color: #A09D95; padding: 4px 16px; letter-spacing: 0.06em; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 9px 16px; font-size: 13px; color: #5F5E5A; border-left: 2px solid transparent; transition: all 0.1s; }
.nav-item:hover { background: #F5F4F0; color: #1A1916; text-decoration: none; }
.nav-item.active { color: #185FA5; border-left-color: #185FA5; background: #E6F1FB; font-weight: 500; }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: #C8C5BC; flex-shrink: 0; }
.nav-item.active .nav-dot { background: #185FA5; }

/* ========== フラッシュメッセージ ========== */
.flash { padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.flash-success { background: #E1F5EE; border: 0.5px solid #5CB891; color: #0F6E56; }
.flash-error { background: #FCEBEB; border: 0.5px solid #F09595; color: #A32D2D; }

/* ========== ページヘッダー ========== */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 600; color: #1A1916; }
.page-sub { font-size: 13px; color: #7A7975; margin-top: 3px; }
.breadcrumb { font-size: 12px; color: #7A7975; margin-bottom: 14px; }
.breadcrumb a { color: #185FA5; }
.breadcrumb span { margin: 0 6px; color: #A09D95; }

/* ========== ボタン（押しやすく改善） ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  min-height: 38px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #C8C5BC;
  background: #fff;
  color: #1A1916;
  transition: all 0.15s ease;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover {
  background: #F5F4F0;
  border-color: #A09D95;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: #185FA5;
  color: #fff;
  border-color: #185FA5;
}
.btn-primary:hover {
  background: #0C447C;
  border-color: #0C447C;
  color: #fff;
}
.btn-outline {
  background: #fff;
  color: #185FA5;
  border-color: #185FA5;
}
.btn-outline:hover {
  background: #E6F1FB;
  color: #185FA5;
}
.btn-danger {
  background: #fff;
  color: #A32D2D;
  border-color: #E5C2C2;
}
.btn-danger:hover {
  background: #FCEBEB;
  border-color: #A32D2D;
  color: #A32D2D;
}
.btn-ghost {
  border-color: #E0DDD5;
  color: #5F5E5A;
  background: #fff;
}
.btn-ghost:hover {
  background: #F5F4F0;
  color: #1A1916;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  min-height: 30px;
}
.btn-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ========== カード ========== */
.card { background: #fff; border: 0.5px solid #E0DDD5; border-radius: 8px; overflow: hidden; margin-bottom: 16px; }
.card-header { padding: 13px 20px; border-bottom: 0.5px solid #E0DDD5; display: flex; align-items: center; gap: 9px; }
.card-title { font-size: 14px; font-weight: 600; color: #1A1916; }
.card-body { padding: 20px 24px; }
.sec-badge { width: 22px; height: 22px; border-radius: 50%; background: #185FA5; color: #fff; font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ========== フォーム ========== */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px 20px; }
.form-grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px 20px; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: 1 / -1; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 12px; font-weight: 500; color: #7A7975; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 9px 11px; border: 0.5px solid #E0DDD5;
  border-radius: 6px; font-size: 13px; background: #fff; color: #1A1916;
  font-family: inherit; transition: border-color 0.1s;
  min-height: 38px;
}
.form-field textarea { min-height: auto; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none; border-color: #185FA5; box-shadow: 0 0 0 2px #E6F1FB;
}
.form-field textarea { resize: vertical; line-height: 1.6; }
.form-field input[readonly] { background: #F5F4F0; color: #7A7975; }
.section-divider { height: 0.5px; background: #E0DDD5; margin: 18px 0; }
.sub-heading { font-size: 13px; font-weight: 600; color: #1A1916; margin-bottom: 14px; padding-bottom: 8px; border-bottom: 0.5px solid #E0DDD5; }

/* ========== アクションバー ========== */
.action-bar { display: flex; align-items: center; justify-content: space-between; padding-top: 16px; gap: 8px; flex-wrap: wrap; }

/* ========== テーブル ========== */
.table-wrap { background: #fff; border: 0.5px solid #E0DDD5; border-radius: 8px; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { background: #F5F4F0; padding: 10px 14px; text-align: left; font-weight: 500; font-size: 12px; color: #7A7975; border-bottom: 0.5px solid #E0DDD5; white-space: nowrap; }
.data-table td { padding: 11px 14px; border-bottom: 0.5px solid #E0DDD5; color: #1A1916; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #F5F4F0; }
.data-table .name-cell { font-weight: 500; }
.data-table .sub-text { font-size: 11px; color: #7A7975; margin-top: 2px; }

/* ========== アクションリンク（ボタン化・改善版） ========== */
.action-links {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  min-height: 30px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid #C8C5BC;
  background: #fff;
  color: #185FA5;
  text-decoration: none;
  transition: all 0.15s ease;
  line-height: 1.2;
}
.action-link:hover {
  background: #E6F1FB;
  border-color: #185FA5;
  text-decoration: none;
  color: #185FA5;
}
.action-link:active {
  transform: scale(0.97);
}
.action-link-danger {
  color: #A32D2D;
  border-color: #E5C2C2;
}
.action-link-danger:hover {
  background: #FCEBEB;
  border-color: #A32D2D;
  color: #A32D2D;
}
.action-link-success {
  color: #1D9E75;
  border-color: #C8DCD0;
}
.action-link-success:hover {
  background: #E1F5EE;
  border-color: #1D9E75;
  color: #0F6E56;
}

/* ========== バッジ ========== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.badge-blue   { background: #E6F1FB; color: #185FA5; }
.badge-teal   { background: #E1F5EE; color: #0F6E56; }
.badge-amber  { background: #FAEEDA; color: #854F0B; }
.badge-red    { background: #FCEBEB; color: #A32D2D; }
.badge-gray   { background: #F1EFE8; color: #5F5E5A; }
.badge-purple { background: #EEEDFE; color: #3C3489; }
.badge-coral  { background: #FAECE7; color: #993C1D; }
.badge-green  { background: #EAF3DE; color: #3B6D11; }

/* ========== 検索ツールバー ========== */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.search-box { flex: 1; min-width: 200px; padding: 9px 14px; border: 0.5px solid #E0DDD5; border-radius: 6px; font-size: 13px; background: #fff; color: #1A1916; font-family: inherit; min-height: 38px; }
.search-box:focus { outline: none; border-color: #185FA5; box-shadow: 0 0 0 2px #E6F1FB; }
.filter-select { padding: 9px 12px; border: 0.5px solid #E0DDD5; border-radius: 6px; font-size: 13px; background: #fff; color: #7A7975; cursor: pointer; font-family: inherit; min-height: 38px; }
.result-info { font-size: 12px; color: #7A7975; margin-bottom: 10px; min-height: 18px; }

/* ========== チップ（選択式） ========== */
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 14px; border: 0.5px solid #E0DDD5; border-radius: 6px; cursor: pointer; font-size: 12px; color: #7A7975; background: #fff; user-select: none; min-height: 30px; transition: all 0.15s; }
.chip:hover { border-color: #185FA5; color: #185FA5; }
.chip.selected { border-color: #185FA5; background: #E6F1FB; color: #185FA5; font-weight: 500; }
.chip-check { width: 12px; height: 12px; border-radius: 2px; border: 0.5px solid currentColor; display: flex; align-items: center; justify-content: center; font-size: 9px; }

/* ========== ADLテーブル ========== */
.adl-table { display: flex; flex-direction: column; gap: 8px; }
.adl-row { display: grid; grid-template-columns: 110px 1fr; border: 0.5px solid #E0DDD5; border-radius: 6px; overflow: hidden; }
.adl-label { background: #F5F4F0; padding: 10px 12px; font-size: 12px; font-weight: 500; color: #7A7975; display: flex; align-items: flex-start; border-right: 0.5px solid #E0DDD5; padding-top: 12px; }
.adl-content { padding: 8px 12px; display: flex; flex-direction: column; gap: 7px; }
.adl-row-inner { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.adl-sub-label { font-size: 11px; color: #A09D95; min-width: 64px; flex-shrink: 0; }
.rchip { display: inline-flex; align-items: center; padding: 6px 14px; border: 0.5px solid #E0DDD5; border-radius: 20px; cursor: pointer; font-size: 12px; color: #7A7975; background: #fff; user-select: none; white-space: nowrap; min-height: 30px; transition: all 0.15s; }
.rchip:hover { border-color: #185FA5; color: #185FA5; }
.rchip.selected { border-color: #185FA5; background: #E6F1FB; color: #185FA5; font-weight: 500; }

/* ========== スタットカード ========== */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
.stat-card { background: #F5F4F0; border-radius: 8px; padding: 12px 16px; cursor: pointer; border: 0.5px solid transparent; transition: all 0.15s; }
.stat-card:hover, .stat-card.active { background: #E6F1FB; border-color: #185FA5; }
.stat-card .stat-label { font-size: 11px; color: #7A7975; margin-bottom: 3px; }
.stat-card.active .stat-label { color: #185FA5; }
.stat-card .stat-value { font-size: 22px; font-weight: 600; color: #1A1916; }
.stat-card.active .stat-value { color: #185FA5; }

/* ========== キーパーソン ========== */
.kp-card { border: 0.5px solid #E0DDD5; border-radius: 6px; overflow: hidden; margin-bottom: 10px; }
.kp-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: #F5F4F0; border-bottom: 0.5px solid #E0DDD5; }
.kp-label { font-size: 12px; font-weight: 500; color: #7A7975; display: flex; align-items: center; gap: 6px; }
.kp-num { width: 18px; height: 18px; border-radius: 50%; background: #C8C5BC; color: #7A7975; font-size: 10px; display: flex; align-items: center; justify-content: center; }
.kp-body { padding: 14px; }
.remove-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  min-height: 30px;
  border-radius: 6px;
  border: 1px solid #E5C2C2;
  background: #fff;
  color: #A32D2D;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}
.remove-btn:hover {
  background: #FCEBEB;
  border-color: #A32D2D;
}
.add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px dashed #185FA5;
  background: #fff;
  color: #185FA5;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 4px;
  font-family: inherit;
  transition: all 0.15s ease;
}
.add-btn:hover {
  background: #E6F1FB;
  border-style: solid;
}

/* ========== 見学予定 ========== */
.visit-row { display: grid; grid-template-columns: 1fr 180px 38px; gap: 8px; align-items: center; margin-bottom: 8px; }
.visit-remove {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid #E5C2C2;
  background: #fff;
  color: #A32D2D;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  font-family: inherit;
  transition: all 0.15s ease;
}
.visit-remove:hover {
  background: #FCEBEB;
  border-color: #A32D2D;
}

/* ========== 医療ボックス ========== */
.medical-box { border: 0.5px solid #E0DDD5; border-radius: 6px; overflow: hidden; }
.medical-box-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: #F5F4F0; border-bottom: 0.5px solid #E0DDD5; }
.medical-box-title { font-size: 12px; font-weight: 500; color: #7A7975; }
.medical-box-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }

/* ========== アップロード ========== */
.upload-area { border: 1px dashed #C8C5BC; border-radius: 6px; padding: 20px; text-align: center; cursor: pointer; background: #F5F4F0; transition: all 0.1s; }
.upload-area:hover { border-color: #185FA5; background: #E6F1FB; }
.upload-area-icon { font-size: 24px; color: #A09D95; margin-bottom: 6px; }
.upload-area-text { font-size: 13px; color: #7A7975; }
.upload-area-sub { font-size: 11px; color: #A09D95; margin-top: 3px; }
.file-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.file-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: #F5F4F0; border-radius: 6px; border: 0.5px solid #E0DDD5; font-size: 12px; }
.file-remove {
  margin-left: auto;
  color: #A09D95;
  cursor: pointer;
  background: none;
  border: none;
  font-size: 16px;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  min-width: 28px;
  min-height: 28px;
  transition: all 0.15s;
}
.file-remove:hover {
  color: #A32D2D;
  background: #FCEBEB;
}

/* ========== アラート ========== */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; display: flex; align-items: flex-start; gap: 10px; font-size: 12px; line-height: 1.6; }
.alert-warn { background: #FAEEDA; border: 0.5px solid #EF9F27; color: #633806; }
.alert-danger { background: #FCEBEB; border: 0.5px solid #F09595; color: #501313; }
.alert-info { background: #E6F1FB; border: 0.5px solid #85B7EB; color: #042C53; }

/* ========== ダッシュボード ========== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-card { background: #fff; border: 0.5px solid #E0DDD5; border-radius: 8px; padding: 14px 16px; }
.kpi-label { font-size: 12px; color: #7A7975; margin-bottom: 5px; }
.kpi-value { font-size: 28px; font-weight: 600; color: #1A1916; line-height: 1; }
.kpi-sub { font-size: 11px; color: #7A7975; margin-top: 5px; }
.kpi-up { color: #1D9E75; }
.kpi-warn { color: #BA7517; }

/* ========== レスポンシブ ========== */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 768px) {
  .main-content {
    margin-left: 0 !important;
    padding: 60px 12px 20px 12px;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }
  .app-layout {
    max-width: 100%;
    overflow-x: hidden;
  }
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Phase 7-9: スマホでテーブルが圧縮されて読みにくいので最小幅指定して横スクロール発火 */
  .table-wrap .data-table {
    min-width: 640px;
  }
  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  .stat-grid {
    grid-template-columns: repeat(2,1fr) !important;
    gap: 8px !important;
  }
  .form-grid-2,
  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr !important;
  }
  .col-span-2,
  .col-span-3,
  .col-span-4 {
    grid-column: 1 !important;
  }
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px;
  }
  .page-header .btn-group {
    flex-wrap: wrap;
    gap: 6px;
  }
  .toolbar {
    flex-wrap: wrap;
  }
  .search-box {
    width: 100%;
    min-width: 0;
  }
  .adl-row {
    grid-template-columns: 76px 1fr !important;
  }
  .card-body {
    padding: 12px;
  }
  /* モバイル時のボタン拡大 */
  .btn {
    min-height: 42px;
    padding: 10px 16px;
  }
  .action-link {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 12px;
  }
  .action-links {
    gap: 5px;
  }
  .login-wrap {
    padding: 12px;
  }
  .login-card {
    padding: 20px 16px;
  }

  /* Phase 7-9: スマホ時の横スクロール対応 */
  /* テーブル直接配置や、grid 固定列レイアウトのスクロール許可 */
  .scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .scroll-x > * {
    min-width: max-content;
  }
  /* logs.php KPI(8列固定) → スマホで4列＋スクロール許可 */
  .kpi-grid-8 {
    grid-template-columns: repeat(4, minmax(120px, 1fr)) !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* 契約書 2カラム grid → スマホで1列 */
  .form-grid-2-resp {
    grid-template-columns: 1fr !important;
  }
}

