:root {
  --green: #087a43;
  --green-strong: #056736;
  --green-soft: #eaf7f0;
  --dark: #102a43;
  --text: #334e68;
  --muted: #64748b;
  --line: #dbe7e1;
  --bg: #f5f9f7;
  --white: #fff;
  --red: #b4232c;
  --shadow-sm: 0 7px 22px rgba(15, 42, 67, 0.055);
  --shadow-md: 0 16px 42px rgba(15, 42, 67, 0.09);
}

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

html {
  min-width: 320px;
  scroll-padding-top: 92px;
  scrollbar-gutter: stable;
}

body {
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 94% 5%, rgba(47, 176, 108, 0.055), transparent 24rem),
    linear-gradient(180deg, #f8fbfa 0%, var(--bg) 100%);
  color: var(--dark);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-weight: 400;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button,
a,
select,
input[type="file"] {
  -webkit-tap-highlight-color: transparent;
}

img {
  max-width: 100%;
}

::selection {
  background: #ccebdd;
  color: var(--dark);
}

.container {
  width: min(1180px, calc(100% - 34px));
}

h1,
h2,
h3,
h4,
th,
strong,
b {
  letter-spacing: 0;
}

h1,
h2,
h3,
h4 {
  color: var(--dark);
}

.topbar,
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid rgba(219, 231, 225, 0.96);
  background: rgba(255, 255, 255, 0.985);
  box-shadow: 0 5px 20px rgba(15, 42, 67, 0.045);
  backdrop-filter: none;
}

.topbar .nav,
.admin-topbar .nav {
  position: relative;
  min-height: 76px;
  gap: 14px;
}

.topbar .brand,
.admin-topbar .brand {
  min-width: 0;
  gap: 11px;
  color: var(--dark);
  line-height: 1.35;
}

.topbar .brand img,
.admin-topbar .brand img {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  object-fit: contain;
}

.topbar .brand div,
.admin-topbar .brand div {
  min-width: 0;
}

