:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --line: #d8dee8;
  --text: #172033;
  --muted: #697589;
  --primary: #1f6feb;
  --primary-dark: #174ea6;
  --danger: #b42318;
  --ok: #1a7f37;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
.button {
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  font: inherit;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--primary-dark);
}

button.secondary,
.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--surface-2);
}

button.danger,
.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #eef1f5;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.readonly-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.readonly-field strong {
  min-height: 39px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef1f5;
  color: var(--text);
  padding: 9px 10px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  background: var(--surface-2);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

td span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 18px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

.login-panel h1,
.page-head h1 {
  margin: 0;
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.alert {
  border: 1px solid #f4c7c3;
  border-radius: 6px;
  background: #fff2f0;
  color: var(--danger);
  padding: 10px 12px;
}

.notification-panel {
  border: 1px solid #fecaca;
  background: #fff7f7;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.notification-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.notification-panel-head h2 {
  font-size: 16px;
  margin: 0;
}

.notification-list {
  display: grid;
  gap: 8px;
}

.notification-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  background: #fff;
  border: 1px solid #fee2e2;
  border-radius: 8px;
  padding: 10px;
}

.notification-item p {
  margin: 3px 0 4px;
  color: var(--muted);
}

.notification-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #dc2626;
  box-shadow: 0 0 0 3px #fee2e2;
  margin-top: 5px;
  display: inline-block;
  flex: 0 0 auto;
}

