/* Shared components added for product polish and accessibility: native
   dialogs, confirmations, undo toasts, the post-wrap sheet, the calendar time
   grid, skip link and focus styles. Loaded after styles.css and theme.css so it
   can reuse (and, where needed, override) their tokens. */

:root {
  --focus-ring: #106367;
  /* Form-field borders need 3:1 contrast against the field. */
  --field-line: #7d878e;
  --toast-bg: #106367;
  --toast-ink: #ffffff;
  --toast-soft: #d5ebe6;
  --danger-solid: #b23a26;
  --danger-solid-hover: #962f1e;
}
:root[data-theme='dark'] {
  --focus-ring: #85d8cd;
  --field-line: #6b7d8f;
  --danger-ink: #ffb8ac;
}

/* Colour contrast (WCAG AA, checked by axe in light and dark) --------------- */
:root {
  /* Was #65717c: just under 4.5:1 on the tinted panels. */
  --muted: #5d6974;
  --danger-ink: #b23a26;
}
.danger-text {
  color: var(--danger-ink) !important;
}
.danger-zone summary,
.student-finance-money.due b {
  color: var(--danger-ink);
}
.month-day.outside .month-date {
  opacity: 1;
}
.avatar,
.button.mint,
.tax-export-actions a:first-child {
  color: var(--forest-2);
}
.chip.warn[aria-pressed='true'] {
  background: #8f5a12;
  border-color: #8f5a12;
}
.chip.danger[aria-pressed='true'] {
  background: var(--danger-solid);
  border-color: var(--danger-solid);
}
[data-theme='dark'] .chip.warn[aria-pressed='true'] {
  background: #936020;
  border-color: #af7a36;
}
[data-theme='dark'] .chip.danger[aria-pressed='true'] {
  background: #a4473b;
  border-color: #bd6357;
}

/* Focus and skip link ----------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
input,
textarea,
select {
  border-color: var(--field-line);
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
#mainContent:focus,
#authMain:focus,
.dialog:focus {
  outline: none;
}
.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 200;
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid var(--focus-ring);
  background: var(--card);
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.skip-link:focus {
  top: 12px;
}

/* Native dialogs ---------------------------------------------------------- */
dialog.overlay {
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  color: var(--ink);
}
dialog.overlay:not([open]) {
  display: none;
}
dialog.overlay::backdrop {
  background: transparent;
}
.confirm-overlay .dialog {
  width: min(460px, 100%);
  height: auto;
}
.confirm-dialog .dialog-head {
  min-height: 0;
  padding: 20px 22px 6px;
  border-bottom: 0;
  background: var(--paper);
}
.confirm-dialog .dialog-body {
  padding: 6px 22px 8px;
}
.confirm-message {
  margin: 0;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.55;
}
.confirm-dialog .dialog-foot {
  position: static;
  border-top: 0;
  background: transparent;
  box-shadow: none;
  padding: 14px 22px 20px;
  flex-wrap: wrap;
}
[data-theme='dark'] .confirm-dialog .dialog-head,
[data-theme='dark'] .confirm-dialog .dialog-foot {
  background: transparent;
}
.button.danger-solid {
  background: var(--danger-solid);
  color: #fff;
}
.button.danger-solid:hover {
  background: var(--danger-solid-hover);
}
@media (max-width: 760px) {
  .confirm-overlay {
    align-items: flex-end;
  }
  .confirm-overlay .dialog {
    width: 100%;
    height: auto;
    max-height: 90vh;
    border-radius: 20px 20px 0 0;
  }
  .confirm-dialog .dialog-body {
    padding: 6px 18px 8px;
  }
  .confirm-dialog .dialog-foot {
    position: static;
    padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
  }
}

