:root {
  --tm-navy: #003b5c;
  --tm-navy-deep: #002a42;
  --tm-accent: #0ea5e9;
  --tm-card: rgba(255, 255, 255, 0.98);
  --tm-muted: #64748b;
  --tm-radius: 1rem;
  --tm-shadow: 0 25px 50px -12px rgba(0, 59, 92, 0.35);
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #0f172a;
  background: linear-gradient(145deg, var(--tm-navy-deep) 0%, var(--tm-navy) 45%, #0c4a6e 100%);
}

body.tm-light {
  background: linear-gradient(160deg, #f0f9ff 0%, #e2e8f0 50%, #f8fafc 100%);
  color: #0f172a;
}

.tm-bg-pattern {
  position: fixed;
  inset: 0;
  opacity: 0.08;
  background-image: radial-gradient(circle at 20% 30%, #fff 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
}

.tm-splash {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  z-index: 100;
  background: var(--tm-navy);
}

.tm-splash .tm-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: tm-spin 0.75s linear infinite;
}

@keyframes tm-spin {
  to {
    transform: rotate(360deg);
  }
}

.tm-shell {
  position: relative;
  z-index: 1;
  max-width: 28rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tm-shell.tm-shell-wide {
  max-width: 36rem;
}

/* Public survey site — use nearly full viewport width (forms index only) */
body.tm-light .tm-shell.tm-shell-survey {
  width: 100%;
  max-width: min(52rem, calc(100vw - 1rem));
  padding: 1.25rem 0.5rem 2.5rem;
  box-sizing: border-box;
}

body.tm-light .tm-shell.tm-shell-survey .tm-card {
  padding: 1.5rem 1rem;
  overflow-x: clip;
}

body.tm-light .tm-shell.tm-shell-survey #form,
body.tm-light .tm-shell.tm-shell-survey .tm-survey-page,
body.tm-light .tm-shell.tm-shell-survey .tm-question,
body.tm-light .tm-shell.tm-shell-survey .tm-question-field {
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 480px) {
  body.tm-light .tm-shell.tm-shell-survey {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  body.tm-light .tm-shell.tm-shell-survey .tm-card {
    padding: 1.75rem 1.35rem;
  }
}

.tm-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tm-topbar .tm-brand {
  margin-bottom: 0;
  justify-content: flex-start;
  flex: 1;
}

.tm-logout {
  flex-shrink: 0;
  padding: 0.45rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.tm-logout:hover {
  background: rgba(255, 255, 255, 0.2);
}

.tm-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.tm-brand img {
  max-height: 3.5rem;
  max-width: 8rem;
  object-fit: contain;
}

.tm-brand .tm-wordmark {
  max-height: 2.25rem;
  opacity: 0.95;
}

.tm-card {
  background: var(--tm-card);
  border-radius: var(--tm-radius);
  box-shadow: var(--tm-shadow);
  padding: 1.75rem 1.5rem;
  backdrop-filter: blur(12px);
  min-width: 0;
}

.tm-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--tm-navy);
}

.tm-card .tm-lead {
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
  color: var(--tm-muted);
  line-height: 1.5;
}

.tm-field {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: #334155;
}

.tm-field input,
.tm-field textarea,
.tm-field select {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.65rem;
  font-size: 1rem;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.tm-field input:focus,
.tm-field textarea:focus {
  outline: none;
  border-color: var(--tm-accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.tm-btn {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.85rem 1rem;
  border: none;
  border-radius: 0.65rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(180deg, var(--tm-navy) 0%, var(--tm-navy-deep) 100%);
  color: #fff;
  transition: transform 0.1s, opacity 0.15s;
}

.tm-btn:hover {
  opacity: 0.95;
}

.tm-btn:active {
  transform: scale(0.98);
}

.tm-btn-secondary {
  background: #f1f5f9;
  color: var(--tm-navy);
}

.tm-msg {
  margin-top: 1rem;
  font-size: 0.9rem;
  text-align: center;
  color: var(--tm-muted);
}

.tm-msg.tm-error {
  color: #b91c1c;
}

.tm-msg.tm-success {
  color: #047857;
}

.tm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 20, 40, 0.55);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.tm-modal-backdrop.tm-open {
  display: flex;
}

.tm-modal {
  width: 100%;
  max-width: 22rem;
  background: var(--tm-card);
  border-radius: var(--tm-radius);
  box-shadow: var(--tm-shadow);
  padding: 1.75rem 1.5rem;
  animation: tm-modal-in 0.25s ease-out;
}

.tm-modal.tm-modal-wide {
  max-width: min(56rem, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 1.25rem;
}

.tm-modal.tm-modal-wide .tm-modal-body {
  flex: 1;
  min-height: 12rem;
  overflow: auto;
}

.tm-modal.tm-modal-wide iframe {
  width: 100%;
  min-height: 70vh;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  background: #fff;
}

.tm-modal.tm-modal-report {
  max-width: min(40rem, 96vw);
}

.tm-modal.tm-modal-report .tm-field select,
.tm-modal.tm-modal-report .tm-field textarea {
  font-size: 1rem;
}

.tm-modal.tm-modal-report .tm-field select {
  white-space: normal;
  word-break: break-word;
}

.tm-modal.tm-modal-report .tm-field textarea {
  min-height: 8rem;
}

.tm-modal.tm-modal-roster .tm-modal-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.tm-modal.tm-modal-roster .tm-modal-head-row h2 {
  margin: 0;
  flex: 1 1 12rem;
}

.tm-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.tm-roster-doc {
  font-size: 0.85rem;
  color: #0f172a;
}

.tm-roster-logo {
  max-height: 3.5rem;
  max-width: 8rem;
  object-fit: contain;
  margin-bottom: 0.5rem;
}

.tm-roster-title {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  color: var(--tm-navy);
}

.tm-roster-generated {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--tm-muted);
}

.tm-roster-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.75rem;
  margin: 0 0 1rem;
  font-size: 0.8rem;
}

.tm-roster-meta dt {
  font-weight: 600;
  color: #475569;
}

.tm-roster-meta dd {
  margin: 0;
}

.tm-roster-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.tm-roster-table th,
.tm-roster-table td {
  border: 1px solid #e2e8f0;
  padding: 0.35rem 0.45rem;
  text-align: left;
  vertical-align: top;
}

.tm-roster-table th {
  background: #f1f5f9;
  font-weight: 600;
}

.tm-roster-table tr.tm-roster-placeholder td:first-child {
  font-style: italic;
  background: #fffbeb;
}

.tm-roster-mail {
  color: var(--tm-navy);
  text-decoration: underline;
  word-break: break-all;
}

.tm-coach-notes-wrap {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.tm-coach-notes-text {
  flex: 1;
  min-width: 0;
}

.tm-coach-notes-edit {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--tm-navy);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.1rem 0.2rem;
  border-radius: 0.25rem;
}

.tm-coach-notes-edit:hover {
  background: #e2e8f0;
}

@media print {
  @page {
    margin: 12mm;
  }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    background: #fff !important;
  }

  /* visibility:hidden still reserves layout space — use display:none instead */
  body.tm-print-roster > *:not(#rosterModal) {
    display: none !important;
  }

  body.tm-print-roster #rosterModal {
    display: block !important;
    position: static !important;
  }

  body.tm-print-roster .tm-modal-backdrop {
    position: static !important;
    display: block !important;
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
    inset: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  body.tm-print-roster .tm-modal,
  body.tm-print-roster .tm-modal-body,
  body.tm-print-roster #rosterPrintArea {
    position: static !important;
    max-width: none !important;
    max-height: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  body.tm-print-roster .tm-modal-head-row,
  body.tm-print-roster .tm-modal-actions {
    display: none !important;
  }
}

.tm-modal-close {
  margin-top: 0.75rem;
}

.tm-team-row {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.65rem;
  background: #f8fafc;
}

.tm-team-row strong {
  display: block;
  color: var(--tm-navy);
  font-size: 0.95rem;
}

.tm-team-row span {
  display: block;
  font-size: 0.8rem;
  color: var(--tm-muted);
  margin-top: 0.2rem;
}

.tm-team-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.tm-btn-inline {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
}

.tm-status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 0.35rem;
  margin-left: 0.35rem;
}

.tm-status-signed {
  background: #d1fae5;
  color: #047857;
}

.tm-status-unsigned {
  background: #fef3c7;
  color: #b45309;
}

.tm-coc-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e2e8f0;
}

.tm-coc-frame {
  width: 100%;
  min-height: 50vh;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}

@keyframes tm-modal-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.tm-modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  color: var(--tm-navy);
}

