:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-muted: #f0f3f5;
  --border: #dce2e7;
  --border-strong: #c8d1d8;
  --text: #1f2933;
  --muted: #66727f;
  --blue: #246bfe;
  --blue-soft: #e7efff;
  --green: #188a42;
  --green-soft: #e4f7eb;
  --red: #c93737;
  --red-soft: #fde8e8;
  --yellow: #946200;
  --yellow-soft: #fff2cc;
  --purple: #6a4ddf;
  --shadow: 0 18px 48px rgba(31, 41, 51, 0.14);
  --time-col: 56px;
  --hour-height: 72px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.modal-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: #182433;
  color: #fff;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #f6c85f;
  color: #1b2632;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 2px 0 0;
  color: #b8c5d1;
  font-size: 13px;
}

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

.nav-tab {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #d9e2ea;
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  background: #26384c;
  border-color: #31465d;
  color: #fff;
}

.side-panel {
  padding: 14px;
  border: 1px solid #31465d;
  border-radius: 8px;
  background: #202f40;
}

.side-panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
}

.today-summary,
.balance-list {
  display: grid;
  gap: 8px;
}

.mini-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #d9e2ea;
  font-size: 13px;
}

.mini-row span:last-child {
  color: #f6c85f;
  font-weight: 700;
}

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

.section {
  display: none;
}

.section.active {
  display: block;
}

.toolbar,
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.toolbar-left,
.toolbar-right,
.settings-actions,
.form-actions,
.lesson-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.week-title {
  font-size: 26px;
  font-weight: 500;
  text-align: center;
}

.icon-button,
.text-button,
.file-button {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  min-height: 36px;
  padding: 8px 12px;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.text-button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.text-button.secondary {
  background: var(--panel-muted);
}

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

.text-button.success {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.calendar-wrap {
  overflow: auto;
  max-height: calc(100vh - 88px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.calendar {
  position: relative;
  min-width: 980px;
  display: grid;
  grid-template-columns: var(--time-col) repeat(7, minmax(126px, 1fr));
  grid-template-rows: 44px repeat(13, var(--hour-height));
}

.corner-cell,
.day-header,
.time-cell,
.day-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.corner-cell,
.day-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fbfcfd;
}

.corner-cell {
  left: 0;
  z-index: 6;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
}

.day-header.today {
  color: var(--blue);
  font-weight: 700;
}

.time-cell {
  position: sticky;
  left: 0;
  z-index: 4;
  padding: 8px 8px 0 0;
  background: #fbfcfd;
  color: #8a96a3;
  text-align: right;
  font-size: 13px;
}

.day-cell {
  position: relative;
  background:
    linear-gradient(to bottom, transparent 35px, rgba(220, 226, 231, 0.55) 36px, transparent 37px),
    #fff;
}

.lesson-block {
  position: absolute;
  left: 6px;
  right: 6px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--blue);
  border-radius: 6px;
  background: #f7fbff;
  box-shadow: 0 4px 10px rgba(31, 41, 51, 0.08);
  overflow: hidden;
  text-align: left;
}

.lesson-block.done {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.lesson-block.cancelled {
  border-left-color: var(--red);
  background: var(--red-soft);
}

.lesson-block.moved {
  border-left-color: var(--yellow);
  background: var(--yellow-soft);
}

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

.lesson-title {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-header h2 {
  margin: 0;
  font-size: 24px;
}

.section-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.table-list {
  display: grid;
  gap: 8px;
}

.record-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(3, minmax(96px, max-content));
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.record-main strong {
  display: block;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.green {
  background: var(--green-soft);
  color: var(--green);
}

.badge.red {
  background: var(--red-soft);
  color: var(--red);
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 36, 51, 0.42);
}

.modal-root[hidden],
.modal-root:empty {
  display: none !important;
}

.modal {
  position: relative;
  z-index: 1;
  display: block;
  width: min(720px, 100%);
  min-height: 120px;
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal-root[data-modal="login"] .modal,
.modal-root[data-modal="problem"] .modal {
  width: min(460px, 100%);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.close-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
}

.modal-body {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

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

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

.form-field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

.form-field textarea {
  min-height: 80px;
  resize: vertical;
}

.checkbox-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 400;
}

.student-lines {
  display: grid;
  gap: 8px;
}

.student-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
}

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

.settings-block {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.settings-block h3 {
  margin: 0 0 8px;
}

.settings-block p {
  margin: 0 0 12px;
  color: var(--muted);
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #182433;
  color: #fff;
  box-shadow: var(--shadow);
}

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

  .sidebar {
    position: static;
  }

  .toolbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .week-title {
    order: -1;
    text-align: left;
    font-size: 22px;
  }

  .form-grid,
  .settings-grid,
  .checkbox-list {
    grid-template-columns: 1fr;
  }

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