:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-strong: #f0f5f2;
  --ink: #192226;
  --muted: #5e6970;
  --line: #dce2e5;
  --accent: #1f7a5c;
  --accent-strong: #145e46;
  --gold: #b98212;
  --danger: #b33a3a;
  --blue: #2f5e9e;
  --shadow: 0 18px 50px rgba(25, 34, 38, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(31, 122, 92, 0.08), transparent 32%),
    linear-gradient(300deg, rgba(47, 94, 158, 0.10), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  filter: drop-shadow(0 10px 18px rgba(25, 34, 38, 0.12));
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 750;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  color: var(--accent-strong);
  font-size: clamp(1.55rem, 3vw, 2.4rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:hover {
  text-decoration: underline;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.1rem;
  letter-spacing: 0;
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tab-button,
.action-button,
.secondary-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}

.tab-button {
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
}

.tab-button.active,
.action-button {
  color: #fff;
  background: var(--accent);
}

.action-button {
  padding: 0 18px;
}

.secondary-button,
.danger-button {
  padding: 0 18px;
  border: 1px solid var(--line);
}

.secondary-button {
  color: var(--ink);
  background: #fff;
}

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

.action-button:hover,
.tab-button.active:hover {
  background: var(--accent-strong);
}

.secondary-button:hover {
  border-color: var(--accent);
  background: #f3f8f5;
}

.danger-button:hover {
  background: #912f2f;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tool-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 20px;
}

.panel-heading p,
.table-header span {
  color: var(--muted);
}

.panel-heading p {
  margin-bottom: 18px;
}

.control-grid {
  display: grid;
  gap: 14px;
}

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

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(31, 122, 92, 0.18);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--ink);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.inline-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-edit-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 4px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.compact-control {
  flex-wrap: nowrap;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  border: 1px solid var(--line);
  color: var(--accent-strong);
  background: #fff;
  font-size: 1.05rem;
}

.icon-button:hover {
  border-color: var(--accent);
  background: #eef7f3;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.compact {
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.class-picker {
  display: grid;
  width: min(310px, 100%);
  gap: 5px;
  position: relative;
}

.field-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

.class-menu-control {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 42px;
  position: relative;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.class-name-input {
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  font-weight: 750;
}

.class-dropdown-toggle {
  min-height: 40px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 5px 5px 0;
  color: var(--accent-strong);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.class-dropdown-toggle:hover {
  background: #eef7f3;
}

.class-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: -1px;
  right: -1px;
  z-index: 20;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.class-dropdown.open {
  display: block;
}

.class-option {
  display: block;
  width: 100%;
  min-height: 38px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.class-option:last-child {
  border-bottom: 0;
}

.class-option:hover,
.class-option.active {
  background: #eef7f3;
  color: var(--accent-strong);
}

.single-grade {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 16px;
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: #eef3fa;
}

.single-grade .label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.single-grade strong {
  font-size: 2.25rem;
  line-height: 1;
}

.table-panel {
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.table-header h2 {
  margin-bottom: 2px;
}

.table-wrap {
  max-height: 620px;
  overflow: auto;
}

.table-wrap.wide {
  max-height: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #334047;
  background: #f8faf9;
  font-size: 0.82rem;
  text-transform: uppercase;
}

td {
  background: rgba(255, 255, 255, 0.88);
}

tbody tr:hover td {
  background: #f3f8f5;
}

.sticky-item-column {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 180px;
  max-width: 240px;
  box-shadow: 1px 0 0 var(--line);
}

th.sticky-item-column {
  z-index: 4;
  background: #f8faf9;
}

td.sticky-item-column {
  background: #fff;
}

tbody tr:hover td.sticky-item-column {
  background: #f3f8f5;
}

tfoot td.sticky-item-column {
  z-index: 3;
  background: #edf5f1;
}

.grade-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 28px;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.grade-pill.warn {
  background: var(--gold);
}

.grade-pill.low {
  background: var(--danger);
}

.full-width {
  margin-bottom: 18px;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  font-weight: 800;
}

.status.ok {
  color: #16543f;
  background: #ddefe7;
}

.status.warning {
  color: #7b5300;
  background: #fff0c8;
}

.status.error {
  color: #7b1f1f;
  background: #ffe0e0;
}

.gradebook-input {
  min-width: 100px;
}

.name-input {
  min-width: 130px;
  font-weight: 750;
}

.student-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 178px;
}

.student-heading .name-input {
  min-width: 0;
  flex: 1 1 auto;
}

.student-heading .remove-button {
  flex: 0 0 auto;
}

.remove-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--danger);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.remove-button:hover {
  border-color: var(--danger);
  background: #fff2f2;
}

.scale-dialog {
  width: min(620px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 26px 80px rgba(25, 34, 38, 0.28);
}

.scale-dialog::backdrop {
  background: rgba(25, 34, 38, 0.42);
}

.scale-panel {
  padding: 18px;
  background: var(--surface);
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.scale-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.scale-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(110px, 150px);
  gap: 10px;
  align-items: end;
}

.scale-row label {
  gap: 5px;
}

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

tfoot td {
  position: sticky;
  bottom: 0;
  border-top: 2px solid var(--line);
  background: #edf5f1;
  font-weight: 850;
}

.muted-cell {
  color: var(--muted);
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 22px, 1180px);
    margin-top: 14px;
  }

  .topbar,
  .layout-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .tabs {
    width: 100%;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
  }

  .table-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .inline-control,
  .toggle-edit-control,
  .modal-actions {
    align-items: stretch;
  }

  .inline-control,
  .toggle-edit-control {
    flex-wrap: wrap;
  }

  .scale-row {
    grid-template-columns: 1fr;
  }
}