/* Toasts ------------------------------------------------------------------ */
.toast {
  top: auto;
  left: auto;
  margin: 0;
  border: 0;
  width: auto;
  height: auto;
  overflow: visible;
  background: var(--toast-bg);
  color: var(--toast-ink);
}
.toast.show {
  pointer-events: auto;
  animation: toast-in 0.22s ease-out;
}
.toast-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}
.toast-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.toast small {
  color: var(--toast-soft);
  margin-top: 0;
}
.toast-undo {
  flex: none;
  margin-left: auto;
  min-height: 40px;
  min-width: 64px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 10px;
  background: transparent;
  color: var(--toast-ink);
  font-weight: 800;
  cursor: pointer;
}
.toast-undo:hover {
  background: rgba(255, 255, 255, 0.14);
}
.toast-undo:focus-visible {
  outline-color: #ffffff;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

/* Post-wrap success sheet --------------------------------------------------- */
.wrap-done {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.wrap-check {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--forest);
  color: #fff;
}
.wrap-check svg {
  width: 24px;
  height: 24px;
}
.wrap-done > div > b {
  display: block;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.wrap-done > div > span {
  color: var(--muted);
  font-size: 13px;
}
.wrap-recorded {
  margin: 0 0 13px;
  padding: 2px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}
.wrap-recorded > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.wrap-recorded > div:last-child {
  border-bottom: 0;
}
.wrap-recorded dt {
  flex: none;
  color: var(--muted);
  font-size: 13px;
}
.wrap-recorded dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 750;
  text-align: right;
  overflow-wrap: anywhere;
}
.wrap-summary {
  min-height: 96px;
  background: var(--paper);
}
.wrap-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

/* Calendar: student colour chips -------------------------------------------- */
.student-c0 {
  --chip-bg: #e2f2ef;
  --chip-edge: #147d80;
}
.student-c1 {
  --chip-bg: #e7eefb;
  --chip-edge: #3b63b8;
}
.student-c2 {
  --chip-bg: #fbe8e3;
  --chip-edge: #c4553d;
}
.student-c3 {
  --chip-bg: #f7efda;
  --chip-edge: #a26a12;
}
.student-c4 {
  --chip-bg: #efe8f9;
  --chip-edge: #7650b4;
}
.student-c5 {
  --chip-bg: #e5f3e6;
  --chip-edge: #3c8a45;
}
.student-c6 {
  --chip-bg: #fbe6f0;
  --chip-edge: #b5457c;
}
.student-c7 {
  --chip-bg: #e4eef4;
  --chip-edge: #3f7390;
}
[data-theme='dark'] .student-c0 {
  --chip-bg: #17403f;
  --chip-edge: #5fc4b8;
}
[data-theme='dark'] .student-c1 {
  --chip-bg: #22355a;
  --chip-edge: #8eb0f0;
}
[data-theme='dark'] .student-c2 {
  --chip-bg: #4a2a24;
  --chip-edge: #f09a84;
}
[data-theme='dark'] .student-c3 {
  --chip-bg: #463616;
  --chip-edge: #e5b860;
}
[data-theme='dark'] .student-c4 {
  --chip-bg: #352a52;
  --chip-edge: #b9a0ef;
}
[data-theme='dark'] .student-c5 {
  --chip-bg: #1f3f26;
  --chip-edge: #86cf8f;
}
[data-theme='dark'] .student-c6 {
  --chip-bg: #4a2238;
  --chip-edge: #ef99c4;
}
[data-theme='dark'] .student-c7 {
  --chip-bg: #213847;
  --chip-edge: #8cc0dc;
}
.calendar-lesson[class*='student-c'],
[data-theme='dark'] .calendar-lesson[class*='student-c'] {
  border-left: 4px solid var(--chip-edge);
}
.month-item[class*='student-c'] {
  border-left: 3px solid var(--chip-edge);
}

/* Calendar: time grid ----------------------------------------------------- */
.time-grid-wrap {
  min-width: 780px;
}
.calendar-legend {
  list-style: none;
  margin: 0;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--chip-bg);
  border: 2px solid var(--chip-edge);
}
.time-grid {
  --hour: 52px;
  display: grid;
  grid-template-columns: 58px repeat(7, minmax(96px, 1fr));
  border-top: 1px solid var(--line);
}
.tg-gutter {
  border-right: 1px solid var(--line);
}
.tg-corner {
  height: 58px;
  border-bottom: 1px solid var(--line);
}
.tg-hours {
  height: calc(var(--hour) * var(--hours, 10));
}
.tg-hour {
  position: relative;
  height: var(--hour);
}
.tg-hour span {
  position: absolute;
  top: -8px;
  right: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.tg-hour:first-child span {
  top: 2px;
}
.tg-hour:not(:first-child) span {
  top: -8px;
}
.tg-day {
  min-width: 0;
  border-right: 1px solid var(--line);
}
.tg-day:last-child {
  border-right: 0;
}
.tg-day-head {
  height: 58px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tg-day-head b {
  margin-top: 2px;
  color: var(--ink);
  font-size: 17px;
  letter-spacing: -0.03em;
}
.tg-day.today .tg-day-head b {
  color: var(--forest-2);
}
.tg-day-body {
  position: relative;
  height: calc(var(--hour) * var(--hours, 10));
  background-image: repeating-linear-gradient(
    to bottom,
    var(--line) 0,
    var(--line) 1px,
    transparent 1px,
    transparent var(--hour)
  );
}
.tg-day.today .tg-day-head,
.tg-day.today .tg-day-body {
  background-color: #f1f8f4;
}
[data-theme='dark'] .tg-day.today .tg-day-head,
[data-theme='dark'] .tg-day.today .tg-day-body {
  background-color: #203437;
}
.tg-item {
  position: absolute;
  left: 3px;
  right: 3px;
  min-height: 24px;
  padding: 3px 7px;
  overflow: hidden;
  border: 1px solid var(--chip-edge);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--chip-bg);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  z-index: 1;
}
.tg-item:hover {
  box-shadow: 0 4px 14px rgba(27, 48, 41, 0.14);
  z-index: 2;
}
.tg-item:focus-visible {
  z-index: 3;
}
.tg-item b {
  display: block;
  overflow: hidden;
  font-size: 11px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tg-item > span:not(.sr-only) {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  color: var(--ink-2);
  font-size: 10px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tg-item.done {
  background: var(--card);
  border-style: dashed;
  border-left-style: solid;
}
.tg-block {
  border: 1px dashed #b07a2a;
  border-left: 4px solid var(--amber);
  background: var(--amber-soft);
  color: #5f3a0a;
}
.tg-block > span:not(.sr-only) {
  color: #6f4610;
}
[data-theme='dark'] .tg-block,
[data-theme='dark'] .tg-block > span:not(.sr-only) {
  color: var(--amber);
}
.tg-now {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--coral);
  z-index: 2;
  pointer-events: none;
}
.tg-now::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--coral);
}

