:root {
  --red-bg: #9e241a;
  --deep-red: #7f1f18;
  --white: #ffffff;
  --green: #09b875;
  --booked: #ff1712;
  --cyan: #13c4dc;
  --gold: #e6a42e;
  --gray: #dedede;
  --ink: #171717;
  --shadow: 0 8px 18px rgba(57, 0, 0, 0.25);
  --cell: 52px;
  --gap: 11px;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #6f1813;
  color: var(--ink);
  font-family: "Noto Sans Thai", Arial, sans-serif;
}

button {
  font: inherit;
}

input,
select,
textarea {
  font: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.schedule-page {
  min-height: 100vh;
  padding: clamp(10px, 2vw, 28px);
  background:
    radial-gradient(circle at 50% 92%, rgba(255, 255, 255, 0.12) 0 1px, transparent 2px),
    repeating-radial-gradient(ellipse at center, transparent 0 14px, rgba(255, 255, 255, 0.08) 15px 17px, transparent 18px 32px),
    linear-gradient(135deg, var(--red-bg), var(--deep-red));
  background-size: 76px 54px, 118px 68px, auto;
}

.schedule-board {
  width: min(100%, 1040px);
  min-height: 760px;
  margin: 0 auto;
  padding: 18px 20px 24px;
  position: relative;
  background:
    radial-gradient(circle at 50% 92%, rgba(255, 255, 255, 0.12) 0 1px, transparent 2px),
    repeating-radial-gradient(ellipse at center, transparent 0 14px, rgba(255, 255, 255, 0.08) 15px 17px, transparent 18px 32px),
    linear-gradient(135deg, var(--red-bg), var(--deep-red));
  background-size: 76px 54px, 118px 68px, auto;
}

.schedule-title {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin: 0 12px 20px;
  border-radius: 999px;
  background: var(--white);
  font-size: 17px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.schedule-admin {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: -8px auto 14px;
}

.schedule-admin a,
.schedule-admin button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.92);
  color: #53150f;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.quick-help {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  border-radius: 999px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.9);
  color: #53150f;
  font-size: 14px;
  font-weight: 700;
}

.advanced-tools {
  margin: 0 auto 14px;
  text-align: center;
}

.advanced-tools summary {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border-radius: 999px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.82);
  color: #53150f;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.editor-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 10px auto 0;
}