.tm-modal p {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--tm-muted);
  line-height: 1.45;
}

.tm-closed {
  text-align: center;
  padding: 2rem 1rem;
}

.tm-closed h2 {
  color: var(--tm-navy);
}

.tm-question {
  margin-bottom: 1.35rem;
  min-width: 0;
}

.tm-question-prompt {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.4;
}

.tm-question-field {
  margin-top: 0.15rem;
  min-width: 0;
  max-width: 100%;
}

/* Match committee preview: full-width inputs (not only under .tm-field). */
.tm-question input[type="text"],
.tm-question input[type="email"],
.tm-question input[type="tel"],
.tm-question input[type="date"],
.tm-question input[type="time"],
.tm-question input[type="datetime-local"],
.tm-question textarea,
.tm-question select {
  display: block;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.65rem;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.tm-question textarea {
  min-height: 6.5rem;
  resize: vertical;
  line-height: 1.45;
}

.tm-question input:focus,
.tm-question textarea:focus,
.tm-question select:focus {
  outline: none;
  border-color: var(--tm-accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.tm-question input[type="range"] {
  width: 100%;
  margin: 0.35rem 0 0;
  accent-color: var(--tm-navy);
}

.tm-slider-hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--tm-muted);
}

.tm-hidden {
  display: none !important;
}

.tm-section-heading {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--tm-navy);
  margin: 1.25rem 0 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--tm-border, #e2e8f0);
}

