:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-alt: #eef4ff;
  --text: #111827;
  --muted: #6b7280;
  --line: #dde5f2;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #dbeafe;
  --ink: #0f172a;
  --blue: #2563eb;
  --warn: #b45309;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.2);
  --radius: 8px;
  font-family: "Pretendard", "Segoe UI", "Noto Sans KR", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.auth-locked .app-shell {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(37, 99, 235, 0.68)),
    var(--bg);
}

body:not(.auth-locked) .login-screen {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 34px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--accent-dark);
  font-size: 20px;
  font-weight: 900;
}

.login-panel label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.login-panel input {
  width: 100%;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: #dc2626;
  font-weight: 700;
}

.admin-only {
  display: none;
}

body.admin .admin-only {
  display: inline-flex;
  align-items: center;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 38px;
  padding: 0 16px;
}

button:hover:not(:disabled),
.nav-item.active {
  background: var(--surface-alt);
}

button:disabled {
  color: #bcc3cf;
  cursor: not-allowed;
}

input,
select {
  min-height: 38px;
  border: 1px solid #c8d3e3;
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 0 12px;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  background: var(--ink);
  border-bottom: 1px solid #1e293b;
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0;
  color: #7dd3fc;
  white-space: nowrap;
}

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

.nav-item {
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  color: #cbd5e1;
}

.nav-item.active {
  color: #ffffff;
  font-weight: 700;
  background: #1e293b;
}

.session {
  margin-left: auto;
  display: flex;
  gap: 18px;
  align-items: center;
  color: #cbd5e1;
}

.link-button {
  border: 0;
  padding: 0;
  min-height: auto;
  background: transparent;
  color: #cbd5e1;
}

main {
  padding: 72px 10px 40px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

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

.filters.compact input {
  width: 220px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.outline-success {
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
  background: white;
}

.outline-success:hover {
  background: #eff6ff;
}

.page-size {
  width: 110px;
}

.select-menu {
  position: relative;
}

.menu-trigger {
  min-width: 130px;
  border-color: #c8d3e3;
  text-align: left;
}

.menu-trigger::after {
  content: "v";
  float: right;
  color: var(--muted);
}

.menu-panel {
  position: absolute;
  top: 42px;
  left: 0;
  display: none;
  min-width: 214px;
  max-height: 260px;
  overflow: auto;
  padding: 10px 0;
  background: var(--surface);
  border: 1px solid #c8d3e3;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  z-index: 20;
}

.menu-panel.wide {
  min-width: 360px;
}

.menu-panel.open {
  display: block;
}

.menu-panel button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  text-align: center;
  background: transparent;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1500px;
  border-collapse: collapse;
}

th,
td {
  height: 58px;
  padding: 0 16px;
  border-right: 1px solid #f0eee8;
  border-bottom: 1px solid #edf2f8;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  height: 56px;
  background: #f8fbff;
  color: var(--accent-dark);
  font-weight: 800;
  text-align: left;
}

td {
  color: #263246;
}

tbody tr:nth-child(even) {
  background: #f8fafc;
}

#slotRows tr,
#userRows tr {
  cursor: pointer;
  transition: background 0.14s ease, box-shadow 0.14s ease;
}

#slotRows tr:hover,
#userRows tr:hover {
  background: #edf5ff;
}

#slotRows tr.selected,
#userRows tr.selected {
  background: var(--accent-soft) !important;
  box-shadow: inset 4px 0 0 var(--accent);
}

#slotRows tr.selected td,
#userRows tr.selected td {
  color: #0f2d5c;
}

.row-check {
  width: 18px;
  height: 18px;
}

.truncate {
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.small-blue {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  background: var(--blue);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.danger-soft {
  border-color: #fecaca;
  background: #fff1f2;
  color: #dc2626;
  font-weight: 700;
}

.danger-soft:disabled {
  border-color: #e5e7eb;
  background: #f8fafc;
  color: #a8b0bd;
}

.more-btn {
  min-height: 34px;
  padding: 0 14px;
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}

.history-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}

.history-tabs button.active {
  font-weight: 700;
  background: var(--surface-alt);
}

.history-filter {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

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

.summary-strip {
  display: flex;
  gap: 44px;
  width: fit-content;
  padding: 18px 22px;
  margin-bottom: 18px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
}

.summary-strip div {
  display: grid;
  gap: 5px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 12px;
}

.summary-strip strong {
  font-size: 20px;
}

.empty td {
  color: var(--muted);
  text-align: left;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: start center;
  padding: 48px 24px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(1180px, 100%);
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 26px 28px 20px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 20px;
  font-size: 18px;
}

.modal h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 20px;
  min-height: 28px;
  width: 28px;
  padding: 0;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  background: white;
}

.selected-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 20px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: white;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.check-line {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
  font-weight: 700;
}

.form-section {
  border-top: 1px solid var(--line);
  padding: 22px 0 16px;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(240px, 320px);
  gap: 24px;
  align-items: center;
  margin: 0 0 2px;
}

.field-row.wide-label {
  grid-template-columns: minmax(420px, 1fr) minmax(260px, 480px);
}

.field-row small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.field-row input,
.field-row select {
  width: 100%;
}

.autocomplete-control {
  position: relative;
  width: 100%;
}

.autocomplete-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.14);
  padding: 4px 0;
}