/* Page headers: every screen opens with a section head (h2 + summary). ----- */
.payment-period.section-head {
  align-items: end;
}
.payment-period.section-head p {
  margin: 0;
  max-width: 520px;
}

/* Offline page (served by the service worker) ------------------------------- */
.offline-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.offline-card {
  width: min(440px, 100%);
  padding: 32px 28px;
  text-align: left;
}
.offline-card .brand-mark {
  margin-bottom: 18px;
}
.offline-card h1 {
  margin: 0 0 10px;
  font-size: 24px;
  letter-spacing: -0.03em;
}
.offline-card p {
  margin: 0 0 12px;
  color: var(--ink-2);
  line-height: 1.55;
}
.offline-card .button {
  margin-top: 10px;
}

/* Touch targets and readable mobile navigation ------------------------------ */
@media (max-width: 760px) {
  .mobile-nav button {
    font-size: 11px;
  }
  .segmented button {
    min-height: 44px;
  }
  .button.small,
  .icon-button {
    min-height: 44px;
  }
  .icon-button {
    width: 44px;
  }
  .chip {
    min-height: 44px;
  }
}

/* Newer tools (extras.js) --------------------------------------------------- */
.extras {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}
.extras-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  align-items: start;
}
.extras-card h3 .plan-tag {
  margin-left: 6px;
}
.extras-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.extras-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.extras-list li > span:first-child {
  min-width: 0;
  flex: 1 1 240px;
}
.extras-list small {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.x-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}
.x-table th,
.x-table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.x-amount {
  width: 7em;
}
.x-fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 12px 0;
}
.x-sample {
  white-space: pre-wrap;
  background: var(--paper-2);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  overflow-x: auto;
}
.x-draft {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}
.x-draft textarea {
  width: 100%;
  min-height: 140px;
}
.x-ai-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--amber);
  margin: 0 0 4px;
}