.topbar .brand strong,
.admin-topbar .brand strong {
  display: block;
  overflow: hidden;
  color: var(--dark);
  font-size: 17px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .brand small,
.admin-topbar .brand small {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .links,
.admin-topbar .links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar .links a,
.admin-topbar .links a {
  padding: 9px 12px;
  border-radius: 10px;
  color: #3d5265;
  font-size: 14px;
  font-weight: 750;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.topbar .links a:hover,
.topbar .links a.active,
.admin-topbar .links a:hover,
.admin-topbar .links a.active {
  background: var(--green-soft);
  color: var(--green-strong);
  box-shadow: none;
}

.nav-toggle {
  width: 42px;
  height: 42px;
  display: none;
  flex: 0 0 42px;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--dark);
  cursor: pointer;
}

.nav-toggle span {
  width: 21px;
  height: 2px;
  display: block;
  margin: 3px auto;
  border-radius: 99px;
  background: currentColor;
  transition: transform 0.16s ease, opacity 0.16s ease;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(5px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-5px) rotate(-45deg);
}

.btn,
.btnx,
.admin-logout-always,
.excel-btn,
.photos-btn,
.back-btn,
.global-rerank-btn,
.photo-file-trigger,
.student-download {
  border-radius: 11px;
  font-weight: 800;
  box-shadow: none;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease, border-color 0.16s ease;
}

.btn:hover,
.btnx:hover,
.admin-logout-always:hover,
.excel-btn:hover,
.photos-btn:hover,
.back-btn:hover,
.global-rerank-btn:hover,
.photo-file-trigger:hover,
.student-download:hover {
  transform: translateY(-1px);
}

.btn:not(.gray):not(.red):not(.light),
.btnx:not(.gray):not(.red) {
  background: linear-gradient(135deg, var(--green-strong), #0d9555);
  color: #fff;
  box-shadow: 0 8px 18px rgba(8, 122, 67, 0.16);
}

.btn.light {
  border-color: #bedccc;
  background: #fff;
  color: var(--green-strong);
}

.btn.red,
.btnx.red,
.admin-logout-always {
  background: var(--red);
  color: #fff;
}

.card,
.panel,
.box,
.report-panel,
.filter-panel,
.student-card,
.student-row,
.admin-stat-card,
.admin-progress-card,
.admin-quick-note,
.admin-action-card,
.registered-group-card {
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.card,
.panel,
.box,
.report-panel {
  border-radius: 18px;
}

.panel:hover,
.box:hover,
.student-card:hover,
.registered-group-card:hover {
  border-color: #c3ddcf;
}

.admin-action-card,
.registered-group-card,
.group-card,
.pref-card {
  transition: transform 0.17s ease, box-shadow 0.17s ease, border-color 0.17s ease;
}

.admin-action-card:hover,
.registered-group-card:hover,
.group-card:hover,
.pref-card:hover {
  transform: translateY(-2px);
}

.admin-action-card:hover {
  box-shadow: var(--shadow-md);
}

.admin-stat-icon svg,
.admin-action-icon svg {
  width: 29px;
  height: 29px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.admin-hero {
  overflow: hidden;
  border-radius: 23px;
  box-shadow: var(--shadow-md);
}

.admin-hero img {
  object-fit: cover;
}

.admin-hero-content {
  padding-block: 42px;
}

.form-control,
.pref-select,
input[type="text"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="search"],
select,
textarea {
  border-color: #c9d9d1;
  background-color: #fff;
  color: var(--dark);
  font-family: inherit;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.form-control:focus,
.pref-select:focus,
input[type="text"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: #178653;
  background-color: #fff;
  box-shadow: 0 0 0 4px rgba(8, 122, 67, 0.1);
}

select.form-control,
select.pref-select,
select.field {
  appearance: none;
  padding-left: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='%23087a43' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: left 14px center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
}

input::placeholder,
textarea::placeholder {
  color: #8b9bab;
  opacity: 1;
}

input[type="file"] {
  max-width: 100%;
  color: var(--text);
}

input[type="file"]::file-selector-button {
  margin-left: 10px;
  border: 1px solid #bdd9ca;
  border-radius: 10px;
  padding: 9px 13px;
  background: var(--green-soft);
  color: var(--green-strong);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.table-wrap,
.preferences-sheet {
  overflow: auto;
  overscroll-behavior-inline: contain;
  border-color: var(--line);
  border-radius: 14px;
  background: #fff;
  scrollbar-color: #adcabe #eef4f1;
  scrollbar-width: thin;
}

.table-wrap:focus-visible,
.preferences-sheet:focus-visible {
  outline: 3px solid rgba(8, 122, 67, 0.2);
  outline-offset: 3px;
}

table {
  font-variant-numeric: tabular-nums;
}

th {
  background: #eaf5ef;
  color: #17384b;
  font-weight: 850;
}

tbody tr {
  transition: background-color 0.12s ease;
}

tbody tr:hover {
  background: #f6fbf8;
}

.notice,
.flash,
.empty,
.empty-state,
.group-empty {
  border: 1px solid transparent;
  border-radius: 13px;
}

.notice.ok,
.flash.ok,
.ok {
  border-color: #bae5cb;
}

.notice.bad,
.flash.bad,
.bad {
  border-color: #fecaca;
}

.notice.warn,
.warn {
  border-color: #fed7aa;
}

.status-pill,
.chip,
.track-group,
.count-box,
.results-badge,
.rank-badge {
  font-weight: 800;
}

.upload {
  border-color: #91cbae;
  background: linear-gradient(180deg, #fbfffd, #f2faf6);
}

.student-card,
.student-row {
  content-visibility: auto;
  contain-intrinsic-size: auto 210px;
}

form.is-submitting {
  cursor: progress;
}

button.is-loading,
input.is-loading {
  position: relative;
  cursor: wait !important;
  opacity: 0.86;
}

button.is-loading::before {
  content: "";
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}

@keyframes ui-spin {
  to { transform: rotate(360deg); }
}

:focus-visible {
  outline: 3px solid rgba(8, 122, 67, 0.24);
  outline-offset: 3px;
}

@media (max-width: 850px) {
  html {
    scroll-padding-top: 78px;
    scrollbar-gutter: auto;
  }

  .container {
    width: calc(100% - 22px);
  }

  .topbar .nav,
  .admin-topbar .nav {
    min-height: 70px;
    gap: 8px;
  }

  .topbar .brand,
  .admin-topbar .brand {
    flex: 1 1 auto;
    overflow: hidden;
  }

  .topbar .brand img,
  .admin-topbar .brand img {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .topbar .brand strong,
  .admin-topbar .brand strong {
    font-size: 14px;
  }

  .nav-toggle {
    display: grid;
  }

  html:not(.js) .topbar .links,
  html:not(.js) .admin-topbar .links {
    max-width: 55vw;
    display: flex;
    overflow-x: auto;
  }

  .js .topbar .links,
  .js .admin-topbar .links {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: 0;
    z-index: 60;
    display: none;
    align-items: stretch;
    flex-direction: column;
    gap: 3px;
    max-height: min(70vh, 430px);
    overflow-y: auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--shadow-md);
  }

  .js .topbar .links.is-open,
  .js .admin-topbar .links.is-open {
    display: flex;
  }

  .js .topbar .links a,
  .js .admin-topbar .links a {
    width: 100%;
    padding: 10px 12px;
    text-align: center;
  }

  .admin-hero-content {
    padding-block: 30px;
  }
}

@media (max-width: 560px) {
  .container {
    width: calc(100% - 18px);
  }

  .has-collapsible-nav .brand div {
    display: none;
  }

  .admin-logout-always {
    padding: 8px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .panel,
  .box,
  .card,
  .report-panel {
    border-radius: 15px;
  }

  .table-wrap,
  .preferences-sheet {
    border-radius: 11px;
  }
}

@media (hover: none) {
  .btn:hover,
  .btnx:hover,
  .admin-action-card:hover,
  .registered-group-card:hover,
  .group-card:hover,
  .pref-card:hover,
  .student-card:hover {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  .nav-toggle {
    display: none !important;
  }

  body {
    background: #fff;
  }
}
