/*
  ----------------------------------------
  Application (Global styles)
  ----------------------------------------
*/

@layer styles {
  /* Desktop nav links */
  .desktop {
    display: flex;
    position: relative;
    align-items: center;
    gap: var(--space-md);
    height: 100%;
    min-height: var(--height-md);

    .nav-link {
      position: relative;
      display: flex;
      align-items: center;
      height: 100%;
      text-decoration: none;
      color: var(--darker);
      font-weight: 600;

      &.active::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 0.25rem;
        background-color: var(--brand-1);
      }
    }
  }

  /* Mobile menu */
  .mobile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: start;
    padding-top: var(--space-md);
    gap: var(--space-sm);

    .nav-link {
      padding: var(--space-sm);
      font-size: var(--text-lg);
      font-weight: var(--font-semibold);
      text-decoration: none;
      color: var(--white);

      &:active {
        background-color: var(--brand-1);
      }
    }
  }

  .main-logo {
    display: block;
    max-width: 100%;
    height: auto;
  }

  .main-logo--header {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: 3.25rem;
    height: auto;
    object-fit: contain;
  }

  /* Crud Header (for tables, forms – also used in custom scaffolds /erb/scaffold/*) */
  .crud-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--space-2xl);
    margin-top: var(--space-sm);

    h3 {
      margin: 0;
    }
  }

  /* Stack – vertical flex containers with themed spacing */
  .stack-3xs {
    display: flex;
    flex-direction: column;
    gap: var(--space-3xs);
  }
  .stack-2xs {
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
  }
  .stack-xs {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
  }
  .stack-sm {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
  }
  .stack-md {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }
  .stack-lg {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }
  .stack-xl {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
  }

  /* Card – white surface with border, radius, and shadow */
  .card {
    background: var(--white);
    border: var(--border) solid var(--light);
    border-radius: var(--rounded-lg);
    box-shadow: var(--shadow-sm);
  }

  /* Eyebrow – small-caps label placed above a heading */
  .eyebrow {
    font-size: var(--text-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--midtone);
  }

  /* Grid display utility (complements Prewind flex utilities) */
  .grid {
    display: grid;
  }

  /* Scoped table grid borders for denser admin listings */
  .ui-table-grid {
    border-collapse: collapse;

    th,
    td {
      border-right: 1px solid var(--light);
    }

    th:last-child,
    td:last-child {
      border-right: 0;
    }
  }

  /* Extra-small border radius between none and sm */
  .rounded-xs {
    border-radius: 0.1875rem;
  }

  /* Remove border */
  .border-none {
    border: none;
  }

  /* ── Missing Prewind utilities ─────────────────────────────────────────────
     Prewind 1.2.5 omits these — defined here so views can use them freely.
  ── */

  /* Font size — xs sits below Prewind's .text-sm */
  .text-xs {
    font-size: var(--text-xs);
  }

  /* Font weight — Prewind only ships .font-normal and .font-bold */
  .font-medium {
    font-weight: var(--font-medium);   /* 500 */
  }
  .font-semibold {
    font-weight: var(--font-semibold); /* 600 */
  }

  /* Font family — monospace for IDs, codes, etc. */
  .font-mono {
    font-family: var(--font-mono);
  }

  /* Text colour utilities missing from Prewind */
  .text-darker { color: var(--darker); }
  .text-dark   { color: var(--dark); }

  /* Shadow utilities */
  .shadow    { box-shadow: var(--shadow); }
  .shadow-lg { box-shadow: var(--shadow-lg); }

  /* Border radius utilities */
  .rounded-lg { border-radius: var(--rounded-lg); }

  /* ── Bare .ui-input ─────────────────────────────────────────────────────────
     A standalone input (outside a .ui-field wrapper) that inherits the same
     height, padding, border, and radius as form builder fields.
     Used in .ui-input-group when a raw field_tag is needed.
  ── */
  .ui-input {
    height: var(--ui-field-height);
    font-size: var(--ui-field-font-size);
    padding: 0 var(--ui-field-padding);
    border: var(--ui-field-border);
    border-radius: var(--ui-field-border-radius);
    background: var(--ui-field-bg);
    color: var(--ui-field-value-color);
    width: 100%;

    &:focus {
      outline: none;
      border-color: var(--ui-field-focus-color);
      box-shadow: var(--ui-field-focus-shadow);
    }

    &::placeholder {
      color: var(--ui-field-placeholder-color);
    }
  }

  /* ── Input Group ────────────────────────────────────────────────────────────
     Attaches an input and a button side-by-side with joined borders.
     Works with .ui-input (bare input) or a .ui-field wrapper containing an input.
  ── */
  /* ── Input Group ────────────────────────────────────────────────────────────
     Lays out an input and button side-by-side with a small gap.
     Button matches the input height; all 4 corners stay rounded.
  ── */
  .ui-input-group {
    display: flex;
    align-items: center;
    gap: var(--space-xs);

    /* If form_with wraps the contents, flatten it so input+button are flex siblings */
    > form {
      display: contents;
    }

    input:not([type="checkbox"], [type="radio"]),
    .ui-field {
      flex: 1;
      min-width: 0;
      margin-bottom: 0;
    }

    /* Match button height to field height and keep all 4 corners rounded */
    .ui-button {
      height: var(--ui-field-height);
      border-radius: var(--rounded-md);
      flex-shrink: 0;
    }
  }
}