.autocomplete-menu[hidden] {
  display: none;
}

.autocomplete-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 500;
}

.autocomplete-menu button:hover,
.autocomplete-menu button:focus {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.success-note {
  color: var(--accent) !important;
}

.date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  border-top: 1px solid var(--line);
  padding-top: 26px;
}

.date-grid.compact-date {
  border-top: 0;
  padding-top: 0;
}

.date-grid label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: end;
  margin-top: 28px;
}

.notice-help {
  padding: 16px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f8fbff;
  color: var(--muted);
  line-height: 1.6;
}

.notice-tools {
  display: grid;
  grid-template-columns: auto auto auto minmax(280px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.notice-tools label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.modal-table table {
  min-width: 900px;
}

.simple-form {
  display: grid;
  gap: 14px;
}

.popup-form {
  display: grid;
  gap: 10px;
  padding-top: 6px;
}

.conditional-section[hidden] {
  display: none;
}

.simple-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.role-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 14px 0 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: white;
}

.role-tabs button {
  min-height: 48px;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  font-weight: 700;
}

.role-tabs button:last-child {
  border-right: 0;
}

.role-tabs .active {
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 14px rgba(37, 99, 235, 0.22);
}

.column-config {
  display: grid;
  gap: 14px;
  max-height: 470px;
  overflow-y: auto;
  padding-right: 10px;
}

.column-config-head,
.column-row {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 64px 64px 42px;
  gap: 16px;
  align-items: center;
}

.column-config-head {
  min-height: 48px;
  padding: 0 12px;
  background: #f1f5fb;
  border-radius: 4px;
}

.column-config-head strong {
  color: #263246;
}

.column-config-head strong:not(:first-child) {
  text-align: center;
}

.column-list {
  display: grid;
  gap: 10px;
}

.column-row {
  min-height: 66px;
  padding: 10px 12px;
  border: 1px solid #eeeae2;
  border-radius: 4px;
  background: white;
}

.column-row input {
  width: 100%;
}

.square-check {
  display: grid;
  place-items: center;
}

.square-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.square-check span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid #cfd6df;
  border-radius: 5px;
  background: white;
}

.square-check input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
}

.square-check input:checked + span::after {
  content: "✓";
  color: white;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

.drag-handle {
  min-height: 32px;
  width: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #263246;
  font-size: 22px;
  cursor: grab;
}

.split-actions {
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 16px;
  border-radius: 8px;
  background: #0f172a;
  color: white;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.26);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.rank-value {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: #1f4f9f;
  font-weight: 700;
}

.rank-history-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 126px;
  justify-content: center;
  padding: 8px 11px;
  border: 1px solid #2563eb;
  border-radius: 4px;
  background: #fff;
  color: #1457d9;
  font-weight: 700;
  white-space: nowrap;
}

.rank-history-button::before {
  content: "";
  width: 16px;
  height: 14px;
  background:
    linear-gradient(#2563eb 0 0) 1px 8px / 4px 5px no-repeat,
    linear-gradient(#2563eb 0 0) 7px 5px / 4px 8px no-repeat,
    linear-gradient(#2563eb 0 0) 13px 2px / 4px 11px no-repeat;
}

.rank-history-button:hover {
  background: #eff6ff;
}

.rank-history-list {
  display: flex;
  gap: 14px;
  min-height: 420px;
  padding: 20px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.rank-history-card {
  display: flex;
  flex: 0 0 112px;
  height: 156px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #bdd2ef;
  border-radius: 6px;
  background: #eaf4ff;
  color: #24324b;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.13);
  text-align: center;
}

.rank-history-card strong {
  font-size: 13px;
}

.rank-history-card span,
.rank-history-card small,
.rank-history-card em {
  color: #64748b;
  font-size: 12px;
  font-style: normal;
}

.rank-history-card b {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  margin-top: 4px;
  border: 1px solid #79b7ff;
  border-radius: 999px;
  background: #fff;
  color: #1d4ed8;
  font-size: 18px;
}

.rank-history-empty {
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar,
  .page-head,
  .toolbar,
  .history-filter,
  .notice-tools {
    align-items: stretch;
    flex-direction: column;
    display: flex;
  }

  .topbar {
    height: auto;
    padding: 12px;
  }

  .nav {
    flex-wrap: wrap;
  }

  main {
    padding-top: 28px;
  }

  .field-row,
  .date-grid {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    width: 100%;
    flex-direction: column;
    gap: 14px;
  }

  .column-config-head,
  .column-row {
    grid-template-columns: minmax(160px, 1fr) 44px 44px 32px;
    gap: 8px;
  }
}
