:root {
  --ink: #1a2332;
  --muted: #5c6b80;
  --line: #e1e8f0;
  --bg: #f3f6f4;
  --card: #ffffff;
  --green: #1d6b45;
  --green-soft: #e7f6ec;
  --edited: #fff4c2;
  --shadow: 0 12px 40px rgba(22, 34, 51, 0.16);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

body.modal-open { overflow: hidden; }

.page {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 22px;
}

h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 1px solid #c9d4e2;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
}

.btn:hover { background: #f5f8fb; }

.btn:focus-visible,
.field input:focus,
.field select:focus {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 11px 16px;
}

.btn-primary:hover { background: #18593a; }

.btn-ghost {
  background: transparent;
  font-size: 13px;
  padding: 11px 12px;
}

.section-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.mobile-hint {
  display: none;
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.count {
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.roster { margin-bottom: 8px; }

.bucket { margin-top: 22px; }

.bucket h3 {
  margin: 0;
  padding: 9px 14px;
  font-size: 15px;
  border-radius: 12px 12px 0 0;
  background: var(--tone-strong);
}

.column-note {
  display: none;
  margin: 0;
  padding: 8px 12px 0;
  background: var(--tone);
  color: #3d4d63;
  font-size: 12px;
  font-weight: 700;
}

.table-frame {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid #d5deea;
  border-radius: 12px;
}

.bucket .table-frame {
  border-radius: 0 0 12px 12px;
  border-color: color-mix(in srgb, var(--tone-strong) 65%, #c5d0dc);
  background: var(--tone);
}

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

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

th {
  font-size: 13px;
  font-weight: 700;
  color: #3d4d63;
  background: #e8eef5;
  white-space: nowrap;
}

.roster td { background: #fff; }

.bucket th { background: var(--tone-strong); }
.bucket td { background: var(--tone); }

.col-uid, .col-birth, .col-phone { white-space: nowrap; }
.col-address { min-width: 180px; line-height: 1.45; }
.col-actions { width: 318px; }

.roster tbody tr.is-edited td { background: var(--edited); }

@media (hover: hover) and (pointer: fine) {
  .roster tr.is-edited td { cursor: help; }
  .roster tr.is-edited .btn { cursor: pointer; }
}

.change-tip {
  position: fixed;
  z-index: 25;
  width: max-content;
  max-width: min(460px, calc(100vw - 16px));
}

.change-tip[hidden] { display: none; }

.change-tip-body,
.change-list {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
}

.change-tip-body {
  background: #1c2838;
  color: #fff;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.28);
}

.change-tip-body p,
.change-list p {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.change-tip-body ul,
.change-list ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.change-tip-body li,
.change-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 10px;
  align-items: baseline;
  font-size: 13px;
}

.change-tip-body li strong,
.change-list li strong {
  grid-row: span 2;
}

.change-before em,
.change-after em {
  margin-right: 6px;
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
}

.change-tip-body .change-before { color: #ffc9c9; }
.change-tip-body .change-after { color: #c9f5d4; }
.change-tip-body .change-before em,
.change-tip-body .change-after em { color: #b7c3d4; }

.change-list {
  margin-bottom: 10px;
  background: #fff8df;
  border: 1px solid #ecd98a;
}

.change-list .change-before { color: #8a4545; }
.change-list .change-after { color: #1d6b45; font-weight: 700; }

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  min-width: 300px;
}

.actions .btn {
  white-space: nowrap;
  padding: 6px 2px;
}

tr.detail { display: none; }

.detail-cell { padding: 4px 12px 14px; }
.detail-grid {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 8px 12px;
  padding-top: 8px;
}
.detail-grid span { color: var(--muted); font-size: 12px; }
.detail-grid strong { font-weight: 650; overflow-wrap: anywhere; }
.detail-cell .actions { margin-top: 14px; }

.tone-green { --tone: #e5f6e9; --tone-strong: #d3efdc; }
.tone-yellow { --tone: #fff1b8; --tone-strong: #ffe07a; }
.tone-gray { --tone: #eceff2; --tone-strong: #e0e4e8; }
.tone-navy { --tone: #e4ebf8; --tone-strong: #d0dcf3; }
.tone-orange { --tone: #ffeadb; --tone-strong: #ffd7bc; }
.tone-red { --tone: #fde4e4; --tone-strong: #f8d0d0; }

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 28, 40, 0.46);
}

.modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.modal-desc {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field span {
  font-size: 13px;
  font-weight: 700;
}

.req {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  vertical-align: 1px;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #cfd8e4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.field input:disabled {
  background: #f2f5f8;
  color: #667588;
}

.form-error {
  margin: 0 0 12px;
  color: #a33b3b;
  font-size: 13px;
  font-weight: 650;
}

.form-error[hidden] { display: none; }

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

.modal-actions .btn {
  min-width: 84px;
  min-height: 42px;
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (hover: hover) and (min-width: 961px) {
  .roster tbody tr.summary:hover td { background: #f6f9fc; }
  .roster tbody tr.summary.is-edited:hover td { background: #ffefad; }
}

@media (max-width: 960px) {
  .page {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .top {
    flex-direction: column;
    align-items: stretch;
  }

  h1 { font-size: 24px; }

  .toolbar { display: grid; grid-template-columns: 1fr auto; }

  .mobile-hint, .column-note { display: block; }

  tr.summary { touch-action: manipulation; }

  table { min-width: 0; table-layout: fixed; }

  .col-uid,
  .col-address,
  .col-flag,
  .col-actions,
  .extra-col { display: none; }

  th, td {
    padding: 11px 4px;
    font-size: 12px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: keep-all;
  }

  tr.summary { cursor: pointer; }

  tr.summary td.col-phone { position: relative; padding-right: 14px; }

  tr.summary td.col-phone::after {
    content: "▾";
    position: absolute;
    right: 1px;
    top: 50%;
    transform: translateY(-50%);
    color: #6d7b8d;
    font-size: 10px;
  }

  tr.summary.is-open td.col-phone::after { content: "▴"; }

  tr.summary.is-open td.col-zone { box-shadow: inset 3px 0 0 var(--green); }

  tr.summary.is-open + tr.detail { display: table-row; }

  .bucket tr.summary.is-open + tr.detail .detail-cell { background: var(--tone-strong); }

  .detail-cell .actions .btn {
    min-height: 40px;
    font-size: 13px;
  }
}

@media (max-width: 380px) {
  th, td { font-size: 11px; padding: 10px 2px; }
  .detail-grid { grid-template-columns: 84px minmax(0, 1fr); }
}
