:root {
  color-scheme: light;
  --bg-main: #f3f4ef;
  --bg-card: #ffffff;
  --bg-soft: #edf3df;
  --bg-accent: #151712;
  --text-main: #161712;
  --text-muted: #5d6256;
  --text-inverse: #f7f9f4;
  --primary: #9cdf2d;
  --primary-soft: #eef8d0;
  --primary-deep: #6d951d;
  --border: #cfd6c4;
  --border-strong: #151712;
  --red: #ff5269;
  --radius: 8px;
  --shadow: 0 16px 40px rgba(21, 23, 18, 0.08);
  --shadow-lg: 0 22px 58px rgba(21, 23, 18, 0.12);
  font-family:
    "Inter", "PingFang SC", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 14px;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-main);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 16px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 2px solid var(--border-strong);
  background: var(--primary);
  color: var(--text-main);
  box-shadow: 4px 4px 0 var(--border-strong);
  transition: background 0.2s, transform 0.1s, box-shadow 0.1s;
}

.button:hover {
  background: var(--primary-deep);
  color: var(--text-inverse);
  box-shadow: 5px 5px 0 var(--border-strong);
}

.button:active {
  transform: translateY(1px);
}

.button.ghost {
  background: var(--bg-soft);
  color: var(--text-main);
}

.button.ghost:hover {
  background: var(--border);
}

.button.danger {
  background: var(--red);
  color: #ffffff;
}

.button.block-action {
  width: 100%;
}

/* Layout */
.app-shell,
.member-page-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-actions select {
  width: auto;
  padding-right: 32px;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Dashboard Home */
.dashboard-layout {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 20px;
  height: 100%;
}

.dashboard-band {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
}

.mission-copy {
  position: relative;
  height: 186px;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--bg-accent);
  color: var(--text-inverse);
  overflow: hidden;
  display: flex;
  align-items: center;
  border: 2px solid var(--border-strong);
  box-shadow: var(--shadow);
}

.mission-copy img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.3;
}

.mission-copy > div {
  position: relative;
  z-index: 1;
}

.mission-copy h2 {
  font-size: 28px;
  line-height: 1.2;
  margin: 4px 0;
}

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

.metric-card {
  padding: 16px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: var(--shadow);
}

.metric-card span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-card strong {
  font-size: 24px;
  font-weight: 800;
  margin: 2px 0;
}

.metric-card small {
  font-size: 11px;
  color: var(--text-muted);
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  min-height: 0;
}

.panel {
  background: var(--bg-card);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
}

.panel-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 20px;
}

.leaderboard {
  display: flex;
  flex-direction: column;
}

.rank-row {
  display: grid;
  grid-template-columns: 40px 48px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-soft);
}

.rank-row:last-child {
  border-bottom: none;
}

.rank-row:hover {
  background: var(--primary-soft);
}

.rank-number {
  font-weight: 800;
  color: var(--text-muted);
  font-size: 18px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.rank-main strong {
  display: block;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-main small {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-progress {
  display: block;
  height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}

.rank-progress i {
  display: block;
  height: 100%;
  width: var(--w, 0);
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.6s ease;
}

.rank-score {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
}

.side-panel-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
}

.side-panel-group .panel {
  flex: 1;
}

.trend-bars {
  height: 100px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 10px 0;
}

.trend-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.trend-item span {
  width: 100%;
  height: var(--h, 0);
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: 2px 2px 0 0;
  transition: height 0.3s;
}

.trend-item:hover span {
  background: var(--primary);
}

.trend-item small {
  font-size: 9px;
  color: var(--text-muted);
}

.breakdown {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.breakdown div {
  flex: 1;
  padding: 8px;
  background: var(--bg-soft);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: center;
}

.breakdown span {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}

.breakdown strong {
  font-size: 16px;
}

.latest-list article {
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-soft);
}

.latest-list article:last-child {
  border-bottom: none;
}

.latest-list span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.latest-list p {
  font-size: 13px;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Member Page */
.member-frame {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  min-height: 0;
}

.member-overview {
  padding: 24px;
}

.member-spotlight {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--bg-accent);
  color: var(--text-inverse);
}

.member-spotlight .avatar {
  width: 100px;
  height: 100px;
  font-size: 32px;
  border: 2px solid var(--primary);
}

.member-spotlight .eyebrow {
  color: rgba(247, 249, 244, 0.84);
}

.member-name {
  font-size: 24px;
  font-weight: 800;
}

.member-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.identity-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

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

.identity-grid strong {
  display: block;
  color: var(--text-main);
  font-size: 14px;
}

.heatmap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 12px;
}

.heat-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--bg-soft);
}

.level-1 { background: #d9ebb5; }
.level-2 { background: #bada6e; }
.level-3 { background: #8ebb20; }
.level-4 { background: var(--primary-deep); }

.checkin-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--bg-soft);
}

.checkin-item:last-child {
  border-bottom: none;
}

.checkin-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.type-pill {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  background: var(--bg-soft);
}

.type-pill.morning { background: var(--primary-soft); color: var(--primary-deep); }
.type-pill.review { background: #e7f0d7; color: #5b7815; }

.checkin-item time {
  font-size: 12px;
  color: var(--text-muted);
}

.checkin-item strong {
  margin-left: auto;
  color: var(--primary);
}

.checkin-item p {
  font-size: 14px;
  white-space: pre-wrap;
}

.checkin-reason {
  display: block;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.media-grid img,
.media-grid video {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.file-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

/* Admin Page */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  overflow-y: auto;
}

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

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stack-form label span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.terminal {
  background: var(--bg-accent);
  color: var(--primary);
  padding: 12px;
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 12px;
  overflow-x: auto;
}

.record-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.record-info {
  min-width: 0;
}

.record-info strong {
  display: block;
}

.record-info p {
  font-size: 13px;
  color: var(--text-muted);
}

.mt-24 { margin-top: 24px; }
.btn-small { height: 32px; padding: 0 12px; font-size: 12px; }

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* Responsive */
@media (max-width: 1024px) {
  html, body { overflow: auto; }
  .app-shell, .member-page-shell { height: auto; }
  .dashboard-band, .content-grid, .member-frame, .admin-grid {
    grid-template-columns: 1fr;
  }
  .mission-copy { height: auto; }
}
