:root {
  --ink: #172033;
  --ink-2: #263142;
  --muted: #667085;
  --soft: #eef4f7;
  --line: #d8e0e7;
  --field: #f7f9fb;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --blue: #2563eb;
  --danger: #b42318;
  --warning: #b54708;
  --shadow: 0 18px 48px rgba(20, 31, 47, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #eef3f6;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(115deg, rgba(15, 118, 110, 0.08), transparent 38%),
    linear-gradient(180deg, #f8fbfd 0%, #eef3f6 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  border-right: 1px solid rgba(216, 224, 231, 0.86);
  background: rgba(255, 255, 255, 0.88);
  padding: 18px 14px;
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 0 4px;
}

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

.brand strong {
  display: block;
  font-size: 15px;
}

.brand span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.school-pill,
.sidebar-footer {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #f5f8fa);
  padding: 13px;
}

.school-pill {
  margin-bottom: 16px;
}

.pill-kicker,
.mini-label {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.school-pill strong {
  font-size: 14px;
}

.school-pill div:not(.pill-kicker) {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 43px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #516071;
  padding: 0 12px;
  text-align: left;
  text-decoration: none;
  font-weight: 780;
}

.nav a::before {
  width: 28px;
  color: #94a3b8;
  content: attr(data-icon);
  font-weight: 900;
}

.nav a span {
  flex: 1;
}

.nav a:hover,
.nav button:hover {
  background: #eef6f8;
  color: var(--ink);
}

.nav a.active,
.nav button.active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 14px 26px rgba(23, 32, 51, 0.16);
}

.nav a.active::before {
  color: rgba(255, 255, 255, 0.78);
}

.sidebar-footer {
  margin-top: auto;
}

.mini-meter,
.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4ebf1;
}

.mini-meter {
  margin: 10px 0;
}

.mini-meter span,
.bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--blue));
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(216, 224, 231, 0.8);
  background: rgba(255, 255, 255, 0.86);
  padding: 16px 24px;
  backdrop-filter: blur(18px);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.message {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--accent);
}

.toolbar,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.compact-field {
  display: flex;
  height: 40px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding-left: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.compact-field .input {
  width: 58px;
  min-width: 0;
  border: 0;
  background: transparent;
  padding-left: 0;
}

.input {
  min-width: 90px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 0 12px;
  outline: none;
}

textarea.input {
  min-height: 92px;
  padding-top: 10px;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.1);
}

.compact-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.1);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  text-decoration: none;
  font-weight: 780;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover {
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.09);
  transform: translateY(-1px);
}

.btn:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
}

.btn:disabled:hover {
  box-shadow: none;
}

.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-dark);
}

.btn.dark {
  border-color: transparent;
  background: var(--ink);
  color: #fff;
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 20px;
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px;
}

.stack {
  display: grid;
  align-content: start;
  gap: 20px;
}

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

.cards.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.panel,
.card,
.tile {
  border: 1px solid rgba(216, 224, 231, 0.88);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.panel-body,
.card,
.tile {
  padding: 16px;
}

.card {
  position: relative;
  overflow: hidden;
}

.card::after {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--accent);
  content: attr(data-icon);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 900;
}

.card-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.card-value {
  max-width: calc(100% - 44px);
  font-size: 25px;
  font-weight: 900;
  word-break: break-word;
}

.tile {
  min-height: 110px;
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.1);
  transform: translateY(-1px);
}

.badge,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #e7f8f5;
  color: var(--accent);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 850;
}

.badge.warn {
  background: #fff2e0;
  color: var(--warning);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
}

.row:first-child {
  border-top: 0;
}

.hero {
  border-color: rgba(15, 118, 110, 0.24);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.13), transparent 58%),
    linear-gradient(180deg, #fff, #f6fbfb);
}

.hero-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 18px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-title {
  max-width: 760px;
  font-size: clamp(24px, 4vw, 36px);
  line-height: 1.08;
}

.bar span {
  width: var(--w);
}

.readiness {
  display: grid;
  gap: 10px;
}

