*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

:root {
  --c-primary: #2563eb;
  --c-primary-dark: #1d4ed8;
  --c-danger: #dc2626;
  --c-success: #16a34a;
  --c-warning: #d97706;
  --c-bg: #f6f7f9;
  --c-card: #ffffff;
  --c-text: #172033;
  --c-muted: #657084;
  --c-soft: #eef2f7;
  --c-border: #dbe2ea;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.08);
}

html {
  font-size: 15px;
}

body {
  min-height: 100vh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 112px;
  padding: 22px 28px;
  color: #fff;
  background: #163a70;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.header-kicker {
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.86rem;
}

.header-title {
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: 0;
}

.header-date {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
}

.tabs {
  display: inline-flex;
  gap: 4px;
  margin: 18px 0;
  padding: 4px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(23, 32, 51, 0.04);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 104px;
  justify-content: center;
  padding: 10px 16px;
  border: 0;
  border-radius: 6px;
  color: var(--c-muted);
  background: transparent;
}

.tab.active {
  color: #fff;
  background: var(--c-primary);
  font-weight: 650;
}

.tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: currentColor;
  color: var(--c-card);
  font-size: 0.72rem;
  font-weight: 700;
}

.tab.active .tab-icon {
  color: var(--c-primary);
  background: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.checkin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(340px, 0.7fr);
  gap: 16px;
  align-items: start;
}

.side-column {
  display: grid;
  gap: 16px;
}

.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.section-head,
.overview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.card-title {
  margin-bottom: 14px;
  font-size: 1.05rem;
  font-weight: 700;
}

.section-head .card-title,
.overview-toolbar .card-title {
  margin-bottom: 0;
}

.hint {
  color: var(--c-muted);
  font-size: 0.86rem;
}

.member-card .hint {
  margin-top: 12px;
}

.user-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.user-chip {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  color: var(--c-text);
  background: #fff;
  text-align: left;
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}

.user-chip:hover,
.user-chip.selected {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.user-chip.red {
  border-color: #fecaca;
  background: #fff7f7;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.status-dot.green { background: var(--c-success); }
.status-dot.orange { background: var(--c-warning); }
.status-dot.red { background: var(--c-danger); }
.status-dot.gray { background: #aab3c0; }

.chip-main {
  min-width: 0;
}

.chip-name-text,
.chip-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-name-text {
  font-weight: 650;
}

.chip-meta {
  margin-top: 2px;
  color: var(--c-muted);
  font-size: 0.78rem;
}

.user-chip.red .chip-name-text,
.overview-table tr.row-red td:first-child strong,
.overview-person.is-red strong {
  color: var(--c-danger);
}

.chip-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--c-muted);
  font-size: 0.78rem;
  background: var(--c-soft);
}

.chip-edit:hover {
  color: #fff;
  background: var(--c-primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 650;
  transition: background 0.16s, color 0.16s, border-color 0.16s, opacity 0.16s;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 34px;
  padding: 7px 12px;
  font-size: 0.86rem;
}

.btn-primary {
  color: #fff;
  background: var(--c-primary);
}

.btn-primary:hover {
  background: var(--c-primary-dark);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-outline {
  color: var(--c-text);
  background: #fff;
  border: 1px solid var(--c-border);
}

.btn-outline:hover {
  color: var(--c-primary);
  border-color: var(--c-primary);
}

.drop-zone {
  min-height: 190px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  padding: 24px;
  border: 2px dashed #b8c4d2;
  border-radius: var(--radius);
  background: #fafcff;
  text-align: center;
  transition: border-color 0.16s, background 0.16s;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--c-primary);
  background: #eff6ff;
}

.drop-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin-bottom: 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--c-primary);
  font-size: 1.6rem;
}

.drop-text {
  font-weight: 650;
}

.drop-sub {
  margin-top: 4px;
  color: var(--c-muted);
  font-size: 0.82rem;
}

.preview {
  margin-bottom: 14px;
  text-align: center;
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  margin: 0 auto 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  object-fit: contain;
}

.today-checkins {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.today-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid #bbf7d0;
  border-radius: 999px;
  color: #166534;
  background: #f0fdf4;
  font-size: 0.88rem;
}

.today-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--c-success);
}

.select {
  min-height: 40px;
  padding: 8px 34px 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  color: var(--c-text);
  background: #fff;
  appearance: auto;
}

.overview-container {
  margin-top: 16px;
}

.overview-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.overview-stats div {
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-card);
  box-shadow: 0 6px 20px rgba(23, 32, 51, 0.05);
}

.overview-stats span {
  display: block;
  color: var(--c-muted);
  font-size: 0.84rem;
}

.overview-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.65rem;
  line-height: 1.1;
}

.overview-table-wrap {
  overflow: auto;
  max-height: 66vh;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-card);
  box-shadow: var(--shadow);
}

