/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:        #4f7fff;
  --blue-light:  #eef2ff;
  --green:       #22c55e;
  --green-light: #dcfce7;
  --amber:       #f59e0b;
  --amber-light: #fef3c7;
  --pink:        #f472b6;
  --pink-light:  #fce7f3;
  --purple:      #a855f7;
  --purple-light:#f3e8ff;
  --teal:        #14b8a6;
  --teal-light:  #ccfbf1;
  --red:         #ef4444;
  --red-light:   #fee2e2;

  --text:        #1e1e2e;
  --text-soft:   #44445a;
  --text-muted:  #888899;
  --border:      #e8e8f0;
  --border-light:#f0f0f8;
  --bg:          #f4f6ff;
  --card:        #ffffff;
  --shadow-sm:   0 2px 6px rgba(80,80,160,0.07);
  --shadow:      0 4px 16px rgba(80,80,160,0.10);
  --shadow-md:   0 8px 28px rgba(80,80,160,0.14);
  --radius:      14px;
  --radius-sm:   10px;
  --radius-xs:   6px;

  /* タッチターゲット最小サイズ */
  --touch: 44px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 15px; /* スマホで読みやすい基本サイズ */
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; /* iOS自動拡大を防ぐ */
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== HEADER ===== */
.site-header {
  background: linear-gradient(90deg, #4f7fff 0%, #a855f7 100%);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 3px 14px rgba(79,127,255,0.30);
  /* iPhoneノッチ対応 */
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.site-title {
  font-size: 17px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -0.3px;
}
.site-title:hover { text-decoration: none; opacity: 0.88; }
.btn-header {
  background: rgba(255,255,255,0.20);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.45);
  padding: 0 16px;
  height: var(--touch);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border-radius: 22px;
  transition: background 0.18s;
  white-space: nowrap;
}
.btn-header:hover { background: rgba(255,255,255,0.35); }

/* 管理者バー */
.admin-bar {
  background: linear-gradient(90deg, #fef3c7, #fde68a);
  border-bottom: 2px solid #fbbf24;
  padding: 9px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #78350f;
  display: none;
}
body.admin-mode .admin-bar { display: block; }

/* ===== MAIN ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 14px 80px; /* 下は余裕を持たせる */
  /* iPhone横スクロール防止 */
  overflow-x: hidden;
}

/* ===== FILTER CARD ===== */
.filter-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.filter-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  margin-bottom: 14px;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* モバイルは2列 */
  gap: 14px;
}
.filter-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  margin-bottom: 6px;
}
.filter-row { display: flex; gap: 6px; align-items: center; }
.filter-row span { font-size: 13px; color: var(--text-muted); }
.filter-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1.5px dashed var(--border);
  align-items: center;
  flex-wrap: wrap;
}