.tm-descriptive {
  font-size: 0.9rem;
  color: #475569;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.tm-choice-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.tm-choice-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 400;
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid #f1f5f9;
  border-radius: 0.65rem;
  background: #fff;
  cursor: pointer;
}

.tm-choice-row:has(input:checked) {
  border-color: var(--tm-accent);
  background: #f0f9ff;
}

.tm-scale-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.tm-scale-btn {
  min-width: 2.5rem;
  min-height: 2.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.65rem;
  background: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s,
    transform 0.08s;
}

.tm-scale-btn-star {
  min-width: 2.75rem;
  min-height: 2.75rem;
  font-size: 1.35rem;
  line-height: 1;
  color: #94a3b8;
}

.tm-scale-btn.tm-scale-selected {
  border-color: var(--tm-navy);
  background: #e0f2fe;
  color: var(--tm-navy);
  font-weight: 700;
}

.tm-scale-btn-star.tm-scale-selected {
  color: #f59e0b;
  background: #fffbeb;
  border-color: #fbbf24;
}

.tm-matrix-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.5rem;
  padding-bottom: 0.2rem;
  overscroll-behavior-x: contain;
}

.tm-matrix-wrap:focus-visible {
  outline: 2px solid var(--tm-accent);
  outline-offset: 2px;
  border-radius: 0.35rem;
}

.tm-matrix {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: 0;
}

.tm-matrix th,
.tm-matrix td {
  border: 1px solid #e2e8f0;
  padding: 0.5rem 0.4rem;
  text-align: center;
  vertical-align: middle;
}

.tm-matrix th {
  font-weight: 600;
  color: #475569;
  font-size: 0.7rem;
  line-height: 1.25;
  white-space: normal;
  min-width: 3.25rem;
  max-width: 5.75rem;
}

.tm-matrix td:first-child,
.tm-matrix th:first-child {
  text-align: left;
  font-weight: 500;
  color: #334155;
  min-width: 7rem;
  max-width: 12rem;
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  box-shadow: 4px 0 6px -4px rgba(15, 23, 42, 0.1);
}

.tm-matrix thead th:first-child {
  background: #f8fafc;
}

.tm-matrix input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  cursor: pointer;
}

/* Narrow screens: stack each statement as a card instead of a wide grid */
@media (max-width: 36rem) {
  .tm-matrix-wrap {
    overflow-x: visible;
  }

  .tm-matrix {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .tm-matrix thead {
    display: none;
  }

  .tm-matrix tbody {
    display: block;
  }

  .tm-matrix tbody tr {
    display: block;
    margin-bottom: 0.85rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.65rem;
    background: #f8fafc;
  }

  .tm-matrix tbody td:first-child {
    display: block;
    position: static;
    box-shadow: none;
    min-width: 0;
    max-width: none;
    padding: 0 0 0.5rem;
    margin-bottom: 0.35rem;
    border: none;
    font-size: 0.9rem;
    line-height: 1.35;
  }

  .tm-matrix tbody td:not(:first-child) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    text-align: left;
    padding: 0.4rem 0;
    border: none;
    border-top: 1px solid #e2e8f0;
  }

  .tm-matrix tbody td:not(:first-child)::before {
    content: attr(data-col-label);
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
    color: #475569;
    line-height: 1.25;
  }
}

.tm-contact input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
}

.tm-ranking {
  margin: 0.5rem 0 0 1.25rem;
  padding: 0;
}
