:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #eef3f5;
  --ink: #172026;
  --muted: #67737b;
  --line: #dbe2e6;
  --brand: #0b6b63;
  --brand-strong: #074b47;
  --accent: #c15b2d;
  --warning: #b98016;
  --danger: #ba2d3a;
  --ok: #237a4d;
  --shadow: 0 14px 35px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  font-weight: 800;
}

#todayLabel {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.top-actions,
.form-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.ghost-button,
.icon-button,
.segment {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--brand);
  color: white;
  font-weight: 700;
  border-color: var(--brand);
}

.primary-button:hover {
  background: var(--brand-strong);
  box-shadow: 0 8px 18px rgba(11, 107, 99, 0.2);
}

.ghost-button {
  padding: 0 16px;
  background: #fff;
  color: var(--danger);
  border-color: #f0c7cc;
}

.ghost-button:hover {
  background: #fff5f6;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: 0 2px 8px rgba(23, 32, 38, 0.05);
}

.icon-button:hover,
.segment:hover,
.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.import-trigger {
  position: relative;
  overflow: hidden;
}

.import-trigger input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

.stat-tile {
  min-height: 104px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-tile span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}

.stat-tile strong {
  font-size: 34px;
  line-height: 1;
}

.stat-tile.alert strong {
  color: var(--warning);
}

.stat-tile.danger strong {
  color: var(--danger);
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-wrap span {
  color: var(--muted);
  font-size: 22px;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(4, 78px);
  gap: 4px;
  padding: 4px;
  background: #e8eef1;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.segment {
  min-height: 38px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(23, 32, 38, 0.08);
}

.student-area {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-head,
.student-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) 110px 120px 120px 140px 70px;
  gap: 12px;
  align-items: center;
}

.table-head {
  min-height: 44px;
  padding: 0 16px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.student-list {
  display: grid;
}

.student-row {
  min-height: 88px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.student-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.student-name {
  font-size: 16px;
  line-height: 1.25;
}

.student-meta,
.student-note {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.student-note:empty {
  display: none;
}

.card-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 72px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: #e5f2ef;
  color: var(--brand-strong);
  font-weight: 700;
  font-size: 13px;
}

.start-date,
.end-date {
  color: var(--muted);
  font-size: 14px;
}

.remaining {
  display: grid;
  gap: 4px;
}

.remaining strong {
  font-size: 20px;
}

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

.student-row.soon .remaining strong {
  color: var(--warning);
}

.student-row.expired .remaining strong {
  color: var(--danger);
}

.student-row.active .remaining strong {
  color: var(--ok);
}

.empty-state {
  display: none;
  min-height: 240px;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

dialog {
  width: min(560px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(23, 32, 38, 0.24);
}

dialog::backdrop {
  background: rgba(14, 24, 28, 0.34);
}

.student-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  font-size: 22px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
  outline: none;
}

textarea {
  padding-top: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 107, 99, 0.12);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  justify-content: space-between;
  margin-top: 4px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 18px;
  }

  .topbar,
  .controls {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: stretch;
  }

  .primary-button {
    flex: 1;
  }

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

  .segmented {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .table-head {
    display: none;
  }

  .student-row {
    grid-template-columns: 1fr 40px;
    gap: 10px;
    min-height: 0;
  }

  .student-main {
    grid-column: 1 / 2;
  }

  .card-type,
  .start-date,
  .end-date,
  .remaining {
    grid-column: 1 / 2;
  }

  .row-actions {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    align-self: start;
  }

  .start-date::before {
    content: "开卡 ";
  }

  .end-date::before {
    content: "到期 ";
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 24px;
  }

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

  .top-actions {
    display: grid;
    grid-template-columns: 40px 40px 1fr;
  }

  .stat-tile {
    min-height: 88px;
  }
}