.editor-bar button {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 6px 13px;
  background: rgba(255, 255, 255, 0.9);
  color: #53150f;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.schedule-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}

.summary-card {
  border-radius: var(--radius);
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.summary-card span {
  display: block;
  color: #7a2018;
  font-size: 12px;
  font-weight: 900;
}

.summary-card strong {
  display: block;
  margin-top: 2px;
  color: #171717;
  font-size: 24px;
  line-height: 1.1;
}

.schedule-layout {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.logo-column {
  display: grid;
  gap: 4px;
  padding-top: 8px;
}

.logo-badge {
  width: 124px;
  height: 124px;
  margin: 0 auto;
  padding: 6px;
  border: 5px solid var(--white);
  border-radius: 50%;
  background: #b72b1f;
  box-shadow: var(--shadow);
}

.logo-inner {
  display: grid;
  place-items: center;
  align-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 34%, #ffe7b0 0 10px, transparent 11px),
    radial-gradient(circle at 64% 34%, #ffe7b0 0 10px, transparent 11px),
    radial-gradient(circle at 50% 52%, #ffd058 0 22px, #b83222 23px 60%);
  color: #fff7dd;
  text-align: center;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.logo-inner strong {
  font-size: 28px;
  line-height: 1;
}

.logo-inner span {
  font-size: 12px;
  font-weight: 700;
}

.day-labels {
  display: grid;
  gap: var(--gap);
  margin-top: 0;
}

.day-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: var(--white);
  color: #171717;
  cursor: grab;
  font-size: 16px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.day-label.selected,
.time-card.selected {
  outline: 4px solid #f4c43f;
}

.table-area {
  display: grid;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.time-row,
.schedule-row {
  display: grid;
  grid-auto-columns: var(--cell);
  grid-auto-flow: column;
  gap: var(--gap);
  width: max-content;
}

.time-card {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cell);
  height: 126px;
  border: 0;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  cursor: grab;
}

.time-card span {
  display: block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-size: 17px;
  font-weight: 500;
}

.grid-wrap {
  display: grid;
  gap: var(--gap);
}

.schedule-row {
  position: relative;
}

.cell {
  display: grid;
  grid-template-rows: 24px auto;
  width: var(--cell);
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.cell.has-student {
  grid-template-rows: 18px 14px;
  gap: 0;
}

.cell.has-student .person {
  transform: scale(0.72);
  transform-origin: center;
}

.cell-name {
  max-width: calc(var(--cell) - 8px);
  overflow: hidden;
  color: inherit;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell.booked .cell-name,
.cell.group .cell-name,
.cell.trial .cell-name {
  color: #ffffff;
}

.cell.booked {
  background: var(--booked);
}

.cell.group {
  background: var(--cyan);
}

.cell.trial {
  background: var(--gold);
}

.cell.dragging,
.day-label.dragging,
.time-card.dragging {
  opacity: 0.48;
}

.cell.drop-target,
.day-label.drop-target,
.time-card.drop-target {
  outline: 4px solid #7ce7ff;
}

.person {
  position: relative;
  display: inline-block;
  width: 25px;
  height: 24px;
}

.person::before {
  content: "";
  position: absolute;
  top: 0;
  left: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.person::after {
  content: "";
  position: absolute;
  left: 4px;
  bottom: 0;
  width: 17px;
  height: 12px;
  border-radius: 9px 9px 3px 3px;
  background: currentColor;
}

.person.green {
  color: var(--green);
}

.person.white {
  color: var(--white);
}

.rest-column,
.vert-break {
  display: grid;
  place-items: center;
  width: 38px;
  border-radius: 999px;
  background: var(--gray);
  color: #171717;
  font-size: 16px;
  font-weight: 700;
  writing-mode: vertical-rl;
}

.vert-break {
  height: 126px;
  margin: 0 1px;
}

.rest-column {
  height: 146px;
  margin-top: calc((40px + var(--gap)) * 4);
}

.schedule-row .vert-break,
.schedule-row .rest-column {
  width: 38px;
  height: 40px;
  margin: 0;
  background: transparent;
  box-shadow: none;
  color: transparent;
}

.schedule-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  max-width: 460px;
}

.legend-item {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  padding: 8px 18px;
  cursor: pointer;
  color: #ffffff;
  font-size: 21px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.legend-item.white {
  background: var(--white);
  color: #171717;
}

.legend-item.red {
  background: var(--booked);
}

.legend-item.cyan {
  background: var(--cyan);
}

.legend-item.gold {
  background: var(--gold);
}

.legend-item.active {
  outline: 4px solid #f4c43f;
  outline-offset: 2px;
}

.updated {
  min-width: 238px;
  min-height: 46px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--white);
  font-size: 17px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.student-panel {
  margin-top: 18px;
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.student-panel[hidden] {
  display: none;
}

.student-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.student-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.student-tools input,
.student-tools select {
  min-height: 34px;
  border: 1px solid #ead6d1;
  border-radius: 999px;
  padding: 6px 12px;
  background: #ffffff;
  color: #171717;
  font-weight: 700;
}

.student-panel h2 {
  margin: 0;
  font-size: 20px;
}

.student-panel span {
  color: #7a2018;
  font-size: 14px;
  font-weight: 800;
}

.student-table-wrap {
  overflow-x: auto;
}

.student-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

.student-table th,
.student-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #ead6d1;
  text-align: left;
  vertical-align: top;
}

.student-table th {
  color: #7a2018;
  font-weight: 900;
}

.student-table td {
  color: #171717;
  font-weight: 700;
}

.student-table .empty-row {
  text-align: center;
  color: #7a2018;
}

.cell-dialog {
  width: min(92vw, 430px);
  border: 0;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}

.cell-dialog::backdrop {
  background: rgba(26, 4, 2, 0.64);
}

.cell-form {
  display: grid;
  gap: 16px;
  padding: 20px;
  background: #ffffff;
}

.cell-form header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.cell-form h2 {
  margin: 0;
  font-size: 22px;
}

.cell-form header button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #f0f0f0;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.cell-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cell-meta span {
  border-radius: 999px;
  padding: 5px 11px;
  background: #f6e7e3;
  color: #7a2018;
  font-weight: 800;
}

.cell-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.cell-form input,
.cell-form select,
.cell-form textarea {
  width: 100%;
  border: 1px solid #d8d8d8;
  border-radius: 8px;
  padding: 10px 12px;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.save-btn,
.danger-btn {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 800;
}

.save-btn {
  background: var(--green);
  color: #ffffff;
}

.danger-btn {
  background: #f4eeee;
  color: #9e241a;
}

@media (max-width: 860px) {
  .schedule-board {
    padding-inline: 6px;
  }

  .schedule-layout {
    grid-template-columns: 124px minmax(0, 1fr);
    gap: 12px;
  }

  .schedule-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .logo-badge {
    width: 100px;
    height: 100px;
  }

  .day-label {
    font-size: 14px;
  }

  .schedule-footer {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  :root {
    --cell: 46px;
    --gap: 8px;
  }

  .schedule-title {
    font-size: 14px;
  }

  .schedule-layout {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .time-card {
    height: 112px;
  }

  .legend-item {
    width: calc(50% - 7px);
    justify-content: center;
    font-size: 17px;
  }

  .updated {
    width: 100%;
  }
}

@media print {
  .schedule-page {
    padding: 0;
  }

  .schedule-admin,
  .quick-help,
  .advanced-tools,
  .editor-bar,
  .cell-dialog {
    display: none;
  }

  .schedule-board {
    width: 1040px;
    margin: 0;
  }
}
