/* Notion-style colours. Dark mode follows the system setting. */
:root {
  --bg: #ffffff;
  --sidebar-bg: rgb(247, 247, 245);
  --text: rgb(55, 53, 47);
  --text-secondary: rgba(55, 53, 47, 0.65);
  --text-tertiary: rgba(55, 53, 47, 0.45);
  --hover: rgba(55, 53, 47, 0.06);
  --active: rgba(55, 53, 47, 0.1);
  --border: rgba(55, 53, 47, 0.09);
  --border-strong: rgba(55, 53, 47, 0.16);
  --shadow: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 3px 6px,
    rgba(15, 15, 15, 0.2) 0 9px 24px;
  --blue: rgb(35, 131, 226);
  --red: rgb(224, 62, 62);

  --tag-gray-bg: rgba(227, 226, 224, 0.6);
  --tag-gray-text: rgb(50, 48, 44);
  --tag-green-bg: rgb(219, 237, 219);
  --tag-green-text: rgb(28, 56, 41);
  --tag-red-bg: rgb(255, 226, 221);
  --tag-red-text: rgb(93, 23, 21);
  --tag-yellow-bg: rgb(253, 236, 200);
  --tag-yellow-text: rgb(64, 44, 27);
  --tag-blue-bg: rgb(211, 229, 239);
  --tag-blue-text: rgb(24, 51, 71);
  --tag-purple-bg: rgb(232, 222, 238);
  --tag-purple-text: rgb(65, 36, 84);
  --tag-orange-bg: rgb(250, 222, 201);
  --tag-orange-text: rgb(73, 41, 14);

  /* FullCalendar's classic theme, recoloured to match */
  --fc-classic-button: var(--bg);
  --fc-classic-button-border: var(--border-strong);
  --fc-classic-button-strong: var(--active);
  --fc-classic-button-strong-border: var(--border-strong);
  --fc-classic-button-outline: var(--border-strong);
  --fc-classic-button-foreground: var(--text);
  --fc-classic-primary: var(--blue);
  --fc-classic-event: var(--tag-blue-bg);
  --fc-classic-event-contrast: var(--tag-blue-text);
  --fc-classic-highlight: rgba(35, 131, 226, 0.14);
  --fc-classic-today: rgba(35, 131, 226, 0.05);
  --fc-classic-now: var(--red);
  --fc-classic-background: var(--bg);
  --fc-classic-foreground: var(--text);
  --fc-classic-muted-foreground: var(--text-secondary);
  --fc-classic-faint-foreground: var(--text-tertiary);
  --fc-classic-border: var(--border);
  --fc-classic-strong-border: var(--border-strong);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: rgb(25, 25, 25);
    --sidebar-bg: rgb(32, 32, 32);
    --text: rgba(255, 255, 255, 0.81);
    --text-secondary: rgba(255, 255, 255, 0.46);
    --text-tertiary: rgba(255, 255, 255, 0.28);
    --hover: rgba(255, 255, 255, 0.055);
    --active: rgba(255, 255, 255, 0.1);
    --border: rgba(255, 255, 255, 0.094);
    --border-strong: rgba(255, 255, 255, 0.16);
    --shadow: rgba(15, 15, 15, 0.2) 0 0 0 1px, rgba(15, 15, 15, 0.4) 0 9px 24px;

    --tag-gray-bg: rgba(255, 255, 255, 0.13);
    --tag-gray-text: rgba(255, 255, 255, 0.88);
    --tag-green-bg: rgb(43, 89, 63);
    --tag-green-text: rgba(255, 255, 255, 0.88);
    --tag-red-bg: rgb(110, 54, 48);
    --tag-red-text: rgba(255, 255, 255, 0.88);
    --tag-yellow-bg: rgb(137, 99, 42);
    --tag-yellow-text: rgba(255, 255, 255, 0.88);
    --tag-blue-bg: rgb(40, 69, 108);
    --tag-blue-text: rgba(255, 255, 255, 0.88);
    --tag-purple-bg: rgb(73, 47, 100);
    --tag-purple-text: rgba(255, 255, 255, 0.88);
    --tag-orange-bg: rgb(133, 76, 29);
    --tag-orange-text: rgba(255, 255, 255, 0.88);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica,
    "Apple Color Emoji", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

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

/* Layout */

.app {
  display: flex;
  height: 100vh;
  /* The visible height, without the space behind a phone browser's address bar */
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 240px;
  flex-shrink: 0;
  padding: 8px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
}

.workspace {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin-bottom: 8px;
  font-weight: 600;
}

.workspace-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--active);
  font-size: 13px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  margin-bottom: 1px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-weight: 500;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--hover);
}