.overview-table {
  min-width: 760px;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.overview-table th,
.overview-table td {
  min-width: 64px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--c-border);
  text-align: center;
  white-space: nowrap;
}

.overview-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--c-muted);
  background: #f8fafc;
  font-size: 0.82rem;
}

.overview-table th span,
.overview-table th small {
  display: block;
}

.overview-table th small {
  margin-top: 2px;
  color: #8b96a6;
  font-size: 0.72rem;
  font-weight: 500;
}

.overview-table th.is-today {
  color: var(--c-primary);
  background: #eff6ff;
}

.overview-table th:first-child,
.overview-table td:first-child {
  position: sticky;
  left: 0;
  min-width: 154px;
  text-align: left;
  z-index: 3;
}

.overview-table td:first-child {
  background: var(--c-card);
}

.overview-table th:first-child {
  background: #f8fafc;
}

.overview-table tr.row-red td {
  background: #fff7f7;
}

.overview-table td:first-child span {
  display: block;
  margin-top: 2px;
  color: var(--c-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.cell-img {
  width: 44px;
  height: 44px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.16s, box-shadow 0.16s;
}

.cell-img:hover {
  transform: translateY(-1px) scale(1.06);
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.16);
}

.cell-empty {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #d7dee8;
}

.overview-mobile-list {
  display: none;
}

.empty-state {
  width: 100%;
  padding: 26px 12px;
  color: var(--c-muted);
  text-align: center;
}

.modal-overlay,
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay {
  padding: 18px;
  background: rgba(15, 23, 42, 0.46);
}

.modal-overlay.active,
.lightbox.active {
  display: flex;
}

.modal {
  width: min(380px, 100%);
  padding: 22px;
  border-radius: var(--radius);
  background: var(--c-card);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.modal-title {
  margin-bottom: 14px;
  text-align: center;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  outline: none;
}

.input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.lightbox {
  padding: 22px;
  background: rgba(0, 0, 0, 0.84);
  z-index: 200;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 22px;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
}

.lightbox-img {
  max-width: min(1100px, 96vw);
  max-height: 90vh;
  border-radius: var(--radius);
  object-fit: contain;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 300;
  max-width: min(420px, calc(100vw - 28px));
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 999px;
  color: #fff;
  background: #172033;
  box-shadow: 0 12px 30px rgba(23, 32, 51, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

.toast.success { background: var(--c-success); }
.toast.error { background: var(--c-danger); }

@media (max-width: 860px) {
  .app {
    padding: 12px 12px 36px;
  }

  .header {
    align-items: flex-start;
    flex-direction: column;
    min-height: auto;
    padding: 20px;
  }

  .header-title {
    font-size: 1.65rem;
  }

  .tabs {
    display: flex;
    width: 100%;
  }

  .tab {
    flex: 1;
    min-width: 0;
  }

  .checkin-layout {
    grid-template-columns: 1fr;
  }

  .section-head,
  .overview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head .btn,
  .overview-toolbar .select {
    width: 100%;
  }

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

  .drop-zone {
    min-height: 170px;
  }

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

  .overview-stats div:last-child {
    grid-column: span 2;
  }

  .overview-table-wrap {
    display: none;
  }

  .overview-mobile-list {
    display: grid;
    gap: 12px;
  }

  .overview-person {
    padding: 14px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-card);
    box-shadow: 0 6px 20px rgba(23, 32, 51, 0.05);
  }

  .overview-person.is-red {
    border-color: #fecaca;
    background: #fff7f7;
  }

  .person-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
  }

  .person-head strong,
  .person-head span {
    display: block;
  }

  .person-head span {
    margin-top: 2px;
    color: var(--c-muted);
    font-size: 0.82rem;
  }

  .person-head b {
    flex: 0 0 auto;
    color: var(--c-muted);
    font-size: 0.82rem;
  }

  .mobile-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-day {
    min-width: 0;
    height: 58px;
    display: grid;
    place-items: center;
    gap: 4px;
    padding: 6px 2px;
    border: 1px solid var(--c-border);
    border-radius: 7px;
    color: var(--c-muted);
    background: #fff;
    text-decoration: none;
  }

  .mobile-day span {
    font-size: 0.72rem;
  }

  .mobile-day i {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #d7dee8;
  }

  .mobile-day.has-image {
    border-color: #bfdbfe;
    background: #eff6ff;
  }

  .mobile-day img {
    width: 30px;
    height: 30px;
    border-radius: 5px;
    object-fit: cover;
  }
}

@media (max-width: 420px) {
  html {
    font-size: 14px;
  }

  .card {
    padding: 14px;
  }

  .overview-stats strong {
    font-size: 1.45rem;
  }

  .mobile-days {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
