:root {
  color-scheme: light;
  --bg: #e8ede7;
  --panel: #f9fbf8;
  --line: #cfd8cf;
  --line-dark: #97aaa0;
  --text: #1f2b25;
  --muted: #69776f;
  --head: #edf2ed;
  --a: #fbe4da;
  --b: #dcecf9;
  --c: #d9f1e5;
  --blank: #f8faf8;
  --blocked: #aeb8ad;
  --class: #da3d40;
  --onsite: #aee5d0;
  --training: #f4cf40;
  --soft: #efe5d5;
  --ok: #15784f;
  --no: #cf3c43;
  --warn: #9a6700;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.35;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 54px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  background: #f7faf7;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
}

h1 {
  font-size: 22px;
  line-height: 1;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
}

.header-actions,
.panel-title-row,
.result-heading,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button,
.segmented button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
}

.icon-button {
  width: 34px;
}

.text-button {
  padding: 0 10px;
}

.text-button.full {
  width: 100%;
  margin-top: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 8px;
  height: calc(100vh - 54px);
  padding: 8px;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.sidebar {
  display: grid;
  gap: 8px;
  align-content: start;
  min-width: 0;
  overflow: auto;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
}

.input-panel,
.schedule-panel,
.decision-panel,
.settings-panel {
  padding: 8px;
}

.panel-title-row {
  justify-content: space-between;
  margin-bottom: 6px;
}

.panel-title-row p,
.helper {
  color: var(--muted);
  font-size: 11px;
}

.status-pill,
.decision-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill {
  background: #e5ece5;
  color: var(--muted);
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
}

textarea:focus,
input:focus,
select:focus,
.sheet-paste:focus {
  outline: 2px solid rgba(31, 143, 95, 0.2);
  border-color: var(--line-dark);
}

input,
select {
  min-height: 32px;
  padding: 0 8px;
}

textarea {
  min-height: 112px;
  padding: 8px;
  resize: vertical;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.calendar-sync {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.calendar-sync textarea {
  min-height: 74px;
}

.calendar-buttons {
  display: grid;
  grid-template-columns: 1fr 68px;
  gap: 6px;
}

.calendar-status {
  justify-self: start;
}

.sheet-paste {
  height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.paste-placeholder {
  display: grid;
  min-height: 218px;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.paste-grid,
.schedule-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  table-layout: auto;
  font-size: 12px;
}

.paste-grid th,
.paste-grid td,
.schedule-table th,
.schedule-table td {
  border: 1px solid var(--line);
  height: 28px;
  padding: 3px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paste-grid th,
.schedule-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--head);
  color: #3f4c45;
  font-weight: 800;
  text-align: left;
}

.paste-grid th,
.paste-grid td {
  width: 58px;
  min-width: 58px;
  max-width: 58px;
}

.paste-grid .row-head,
.paste-grid .corner {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 38px;
  width: 38px;
  background: var(--head);
  color: var(--muted);
  text-align: center;
}

.paste-grid .corner {
  z-index: 4;
}

.raw-data {
  margin-top: 6px;
}

.raw-data textarea {
  min-height: 90px;
}

.schedule-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, 34px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #e7ede7;
}

.segmented button {
  min-height: 26px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.segmented button.active {
  background: #fff;
  color: #0f6c49;
}

.table-wrap {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.schedule-table th,
.schedule-table td {
  width: 58px;
  min-width: 58px;
  max-width: 58px;
}

.schedule-table .time-cell {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 60px;
  background: #f6f8f6;
  font-weight: 800;
}

.schedule-table th:first-child {
  left: 0;
  z-index: 4;
  min-width: 60px;
}

.schedule-table .class-cell {
  width: 58px;
  min-width: 58px;
  max-width: 58px;
  text-align: center;
  font-weight: 800;
}

.schedule-table .open-slot {
  cursor: pointer;
}

.schedule-table .open-slot:hover {
  background: #fff7bd;
  box-shadow: inset 0 0 0 2px #6ac2a0;
}

.schedule-table .planned-ok {
  color: #087a4b;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.schedule-table .planned-no {
  color: #d51f2c;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.schedule-table .public-course {
  color: #0c5f98;
  background: #e8f3fb;
  box-shadow: inset 0 0 0 2px rgba(12, 95, 152, 0.28);
}

.schedule-table .public-closed {
  color: #7c4a00;
  background: #fff0c2;
  box-shadow: inset 0 0 0 2px rgba(154, 103, 0, 0.28);
}

.schedule-table .selected-machine {
  box-shadow: inset 0 0 0 2px #6ac2a0;
}

.schedule-table .is-selected-time td {
  box-shadow: inset 0 0 0 2px #6ac2a0;
}

.class-a,
.paste-a {
  background: var(--a);
}

.class-b,
.paste-b {
  background: var(--b);
}

.class-c,
.paste-c {
  background: var(--c);
}

.cell-empty,
.paste-empty {
  background: var(--blank);
}

.cell-blocked,
.paste-blocked {
  background: var(--blocked);
  color: #fff;
}

.cell-onsite,
.paste-onsite {
  background: var(--onsite);
}

.cell-class,
.paste-class {
  background: var(--class);
  color: #fff;
  font-weight: 800;
}

.course-bc-single {
  background: #0f5590;
  color: #fff;
  font-weight: 800;
}

.course-bc-double {
  background: #d91f2b;
  color: #fff;
  font-weight: 800;
}

.course-a-single {
  background: #bfe1f7;
  color: #1f2b25;
  font-weight: 800;
}

.course-a-double {
  background: #f7c9c4;
  color: #1f2b25;
  font-weight: 800;
}

.assistant-bc {
  background: #d8c7f2;
  color: #1f2b25;
  font-weight: 800;
}

.assistant-a {
  background: #f4df87;
  color: #1f2b25;
  font-weight: 800;
}

.cell-training,
.paste-training {
  background: var(--training);
}

.cell-sales,
.paste-sales {
  background: #f1b866;
  color: #1f2b25;
  font-weight: 800;
}

.cell-soft,
.paste-soft {
  background: var(--soft);
}

.decision-panel h2 {
  margin-bottom: 6px;
}

.mini-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.hidden-state {
  display: none;
}

.course-dialog {
  width: min(440px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
}

.qualification-dialog {
  width: min(1280px, calc(100vw - 24px));
}

.qualification-actions {
  justify-content: flex-start;
  margin-bottom: 8px;
}

.course-dialog::backdrop {
  background: rgba(31, 43, 37, 0.28);
}

.dialog-panel {
  margin: 0;
  padding: 10px;
  background: var(--panel);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.dialog-head p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.modal-grid {
  grid-template-columns: 1fr 1.2fr 88px;
}

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

label span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.toggle-row {
  align-items: center;
  justify-content: space-between;
  margin: 8px 0;
  flex-wrap: wrap;
}

.toggle-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 800;
}

.toggle-row input {
  width: 16px;
  min-height: 16px;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  background: #fff;
}

.result-heading {
  justify-content: space-between;
  margin-bottom: 8px;
}

.decision-badge.neutral {
  background: #e5ece5;
  color: var(--muted);
}

.decision-badge.ok {
  background: #d7efe2;
  color: var(--ok);
}

.decision-badge.no {
  background: #f6dadd;
  color: var(--no);
}

.decision-badge.warn {
  background: #f6e5bd;
  color: var(--warn);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 8px;
}

.metrics div {
  min-width: 0;
  padding: 7px;
  border: 1px solid #e2e9e2;
  border-radius: 4px;
  background: #eef5f0;
}

.metrics dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.metrics dd {
  margin: 1px 0 0;
  font-size: 18px;
  font-weight: 900;
}

.result-section + .result-section {
  margin-top: 8px;
}

ul {
  margin: 0;
  padding-left: 18px;
}

li + li {
  margin-top: 3px;
}

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

details + details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

summary {
  cursor: pointer;
  font-weight: 900;
}

details .setting-grid,
details .helper,
details textarea {
  margin-top: 8px;
}

#qualificationInput {
  min-height: 120px;
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    overflow: visible;
  }
}

.qualifications-page {
  min-height: 100%;
  overflow: auto;
}

.qualification-layout {
  padding: 8px;
}

.qualification-panel {
  padding: 8px;
}

.qualification-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 126px);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.qualification-table-wrap.embedded {
  max-height: min(760px, calc(100vh - 150px));
}

.qualification-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.qualification-table th,
.qualification-table td {
  height: 32px;
  border: 1px solid var(--line);
  padding: 3px 5px;
  text-align: center;
  white-space: nowrap;
}

.qualification-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--head);
}

