:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --border: #dfe7e3;
  --text: #17231f;
  --muted: #60706a;
  --accent: #176f58;
  --accent-dark: #105743;
  --free-bg: #dff5e7;
  --free-border: #9bd8af;
  --busy-bg: #ffe1df;
  --busy-border: #f2a19b;
  --unknown-bg: #f1f4f3;
  --shadow: 0 12px 30px rgba(25, 42, 35, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.api-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.panel,
.summary-card,
.week-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls-panel {
  padding: 16px;
  margin-bottom: 14px;
}

.admin-panel {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.admin-key-inline {
  width: min(420px, 100%);
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tab-button {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
}

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

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.mode-group {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
}

.mode-option {
  display: block;
  cursor: pointer;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option span {
  display: block;
  min-width: 128px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.mode-option input:checked + span {
  background: var(--accent);
  color: #ffffff;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) minmax(220px, 1.1fr) repeat(6, minmax(120px, 0.7fr));
  gap: 12px;
  align-items: end;
}

.availability-grid {
  grid-template-columns: minmax(220px, 1.2fr) minmax(220px, 1.1fr) minmax(150px, 0.7fr) minmax(240px, 1.2fr) minmax(150px, 0.7fr);
}

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

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 111, 88, 0.14);
}

.field.disabled {
  opacity: 0.55;
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 900;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.secondary-button {
  background: var(--panel-soft);
  color: var(--accent);
  border: 1px solid var(--border);
}

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

.small-button {
  min-height: 32px;
  border-radius: 6px;
  padding: 0 10px;
  font-size: 12px;
}

.status-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-text.error {
  color: #9d2c24;
}

.summary-grid,
.subject-summary-grid {
  display: grid;
  gap: 12px;
}

.summary-grid {
  grid-template-columns: repeat(3, minmax(150px, 1fr)) minmax(280px, 2fr);
  margin-bottom: 14px;
}

.subject-summary-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin: -2px 0 14px;
}

.subject-summary-grid[hidden] {
  display: none;
}

.summary-card {
  padding: 14px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.summary-card strong {
  display: block;
  min-height: 28px;
  font-size: 22px;
  line-height: 1.25;
}

.summary-card.wide strong {
  font-size: 15px;
  line-height: 1.35;
}

.admin-key-field {
  grid-column: span 2;
}

.warnings-root {
  margin-top: 12px;
  border: 1px solid #ead28a;
  border-radius: 8px;
  background: #fff8dc;
  color: #6c5414;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
}

.warnings-root[hidden] {
  display: none;
}

.calendar-root {
  display: grid;
  gap: 14px;
}

.diagnostics-panel {
  padding: 16px;
  margin-top: 18px;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.section-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.section-controls {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(220px, 320px);
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.diagnostics-root {
  margin-top: 12px;
}

.diagnostics-scroll {
  overflow: auto;
}

.diagnostics-table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.diagnostics-table th,
.diagnostics-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.diagnostics-table th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.diagnostics-table tr:last-child td {
  border-bottom: 0;
}

.diagnostics-table th:last-child,
.diagnostics-table td:last-child {
  border-right: 0;
}

.diagnostics-warning-row {
  background: #fffdf2;
}

.priority-row {
  background: #f1fbf5;
}

.inactive-row {
  background: #f7f8f7;
}

.cell-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-chip,
.warning-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-chip.ok {
  background: var(--free-bg);
  color: #17603f;
}

.status-chip.warn,
.warning-chip {
  background: #fff0cf;
  color: #74520b;
}

.status-chip.muted {
  background: var(--unknown-bg);
  color: var(--muted);
}

.warning-chip {
  margin: 0 5px 5px 0;
}

.hours-value {
  display: inline-block;
  color: #17603f;
  font-size: 15px;
  line-height: 1.4;
}

.empty-state,
.error-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  padding: 26px;
  text-align: center;
  font-weight: 700;
}

.error-state {
  border-color: var(--busy-border);
  background: #fff4f2;
  color: #9d2c24;
}

.week-section {
  overflow: hidden;
}

.week-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}

.week-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.week-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend span::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.legend .free-dot::before {
  background: var(--free-bg);
  border-color: var(--free-border);
}

.legend .busy-dot::before {
  background: var(--busy-bg);
  border-color: var(--busy-border);
}

.calendar-scroll {
  overflow: auto;
  max-height: 72vh;
}

.availability-table {
  width: 100%;
  min-width: 920px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.availability-table th,
.availability-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.availability-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #ffffff;
  padding: 10px 8px;
  font-size: 13px;
}

.availability-table th:first-child,
.availability-table td.time-cell {
  position: sticky;
  left: 0;
  z-index: 4;
  width: 86px;
  background: #ffffff;
}

.availability-table th:first-child {
  z-index: 5;
}

.day-name {
  display: block;
  color: var(--text);
  font-weight: 900;
  text-transform: capitalize;
}

.day-date {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.time-cell {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding: 8px 6px;
}

.slot-cell {
  height: 32px;
  padding: 3px 4px;
  font-size: 12px;
  font-weight: 900;
}

.slot-label,
.slot-meta {
  display: block;
  line-height: 1.1;
}

.slot-meta {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 800;
  color: currentColor;
  opacity: 0.78;
}

.slot-cell.free {
  background: var(--free-bg);
  color: #17603f;
}

.slot-cell.busy {
  background: var(--busy-bg);
  color: #9d2c24;
}

.slot-cell.unknown {
  background: var(--unknown-bg);
  color: var(--muted);
}

.slot-cell:hover {
  outline: 2px solid rgba(23, 111, 88, 0.35);
  outline-offset: -2px;
}

.slot-cell.free {
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(23, 35, 31, 0.42);
  padding: 18px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(23, 35, 31, 0.24);
}

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

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

.modal-close {
  min-height: 34px;
  padding: 0 12px;
}

.modal-body {
  padding: 12px;
}

.teacher-form,
.subjects-form {
  display: grid;
  gap: 12px;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.check-field input {
  width: 18px;
  height: 18px;
}

.subjects-modal {
  width: min(760px, 100%);
}

.subjects-checkboxes {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 8px;
  max-height: 52vh;
  overflow: auto;
  padding-right: 4px;
}

.subject-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.subject-check input {
  margin-top: 2px;
  width: 18px;
  height: 18px;
}

.subject-check span {
  display: grid;
  gap: 2px;
}

.subject-check strong {
  font-size: 13px;
  line-height: 1.25;
}

.subject-check small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.teachers-admin-table {
  min-width: 1180px;
}

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

.modal-teacher-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.modal-teacher-row div {
  display: grid;
  gap: 3px;
}

.modal-teacher-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .form-grid,
  .availability-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .summary-grid,
  .subject-summary-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .admin-key-field {
    grid-column: span 1;
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100% - 20px, 1440px);
    padding-top: 14px;
  }

  .page-header,
  .admin-panel,
  .section-header,
  .modal-header,
  .modal-teacher-row,
  .week-header,
  .actions-row,
  .button-row,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .mode-group,
  .tabs,
  .form-grid,
  .section-controls,
  .summary-grid,
  .subject-summary-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .mode-option span {
    min-width: 0;
  }

  .subjects-checkboxes {
    grid-template-columns: 1fr;
  }
}