.readiness-row {
  display: grid;
  grid-template-columns: 150px 1fr 88px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.module-tabs,
.timetable-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.constraint-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px;
  gap: 10px;
  margin-bottom: 12px;
}

.constraint-tabs {
  padding-bottom: 4px;
}

.search-input {
  width: 100%;
}

.module-tabs button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 0 13px;
  font-weight: 800;
}

.module-tabs button.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.section-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #f8fbfd);
  padding: 15px;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title strong {
  font-size: 15px;
}

.section-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: #475569;
  font-size: 12px;
  font-weight: 850;
}

.field.full {
  grid-column: 1 / -1;
}

.constraint-card {
  display: grid;
  grid-template-columns: auto 1fr 112px 94px;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.toggle-list {
  display: grid;
  gap: 10px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.switch input {
  width: 0;
  height: 0;
  opacity: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #dbe5ee;
  transition: 0.18s;
}

.slider::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.18);
  content: "";
  transition: 0.18s;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:disabled + .slider {
  cursor: not-allowed;
  opacity: 0.68;
}

.input:disabled {
  cursor: not-allowed;
  background: #eef2f6;
  color: #697586;
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.weight {
  width: 100%;
  accent-color: var(--accent);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tt-grid {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}

.tt-grid th,
.tt-grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

.tt-grid th {
  position: sticky;
  top: 0;
  background: #f8fbfd;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.tt-grid td {
  height: 92px;
  font-size: 13px;
  font-weight: 850;
}

.tt-grid td span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 500;
}

.tt-grid td em {
  color: #94a3b8;
  font-style: normal;
  font-weight: 500;
}

.tt-grid td hr {
  height: 1px;
  border: 0;
  background: var(--line);
  margin: 8px 0;
}

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

.login-panel {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  width: min(980px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.login-copy {
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.24), transparent 58%),
    var(--ink);
  color: #fff;
  padding: 38px;
}

.login-copy .brand span {
  color: #cbd5e1;
}

.login-copy p {
  color: #d7dee7;
  line-height: 1.65;
}

.login-form {
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 38px;
}

.mobile-bar,
.overlay {
  display: none;
}

.mobile-status {
  border-radius: 999px;
  background: #e7f8f5;
  color: var(--accent);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 850;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 58px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    padding: 0 14px;
    backdrop-filter: blur(14px);
  }

  .menu-btn {
    display: grid;
    width: 40px;
    height: 40px;
    place-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
  }

  .menu-btn span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 99px;
    background: var(--ink);
  }

  .sidebar {
    position: fixed;
    z-index: 8;
    top: 0;
    left: 0;
    width: min(86vw, 292px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .overlay.open {
    position: fixed;
    inset: 0;
    z-index: 7;
    display: block;
    background: rgba(15, 23, 42, 0.28);
  }

  .topbar {
    top: 58px;
  }

  .content {
    grid-template-columns: 1fr;
    padding: 16px;
  }

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

  .hero-layout,
  .login-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .cards,
  .cards.four,
  .grid-2,
  .grid-3,
  .form-grid,
  .constraint-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 14px;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar .btn,
  .compact-field {
    flex: 1 1 46%;
    min-width: 0;
  }

  .toolbar .btn.primary,
  #logoutBtn {
    flex-basis: 100%;
  }

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

  .constraint-toolbar {
    grid-template-columns: 1fr;
  }

  .login-shell {
    padding: 14px;
  }

  .login-copy,
  .login-form {
    padding: 24px;
  }
}

/* Modern interface polish layer */
.topbar {
  padding: 18px 26px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.045);
}

.content {
  gap: 22px;
  padding: 26px;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 20px 56px rgba(20, 31, 47, 0.085);
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.panel:hover {
  box-shadow: 0 24px 70px rgba(20, 31, 47, 0.13);
}

.panel-head {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 251, 253, 0.9));
}

.card {
  min-height: 118px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 252, 0.92));
}

.card::after {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(37, 99, 235, 0.13));
}