.nav-item.active {
  background: var(--active);
  color: var(--text);
}

.nav-icon {
  width: 20px;
  text-align: center;
}

/* The tab bar's shorter label, and other text shown only on a phone */
.nav-short,
.show-phone {
  display: none;
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 64px 48px 96px;
}

/* Who is logged in, pinned to the bottom of the sidebar */

.account {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.account-name {
  padding: 4px 8px;
  font-weight: 500;
}

.account-logout {
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
}

/* Login */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--sidebar-bg);
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 320px;
  padding: 32px;
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login-icon {
  width: 36px;
  height: 36px;
  font-size: 20px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-secondary);
}

.login-card input,
.notes {
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.notes {
  width: 100%;
  min-height: 60px;
  box-sizing: border-box;
  resize: vertical;
}

.button.primary {
  padding: 6px 8px;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 500;
}

/* Page text */

.breadcrumbs {
  margin-bottom: 24px;
  color: var(--text-secondary);
}

.breadcrumbs a {
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  font-size: 40px;
  font-weight: 700;
  line-height: 1.2;
}

.page-icon {
  font-size: 0.9em;
}

.page-description {
  margin: 0 0 32px;
  color: var(--text-secondary);
}

.section-title {
  margin: 40px 0 8px;
  font-size: 20px;
  font-weight: 600;
}

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

.empty {
  padding: 32px 0;
  color: var(--text-tertiary);
}

.error {
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--tag-red-bg);
  color: var(--tag-red-text);
}

.avatar {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 16px;
  border-radius: 50%;
  background: var(--tag-blue-bg);
  color: var(--tag-blue-text);
  font-size: 32px;
  font-weight: 600;
}

/* Properties, like the top of a Notion database page */

.properties {
  display: grid;
  grid-template-columns: 160px 1fr;
  margin: 24px 0 0;
}

.properties dt,
.properties dd {
  display: flex;
  align-items: center;
  min-height: 34px;
  margin: 0;
}

.properties dt {
  color: var(--text-secondary);
}

/* Tags */

.tag {
  display: inline-block;
  padding: 0 6px;
  border-radius: 3px;
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}

.tag-select {
  border: none;
  cursor: pointer;
  appearance: none;
  text-transform: capitalize;
}

.status-enrolled { background: var(--tag-gray-bg); color: var(--tag-gray-text); }
.status-present { background: var(--tag-green-bg); color: var(--tag-green-text); }
.status-absent { background: var(--tag-red-bg); color: var(--tag-red-text); }
.status-excused { background: var(--tag-yellow-bg); color: var(--tag-yellow-text); }
.weapon-foil { background: var(--tag-blue-bg); color: var(--tag-blue-text); }
.weapon-epee { background: var(--tag-purple-bg); color: var(--tag-purple-text); }
.weapon-sabre { background: var(--tag-orange-bg); color: var(--tag-orange-text); }
.weapon-mixed { background: var(--tag-gray-bg); color: var(--tag-gray-text); }
.category-conditioning { background: var(--tag-green-bg); color: var(--tag-green-text); }

/* Attendance rate */

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

.rate-bar {
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: var(--active);
  overflow: hidden;
}

.rate-fill {
  display: block;
  height: 100%;
  background: var(--blue);
}

/* Tables */

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 400;
  text-align: left;
}

.table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.database th + th,
.database td + td {
  border-left: 1px solid var(--border);
}

