/* ============================================================
   Field-TM — Shared Application Styles
   ============================================================
   Reusable utility classes used across all server-rendered
   templates. Keeps templates thin and style changes centralized.

   Naming convention:  .ftm-<component>[-modifier]

   Tokens: references HOT design system tokens from hot.css /
   hot-wa.css which are loaded via @hotosm/ui style-core.css.
   ============================================================ */

/* --- Body typography -------------------------------------- */
body {
  font-family: var(--hot-font-sans, Archivo, -apple-system, Roboto, Helvetica, Arial, sans-serif);
  color: var(--hot-color-neutral-900, #404248);
}

/* --- Design tokens (custom properties) -------------------- */
:root {
  --ftm-brand: var(--hot-color-primary-600, #d73f3f);
  --ftm-text: var(--hot-color-neutral-900, #404248);
  --ftm-text-muted: var(--hot-color-neutral-600, #716f73);
  --ftm-text-light: var(--hot-color-neutral-500, #828085);
  --ftm-border: var(--hot-color-neutral-200, #c4c3c5);
  --ftm-bg-success: var(--hot-color-success-50, #e3f8f8);
  --ftm-bg-muted: var(--hot-color-neutral-50, #f3f3f3);
  --ftm-bg-info: var(--hot-color-cyan-50, #e3f8f8);
  --ftm-color-success: var(--hot-color-success-500, #50c1cb);
  --ftm-radius: var(--hot-border-radius-large, 0.5rem);
  --ftm-radius-sm: var(--hot-border-radius-medium, 0.25rem);
}

/* --- Page layouts ----------------------------------------- */
.ftm-page {
  padding: 24px;
}

.ftm-page--narrow {
  max-width: 800px;
  margin: 0 auto;
}

.ftm-page--wide {
  max-width: 1200px;
  margin: 0 auto;
}

/* Muted background — used only on list/index pages where cards need to pop */
.ftm-page--muted {
  background-color: var(--hot-color-neutral-100, #e8e8e8);
  min-height: calc(100vh - 60px);
}

.ftm-page--projects {
  background-color: white;
  min-height: calc(100vh - 60px);
  padding-top: 0;
  padding-left: 0;
  padding-right: 0;
}

/* --- Page header ------------------------------------------ */
.ftm-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.ftm-page-title {
  margin: 0;
  font-size: var(--hot-font-size-x-large);
  font-family: var(--hot-font-sans-variant-condensed);
  color: var(--ftm-text);
}

.ftm-projects-shell {
  border-bottom: 1px solid var(--ftm-border);
}

/* --- Projects toolbar (desktop: single row) ------------------ */
.ftm-projects-toolbar {
  display: flex;
  align-items: end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  max-width: 100%;
  box-sizing: border-box;
}

.ftm-projects-filters {
  display: flex;
  align-items: end;
  gap: 0.75rem;
  flex: 1 1 0;
  min-width: 0;
}

.ftm-projects-filter {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  flex: 0 0 auto;
  min-width: 0;
  width: 7.5rem;
}

.ftm-projects-filter--search {
  flex: 1 1 14rem;
  min-width: 10rem;
  max-width: 25vw;
  width: auto;
}

.ftm-projects-filter--search wa-input {
  width: 100%;
  min-width: 0;
}

.ftm-projects-filter__label {
  font-size: var(--hot-font-size-x-small);
  font-weight: var(--hot-font-weight-semibold);
  color: var(--ftm-text-light);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.ftm-projects-filter__select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.5rem;
  border: 1px solid var(--ftm-border);
  border-radius: var(--ftm-radius-sm);
  background-color: white;
  color: var(--ftm-text);
  font: inherit;
  font-size: var(--hot-font-size-small);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ftm-projects-toolbar > .ftm-create-btn {
  flex: 0 0 auto;
  margin-left: 1rem;
  white-space: nowrap;
}

.ftm-projects-filter__select:focus {
  outline: 2px solid color-mix(in oklab, var(--ftm-brand) 16%, transparent);
  outline-offset: 1px;
  border-color: color-mix(in oklab, var(--ftm-brand) 35%, white);
}

.ftm-projects-results {
  margin: 0;
  padding: 0.5rem 1.5rem 0.75rem;
  font-size: var(--hot-font-size-small);
  color: var(--ftm-text-light);
}

/* Desktop: collapsible wrapper is transparent, toggle is hidden */
.ftm-filters-collapsible {
  display: contents;
}

.ftm-filters-toggle {
  display: none;
}

/* Short label for create button hidden on desktop */
.ftm-create-btn__short {
  display: none;
}

.ftm-create-btn__full {
  display: inline;
}

/* --- Card grid (project listing) -------------------------- */
.ftm-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  align-items: stretch;
}

/* --- Project card ----------------------------------------- */
/* wa-card has no "base" part — style the host element directly.           */
/* External styles win over shadow-DOM :host styles per CSS Scoping spec.  */
.ftm-project-card {
  display: block;
  height: 100%;
  cursor: pointer;
  background-color: white;
  border: 1px solid color-mix(in oklab, var(--hot-color-neutral-300, #b3b1b4) 80%, white);
  border-radius: 0.75rem;
  box-shadow:
    0 0.0625rem 0.125rem color-mix(in oklab, var(--hot-color-neutral-950) 4%, transparent),
    0 0.375rem 1rem color-mix(in oklab, var(--hot-color-neutral-950) 3%, transparent);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.ftm-project-card:hover,
.ftm-project-card:focus-within {
  transform: translateY(-0.125rem);
  border-color: color-mix(in oklab, var(--ftm-brand) 28%, white);
  box-shadow:
    0 0.5rem 1.5rem color-mix(in oklab, var(--hot-color-neutral-950) 8%, transparent),
    0 0 0 0.1875rem color-mix(in oklab, var(--ftm-brand) 10%, transparent);
}

.ftm-project-card__id {
  font-size: var(--hot-font-size-x-small);
  color: var(--ftm-text-light);
  font-weight: var(--hot-font-weight-semibold);
}

.ftm-project-card__header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ftm-project-card__header-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ftm-project-card__name {
  font-weight: var(--hot-font-weight-bold);
  font-size: var(--hot-font-size-large);
}

.ftm-project-card__badges {
  display: flex;
  align-items: center;
  gap: var(--hot-spacing-x-small);
}

.ftm-project-card__body {
  padding: 0.625rem 0;
}

.ftm-project-card__location {
  margin: 0.5rem 0;
  font-size: var(--hot-font-size-small);
  color: var(--hot-color-neutral-700);
}

.ftm-project-card__location-inner {
  display: flex;
  align-items: center;
  gap: var(--hot-spacing-2x-small);
}

.ftm-project-card__description {
  margin: 10px 0 8px 0;
  color: var(--ftm-text-muted);
  line-height: var(--hot-line-height-normal);
  font-size: var(--hot-font-size-small);
}

.ftm-project-card__tags {
  margin: 10px 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--hot-spacing-x-small);
}

.ftm-project-card__footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--ftm-border);
  font-size: var(--hot-font-size-x-small);
  color: var(--ftm-text-light);
}

.ftm-empty-state {
  text-align: center;
  color: var(--ftm-text-muted);
  margin: 2.5rem 1.5rem 0;
}

/* --- Detail page ------------------------------------------ */
.ftm-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.ftm-detail-label {
  color: var(--ftm-text-muted);
  font-size: var(--hot-font-size-small);
  margin-bottom: 5px;
  font-weight: var(--hot-font-weight-bold);
}

.ftm-detail-value {
  color: var(--ftm-text);
  font-size: var(--hot-font-size-large);
}

.ftm-section-title {
  color: var(--ftm-brand);
  font-family: var(--hot-font-sans-variant-condensed);
  margin-bottom: 10px;
}

.ftm-section {
  margin-bottom: 30px;
}

.ftm-external-info {
  margin-bottom: 30px;
  padding: 15px;
  background-color: var(--ftm-bg-muted);
  border-radius: var(--ftm-radius-sm);
}

.ftm-manager-section {
  margin: 40px 0 20px;
  padding-top: 24px;
  border-top: 1px solid var(--ftm-border);
}

.ftm-manager-section__title {
  margin: 0 0 8px;
  color: var(--ftm-text);
  font-size: var(--hot-font-size-large);
  font-family: var(--hot-font-sans-variant-condensed);
}

.ftm-manager-section__subtitle {
  margin: 0;
  color: var(--ftm-text-muted);
  font-size: var(--hot-font-size-small);
}

.ftm-project-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ftm-project-title-wrap h1 {
  overflow: hidden;
  text-overflow: ellipsis;
}

.ftm-manager-summary-section {
  margin-top: 10px;
}

/* --- Mobile layout (<=720px) --------------------------------- */
@media (max-width: 720px) {
  .ftm-projects-toolbar,
  .ftm-card-grid {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .ftm-projects-toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .ftm-projects-filters {
    flex-wrap: wrap;
    flex-basis: 100%;
    gap: 0.5rem;
    position: relative;
  }

  .ftm-projects-results {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Show the mobile filters toggle button */
  .ftm-filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--ftm-border);
    border-radius: var(--ftm-radius-sm);
    background-color: white;
    color: var(--ftm-text);
    font: inherit;
    font-size: var(--hot-font-size-small);
    cursor: pointer;
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .ftm-filters-toggle:hover {
    background-color: var(--ftm-bg-muted);
  }

  /* Hide inline status filter, show via dropdown */
  .ftm-filters-collapsible {
    display: none;
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    z-index: 20;
    background: white;
    border: 1px solid var(--ftm-border);
    border-radius: var(--ftm-radius-sm);
    padding: 0.75rem;
    box-shadow: 0 4px 12px color-mix(in oklab, var(--hot-color-neutral-950) 10%, transparent);
    min-width: 12rem;
  }

  .ftm-filters--open .ftm-filters-collapsible {
    display: block;
  }

  .ftm-filters-collapsible .ftm-projects-filter {
    flex: 1 1 auto;
    width: 100%;
  }

  /* Sort stays in the first row */
  .ftm-projects-filter[for="projects-sort-filter"] {
    flex: 1 1 auto;
  }

  /* Search takes full width on second row */
  .ftm-projects-filter--search {
    flex-basis: 100%;
    min-width: 0;
  }

  /* Compact create button on mobile */
  .ftm-create-btn__full {
    display: none;
  }

  .ftm-create-btn__short {
    display: inline;
  }

  .ftm-projects-toolbar > .ftm-create-btn {
    margin-left: 0;
  }
}

/* --- Flex/layout utilities -------------------------------- */
.ftm-flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ftm-flex-center {
  display: flex;
  align-items: center;
  gap: var(--hot-spacing-x-small);
}

.ftm-flex-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: var(--hot-spacing-x-small);
}

.ftm-flex-gap {
  display: flex;
  gap: 10px;
}

.ftm-flex-end {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* --- Form styles ------------------------------------------ */
.ftm-form-group {
  margin-bottom: 20px;
}

.ftm-form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: var(--hot-font-weight-bold);
  line-height: var(--hot-line-height-dense);
}

.ftm-form-required {
  color: var(--hot-color-danger-500);
  display: inline;
}

.ftm-form-help {
  display: block;
  margin-top: 8px;
  color: var(--ftm-text-muted);
  font-size: var(--hot-font-size-small);
}

.ftm-form-actions {
  display: flex;
  gap: 10px;
  margin-top: 30px;
  align-items: center;
}

.ftm-radio-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.ftm-radio-card {
  display: flex;
  align-items: center;
  gap: var(--hot-spacing-x-small);
  cursor: pointer;
  padding: 12px;
  border: 2px solid var(--ftm-border);
  border-radius: var(--ftm-radius);
  flex: 1;
  min-width: 150px;
  transition:
    border-color 0.2s,
    background-color 0.2s;
}

.ftm-radio-card:hover,
.ftm-radio-card--selected {
  border-color: var(--hot-color-primary-600);
  background-color: var(--hot-color-primary-50);
}

.ftm-map-container {
  width: 100%;
  height: 400px;
  border: 1px solid var(--ftm-border);
  border-radius: var(--ftm-radius-sm);
  margin-top: 10px;
}

.ftm-map-actions {
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ftm-checkbox-row {
  margin-top: 10px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: var(--hot-spacing-x-small);
}

.ftm-checkbox-label {
  cursor: pointer;
  font-size: var(--hot-font-size-small);
  color: var(--ftm-text);
  user-select: none;
}

.ftm-hashtags-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--hot-spacing-x-small);
  margin-top: 12px;
  min-height: 32px;
}

/* --- Setup steps ------------------------------------------ */
.ftm-setup-header {
  color: var(--ftm-brand);
  font-family: var(--hot-font-sans-variant-condensed);
  margin-bottom: 20px;
  font-size: var(--hot-font-size-x-large);
}

.ftm-step {
  margin-bottom: 30px;
  padding: 20px;
  border-radius: var(--ftm-radius);
}

.ftm-step--pending {
  background-color: var(--ftm-bg-muted);
  border-left: 4px solid var(--ftm-brand);
}

.ftm-step--complete {
  background-color: var(--ftm-bg-success);
  border-left: 4px solid var(--ftm-color-success);
}

.ftm-step__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.ftm-step__title {
  color: var(--ftm-text);
  margin: 0;
  font-size: var(--hot-font-size-large);
  font-family: var(--hot-font-sans-variant-condensed);
}

.ftm-step__check {
  color: var(--ftm-color-success);
  margin-left: 8px;
}

.ftm-step__description {
  color: var(--ftm-text-muted);
  margin-bottom: 15px;
  font-size: var(--hot-font-size-small);
}

.ftm-step__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.ftm-step__actions > button.wa-button {
  min-width: 180px;
}

.ftm-step__success {
  padding: 10px;
  background-color: white;
  border-radius: var(--ftm-radius-sm);
  color: var(--ftm-color-success);
  font-weight: var(--hot-font-weight-semibold);
}

.ftm-step__status {
  margin-top: 10px;
}

/* --- Split form ------------------------------------------- */
.ftm-split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
  margin-bottom: 15px;
}

.ftm-split-grid--advanced {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 8px;
}

.ftm-split-grid--advanced > div:last-child {
  grid-column: 1 / -1;
}

.ftm-split-label {
  display: block;
  margin-bottom: 5px;
  font-weight: var(--hot-font-weight-semibold);
  color: var(--ftm-text);
}

.ftm-split-select,
.ftm-split-input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--ftm-border);
  border-radius: var(--ftm-radius-sm);
}

.ftm-split-submit {
  display: flex;
  align-items: flex-end;
}

/* --- Form config ------------------------------------------ */
.ftm-form-config {
  display: none;
  margin-top: 20px;
  padding: 15px;
  background-color: white;
  border-radius: var(--ftm-radius-sm);
  border: 1px solid var(--ftm-border);
}

.ftm-form-config--visible {
  display: block;
}

.ftm-advanced-config {
  margin-top: 8px;
  border: 1px solid var(--ftm-border);
  border-radius: var(--ftm-radius-sm);
  background-color: var(--hot-color-neutral-50);
  padding: 10px 12px;
}

.ftm-advanced-toggle {
  background-color: var(--hot-color-neutral-50);
  border-color: var(--hot-color-neutral-200);
  color: var(--hot-color-neutral-700);
}

.ftm-advanced-toggle:hover {
  background-color: var(--hot-color-neutral-100);
}

.ftm-advanced-config--hidden {
  display: none;
}

.ftm-advanced-config__summary {
  cursor: pointer;
  font-weight: var(--hot-font-weight-semibold);
  color: var(--ftm-text);
}

.ftm-advanced-config__content {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.ftm-split-feature-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  margin-top: 6px;
}

.ftm-split-feature-options .ftm-checkbox-label {
  display: flex;
  align-items: center;
}

.ftm-config-note {
  padding: 8px;
  border-radius: var(--ftm-radius-sm);
  font-size: var(--hot-font-size-small);
  color: var(--ftm-text-muted);
}

.ftm-config-note--info {
  background-color: var(--ftm-bg-info);
}

.ftm-config-note--muted {
  background-color: var(--hot-color-neutral-100);
}

@media (max-width: 900px) {
  .ftm-split-grid,
  .ftm-split-grid--advanced {
    grid-template-columns: 1fr;
  }

  .ftm-split-feature-options {
    grid-template-columns: 1fr;
  }
}

/* --- Published project ------------------------------------ */
.ftm-published-header {
  color: var(--ftm-color-success);
  font-family: var(--hot-font-sans-variant-condensed);
  margin-bottom: 10px;
  font-size: var(--hot-font-size-x-large);
}

.ftm-published-divider {
  margin-top: 40px;
  padding-top: 30px;
  border-top: 2px solid var(--ftm-border);
}

.ftm-published-divider--top {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.ftm-qr-hero {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.ftm-qr-hero__container {
  width: 100%;
  max-width: 560px;
}

.ftm-qr-hero__loading {
  text-align: center;
  padding: 20px;
  border: 1px dashed var(--ftm-border);
  border-radius: var(--ftm-radius);
  background-color: var(--ftm-bg-muted);
}

.ftm-setup-summary {
  margin-top: 0;
  padding: 0 16px;
  border: 1px solid var(--ftm-border);
  border-radius: var(--ftm-radius);
  background-color: white;
}

.ftm-setup-summary__summary {
  cursor: pointer;
  font-weight: var(--hot-font-weight-semibold);
  color: var(--ftm-text);
  margin: 0;
  padding: 12px 0;
}

.ftm-setup-summary[open] .ftm-setup-summary__summary {
  margin-bottom: 0;
  border-bottom: 1px solid var(--ftm-border);
}

.ftm-setup-summary__content {
  padding: 12px 0 16px;
}

.ftm-setup-summary__description {
  margin: 0 0 12px;
  color: var(--ftm-text-muted);
  font-size: var(--hot-font-size-small);
}

.ftm-qr-panel {
  text-align: center;
  padding: 24px;
  background-color: var(--hot-color-neutral-50);
  border: 1px solid var(--hot-color-neutral-100);
  border-radius: var(--ftm-radius);
}

.ftm-qr-panel__title {
  color: var(--ftm-text);
  margin: 0 0 12px;
  font-size: var(--hot-font-size-large);
  font-family: var(--hot-font-sans-variant-condensed);
}

.ftm-qr-panel__description {
  color: var(--ftm-text-muted);
  margin: 0 0 16px;
}

.ftm-qr-panel__image-wrap {
  display: inline-flex;
  padding: 16px;
  background-color: white;
  border: 1px solid var(--ftm-border);
  border-radius: var(--ftm-radius-sm);
  margin-bottom: 16px;
}

.ftm-qr-panel__image {
  width: min(360px, 100%);
  height: auto;
}

@media (max-width: 640px) {
  .ftm-published-header {
    font-size: var(--hot-font-size-large);
  }

  .ftm-qr-panel {
    padding: 16px;
  }

  .ftm-qr-panel__image {
    width: min(280px, 100%);
  }
}

/* --- Loading / spinner ------------------------------------ */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.ftm-spinner {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
  animation: spin 1s linear infinite;
}

.ftm-spinner--lg {
  width: 32px;
  height: 32px;
  color: var(--ftm-brand);
}

.ftm-loading {
  display: none;
  text-align: center;
  padding: 20px;
}

.htmx-indicator {
  opacity: 1;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

.htmx-request.htmx-indicator {
  opacity: 1;
}

/* --- Credentials modal ------------------------------------ */
.ftm-modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--wa-color-overlay-modal);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.ftm-modal-backdrop--visible {
  display: flex;
}

.ftm-modal {
  background: white;
  padding: 30px;
  border-radius: var(--ftm-radius);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.ftm-modal__title {
  margin-top: 0;
  margin-bottom: 20px;
}

.ftm-modal__footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 10px;
}

/* --- App logo -------------------------------------------- */
.ftm-app-logo {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.ftm-app-logo--lg {
  width: 32px;
  height: 32px;
}

.ftm-app-logo--header {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* --- Private badge ---------------------------------------- */
.ftm-private-icon {
  color: var(--ftm-brand);
  margin-left: 4px;
}

/* --- Link styles ----------------------------------------- */
.ftm-link--brand {
  color: var(--ftm-brand);
  text-decoration: none;
  font-weight: var(--hot-font-weight-semibold);
}

.ftm-link--brand:hover {
  text-decoration: underline;
}
