:root {
  --bg: #111827;
  --side: #0F172A;
  --card: #1F2937;
  --card-soft: #253244;
  --accent: #00CFC8;
  --accent-hover: #39E6DF;
  --text: #FFFFFF;
  --muted: #A7B0C0;
  --line: #334155;
  --danger: #EF4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.32);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

body,
button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #0F172A;
  color: var(--accent);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #0F172A;
}

::-webkit-scrollbar-thumb {
  background: #3B4658;
  border: 2px solid #0F172A;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: var(--side);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 8px 24px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #071113;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
}

.nav-menu {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, color 180ms ease;
}

.nav-item span {
  display: grid;
  width: 24px;
  place-items: center;
  color: var(--accent);
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(0, 207, 200, 0.32);
  background: rgba(0, 207, 200, 0.11);
  color: var(--text);
  transform: translateX(3px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(360px, 580px) auto;
  gap: 18px;
  align-items: center;
  min-height: 86px;
  padding: 18px 28px;
  background: rgba(17, 24, 39, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

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

.topbar h1 {
  margin-bottom: 0;
  font-size: 1.5rem;
}

.eyebrow,
.section-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.top-stats article,
.panel,
.stat-card,
.member-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.top-stats article {
  min-width: 0;
  padding: 12px;
}

.top-stats span,
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-stats strong {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.section-heading {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0;
}

.stats-grid,
.dashboard-grid,
.settings-grid,
.profile-grid {
  display: grid;
  gap: 18px;
}

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.dashboard-grid,
.settings-grid,
.profile-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.stat-card {
  min-height: 118px;
  padding: 20px;
  border-top: 3px solid rgba(0, 207, 200, 0.75);
}

.stat-card strong {
  display: block;
  margin-top: 18px;
  color: var(--accent);
  font-size: 2rem;
}

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

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

.panel-header h3 {
  margin: 0;
}

.stack-list,
.timeline,
.ranking-list,
.admin-list,
.grade-list,
.history-list {
  display: grid;
  gap: 10px;
}

.empty-state,
.notice {
  padding: 16px;
  border: 1px dashed #475569;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.notice {
  border-style: solid;
  border-color: rgba(0, 207, 200, 0.25);
  background: rgba(0, 207, 200, 0.08);
  text-align: left;
}

.mini-row,
.timeline-item,
.ranking-row,
.admin-row,
.grade-row,
.history-item {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.38);
}

.mini-row {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.timeline-item {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.ranking-row {
  grid-template-columns: 54px auto minmax(0, 1fr) auto auto;
}

.admin-row {
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 0.8fr) minmax(300px, 1fr);
}

.grade-row,
.history-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

.history-item {
  grid-template-columns: 150px minmax(0, 1fr) 160px auto;
}

.avatar,
.profile-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  color: #071113;
  font-weight: 900;
}

.profile-avatar {
  width: 62px;
  height: 62px;
  background: var(--accent);
  font-size: 1.4rem;
}

.row-main,
.member-main {
  min-width: 0;
}

.row-main strong,
.member-main h3 {
  display: block;
  overflow: hidden;
  margin: 0 0 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-main span,
.muted,
.member-notes,
.timeline-item span,
.history-item span,
.history-item time {
  color: var(--muted);
  font-size: 0.9rem;
}

.score-pill,
.rank-pill,
.position {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.score-pill {
  border: 1px solid rgba(0, 207, 200, 0.36);
  color: var(--accent);
}

.rank-pill {
  color: #071113;
}

.position {
  color: var(--accent);
  font-size: 1rem;
}

.value-plus {
  color: var(--accent);
}

.value-minus {
  color: #FCA5A5;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 220px auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.search-field {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: #0F172A;
  color: var(--text);
}

input,
select {
  padding: 9px 11px;
}

textarea {
  padding: 10px 11px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 207, 200, 0.13);
}

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

.form-stack,
.member-form,
.grade-form {
  display: grid;
  gap: 12px;
}

.member-form {
  grid-template-columns: minmax(180px, 1fr) 180px minmax(220px, 1.4fr) auto;
  align-items: end;
}

.grade-form {
  grid-template-columns: minmax(180px, 1fr) 110px 100px auto auto;
  align-items: end;
  margin-bottom: 16px;
}

.form-panel {
  margin-bottom: 18px;
}

.form-actions,
.row-actions,
.member-actions,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
}

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
}

.member-card {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.member-card-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

details {
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  padding-top: 10px;
}

summary {
  color: var(--accent);
  font-weight: 800;
}

.compact {
  margin-top: 10px;
  max-height: 260px;
  overflow: auto;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.tiny-button,
.icon-button {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 800;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.primary-button {
  padding: 10px 14px;
  background: var(--accent);
  color: #071113;
}

.primary-button:hover {
  background: var(--accent-hover);
  box-shadow: 0 12px 24px rgba(0, 207, 200, 0.22);
  transform: translateY(-1px);
}

.secondary-button,
.tiny-button {
  padding: 9px 12px;
  border-color: rgba(0, 207, 200, 0.35);
  background: rgba(0, 207, 200, 0.08);
  color: var(--accent);
}

.secondary-button:hover,
.tiny-button:hover {
  border-color: var(--accent);
  background: rgba(0, 207, 200, 0.16);
  color: var(--accent-hover);
  transform: translateY(-1px);
}

.ghost-button {
  padding: 9px 12px;
  border-color: var(--line);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
}

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

.danger-button {
  padding: 9px 12px;
  border-color: rgba(248, 113, 113, 0.38);
  background: var(--danger-soft);
  color: #FECACA;
}

.danger-button:hover {
  background: var(--danger);
  color: var(--text);
  transform: translateY(-1px);
}

.tiny-button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.86rem;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border-color: var(--line);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  font-size: 1.08rem;
}

.wide {
  width: 100%;
  margin-top: 12px;
}

.logout-form {
  justify-self: end;
}

.profile-card {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(10px);
}

.modal-backdrop.show {
  display: grid;
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.modal-card form {
  display: grid;
  gap: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.quick-values,
.reason-presets {
  display: grid;
  gap: 8px;
}

.quick-values {
  grid-template-columns: repeat(4, 1fr);
}

.reason-presets {
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
}

.quick-values button,
.reason-presets button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  font-weight: 800;
}

.quick-values button:hover,
.reason-presets button:hover,
.reason-presets button.active {
  border-color: var(--accent);
  background: rgba(0, 207, 200, 0.16);
  color: var(--accent-hover);
}

.toast {
  margin-bottom: 12px;
  padding: 13px 14px;
  border: 1px solid rgba(0, 207, 200, 0.28);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: #0F172A;
  box-shadow: var(--shadow);
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.danger {
  border-color: rgba(248, 113, 113, 0.3);
  border-left-color: var(--danger);
}

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 24px;
  width: min(1100px, 100%);
}

.auth-shell.single {
  grid-template-columns: minmax(320px, 680px);
}

.auth-hero {
  align-self: center;
}

.auth-brand {
  padding-left: 0;
}

.auth-hero h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.05;
}

.auth-hero p {
  color: var(--muted);
  line-height: 1.65;
}

.auth-panels {
  display: grid;
  gap: 16px;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-menu {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    min-width: 130px;
  }

  .topbar,
  .dashboard-grid,
  .settings-grid,
  .profile-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .top-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .logout-form {
    justify-self: start;
  }
}

@media (max-width: 720px) {
  .content,
  .topbar,
  .sidebar {
    padding: 16px;
  }

  .top-stats,
  .toolbar,
  .member-form,
  .grade-form,
  .ranking-row,
  .timeline-item,
  .mini-row,
  .admin-row,
  .history-item,
  .member-card-header {
    grid-template-columns: 1fr;
  }

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

  .section-heading {
    display: grid;
  }

  .member-actions,
  .modal-actions,
  .row-actions {
    align-items: stretch;
  }

  .member-actions > *,
  .modal-actions > *,
  .row-actions > * {
    flex: 1 1 auto;
  }
}