.notification-badge,
.notification-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 58px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.nav div {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.nav form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.brand {
  color: var(--text);
  font-weight: 800;
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 26px 22px 48px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.back-link::before {
  content: "<";
  margin-right: 6px;
}

.summary {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.summary strong {
  font-size: 24px;
}

.filters,
.actions {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.page-head .actions {
  margin-bottom: 0;
}

.filters input,
.filters select {
  width: 170px;
}

.table-wrap,
.panel,
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.panel,
.metric {
  padding: 18px;
}

.panel h2,
.metric h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #e9f2ff;
  color: var(--primary-dark);
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
}

.period-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 1px 8px;
  margin: 4px 0 2px;
  width: fit-content;
  font-size: 12px;
  font-weight: 700;
}

.period-chip.current {
  background: #e7f8ee;
  color: #17613a;
}

.period-chip.past {
  background: #eef1f5;
  color: var(--muted);
}

.period-chip.future {
  background: #e8f3ff;
  color: #195b92;
}

.current-period-row td {
  background: #fbfffd;
}

.period-admin-panel {
  margin-bottom: 16px;
}

.period-admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 18px;
}

.period-admin-grid h3 {
  margin: 0;
  font-size: 15px;
}

.compact-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.numeric {
  text-align: right;
}

.criteria {
  color: #334155;
  font-size: 13px;
}

.section-title {
  margin: 20px 0 10px;
}

.section-title h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.actions-cell {
  min-width: 170px;
  white-space: nowrap;
}

.actions-cell > a,
.actions-cell form {
  display: inline-flex;
  vertical-align: middle;
  margin: 0 8px 0 0;
}

.actions-cell button,
.actions-cell .button {
  width: auto;
}

.actions-cell > a:last-child,
.actions-cell form:last-child {
  margin-right: 0;
}

.form-panel {
  display: grid;
  gap: 18px;
  max-width: 980px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 0 6px;
}

.check-grid {
  display: flex;
  gap: 10px 18px;
  flex-wrap: wrap;
}

.check-row {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-row input {
  width: auto;
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.score-input {
  width: 86px;
  text-align: right;
}

.score-edit-cell {
  text-align: right;
}

.score-edit-cell .score-input {
  width: min(100%, 92px);
}

.bulk-score-form {
  display: grid;
  gap: 12px;
}

.bulk-score-actions {
  justify-content: flex-end;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.stack {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.note {
  border-left: 3px solid var(--primary);
  background: #f8fbff;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.note p {
  margin: 6px 0 0;
}

.note span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.comment-edit {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  margin-top: 10px;
}

.comment-edit summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary-dark);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.history-grid {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.upload-form {
  margin-bottom: 8px;
  align-items: stretch;
}

.upload-form input[type="file"] {
  max-width: 520px;
}

.compact-table {
  margin-top: 12px;
}

.compact-table table {
  min-width: 0;
}

.user-table {
  min-width: 1280px;
  table-layout: auto;
}

.user-table th:last-child,
.user-table td:last-child {
  width: 210px;
  min-width: 210px;
}

.category-list {
  display: grid;
  gap: 18px;
}

.category-section {
  display: grid;
  gap: 10px;
}

.category-section header {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.category-section h2 {
  margin: 0;
  font-size: 20px;
}

.category-section header span {
  color: var(--muted);
  font-size: 13px;
}

.category-row th {
  background: #edf7f1;
  color: #13522b;
  font-size: 13px;
}

.score-groups {
  display: grid;
  gap: 18px;
}

.score-major-section {
  display: grid;
  gap: 10px;
}

.score-major-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 0 2px 4px;
  border-bottom: 2px solid var(--line);
}

.score-major-header h3 {
  margin: 0;
  font-size: 20px;
}

.score-major-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.score-major-items {
  display: grid;
  gap: 10px;
}

.score-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.score-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  cursor: pointer;
  background: #f2f6fb;
}

.score-group summary strong {
  display: block;
  margin-top: 2px;
}

.score-category,
.score-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.score-table-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.score-table {
  min-width: 980px;
}

.score-col-detail {
  width: 24%;
}

.score-col-criteria {
  width: 34%;
}

.score-col-number {
  width: 10.5%;
}

.score-table th:nth-child(n + 3),
.score-table td:nth-child(n + 3) {
  text-align: center;
  vertical-align: middle;
}

.score-table .score-edit-cell .score-input {
  margin: 0 auto;
  text-align: center;
}

@media (max-width: 900px) {
  .nav {
    grid-template-columns: 1fr;
    padding: 12px 16px;
  }

  .page-head,
  .grid-2,
  .form-grid,
  .period-admin-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

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

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 860px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  button,
  .button {
    min-height: 40px;
    padding: 0 12px;
  }

  .login-shell {
    align-items: start;
    padding: 16px;
  }

  .login-panel {
    padding: 20px;
    gap: 14px;
  }

  .login-panel h1,
  .page-head h1 {
    font-size: 22px;
    line-height: 1.25;
  }

  .nav {
    position: static;
    gap: 10px;
    padding: 10px 12px;
  }

  .nav div {
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .nav div a {
    flex: 0 0 auto;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
  }

  .nav form {
    justify-content: space-between;
    align-items: center;
  }

  .nav form span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-shell {
    padding: 16px 12px 36px;
  }

  .page-head {
    gap: 12px;
    margin-bottom: 14px;
  }

  .page-head .actions,
  .actions,
  .filters,
  .form-actions,
  .inline-form {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    width: 100%;
  }

  .filters input,
  .filters select {
    width: 100%;
  }

  .page-head .actions a,
  .page-head .actions button,
  .actions a,
  .actions button,
  .form-actions a,
  .form-actions button,
  .inline-form button {
    width: 100%;
  }

  .summary {
    justify-items: start;
  }

  .table-wrap {
    border-radius: 6px;
  }

  table {
    min-width: 720px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .compact-table table {
    min-width: 560px;
  }

  .actions-cell {
    white-space: normal;
  }

  .actions-cell > a,
  .actions-cell form {
    display: flex;
    width: 100%;
    margin: 0 0 8px;
  }

  .actions-cell button,
  .actions-cell .button {
    width: 100%;
  }

  .panel,
  .metric,
  .form-panel {
    padding: 14px;
    border-radius: 6px;
  }

  .compact-grid,
  .form-grid,
  .grid-2,
  .period-admin-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .notification-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .notification-item form {
    grid-column: 2;
  }

  .notification-item button {
    width: 100%;
  }

  .upload-form input[type="file"] {
    max-width: none;
  }

  .category-section header,
  .score-major-header,
  .score-group summary {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .score-major-header h3,
  .category-section h2 {
    font-size: 18px;
  }

  .score-major-header span,
  .score-meta {
    white-space: normal;
  }

  .score-group summary {
    gap: 6px;
    padding: 11px 12px;
  }

  .score-table {
    min-width: 720px;
  }

  .score-input {
    width: 72px;
  }

  .check-grid {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 10px;
  }

  .brand {
    font-size: 16px;
  }

  .nav form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .period-chip,
  .status {
    max-width: 100%;
  }

  table {
    min-width: 640px;
  }

  .score-table {
    min-width: 680px;
  }
}