.table tbody tr:hover {
  background: var(--hover);
}

.cell-right {
  text-align: right;
}

.row-link {
  text-decoration: none;
}

.row-link:hover {
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
}

.strong {
  font-weight: 500;
}

/* Controls */

.button,
.filter,
input[type="date"] {
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}

.button:hover,
.filter:hover {
  background: var(--hover);
}

.icon-button {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--hover);
  color: var(--text);
}

/* Calendar page */

.calendar-page {
  display: flex;
  height: 100%;
}

.calendar {
  flex: 1;
  min-width: 0;
  padding: 32px 32px 16px;
  display: flex;
  flex-direction: column;
}

.calendar .page-title {
  font-size: 32px;
}

.calendar-body {
  flex: 1;
  min-height: 0;
}

.filters {
  display: flex;
  gap: 8px;
  margin: 8px 0 16px;
}

/* Table view: the page scrolls, the side panel stays put */

.page-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.clickable tbody tr {
  cursor: pointer;
}

.table tbody tr.selected {
  background: var(--active);
}

/* A text box with a button on its right, e.g. Name + Generate */

.input-with-button {
  display: flex;
  gap: 8px;
}

.input-with-button input {
  flex: 1;
  min-width: 0;
}

/* Filters on the left, the New button on the right */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0 16px;
}

.toolbar .filters {
  margin: 0;
}

/* Forms in a centred dialog */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 15, 15, 0.4);
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 600;
}

.modal .close {
  float: right;
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 20px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form label {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--text-secondary);
}

