:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-subtle: #fbfcfd;
  --text: #1f2933;
  --muted: #657282;
  --line: #d9e0e7;
  --accent: #0b7285;
  --accent-dark: #075b6b;
  --accent-soft: #f0fafb;
  --accent-line: #c8e8ed;
  --danger: #b42318;
  --success: #177245;
  --control-muted: #e8eef3;
  --warn-bg: #fff4d6;
  --warn-text: #765200;
}

* {
  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", sans-serif;
  font-size: 15px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-dark);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--accent-line);
  outline-offset: 2px;
}

main {
  margin: 0 auto;
  max-width: 1180px;
  padding: 24px;
}

h2 {
  font-size: 17px;
  margin: 0 0 14px;
}

code,
pre {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

pre {
  white-space: pre-wrap;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 18px 28px;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
}

.topbar p {
  color: var(--muted);
  margin: 2px 0 0;
}

nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.grid {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.priority-panel,
main > .panel {
  margin-bottom: 18px;
}

.priority-panel {
  border-color: #a8d8df;
}

.panel > :last-child {
  margin-bottom: 0;
}

.panel-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.panel-head h2 {
  margin: 0;
}

.panel-subtitle {
  margin: 4px 0 0;
}

.auth-panel {
  margin: 40px auto;
  max-width: 460px;
}

.week-nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-top: 18px;
}

.week-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  margin-top: 14px;
}

.day-column {
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px;
  position: relative;
}

.day-column.next-week-start {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}

.day-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
}

.day-title {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

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

.day-head .week-marker {
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.day-targets {
  display: grid;
  gap: 8px;
}

.empty-day {
  font-size: 13px;
  margin: 0;
}

.class-slot {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  padding: 10px;
}

.target-default {
  background: #eef8f6;
  border-color: #b8ddd7;
}

.target-default-booked {
  background: #e3f5e8;
  border-color: #9fd3ad;
}

.target-booked {
  background: #edf7f2;
  border-color: #b7dbc8;
}

.target-prebookable {
  background: #f7f4ff;
  border-color: #d7cff5;
}

.target-prebooked {
  background: #eaf3ff;
  border-color: #b9d6f7;
}

.target-skipped {
  background: #f4f6f8;
  border-color: var(--line);
}

.slot-main {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.target-time {
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.target-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.target-actions form {
  margin: 0;
}

.booked-summary {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.booked-summary h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

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

.booked-row {
  align-items: center;
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
}

.booked-row form {
  margin: 0;
}

button {
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  min-height: 36px;
  padding: 0 14px;
  white-space: nowrap;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

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

button.danger:hover {
  background: #f9d0ca;
}

.button-link {
  align-items: center;
  border-radius: 6px;
  display: inline-flex;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  text-align: center;
}

.icon-link {
  min-width: 36px;
}

.button-link.secondary {
  background: var(--control-muted);
  color: var(--text);
}

.nav-form {
  margin: 0;
}

.link-button {
  background: transparent;
  color: var(--accent);
  min-height: auto;
  padding: 0;
}

.link-button:hover {
  background: transparent;
  color: var(--accent-dark);
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  max-width: 100%;
  min-height: 36px;
  padding: 0 10px;
}

select {
  width: 100%;
}

.stack-form {
  display: grid;
  gap: 12px;
}

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

.stack-form.compact {
  max-width: 420px;
}

.inline-form {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 150px minmax(140px, 1fr) auto;
}

.invite-form {
  grid-template-columns: minmax(180px, 320px) auto;
}

.toolbar-form {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.settings-head {
  align-items: flex-start;
  margin-bottom: 14px;
}

.settings-head form {
  margin: 0;
}

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

.preference-row {
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.settings-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.actions-cell,
.inline-admin-form {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions-cell form,
.inline-admin-form {
  margin: 0;
}

.inline-admin-form select {
  min-width: 110px;
  width: auto;
}

table {
  border-collapse: collapse;
  margin-top: 12px;
  width: 100%;
}

.table-wrap {
  overflow-x: auto;
  width: 100%;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.notice,
.warning {
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.notice {
  background: #e6f6ee;
  color: #0f5a35;
}

.warning {
  background: var(--warn-bg);
  color: var(--warn-text);
}

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

.hidden {
  display: none !important;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  text-transform: uppercase;
}

.status.success {
  background: #dff5e8;
  color: var(--success);
}

.status.failed {
  background: #fde7e4;
  color: var(--danger);
}

.status.cancelled,
.status.skipped {
  background: var(--control-muted);
  color: var(--muted);
}

.status.pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status.prebooked {
  background: #e3f2fd;
  color: #075985;
}

.status.default {
  background: #edf7f8;
  color: var(--accent-dark);
}

@media (max-width: 820px) {
  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    padding: 16px;
  }

  main {
    padding: 16px;
  }

  .grid,
  .inline-form,
  .invite-form {
    grid-template-columns: 1fr;
  }

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

  .week-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  input:not([type="checkbox"]),
  select,
  main > form button,
  .inline-form button,
  .toolbar-form button,
  .panel-head button {
    width: 100%;
  }

  .target-actions {
    justify-content: stretch;
    width: 100%;
  }

  .target-actions form {
    flex: 1 1 96px;
    min-width: 0;
  }

  .target-actions button {
    padding: 0 10px;
    width: 100%;
  }

  .target-time {
    font-size: 17px;
  }
}

@media (max-width: 640px) {
  .week-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .week-nav {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
    text-align: center;
  }

  .week-nav strong {
    order: -1;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  main {
    padding: 12px;
  }

  nav {
    gap: 10px;
  }

  .panel {
    padding: 14px;
  }

  .week-grid {
    grid-template-columns: 1fr;
  }

  .class-slot,
  .booked-row {
    align-items: stretch;
    flex-direction: column;
  }

  .booked-row button {
    width: 100%;
  }

  .slot-main {
    justify-content: space-between;
  }

  th,
  td {
    padding: 9px 6px;
  }
}