.qualification-table .name-head,
.qualification-table .name-cell,
.qualification-table .row-label {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 128px;
  min-width: 128px;
  background: #fff;
  text-align: left;
}

.qualification-table .name-head,
.qualification-table .row-label {
  z-index: 4;
  background: var(--head);
}

.qualification-table input[type="text"] {
  min-height: 26px;
  padding: 0 6px;
}

.qualification-table .coach-head {
  position: sticky;
  top: 0;
  width: 92px;
  min-width: 92px;
  max-width: 92px;
  padding-top: 17px;
  vertical-align: top;
}

.qualification-table .coach-head input {
  width: 100%;
  min-height: 24px;
  padding: 0 4px;
  font-size: 12px;
}

.qualification-table td {
  width: 92px;
  min-width: 92px;
  max-width: 92px;
  padding: 2px;
}

.qualification-table select {
  width: 100%;
  min-height: 26px;
  padding: 0 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.qualification-table .name-cell {
  display: flex;
  align-items: center;
  gap: 5px;
}

.qualification-table .drag-handle {
  flex: 0 0 auto;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #eef2ee;
  color: var(--muted);
  cursor: grab;
  font-size: 11px;
  font-weight: 900;
}

.qualification-table .coach-head .drag-handle {
  position: absolute;
  top: 2px;
  left: 4px;
  display: inline-flex;
  min-height: 14px;
  align-items: center;
  line-height: 1;
}

.qualification-table tr.dragging {
  opacity: 0.55;
}

.qualification-table tr.drag-over td {
  box-shadow: inset 0 2px 0 #42a57d;
}

.qualification-table input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

.qualification-table .group-main {
  background: #e9f4ee;
}

.qualification-table .group-assistant {
  background: #edf2fb;
}

.qualification-table .delete-coach {
  width: 34px;
  min-height: 26px;
  padding: 0;
}

.qualification-table [data-coach-index].drag-over {
  box-shadow: inset 3px 0 0 #42a57d;
}

.qualification-table .qual-none {
  background: #aeb8ad;
}

.qualification-table .qual-none select {
  color: #f6f8f6;
}

.qualification-table .qual-main {
  background: #f3c4bf;
}

.qualification-table .qual-assist {
  background: #c9def3;
}

.qualification-table .qual-toddler {
  background: #ead8f5;
}

.qualification-table .qual-sales-all {
  background: #17823d;
}

.qualification-table .qual-sales-all select {
  color: #fff;
}

.qualification-table .qual-sales-limited {
  background: #f2df91;
}

.qualification-table .qual-na {
  background: #d9d9d9;
}

.qualification-table .qual-sk {
  background: #f3c4bf;
}

.qualification-table .qual-sb {
  background: #c9def3;
}

@media (max-width: 680px) {
  .app-header {
    height: auto;
    align-items: flex-start;
  }

  .panel-title-row,
  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .segmented {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }
}
