* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  background: linear-gradient(152deg, #f7efe1 0%, #f2e1c7 52%, #edd3ad 100%);
  color: #2f221b;
}

.students-back-link {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 140;
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #3b291d;
  text-decoration: none;
}

.students-wrap {
  width: min(1440px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 76px 0 26px;
  display: grid;
  gap: 12px;
}

.students-header h1 {
  margin: 0;
}

.students-header p {
  margin: 6px 0 0;
  color: rgba(47, 34, 27, 0.76);
}

.students-panel,
.students-table-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(138, 100, 64, 0.2);
  border-radius: 14px;
  box-shadow: 0 10px 20px rgba(61, 38, 20, 0.1);
  padding: 14px;
}

.students-panel h2 {
  margin: 0 0 10px;
  font-size: 16px;
}
.credit-ledger-v2-panel {
  border-color: #9fb8a4;
  background: rgba(247, 252, 248, 0.96);
}
.credit-ledger-v2-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.credit-ledger-v2-activation-controls,
.students-detail-balance-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.remaining-badge.not-ready {
  color: #9a3412;
  background: #ffedd5;
}
.credit-ledger-v2-heading-row h2 {
  margin-bottom: 4px;
}
.credit-ledger-v2-heading-row p {
  margin: 0;
  color: #5a6b5d;
  font-size: 12px;
}
#credit-ledger-v2-progress {
  flex: 0 0 auto;
  color: #245d38;
  font-size: 14px;
}
.credit-ledger-v2-table {
  min-width: 1120px;
}
.credit-ledger-v2-table td:nth-child(3) {
  min-width: 190px;
}
.credit-ledger-v2-table td:nth-child(4) {
  min-width: 360px;
}
.credit-ledger-v2-opening-input {
  width: 90px;
  border: 1px solid #b8c9bb;
  border-radius: 6px;
  padding: 6px 8px;
  margin-right: 6px;
}
.credit-ledger-v2-confirm,
.credit-ledger-v2-preview,
.credit-ledger-v2-payment-confirm {
  background: #e4f1e7;
  color: #245d38;
}
.credit-ledger-v2-payment-list {
  display: grid;
  gap: 6px;
}
.credit-ledger-v2-payment-item {
  display: grid;
  grid-template-columns: 84px 72px 64px minmax(90px, 1fr) auto auto;
  align-items: center;
  gap: 5px;
}
.credit-ledger-v2-payment-item input {
  min-width: 0;
  border: 1px solid #b8c9bb;
  border-radius: 6px;
  padding: 5px 6px;
}
.credit-ledger-v2-payment-item .credit-ledger-v2-payment-credits {
  width: 64px;
}
.credit-ledger-v2-payment-reference,
.credit-ledger-v2-payment-empty {
  color: #68756a;
  font-size: 11px;
}
.credit-ledger-v2-payment-item.is-confirmed {
  color: #245d38;
}
.credit-ledger-v2-preview:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.credit-ledger-v2-balance,
#credit-ledger-v2-current-balance {
  color: #245d38;
  font-variant-numeric: tabular-nums;
}
.credit-ledger-v2-balance.negative,
#credit-ledger-v2-current-balance.negative {
  color: #b12626;
}

.students-form {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) 1.2fr repeat(3, minmax(120px, 1fr)) 110px;
  gap: 8px;
}

.students-table-tabs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 3px;
  border: 1px solid #ddcfbd;
  border-radius: 8px;
  background: #f5eee5;
}

.students-table-tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #695142;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.students-table-tab.is-active {
  background: #fff;
  color: #1f4d9a;
  box-shadow: 0 2px 7px rgba(61, 38, 20, 0.12);
}

.students-form-field {
  display: grid;
  gap: 5px;
}

.students-form-field label {
  font-size: 12px;
  color: #5f4838;
  font-weight: 700;
}

.students-form input,
.students-form select,
.students-form button,
.students-edit-form input,
.students-edit-form select {
  border: 1px solid #d8c8b4;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
}

.students-edit-form input:disabled,
.students-edit-form select:disabled {
  background: #f2f2f2;
  color: #7a6a5d;
  cursor: not-allowed;
}

.students-field-note {
  font-size: 11px;
  line-height: 1.3;
  color: #7d6656;
}

.students-submit-btn {
  align-self: end;
}

.students-form button,
.students-submit-btn {
  border: 0;
  background: #1f6fd6;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.students-table-wrap {
  width: 100%;
  overflow: auto;
}