/* ===== FORM CONTROLS ===== */
input[type="number"], input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  padding: 11px 13px; /* タッチしやすい高さ */
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* iOSズーム防止: 16px未満でズームが起きる */
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79,127,255,0.13);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
textarea { resize: vertical; min-height: 90px; font-size: 15px; }
.checkbox-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 15px; min-height: var(--touch); }
.checkbox-label input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; accent-color: var(--blue); flex-shrink: 0; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  padding: 0 22px;
  border-radius: 22px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  transition: all 0.18s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary  { background: linear-gradient(90deg,#4f7fff,#7c5cfc); color: #fff; box-shadow: 0 3px 10px rgba(79,127,255,0.30); }
.btn-primary:active  { transform: scale(0.97); }
.btn-secondary{ background: #fff; color: var(--text-soft); border: 1.5px solid var(--border); }
.btn-secondary:active { background: var(--bg); }
.btn-danger   { background: linear-gradient(90deg,#ef4444,#f97316); color: #fff; box-shadow: 0 3px 10px rgba(239,68,68,0.25); }
.btn-danger:active { transform: scale(0.97); }
.btn-success  { background: linear-gradient(90deg,#22c55e,#14b8a6); color: #fff; box-shadow: 0 3px 10px rgba(34,197,94,0.28); }
.btn-success:active { transform: scale(0.97); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }

/* ===== RESULT HEADER ===== */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.result-count { font-size: 13px; font-weight: 700; color: var(--text-muted); }

/* ===== SCHOOL GRID ===== */
.school-grid {
  display: grid;
  grid-template-columns: 1fr; /* モバイルは1列 */
  gap: 14px;
}

/* ===== SCHOOL CARD ===== */
.school-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
.school-card:active { transform: scale(0.985); }

.school-card::before {
  content: '';
  display: block;
  height: 5px;
  background: linear-gradient(90deg, #4f7fff, #a855f7, #f472b6);
}

.school-card-top { padding: 16px 16px 12px; flex: 1; }
.school-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.school-name { font-size: 19px; font-weight: 900; letter-spacing: -0.3px; line-height: 1.3; }

/* バッジ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
  border-radius: 20px;
}
.badge-deviation { background: linear-gradient(90deg,#4f7fff,#7c5cfc); color: #fff; }

/* チップ */
.school-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: #f4f6ff;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}
.meta-chip.green  { background: var(--green-light);  border-color: #86efac; color: #15803d; }
.meta-chip.amber  { background: var(--amber-light);  border-color: #fcd34d; color: #92400e; }
.meta-chip.purple { background: var(--purple-light); border-color: #d8b4fe; color: #7e22ce; }

/* カード下部 */
.school-card-bottom {
  padding: 11px 16px;
  background: #fafbff;
  border-top: 1.5px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 20px;
}
.status-tag.done    { background: var(--green-light);  color: #15803d; border: 1.5px solid #86efac; }
.status-tag.pending { background: var(--amber-light);  color: #92400e; border: 1.5px solid #fcd34d; }
.memo-preview {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.card-admin-actions { display: none; gap: 8px; padding: 10px 16px; border-top: 1.5px dashed var(--border); background: #fafbff; flex-wrap: wrap; }
body.admin-mode .card-admin-actions { display: flex; }

/* ===== DETAIL PAGE ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 18px;
  padding: 8px 4px;
  min-height: var(--touch);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.back-link:hover, .back-link:active { color: var(--blue); text-decoration: none; }

/* 詳細ヘッダー */
.detail-header {
  background: linear-gradient(135deg, #4f7fff 0%, #7c5cfc 55%, #f472b6 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 24px 18px 22px;
  margin-bottom: 16px;
  box-shadow: 0 6px 28px rgba(79,127,255,0.28);
}
.detail-school-name {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.5px;
  margin-bottom: 14px;
  line-height: 1.25;
}
.detail-badges { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.badge-lg { padding: 6px 14px; font-size: 13px; font-weight: 700; border-radius: 20px; }
.badge-white  { background: rgba(255,255,255,0.22); color: #fff; border: 1.5px solid rgba(255,255,255,0.4); }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-gray   { background: rgba(255,255,255,0.10); color: rgba(255,255,255,0.6); border: 1px solid rgba(255,255,255,0.2); }

.detail-status-row { display: flex; flex-wrap: wrap; gap: 6px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 13px;
  border-radius: 20px;
}
.status-pill.done    { background: rgba(255,255,255,0.92); color: #15803d; }
.status-pill.pending { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.85); border: 1.5px solid rgba(255,255,255,0.3); }

.detail-admin-actions { display: none; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.25); flex-wrap: wrap; }
body.admin-mode .detail-admin-actions { display: flex; }

/* ===== SECTION CARDS ===== */
.section-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.section-card-header {
  padding: 14px 16px;
  border-bottom: 1.5px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 9px;
  background: linear-gradient(to right, #f8f9ff, #f4f6ff);
}
.section-card-icon { font-size: 18px; line-height: 1; }
.section-card-title { font-size: 14px; font-weight: 800; color: var(--text); }

/* ===== 情報テーブル（モバイルはラベル上・値下の縦積み） ===== */
.info-table { width: 100%; border-collapse: collapse; }

/* 各行を縦積みブロックに */
.info-table tr {
  display: block;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-light);
}
.info-table tr:last-child { border-bottom: none; }
.info-table tr:hover { background: #fafbff; }

.info-table th {
  display: block;
  width: 100%;
  padding: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: left;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.info-table td {
  display: block;
  width: 100%;
  padding: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* メモブロック */
.memo-block {
  padding: 18px 16px;
  background: linear-gradient(to right, #fffbeb, #fef9f0);
  border-top: 2px dashed #fcd34d;
  font-size: 15px;
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
  color: #78350f;
}
.memo-block-empty { padding: 18px 16px; font-size: 14px; color: var(--text-muted); font-style: italic; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(30,30,60,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: flex-end; /* スマホはシートとして下から出す */
  justify-content: center;
  padding: 0;
  opacity: 0; pointer-events: none; transition: opacity 0.22s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0; /* 下は角丸なし */
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 680px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 -8px 40px rgba(30,30,80,0.18);
  transform: translateY(40px); transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
}
.modal-overlay.active .modal { transform: translateY(0); }

/* ドラッグハンドル */
.modal::before {
  content: '';
  display: block;
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; padding-bottom: 14px;
  border-bottom: 2px solid var(--border-light);
}
.modal-title { font-size: 17px; font-weight: 900; }
.modal-close {
  background: #f4f6ff; border: none;
  width: var(--touch); height: var(--touch);
  cursor: pointer; font-size: 18px; color: var(--text-muted);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.modal-close:active { background: var(--border); }
.modal-footer {
  display: flex; justify-content: stretch; gap: 10px;
  margin-top: 20px; padding-top: 16px; border-top: 2px dashed var(--border-light);
}
.modal-footer .btn { flex: 1; } /* ボタンを横幅いっぱいに */

/* フォームセクション区切り */
.form-section-header {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 0 2px;
  border-top: 2px dashed var(--border);
  margin-top: 8px;
  font-size: 12px; font-weight: 800;
  color: var(--text-soft);
}

/* フォームグリッド */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; } /* モバイルは常に1列 */
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; font-weight: 700; color: var(--text-soft); }

/* アラート */
.alert { padding: 13px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; font-weight: 600; }
.alert-error   { background: var(--red-light);   border: 1.5px solid #fca5a5; color: #b91c1c; }
.alert-success { background: var(--green-light);  border: 1.5px solid #86efac; color: #15803d; }

/* 空状態 */
.empty-state { text-align: center; padding: 64px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 52px; margin-bottom: 14px; }
.empty-state-text { font-size: 15px; font-weight: 600; }

/* ローディング */
.loading { text-align: center; padding: 60px; color: var(--text-muted); }
.loading::before {
  content: ''; display: block;
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 内申点カード ===== */
.naishin-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.naishin-card::before {
  content: '';
  display: block;
  height: 4px;
  margin: -16px -16px 14px;
  background: linear-gradient(90deg, #f472b6, #a855f7, #4f7fff);
}
.naishin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.naishin-title { font-size: 14px; font-weight: 800; color: var(--text); }
.naishin-total-area { display: flex; align-items: center; gap: 10px; }
.naishin-total {
  font-size: 26px;
  font-weight: 900;
  padding: 4px 14px;
  border-radius: 10px;
  line-height: 1.2;
}
.naishin-max { font-size: 14px; font-weight: 600; opacity: 0.7; }

.naishin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 14px;
}
.naishin-chip {
  background: #f4f6ff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.naishin-chip-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-align: center; line-height: 1.3; }
.naishin-chip-score { font-size: 22px; font-weight: 900; color: var(--text); }
.chip-5 { background: #dcfce7; border-color: #86efac; }
.chip-5 .naishin-chip-score { color: #15803d; }
.chip-4 { background: #dbeafe; border-color: #93c5fd; }
.chip-4 .naishin-chip-score { color: #1d4ed8; }
.chip-3 { background: #fef3c7; border-color: #fcd34d; }
.chip-3 .naishin-chip-score { color: #92400e; }
.chip-low { background: #fee2e2; border-color: #fca5a5; }
.chip-low .naishin-chip-score { color: #b91c1c; }

/* 内申モーダル専用 */
.naishin-input-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.naishin-input-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: #f8f9ff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
}
.naishin-input-group label { font-size: 12px; font-weight: 700; color: var(--text-soft); text-align: center; line-height: 1.3; }
.naishin-input-group input {
  width: 60px;
  text-align: center;
  font-size: 22px;
  font-weight: 900;
  padding: 4px 6px;
  border-radius: var(--radius-xs);
}
.naishin-preview {
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: var(--blue);
  padding: 12px;
  background: var(--blue-light);
  border-radius: var(--radius-sm);
  margin-top: 10px;
}

/* ===== タブレット以上（640px〜）===== */
@media (min-width: 640px) {
  main { padding: 28px 20px 64px; }

  .header-inner { padding: 0 24px; }
  .header-inner { height: 60px; }

  .filter-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

  .school-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
  .school-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); border-color: #c5d0ff; }
  .school-card:active { transform: none; }

  .school-name { font-size: 17px; }

  /* デスクトップではモーダルを中央に */
  .modal-overlay { align-items: center; padding: 16px; }
  .modal {
    border-radius: var(--radius);
    max-width: 660px;
    padding: 30px;
    transform: translateY(10px) scale(0.99);
  }
  .modal-overlay.active .modal { transform: translateY(0) scale(1); }
  .modal::before { display: none; } /* ハンドル非表示 */
  .modal-footer .btn { flex: none; }
  .modal-footer { justify-content: flex-end; }

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

  /* デスクトップ: テーブルを左右2列に戻す */
  .info-table tr {
    display: table-row;
    padding: 0;
  }
  .info-table tr:last-child { border-bottom: none; }
  .info-table tr + tr td,
  .info-table tr + tr th { border-top: 1px solid var(--border-light); }
  .info-table th {
    display: table-cell;
    width: 37%;
    padding: 13px 12px 13px 22px;
    font-size: 12px;
    text-align: right;
    vertical-align: top;
    text-transform: uppercase;
  }
  .info-table td {
    display: table-cell;
    padding: 13px 22px 13px 14px;
    font-size: 14px;
  }

  .detail-header { padding: 30px 30px 26px; }
  .detail-school-name { font-size: 30px; }
  .section-card-header { padding: 14px 22px; }
  .filter-card { padding: 22px 24px 20px; }
  .school-card-top { padding: 18px 20px 14px; }
  .school-card-bottom { padding: 11px 20px; }
  .card-admin-actions { padding: 10px 20px; }
  .memo-block { padding: 20px 22px; }
  .memo-block-empty { padding: 20px 22px; }
}