.hero {
  background:
    radial-gradient(circle at 88% 18%, rgba(37, 99, 235, 0.13), transparent 28%),
    linear-gradient(135deg, rgba(15, 118, 110, 0.14), transparent 58%),
    linear-gradient(180deg, #fff, #f6fbfb);
}

.teacher-row,
.subject-row {
  background: rgba(255, 255, 255, 0.72);
}

.table-wrap {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.tt-grid td {
  background: #fff;
  transition: background 0.15s ease;
}

.tt-grid td:hover {
  background: #f1f8f7;
}

.version-select {
  min-width: min(100%, 340px);
}

.version-actions {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.mini-input {
  width: 82px;
  min-width: 82px;
}

input[type="color"].input {
  padding: 4px;
}

/* Clean stacked layout: removes awkward blank right-side space. */
.content {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1480px;
}

#secondary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.module-tabs,
.timetable-tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: stretch;
}

.constraint-tabs {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.module-tabs button,
.timetable-tools .btn,
.timetable-tools .input {
  width: 100%;
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.cards.four {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.row {
  min-width: 0;
}

.row > div:first-child {
  min-width: min(100%, 240px);
}

.row .toolbar {
  justify-content: flex-end;
}

.toolbar .btn {
  min-width: max-content;
}

.section-box + .panel,
form.section-box + .panel {
  margin-top: 14px;
}

@media (max-width: 760px) {
  .content {
    padding: 16px;
  }

  .module-tabs,
  .timetable-tools,
  .constraint-tabs,
  #secondary {
    grid-template-columns: 1fr;
  }

  .row .toolbar,
  .toolbar .btn {
    width: 100%;
  }
}

/* Final stacked modern layout */
.main {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.54), rgba(247, 250, 252, 0.72)),
    #eef3f6;
}

.content {
  display: flex;
  width: min(100%, 1480px);
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.stack,
#primary,
#secondary {
  display: grid;
  width: 100%;
  grid-template-columns: 1fr;
  gap: 14px;
}

#secondary {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.panel,
.card,
.tile,
.section-box {
  width: 100%;
}

.panel {
  border-color: rgba(203, 213, 225, 0.82);
}

.panel-body {
  padding: 14px;
}

.panel-head {
  min-height: 50px;
  padding: 12px 14px;
}

.cards,
.cards.four,
.grid-2,
.grid-3,
.form-grid {
  display: grid;
  width: 100%;
  gap: 12px;
}

.cards,
.cards.four {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.grid-2,
.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.module-tabs,
.timetable-tools,
.constraint-tabs {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.constraint-tabs {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.module-tabs button,
.timetable-tools .btn,
.timetable-tools .input,
.constraint-toolbar .input {
  width: 100%;
  min-width: 0;
}

.constraint-toolbar {
  grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
}

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

.row > div:first-child {
  min-width: 0;
}

.row .toolbar {
  width: auto;
  justify-content: end;
}

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

.version-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  justify-content: start;
}

@media (max-width: 900px) {
  .content {
    padding: 14px;
  }

  #secondary,
  .hero-layout,
  .row,
  .constraint-toolbar {
    grid-template-columns: 1fr;
  }

  .row .toolbar,
  .version-actions {
    width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    justify-content: stretch;
  }

  .toolbar .btn,
  .toolbar .badge,
  .toolbar .input,
  .version-actions .btn,
  .version-actions .badge {
    width: 100%;
  }
}

/* Compact spacing pass */
.topbar {
  padding: 14px 18px;
}

.content {
  gap: 10px;
  padding: 12px;
}

.stack,
#primary,
#secondary {
  gap: 10px;
}

#secondary {
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.panel-body,
.card,
.tile {
  padding: 12px;
}

.panel-head {
  min-height: 46px;
  padding: 10px 12px;
}

.cards,
.cards.four,
.grid-2,
.grid-3,
.form-grid,
.readiness,
.toggle-list {
  gap: 10px;
}

.section-box {
  margin-top: 10px;
  padding: 12px;
}

.module-tabs,
.timetable-tools,
.constraint-tabs {
  gap: 6px;
  margin-bottom: 10px;
}

.module-tabs button {
  height: 36px;
}

.row {
  padding: 10px 12px;
}

.hero-title {
  max-width: 100%;
}

@media (max-width: 980px) {
  .topbar {
    top: 58px;
    padding: 12px;
  }

  .content {
    padding: 10px;
  }
}

@media (max-width: 640px) {
  .mobile-bar {
    height: 54px;
  }

  .topbar {
    top: 54px;
  }

  h1 {
    font-size: 22px;
  }

  .content {
    padding: 8px;
    gap: 8px;
  }

  .stack,
  #primary,
  #secondary,
  .cards,
  .cards.four,
  .grid-2,
  .grid-3,
  .form-grid,
  .module-tabs,
  .timetable-tools,
  .constraint-tabs,
  .constraint-toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel-body,
  .card,
  .tile,
  .section-box {
    padding: 10px;
  }

  .toolbar,
  .actions {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .toolbar .btn,
  .toolbar .input,
  .actions .btn,
  .compact-field {
    width: 100%;
    min-width: 0;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

/* Edge-to-edge workspace pass */
.app {
  gap: 0;
}

.main-shell {
  min-width: 0;
  width: 100%;
}

.content {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 8px;
}

.topbar {
  margin: 0;
  border-radius: 0;
}

@media (max-width: 980px) {
  .content {
    padding: 8px;
  }
}

@page {
  size: A4 landscape;
  margin: 6mm;
}

@media print {
  body.printing-timetable {
    background: #ffffff;
  }

  body.printing-timetable .sidebar,
  body.printing-timetable .mobile-bar,
  body.printing-timetable .topbar,
  body.printing-timetable .timetable-tools,
  body.printing-timetable .version-actions,
  body.printing-timetable .toast {
    display: none !important;
  }

  body.printing-timetable .app,
  body.printing-timetable .main-shell,
  body.printing-timetable .content,
  body.printing-timetable #view,
  body.printing-timetable .panel,
  body.printing-timetable .panel-body,
  body.printing-timetable .table-wrap {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    box-shadow: none !important;
    border: 0 !important;
    background: #ffffff !important;
  }

  body.printing-timetable .panel-head {
    min-height: 0;
    padding: 0 0 4mm;
    border: 0;
    background: #ffffff;
  }

  body.printing-timetable .panel-head h2 {
    font-size: 13px;
  }

  body.printing-timetable .tt-grid {
    width: 100% !important;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 7.2px;
    line-height: 1.12;
    page-break-inside: avoid;
  }

  body.printing-timetable .tt-grid th,
  body.printing-timetable .tt-grid td {
    padding: 2px 3px;
    height: 34px;
    border: 0.5px solid #9ca3af;
    color: #111827;
    background: #ffffff;
    vertical-align: top;
  }

  body.printing-timetable .tt-grid th:first-child {
    width: 58px;
  }

  body.printing-timetable .lesson-card {
    padding: 0;
    border: 0;
    background: transparent;
    color: #111827;
    box-shadow: none;
  }

  body.printing-timetable .lesson-card strong,
  body.printing-timetable .lesson-card span {
    display: block;
    white-space: normal;
  }
}

.print-title {
  display: grid;
  gap: 3px;
  margin-bottom: 10px;
  color: var(--ink);
}

.print-title h2 {
  margin: 0;
  font-size: 18px;
}

.print-title span,
.print-title strong {
  font-size: 12px;
}

.tt-grid .break-cell {
  background: #f8fafc;
  color: #64748b;
  text-align: center;
  vertical-align: middle;
}

.teacher-row .toolbar {
  align-items: end;
}

.compact-field {
  display: grid;
  gap: 4px;
  min-width: 92px;
}

.compact-field span {
  font-size: 10px;
  color: var(--muted);
}

.compact-field .mini-input {
  width: 100%;
}

.workload-row {
  border-left: 4px solid #ef4444;
}

.workload-row .toolbar,
.teacher-row .toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .workload-row .toolbar,
  .teacher-row .toolbar {
    justify-content: stretch;
  }

  .workload-row .btn,
  .teacher-row .btn {
    width: 100%;
  }
}

/* Final form polish */
.field,
.form-grid,
.toolbar,
.compact-field {
  min-width: 0;
}

.input,
.mini-input,
select.input,
textarea.input {
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input::placeholder,
textarea.input::placeholder {
  color: #94a3b8;
  opacity: 1;
}

.teacher-row {
  align-items: start;
}

.teacher-row .toolbar {
  gap: 8px;
}

.teacher-row .compact-field {
  flex: 1 1 112px;
}

.teacher-row .compact-field span {
  white-space: nowrap;
}

@media print {
  body.printing-timetable .print-title {
    display: grid !important;
    gap: 1mm;
    margin: 0 0 3mm;
    text-align: center;
  }

  body.printing-timetable .print-title h2 {
    font-size: 15px;
  }

  body.printing-timetable .print-title span,
  body.printing-timetable .print-title strong {
    font-size: 9px;
  }
}

/* Interaction feedback and overflow stabilization */
body {
  overflow-x: hidden;
}

.message {
  min-height: 20px;
  overflow-wrap: anywhere;
  transition: color 0.16s ease;
}

.message.working {
  color: var(--blue);
}

.message.working::before {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border: 2px solid rgba(37, 99, 235, 0.22);
  border-top-color: var(--blue);
  border-radius: 50%;
  content: "";
  animation: spin 0.75s linear infinite;
  vertical-align: -1px;
}

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

.toast-tray {
  position: fixed;
  top: 76px;
  right: 16px;
  z-index: 30;
  display: grid;
  width: min(420px, calc(100vw - 32px));
  gap: 10px;
  pointer-events: none;
}

.toast {
  transform: translateY(10px);
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
  color: var(--ink);
  opacity: 0;
  overflow-wrap: anywhere;
  padding: 12px 14px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  border-left-color: var(--danger);
}

.btn.is-loading,
.btn[aria-disabled="true"] {
  position: relative;
  pointer-events: none;
  opacity: 0.82;
}

.btn.is-loading::before {
  width: 13px;
  height: 13px;
  margin-right: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 0.75s linear infinite;
}

.panel,
.panel-head,
.panel-body,
.section-box,
.card,
.tile,
.row,
.toolbar,
.actions,
.field {
  min-width: 0;
}

.panel-head h2,
.section-title,
.section-title > div,
.row > *,
.card-label,
.card-value,
.badge,
.chip,
.muted,
.field label,
.tile strong,
.tile div {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.badge,
.chip {
  white-space: normal;
  text-align: center;
}

.btn {
  max-width: 100%;
  min-width: 0;
  white-space: normal;
  text-align: center;
  line-height: 1.15;
}

.toolbar,
.actions {
  align-items: stretch;
}

.toolbar .btn,
.actions .btn {
  min-height: 40px;
  height: auto;
}

.input,
.mini-input,
select.input,
textarea.input {
  height: auto;
  min-height: 40px;
}

select.input {
  padding-right: 30px;
}

.compact-field {
  height: auto;
  min-height: 42px;
  align-content: center;
}

.row {
  overflow: hidden;
}

.row .toolbar {
  max-width: 100%;
}

.tt-grid {
  table-layout: fixed;
}

.tt-grid th,
.tt-grid td {
  min-width: 96px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tt-grid th:first-child {
  min-width: 92px;
}

.tt-grid td {
  line-height: 1.25;
}

.version-actions {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}

.quality-report {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.quality-report .card {
  box-shadow: none;
}

@media (max-width: 760px) {
  .toast-tray {
    top: 64px;
    right: 10px;
    width: calc(100vw - 20px);
  }

  .panel-head,
  .section-title {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .topbar .toolbar .btn,
  .topbar .toolbar .compact-field {
    width: 100%;
  }
}