.students-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1240px;
}

.students-table th,
.students-table td {
  border-bottom: 1px solid #f0e6da;
  padding: 8px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

.students-table th {
  position: sticky;
  top: 0;
  background: #fcf8f2;
  z-index: 1;
  font-weight: 700;
  color: #4a3427;
}

.students-table .num-cell {
  width: 70px;
  text-align: center;
  color: #71513d;
  font-weight: 700;
}

.students-table .cell-text {
  color: #3f2f24;
}

.students-table .payment-cell {
  min-width: 170px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.students-table .payment-cell .cell-text {
  display: inline-block;
  margin-bottom: 0;
  min-width: 0;
}

.students-table .remaining-badge {
  display: inline-flex;
  min-width: 52px;
  justify-content: center;
  border-radius: 999px;
  background: #eef4ff;
  color: #1d4f9c;
  font-weight: 700;
  padding: 6px 10px;
}

.students-table .remaining-badge.negative {
  background: #fff2f2;
  color: #b12626;
}

.students-table .action-cell {
  width: 220px;
}

.students-table .row-action-btn {
  border: 0;
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.students-table .row-action-btn + .row-action-btn {
  margin-left: 6px;
}

.students-table .row-action-btn.edit {
  background: #e6eefc;
  color: #1f4d9a;
}

.students-table .row-action-btn.delete {
  background: #fdecec;
  color: #b62d2d;
}

.students-table .row-action-btn.detail {
  background: #e7f6ef;
  color: #1a6f4f;
}

.students-table .row-action-btn.payment-add {
  background: #f7efe2;
  color: #6d3f18;
}

.empty-row td {
  text-align: center;
  color: #8f7665;
  padding: 18px 8px;
}

.user-info {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 160;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border: 1px solid #e0d5c7;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 6px 18px rgba(39, 25, 14, 0.12);
  font-size: 13px;
  color: #25314a;
}

.logout-btn {
  border: 0;
  border-radius: 999px;
  background: #f15a4a;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
}

.students-modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.48);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 260;
}

.students-modal.open {
  display: flex;
}

.students-modal-content {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #e2d7c7;
  padding: 16px;
}

.students-modal-wide {
  width: min(1120px, calc(100vw - 24px));
}

.students-modal-detail {
  width: min(1260px, calc(100vw - 24px));
}

.students-detail-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.students-detail-header-row h2 {
  margin: 0;
}

.students-detail-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.students-detail-card-wide {
  grid-column: span 2;
}

.students-detail-card {
  border: 1px solid #e8dccd;
  border-radius: 10px;
  background: #fffaf5;
  padding: 10px;
  min-height: 320px;
  display: grid;
  grid-template-rows: auto 1fr;
}

.students-detail-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #4a3427;
}

.students-detail-table {
  width: 100%;
  border-collapse: collapse;
  overflow: auto;
  max-height: 460px;
  display: block;
}

.students-detail-table thead,
.students-detail-table tbody,
.students-detail-table tr {
  width: 100%;
}

.students-detail-table thead tr,
.students-detail-table tbody tr {
  display: table;
  table-layout: fixed;
}

.students-detail-table thead tr {
  position: sticky;
  top: 0;
  z-index: 2;
}

.students-detail-table th,
.students-detail-table td {
  border: 1px solid #eadfcf;
  background: #fff;
  padding: 8px;
  font-size: 12px;
  color: #3f2f24;
  line-height: 1.3;
  vertical-align: top;
}

.students-detail-table th {
  background: #fcf8f2;
  color: #5c4432;
  font-weight: 700;
}

.students-detail-table tbody {
  display: block;
  max-height: 420px;
  overflow: auto;
}

#student-detail-payment-table {
  display: table;
  table-layout: fixed;
}

#student-detail-payment-table th,
#student-detail-payment-table td {
  padding: 5px 7px;
  line-height: 1.15;
  white-space: nowrap;
}

#student-detail-payment-table thead,
#student-detail-payment-table tbody {
  display: table-row-group;
  width: auto;
  max-height: none;
  overflow: visible;
}

#student-detail-payment-table tr,
#student-detail-payment-table thead tr,
#student-detail-payment-table tbody tr {
  display: table-row;
}

.students-detail-table-scroll {
  overflow-x: auto;
}

