:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --line: #d9e1df;
  --line-strong: #b9c7c5;
  --text: #1e2628;
  --muted: #647173;
  --primary: #2f6f73;
  --primary-ink: #ffffff;
  --accent: #d9822b;
  --blue: #3d5a80;
  --danger: #b84a62;
  --shadow: 0 14px 32px rgba(25, 39, 42, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans KR", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--primary);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

button.ghost {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--primary);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  flex: 0 0 auto;
}

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

h1 {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  font-weight: 760;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary);
  padding: 0 9px;
  font-weight: 700;
}

.badge.local {
  background: #fff1df;
  color: #8a4a0d;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

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

.kpi {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  line-height: 1;
}

.main-grid,
.lower-grid {
  display: grid;
  gap: 12px;
}

.main-grid {
  grid-template-columns: minmax(320px, 0.95fr) minmax(320px, 1.05fr);
}

.lower-grid {
  grid-template-columns: minmax(280px, 0.8fr) minmax(360px, 1.2fr);
  margin-top: 12px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 14px;
}

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

label.wide,
.form-actions.wide {
  grid-column: 1 / -1;
}

.suggest-field {
  position: relative;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 111, 115, 0.2);
  outline-offset: 1px;
}

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 8;
  overflow: auto;
  max-height: 220px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 4px;
}

.suggestion-option {
  display: block;
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
}

.suggestion-option:hover,
.suggestion-option.active {
  background: var(--surface-soft);
  color: var(--primary);
}

.suggestion-empty {
  padding: 9px 10px;
  color: var(--muted);
  font-size: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.assignment-list,
.ranking-list,
.recent-list,
.queue-list {
  display: grid;
  gap: 8px;
}

.assignment-item,
.ranking-item,
.recent-item,
.queue-item {
  display: grid;
  gap: 4px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 10px 12px;
}

.assignment-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.assignment-item strong,
.ranking-item strong,
.recent-item strong,
.queue-item strong {
  overflow-wrap: anywhere;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 760;
}

.pill.orange {
  background: #fff1df;
  color: #8a4a0d;
}

.pill.red {
  background: #fae6eb;
  color: #8f2d42;
}

.ranking-item {
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
}

.rank-num {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.recent-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.modal {
  width: min(720px, calc(100% - 24px));
  max-height: min(780px, calc(100vh - 28px));
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

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

.modal::backdrop {
  background: rgba(18, 26, 28, 0.42);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 16px;
}

.toolbar,
.queue-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 10px;
  padding: 14px 16px 0;
}

.queue-form {
  grid-template-columns: minmax(0, 1fr) 140px auto;
  align-items: end;
  padding-bottom: 14px;
}

.table-wrap {
  overflow: auto;
  max-height: 60vh;
  margin: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.compact {
  max-height: 420px;
  margin: 0;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4f2;
  color: #405052;
  font-size: 12px;
  font-weight: 800;
}

td.actions {
  width: 132px;
  white-space: nowrap;
}

td.actions button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

td.actions button.danger {
  border-color: #efbdc9;
  color: var(--danger);
}

.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 16px;
  padding: 16px;
}

#statsDialog > section {
  padding: 0 16px 16px;
}

.month-chart {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.month-bar {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.month-bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e7eceb;
  overflow: hidden;
}

.month-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.queue-list {
  padding: 0 16px 16px;
}

.queue-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.queue-actions {
  display: flex;
  gap: 6px;
}

.queue-actions button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100% - 36px));
  border-radius: 8px;
  background: #1f2a2d;
  color: white;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

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

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 12px;
  }

  .topbar,
  .brand {
    align-items: flex-start;
  }

  .topbar,
  .main-grid,
  .lower-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

  .queue-form,
  .toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .record-form,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .assignment-item,
  .recent-item,
  .queue-item {
    grid-template-columns: 1fr;
  }

  .ranking-item {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .ranking-item .pill-row {
    grid-column: 2;
  }

  .top-actions button {
    flex: 1 1 calc(50% - 8px);
  }
}
