:root {
  --bg: #f5f2ec;
  --panel: #fffdf9;
  --ink: #26211c;
  --muted: #756b62;
  --line: #e2d8cb;
  --accent: #ef6c00;
  --accent-dark: #bd4f00;
  --soft: #fff3e4;
  --shadow: 0 18px 50px rgba(38, 33, 28, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #201f1d;
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  border-top: 5px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  padding: 30px;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 6px;
}

.login-card label span {
  color: var(--muted);
}

.login-card input {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.login-error {
  margin: -6px 0 0;
  color: #b42318;
  font-size: 14px;
  font-weight: 800;
}

.login-button,
.logout-button,
.tool-button {
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 900;
}

.login-button {
  height: 44px;
}

.logout-button {
  height: 42px;
  padding: 0 14px;
  white-space: nowrap;
}

.tool-button {
  min-height: 36px;
  padding: 0 12px;
}

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.logout-button:hover,
.login-button:hover,
.tool-button:hover {
  background: var(--accent-dark);
}

.secondary-button:hover {
  background: #f3ece3;
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px;
  background: #201f1d;
  color: #fff9f0;
  overflow: auto;
}

.brand-block {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 32px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
}

.filters {
  display: grid;
  gap: 16px;
}

label span {
  display: block;
  margin-bottom: 8px;
  color: #d9cbbd;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff9f0;
  padding: 0 12px;
  outline: none;
}

textarea {
  min-height: 70px;
  padding: 10px 12px;
  resize: vertical;
}

select option {
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 28px;
}

.summary-grid div,
.summary-card {
  min-height: 76px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.summary-card {
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.summary-card:hover {
  border-color: rgba(239, 108, 0, 0.7);
  background: rgba(239, 108, 0, 0.13);
}

.summary-grid strong {
  display: block;
  color: var(--accent);
  font-size: 28px;
}

.summary-grid span {
  color: #d9cbbd;
  font-size: 13px;
}

.detail-modal {
  position: relative;
  z-index: 1001;
  width: min(920px, 100%);
  max-height: min(760px, calc(100vh - 56px));
  overflow: auto;
  border-top: 5px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  padding: 30px;
  box-shadow: var(--shadow);
}

.chart-modal {
  position: relative;
  z-index: 1001;
  width: min(1180px, 100%);
  max-height: min(820px, calc(100vh - 56px));
  overflow: auto;
  border-top: 5px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  padding: 30px;
  box-shadow: var(--shadow);
}

.chart-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.chart-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.chart-panel h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

.chart-scroll {
  max-height: 560px;
  overflow: auto;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 38px;
  gap: 10px;
  align-items: center;
  min-height: 30px;
  margin-bottom: 8px;
  font-size: 13px;
}

.bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.bar-track {
  height: 14px;
  border-radius: 999px;
  background: #f2eadf;
  overflow: hidden;
}

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

.bar-value {
  color: var(--muted);
  font-weight: 900;
  text-align: right;
}

.chart-stats,
.sales-chart-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.chart-stats div,
.sales-chart-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
}

.chart-stats strong,
.sales-chart-stats strong {
  display: block;
  color: var(--accent);
  font-size: 24px;
}

.chart-stats span,
.sales-chart-stats span,
.bar-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.referral-chart-grid,
.sales-chart-grid {
  grid-template-columns: 1fr 1fr;
}

.referral-ranking-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 18px;
  align-items: start;
  max-height: 560px;
}

.referral-bar-row {
  grid-template-columns: minmax(120px, 1fr) minmax(90px, 1.2fr) 38px;
  break-inside: avoid;
}

.wide-chart-panel {
  grid-column: 1 / -1;
}

.sales-bar-row {
  grid-template-columns: minmax(150px, 1fr) minmax(130px, 1.2fr) 112px 42px;
}

.clickable-bar-row {
  cursor: pointer;
}

.clickable-bar-row:hover .bar-name {
  color: var(--accent-dark);
  text-decoration: underline;
}

.chart-empty {
  padding: 18px;
}

.network-wrap {
  overflow: auto;
  border-radius: 8px;
  background: #fbf6ef;
}

.relation-list-wrap {
  display: grid;
  gap: 10px;
  max-height: 560px;
  padding: 10px;
}

.relation-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid #eadfD2;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.relation-referrer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: #fff3e4;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
  font-weight: 900;
}

.relation-referrer:disabled {
  cursor: default;
  opacity: 0.72;
}

.relation-referrer span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-referrer strong {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
}

.relation-people {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.relation-chip {
  border: 1px solid #ffd0a3;
  border-radius: 999px;
  background: #fff7ed;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
}

.relation-chip.unresolved {
  border-color: var(--line);
  background: #f5f2ec;
  color: var(--muted);
  cursor: default;
}

.relation-referrer:not(:disabled):hover,
.relation-chip:not(.unresolved):hover {
  background: #ffe8d1;
}

.network-wrap svg {
  display: block;
  min-width: 680px;
}

.network-node {
  cursor: pointer;
}

.network-node:hover text {
  fill: var(--accent-dark);
  text-decoration: underline;
}

.detail-modal-header h2 {
  margin-bottom: 4px;
  font-size: 28px;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.detail-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 110px;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.detail-row button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf6ef;
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  font-weight: 800;
}

.pending-row {
  grid-template-columns: 210px minmax(0, 1fr) 100px;
}

.pending-match {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 8px;
  margin-top: 10px;
}

.pending-referral-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.pending-referral-box div {
  border: 1px solid #f0ddc8;
  border-radius: 8px;
  background: #fffaf4;
  padding: 8px 10px;
}

.pending-referral-box strong {
  display: block;
  color: var(--accent-dark);
  font-size: 12px;
  margin-bottom: 4px;
}

.pending-referral-box span {
  font-weight: 900;
}

.pending-match input {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.pending-candidates {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.candidate-button {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
}

.candidate-button:hover {
  border-color: rgba(239, 108, 0, 0.65);
  background: #fff7ed;
}

.candidate-button strong {
  color: var(--accent-dark);
}

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

.pending-type {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 900;
  text-align: right;
}

.content-panel {
  min-width: 0;
  padding: 28px;
}

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

.toolbar h2 {
  margin: 0;
  font-size: 30px;
}

.result-count {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 700;
}

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

.file-input {
  display: none;
}

.pagination-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.page-status {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(38, 33, 28, 0.08);
}

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

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.select-col {
  width: 42px;
  text-align: center;
}

.select-col input,
td input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbf6ef;
  color: var(--muted);
  font-size: 13px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--soft);
}

.student-name {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mini-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid #ffd3a7;
  border-radius: 8px;
  background: #fff7ed;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.15;
  overflow: hidden;
  padding: 3px;
  text-align: center;
  word-break: break-all;
}

.primary {
  margin-bottom: 4px;
  font-weight: 900;
}

.secondary {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin: 0 6px 6px 0;
  border-radius: 999px;
  background: #f2eadf;
  padding: 3px 9px;
  color: #6a5e52;
  font-size: 12px;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(21, 19, 17, 0.74);
}

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

.profile-card {
  position: relative;
  z-index: 1001;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  width: min(980px, 100%);
  max-height: min(760px, calc(100vh - 56px));
  overflow: auto;
  border-top: 5px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.icon-button {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #eee8df;
  color: var(--ink);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

.profile-side {
  padding: 38px 28px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.serial-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border-radius: 999px;
  background: #fff0df;
  padding: 7px 18px;
  color: var(--accent);
  font-weight: 900;
  letter-spacing: 0.06em;
}

.avatar-placeholder {
  display: grid;
  place-items: center;
  width: 210px;
  height: 210px;
  margin: 16px auto 12px;
  border: 3px solid #f3b000;
  border-radius: 14px;
  background: #fff7ed;
  color: var(--accent-dark);
  font-size: clamp(28px, 6vw, 56px);
  font-weight: 900;
  line-height: 1.1;
  overflow: hidden;
  padding: 12px;
  text-align: center;
  word-break: break-all;
}

.profile-side h3 {
  margin-bottom: 4px;
  font-size: 34px;
}

.nickname {
  margin-bottom: 16px;
  color: var(--accent);
  font-size: 22px;
  font-weight: 900;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.tag-list span {
  border-radius: 999px;
  background: #fff0df;
  padding: 7px 12px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
}

.profile-main {
  padding: 38px 34px;
}

.profile-actions {
  display: flex;
  justify-content: flex-end;
  margin: 10px 0;
}

.edit-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf6ef;
  padding: 14px;
  margin: 12px 0;
}

.edit-form label span {
  color: var(--muted);
}

.edit-form input,
.edit-form textarea {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

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

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

.profile-main h2 {
  margin-bottom: 4px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent);
  font-size: 30px;
}

.role-line {
  color: var(--muted);
  font-weight: 800;
}

.info-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px 14px;
}

.info-card.warm {
  background: #fff8ed;
  border-color: #ffd8aa;
  margin: 18px 0 10px;
}

.info-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 14px;
}

.info-card p {
  margin-bottom: 0;
  line-height: 1.75;
}

.person-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0 6px 6px 0;
  border: 1px solid #ffd0a3;
  border-radius: 999px;
  background: #fff7ed;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.person-link:hover {
  background: #ffe8d1;
}

.person-link.unresolved {
  border-color: var(--line);
  background: #f5f2ec;
  color: var(--muted);
  cursor: default;
}

.inline-edit-button {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf6ef;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 900;
}

.inline-edit-button:hover {
  background: #f3ece3;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.timeline-block {
  margin-top: 18px;
}

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

.timeline-header h4 {
  margin: 0;
  font-size: 20px;
}

.timeline-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.timeline {
  display: grid;
  gap: 8px;
}

.timeline-item {
  border-left: 3px solid var(--accent);
  background: #fff;
  padding: 10px 12px;
}

.timeline-item strong {
  color: var(--accent-dark);
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .profile-card {
    grid-template-columns: 1fr;
  }

  .profile-side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-stats,
  .sales-chart-stats {
    grid-template-columns: 1fr;
  }

  .wide-chart-panel {
    grid-column: auto;
  }

  .sales-bar-row {
    grid-template-columns: 1fr;
  }

  .referral-ranking-list {
    grid-template-columns: 1fr;
  }

  .referral-bar-row {
    grid-template-columns: 1fr;
  }

  .relation-row {
    grid-template-columns: 1fr;
  }

  .pending-row,
  .pending-match,
  .pending-referral-box {
    grid-template-columns: 1fr;
  }

  .pending-type {
    text-align: left;
  }
}