.form input,
.form select,
.form textarea {
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

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

.form .checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.form-row {
  display: flex;
  gap: 12px;
}

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

@media (max-width: 560px) {
  .form-row {
    flex-direction: column;
  }
}

/* Side panel, like Notion's peek view */

.panel {
  width: 360px;
  flex-shrink: 0;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
}

.panel h3 {
  margin: 28px 0 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel .close {
  float: right;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.panel .close:hover {
  background: var(--hover);
}

.panel .meta {
  margin: 0;
  color: var(--text-secondary);
}

.attendance {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.attendance li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 3px 4px;
  border-radius: 4px;
}

.attendance li:hover {
  background: var(--hover);
}

.attendance li .row-link {
  flex: 1;
}

.danger {
  display: block;
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--red);
  cursor: pointer;
}

.danger-zone {
  margin-top: 32px;
}

.danger:hover {
  background: var(--tag-red-bg);
}

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

/* Logins */

.link-button {
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
}

.link-button:hover {
  color: var(--text);
  text-decoration: underline;
}

.login-link-button {
  text-align: center;
  text-decoration: none;
}

.login-card p {
  margin: 0;
}

.hint {
  color: var(--text-tertiary);
  font-size: 12px;
}

.notice {
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--tag-green-bg);
  color: var(--tag-green-text);
}

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

.login-row {
  gap: 8px;
}

/* Private lessons: a coach's week, with room for the requests table below */
.page-wide {
  max-width: 1100px;
}

.lesson-calendar {
  height: 620px;
  margin-bottom: 32px;
}

/* Member peek: the same details as the profile page, fitted to the panel */
.panel .page-title {
  margin-top: 0;
  font-size: 28px;
}

.panel .avatar {
  width: 56px;
  height: 56px;
  font-size: 26px;
}

.panel .properties {
  grid-template-columns: 112px 1fr;
}

.panel .properties dd {
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-session {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.history-session .muted {
  font-size: 12px;
}

/* Pending lesson requests on the calendar: dashed until a coach answers */
.event-request {
  border: 1.5px dashed var(--tag-yellow-text) !important;
}

.panel-actions {
  justify-content: flex-start;
  margin: 24px 0 8px;
}

/* Sessions heading, with the Calendar | List switch */
.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.view-toggle {
  display: flex;
  flex-shrink: 0;
  padding: 2px;
  border-radius: 8px;
  background: var(--hover);
}

.view-toggle a {
  padding: 4px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
}

.view-toggle a.active {
  background: var(--bg);
  box-shadow: var(--shadow);
  color: var(--text);
}

/* htmx and Alpine */

/* Alpine shows these once it has started, so they don't flash before. */
[x-cloak] {
  display: none !important;
}

/* The side peek's slot. Its <aside class="panel"> is the flex item. */
#panel {
  display: contents;
}

.field-error {
  color: var(--red);
  font-size: 12px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card .link-button {
  text-align: center;
}

/* FullCalendar's height: 100% fills this */
.calendar-fill {
  height: 100%;
}

/* Calendar sync: the secret link, and how to add it */
.feed-url {
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--sidebar-bg);
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.feed-link .hint {
  margin: 8px 0 0;
}

.feed-actions {
  align-items: center;
  margin-top: 8px;
}

.steps {
  margin: 0 0 12px;
  padding-left: 20px;
  line-height: 1.8;
}

/* Phones, and narrow windows. The sidebar becomes a tab bar along the bottom, peeks
   and dialogs fill the screen, and tables drop their less important columns. */

@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    order: 1;
    flex-direction: row;
    width: auto;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .workspace,
  .account-name,
  .nav-item:has(.nav-short) .nav-label {
    display: none;
  }

  .nav-short,
  .show-phone {
    display: inline;
  }

  /* Log out sits in the tab bar with the rest */
  .account,
  .account form {
    display: contents;
  }

  .nav-item,
  .account-logout {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    margin: 0;
    padding: 6px 2px;
    font-size: 11px;
    white-space: nowrap;
  }

  .nav-item:hover {
    background: none;
  }

  .nav-item.active {
    background: var(--active);
  }

  .nav-icon {
    width: auto;
    font-size: 20px;
    line-height: 1.2;
  }

  /* Pages */

  .page {
    padding: 16px 16px 32px;
  }

  .page-title {
    font-size: 28px;
  }

  .page-description {
    margin-bottom: 16px;
  }

  .section-title {
    margin-top: 28px;
  }

  .hide-phone {
    display: none;
  }

  .table th,
  .table td {
    padding: 8px 6px;
  }

  .properties {
    grid-template-columns: 112px 1fr;
  }

  /* 16px stops iOS zooming in on a field when it's tapped */
  .form input,
  .form select,
  .form textarea,
  .filter,
  .notes,
  .login-card input,
  input[type="date"] {
    font-size: 16px;
  }

  .button,
  .filter {
    padding: 6px 10px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
  }

  .login-card {
    width: calc(100% - 32px);
    max-width: 360px;
  }

  /* Calendar: just enough room above it for the heading and filters */

  .calendar {
    padding: 12px 12px 8px;
  }

  .calendar .page-title {
    margin-bottom: 4px;
    font-size: 24px;
  }

  .toolbar {
    margin: 4px 0 8px;
  }

  /* The filters scroll sideways, rather than wrapping onto more lines */
  .toolbar .filters {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolbar .filters > *,
  .toolbar > .button {
    flex-shrink: 0;
  }

  /* The Private lessons calendar fills the screen once scrolled to */
  .lesson-calendar {
    height: calc(100dvh - 140px);
    min-height: 420px;
  }

  /* Peeks open full screen, over the tab bar */

  .panel {
    position: fixed;
    inset: 0;
    z-index: 50;
    width: auto;
    padding: 12px 16px calc(32px + env(safe-area-inset-bottom));
    box-shadow: none;
  }

  /* The × stays in reach while a long peek scrolls */
  .panel .close {
    position: sticky;
    top: 0;
    z-index: 1;
    width: 40px;
    height: 40px;
    background: var(--bg);
    font-size: 26px;
  }

  .panel .page-title {
    font-size: 24px;
  }

  /* Dialogs too */

  .modal-backdrop {
    padding: 0;
    place-items: stretch;
  }

  .modal {
    max-width: none;
    max-height: none;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    border-radius: 0;
  }

  .modal .close {
    width: 40px;
    height: 40px;
    margin: -8px -8px 0 0;
    font-size: 26px;
  }
}
