:root {
  --primary: #4f46e5;
  --primary-light: #eef2ff;
  --primary-dark: #3730a3;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -.5px;
}
nav { display: flex; gap: .5rem; }
nav a {
  padding: .4rem .9rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  color: var(--gray-600);
  transition: background .15s;
}
nav a:hover { background: var(--gray-100); }
nav a.active { background: var(--primary-light); color: var(--primary); }

/* ── Main layout ── */
main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Card ── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.25rem;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: .9; }
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-sm { padding: .4rem .9rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ── */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--gray-600); margin-bottom: .35rem; }
input[type="text"], textarea, select {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
  transition: border-color .15s;
  background: #fff;
}
input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
textarea { resize: vertical; min-height: 80px; }

/* ── Student Home ── */
.home-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 56px - 4rem);
}
.home-card {
  width: 100%;
  max-width: 460px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  text-align: center;
}
.home-icon { font-size: 3rem; margin-bottom: 1rem; }
.home-card h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: .5rem; }
.home-card p { color: var(--gray-600); font-size: .9rem; margin-bottom: 2rem; }
.home-card .form-group { text-align: left; margin-bottom: 1.25rem; }
.home-card .btn { width: 100%; justify-content: center; }

/* ── Chat layout ── */
.chat-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 800px) {
  .chat-layout { grid-template-columns: 1fr; }
}

.chat-panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 4rem);
  min-height: 500px;
}
.chat-panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-panel-header h2 { font-size: 1rem; font-weight: 700; }
.student-badge {
  font-size: .75rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: .2rem .6rem;
  border-radius: 20px;
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.message { display: flex; gap: .75rem; max-width: 88%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.message.user .avatar { background: var(--primary); color: #fff; }
.message.assistant .avatar { background: var(--gray-100); }

.bubble {
  padding: .65rem 1rem;
  border-radius: 16px;
  font-size: .9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--gray-100);
  color: var(--gray-800);
  border-bottom-left-radius: 4px;
}

.chat-input-area {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: .75rem;
  align-items: flex-end;
}
.chat-input-area textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  border-radius: 10px;
  padding: .6rem .9rem;
}
.send-btn {
  height: 44px;
  width: 44px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.loading-dot {
  display: inline-flex;
  gap: 3px;
  padding: .65rem 1rem;
  background: var(--gray-100);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
.loading-dot span {
  width: 7px; height: 7px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.loading-dot span:nth-child(2) { animation-delay: .2s; }
.loading-dot span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Summary panel ── */
.summary-panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.summary-panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.summary-panel-header h2 { font-size: 1rem; font-weight: 700; }
.summary-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.field-hint { font-size: .75rem; color: var(--gray-400); }
.submitted-badge {
  background: #dcfce7;
  color: #166534;
  padding: 1rem;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
}

/* ── Teacher list ── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-header p { color: var(--gray-600); font-size: .9rem; margin-top: .25rem; }

.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--gray-50);
  padding: .75rem 1rem;
  text-align: left;
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200);
}
td {
  padding: .85rem 1rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-fix { background: #fee2e2; color: #991b1b; }
.badge-caution { background: #ffedd5; color: #9a3412; }

/* ── Teacher detail ── */
.detail-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: var(--gray-600);
  text-decoration: none;
  font-size: .875rem;
  margin-bottom: 1rem;
}
.back-link:hover { color: var(--primary); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

.section-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 1rem;
}
.field-row { margin-bottom: 1rem; }
.field-row .field-label { font-size: .75rem; font-weight: 600; color: var(--gray-400); margin-bottom: .25rem; }
.field-row .field-value { font-size: .9rem; color: var(--gray-800); }

.ai-analysis-box {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  padding: 1rem;
  font-size: .875rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: #0c4a6e;
}

.rating-group { display: flex; gap: .75rem; margin-bottom: 1rem; }
.rating-btn {
  flex: 1;
  padding: .6rem;
  border-radius: 8px;
  border: 2px solid var(--gray-200);
  background: #fff;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.rating-btn:hover { border-color: var(--primary); }
.rating-btn.selected-適切 { border-color: var(--success); background: #dcfce7; color: #166534; }
.rating-btn.selected-要修正 { border-color: var(--warning); background: #fef3c7; color: #92400e; }
.rating-btn.selected-不適切 { border-color: var(--danger); background: #fee2e2; color: #991b1b; }

.chat-history {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: .5rem 0;
}
.history-msg { display: flex; gap: .6rem; }
.history-msg.user { flex-direction: row-reverse; }
.history-msg .bubble { max-width: 80%; }
.history-msg.user .bubble { background: var(--primary-light); color: var(--primary-dark); }
.history-msg.assistant .bubble { background: var(--gray-100); }
.history-label { font-size: .7rem; color: var(--gray-400); margin-top: .25rem; text-align: right; }
.history-msg.assistant .history-label { text-align: left; }

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--gray-400);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }

.save-status { font-size: .85rem; color: var(--success); margin-left: .75rem; display: none; }