.students-detail-table .payment-remove-btn {
  border: 0;
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: #fdecec;
  color: #b62d2d;
}

.students-detail-table .payment-remove-btn:disabled {
  background: #eee7dd;
  color: #9b8a7a;
  cursor: not-allowed;
}

.students-detail-row-empty td {
  color: #8f7665;
  text-align: center;
  padding: 16px 10px;
}
.credit-ledger-v2-history-table {
  display: table;
  max-height: none;
  table-layout: fixed;
}
.credit-ledger-v2-history-table thead,
.credit-ledger-v2-history-table tbody {
  display: table-row-group;
}
.credit-ledger-v2-history-table tr {
  display: table-row;
}
.credit-ledger-v2-history-table th,
.credit-ledger-v2-history-table td {
  width: 22%;
}
.credit-ledger-v2-history-table th:last-child,
.credit-ledger-v2-history-table td:last-child {
  width: 12%;
}
.credit-ledger-v2-adjustment-form {
  display: grid;
  grid-template-columns: 150px 120px minmax(180px, 1fr) auto;
  align-items: end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e2d7c7;
}
.credit-ledger-v2-adjustment-form[hidden] {
  display: none;
}
.credit-ledger-v2-adjustment-form input {
  width: 100%;
  border: 1px solid #d8c8b4;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
}

.students-modal-info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  color: #4a3427;
}

.students-modal-check-row {
  margin-bottom: 10px;
  font-size: 13px;
  color: #4a3427;
}

.students-modal-check-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.slot-week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.slot-week-nav button {
  border: 1px solid #d8c8b4;
  border-radius: 8px;
  background: #fff;
  padding: 7px 11px;
  cursor: pointer;
}

.slot-selector-wrap {
  border: 1px solid #e0d2c1;
  border-radius: 10px;
  overflow: auto;
  max-height: 540px;
  background: #fff;
}

.slot-grid {
  display: grid;
  grid-template-columns: 56px repeat(7, minmax(0, 1fr));
  min-width: 860px;
}

.slot-head,
.slot-time,
.slot-cell {
  height: 22px;
  border-top: 1px solid #f1e8de;
}

.slot-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fcf8f2;
  font-size: 11px;
  font-weight: 700;
  color: #5c4432;
  text-align: center;
  border-top: 0;
  border-bottom: 1px solid #eadfce;
  padding-top: 4px;
}

.slot-time {
  font-size: 10px;
  color: #7f6756;
  text-align: center;
  padding-top: 3px;
}

.slot-cell {
  border-left: 1px solid #f1e8de;
  background: #fff;
  position: relative;
}

.slot-cell.class-slot {
  background: #dff4e4;
  cursor: pointer;
  border-top-color: transparent;
}

.slot-cell.class-slot.block-start {
  border-top-color: #d2e7d7;
}

.slot-cell.class-slot:hover {
  filter: brightness(0.97);
}

.slot-cell.class-slot.selected {
  outline: none;
  background: #c8e6ff;
}

.slot-cell.full {
  background: #f2f2f2;
  cursor: not-allowed;
}

.slot-block-label {
  position: absolute;
  left: 4px;
  right: 4px;
  top: 3px;
  font-size: 10px;
  line-height: 1.1;
  color: #31553b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-block-capacity {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 9px;
  color: #5f6f8a;
}

.slot-selection-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: #6b5445;
}

.students-primary-btn,
.students-secondary-btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.students-primary-btn {
  background: #1f6fd6;
  color: #fff;
}

.students-secondary-btn {
  background: #e8edf7;
  color: #24324c;
}

.students-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.students-edit-form .students-form-field {
  align-content: start;
}

.students-edit-form .students-field-note {
  display: block;
  min-height: 28px;
}

.students-payment-rule-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 3px solid #1f6fd6;
  background: #f3f7fd;
  color: #3f4d63;
  font-size: 12px;
  line-height: 1.5;
}

.students-field-note-spacer {
  visibility: hidden;
}

@media (max-width: 1060px) {
  .credit-ledger-v2-heading-row,
  .credit-ledger-v2-adjustment-form {
    display: grid;
    grid-template-columns: 1fr;
  }
  .students-detail-cards {
    grid-template-columns: 1fr;
  }

  .students-detail-card-wide {
    grid-column: auto;
  }

  .students-detail-card {
    min-height: 220px;
  }

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

  .students-edit-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  #student-detail-payment-class-table {
    min-width: 680px;
  }
}
