/* ===================================================
   課題評価システム - Main Stylesheet
   =================================================== */

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
}

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

body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Header ---- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 1rem;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}
.header-logo i { font-size: 1.4rem; }

.header-ofuse {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-steps {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.step {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .7rem;
  border-radius: 999px;
  font-size: .8rem;
  color: var(--text-muted);
  transition: all .2s;
}
.step .step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.step.active .step-num {
  background: var(--primary);
  color: #fff;
}
.step.active {
  color: var(--primary);
  font-weight: 600;
}
.step.completed .step-num {
  background: var(--success);
  color: #fff;
}
.step.completed { color: var(--success); }
.step-arrow { color: var(--border); font-size: .7rem; }

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

/* ---- Panel ---- */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}
.panel-header i {
  font-size: 1.3rem;
  color: var(--primary);
}
.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.panel-body { padding: 1.75rem; }

.panel-footer {
  padding: 1.25rem 1.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  background: var(--surface-2);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .2s;
  text-decoration: none;
  font-family: inherit;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:not(:disabled):hover { background: var(--primary-dark); }
.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:not(:disabled):hover { background: #059669; }
.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-outline:not(:disabled):hover { border-color: var(--primary); color: var(--primary); background: #f0f0ff; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.btn-add-keyword {
  margin-top: .5rem;
  border-style: dashed;
  color: var(--primary);
  border-color: var(--primary-light);
}
.btn-add-keyword:hover { background: #f0f0ff; }

/* ---- Upload Zone ---- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  background: var(--surface-2);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: #f0f0ff;
}
.upload-zone i {
  font-size: 2.5rem;
  color: var(--primary-light);
  margin-bottom: .75rem;
  display: block;
}
.upload-zone p { color: var(--text-muted); margin-bottom: .75rem; font-size: .95rem; }
.upload-hint { font-size: .78rem; color: #94a3b8; margin-top: .5rem; }

.upload-zone-sm {
  padding: 1.5rem 2rem;
}
.upload-zone-sm i { font-size: 1.8rem; }

/* ---- Upload Result ---- */
.upload-result {
  margin-top: 1rem;
}
.upload-result.hidden { display: none; }
.result-info {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  background: #ecfdf5;
  border-radius: var(--radius-sm);
  border: 1px solid #6ee7b7;
  margin-bottom: .75rem;
}
.result-info i { font-size: 1.2rem; }
.result-info > div { flex: 1; }
.result-info strong { display: block; font-size: .95rem; }
.result-info span { font-size: .82rem; color: var(--text-muted); }
.text-success { color: var(--success); }

/* ---- Preview Table ---- */
.preview-table-wrap {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}
.preview-table th {
  background: var(--surface-2);
  padding: .5rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.preview-table td {
  padding: .45rem .75rem;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-table tr:last-child td { border-bottom: none; }

/* ---- Setting Blocks ---- */
.setting-block {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
.setting-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.setting-title {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .6rem;
}
.setting-title i { color: var(--primary); font-size: 1rem; }
.setting-title h3 { font-size: 1rem; font-weight: 700; }

.setting-desc {
  font-size: .88rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  line-height: 1.7;
}

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #dc2626; }

/* ---- Toggle Switch ---- */
.toggle-label {
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  font-size: .9rem;
  user-select: none;
  margin-bottom: .5rem;
}
.toggle-label input[type="checkbox"] { display: none; }
.toggle-switch {
  width: 38px;
  height: 22px;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-label input:checked + .toggle-switch { background: var(--primary); }
.toggle-label input:checked + .toggle-switch::after { left: 19px; }

/* ---- Keyword List ---- */
.keyword-options { margin-bottom: 1rem; }
.keyword-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: .75rem;
}
.keyword-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  transition: border-color .2s;
}
.keyword-item:focus-within { border-color: var(--primary); }
.keyword-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.keyword-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: .9rem;
  outline: none;
  font-family: inherit;
  color: var(--text);
}
.keyword-input::placeholder { color: #94a3b8; }
.keyword-weight-input {
  width: 60px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .25rem .4rem;
  font-size: .82rem;
  text-align: center;
  background: var(--surface);
  font-family: inherit;
}
.keyword-weight-label { font-size: .75rem; color: var(--text-muted); }
.keyword-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: #cbd5e1;
  transition: color .2s;
  padding: .1rem .3rem;
  font-size: .9rem;
}
.keyword-delete:hover { color: var(--danger); }

.keyword-weight-info {
  margin-top: 1rem;
  padding: .75rem 1rem;
  background: #f0f0ff;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.keyword-weight-info strong { color: var(--primary); }
.weight-slider {
  width: 140px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ---- Lecture Preview ---- */
.lecture-preview {
  max-height: 120px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem;
  font-size: .82rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: .5rem;
}

/* ---- Length Config ---- */
.length-config { margin-top: .25rem; }

/* ---- Target Average ---- */
.target-avg-block {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px dashed var(--border);
}
.target-avg-header { margin-bottom: .5rem; }
.target-avg-body { margin-top: .75rem; }
.target-avg-body.hidden { display: none; }
.target-avg-desc {
  font-size: .85rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 1rem;
  padding: .65rem .9rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.target-avg-inputs {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.target-avg-input-wrap {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.target-avg-input {
  width: 90px;
  padding: .45rem .7rem;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  text-align: center;
  color: var(--primary);
}
.target-avg-input:focus { outline: none; box-shadow: 0 0 0 3px #e0e7ff; }
.target-avg-unit { font-size: .9rem; color: var(--text-muted); font-weight: 500; }
.target-avg-preview {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .9rem;
  background: #f0f0ff;
  border-radius: var(--radius-sm);
  border: 1px solid #c7d2fe;
  font-size: .85rem;
  color: var(--primary);
  flex: 1;
  min-width: 200px;
}
.target-avg-preview i { flex-shrink: 0; }
.scaling-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  background: #e0e7ff;
  color: var(--primary-dark);
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  margin-left: .5rem;
}

/* ---- Lecture Slots ---- */
.lecture-slots {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-bottom: .75rem;
}
.lecture-slot { display: flex; flex-direction: column; gap: .5rem; }
.lecture-slot.hidden { display: none; }

.lecture-weight-info {
  margin-top: .75rem;
  padding: .6rem 1rem;
  background: #f0fdf4;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  color: var(--text-muted);
}
.lecture-weight-info strong { color: var(--success); }

/* ---- Score Config ---- */
.score-config {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.score-option {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.score-option label { font-size: .88rem; font-weight: 500; }
.score-option select, .score-option input {
  padding: .45rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  background: var(--surface);
  min-width: 180px;
}
.score-option select:focus, .score-option input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---- Progress ---- */
.progress-wrap {
  margin-bottom: 1.5rem;
}
.progress-bar-outer {
  width: 100%;
  height: 12px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: .75rem;
}
.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 999px;
  transition: width .4s ease;
  width: 0%;
}
.progress-status {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .25rem;
}
.progress-detail {
  font-size: .82rem;
  color: var(--text-muted);
}
.log-box {
  background: #1e293b;
  color: #94a3b8;
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  font-family: 'Courier New', monospace;
  font-size: .78rem;
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.8;
}
.log-box .log-line { display: block; }
.log-box .log-ok { color: #6ee7b7; }
.log-box .log-warn { color: #fde68a; }
.log-box .log-info { color: #93c5fd; }
.log-box .log-err { color: #fca5a5; }

/* ---- Summary Cards ---- */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.summary-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  border: 1px solid var(--border);
}
.summary-icon { font-size: 1.5rem; color: var(--primary); margin-bottom: .5rem; }
.summary-value { font-size: 2rem; font-weight: 800; color: var(--text); }
.summary-label { font-size: .82rem; color: var(--text-muted); margin-top: .25rem; }

/* ---- Result Toolbar ---- */
.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.result-filters {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  flex: 1;
}
.search-input, .result-filters select {
  padding: .5rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-family: inherit;
  background: var(--surface);
  min-width: 160px;
}
.search-input { min-width: 200px; flex: 1; }
.search-input:focus, .result-filters select:focus {
  outline: none;
  border-color: var(--primary);
}
.result-actions { display: flex; gap: .6rem; }

/* ---- Result Table ---- */
.result-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 520px;
}
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.result-table thead th {
  background: var(--surface-2);
  padding: .65rem .9rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
  font-weight: 600;
}
.result-table tbody tr {
  cursor: pointer;
  transition: background .15s;
}
.result-table tbody tr:hover { background: #f8f5ff; }
.result-table tbody td {
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--border);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-table tbody tr:last-child td { border-bottom: none; }

/* ---- Score Display ---- */
.score-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 28px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .85rem;
}
.score-high { background: #dcfce7; color: #15803d; }
.score-mid  { background: #fef9c3; color: #a16207; }
.score-low  { background: #fee2e2; color: #b91c1c; }
.score-none { background: var(--border); color: var(--text-muted); }

/* ---- Keyword Match Badges ---- */
.keyword-match-wrap { display: flex; flex-wrap: wrap; gap: .25rem; }
.kw-tag {
  padding: .15rem .45rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}
.kw-matched   { background: #dcfce7; color: #15803d; }
.kw-missing   { background: #fee2e2; color: #b91c1c; text-decoration: line-through; }
.kw-crosslang { background: #dbeafe; color: #1d4ed8; }

.click-hint { font-size: .8rem; color: var(--text-muted); text-align: center; margin-top: .75rem; }
.click-hint i { margin-right: .25rem; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: color .2s;
}
.modal-close:hover { color: var(--danger); }
.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

/* ---- Modal Content ---- */
.modal-section { margin-bottom: 1.5rem; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-title {
  font-size: .85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .6rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.modal-section-title i { color: var(--primary); }
.answer-text {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-size: .88rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.score-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1rem;
}
.score-detail-item {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  border: 1px solid var(--border);
}
.score-detail-item .label { font-size: .78rem; color: var(--text-muted); margin-bottom: .25rem; }
.score-detail-item .value { font-size: 1.3rem; font-weight: 800; color: var(--text); }
.score-edit-input {
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: .3rem .5rem;
  font-size: 1rem;
  font-weight: 700;
  width: 80px;
  text-align: center;
  font-family: inherit;
}

.eval-bar-wrap { margin-bottom: .4rem; }
.eval-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  margin-bottom: .2rem;
}
.eval-bar {
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.eval-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .5s ease;
}
.eval-bar-fill.keyword { background: var(--primary); }
.eval-bar-fill.lecture { background: var(--success); }
.eval-bar-fill.total   { background: linear-gradient(90deg, var(--primary), var(--success)); }

.lecture-comment {
  background: #f0fdf4;
  border: 1px solid #6ee7b7;
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .85rem;
  line-height: 1.7;
  color: var(--text);
}

/* ---- Inline score edit ---- */
.inline-score-input {
  width: 55px;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: .2rem .3rem;
  font-size: .85rem;
  text-align: center;
  font-family: inherit;
  font-weight: 700;
  background: var(--surface);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; height: auto; padding: .75rem 0; gap: .5rem; }
  .header-steps { justify-content: center; }
  .step-label { display: none; }
  .app-main { padding: 0 .75rem 3rem; margin: 1rem auto; }
  .panel-body { padding: 1rem; }
  .panel-footer { flex-direction: column-reverse; }
  .score-detail-grid { grid-template-columns: 1fr; }
  .result-toolbar { flex-direction: column; align-items: stretch; }
  .result-actions { flex-direction: column; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
}
