@layer reset, base, components, utilities;

@layer base {
  html {
    font-size: 100%;

    @media (min-width: 100ch) {
      font-size: 1.1875rem;
    }
  }

  body {
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: none;
    background-color: var(--color-bg-white);
    color: var(--color-text);
    font-family: var(--font-sans);
    interpolate-size: allow-keywords;
    line-height: 1.375;
    max-inline-size: 100vw;
    scroll-behavior: auto;
    text-rendering: optimizeLegibility;
    text-size-adjust: none;
  }

  a {
    text-decoration: none;

    &:not([class]) {
      color: var(--color-link);
      text-decoration: underline;
      text-decoration-skip-ink: auto;
    }
  }

  :is(a, button, input, textarea, .switch, .btn) {
    transition: 100ms ease-out;
    transition-property: background-color, border-color, box-shadow, filter, outline;
    touch-action: manipulation;

    /* Keyboard navigation */
    &:where(:focus-visible) {
      border-radius: 0.25ch;
      outline: var(--focus-ring-size) solid var(--focus-ring-color);
      outline-offset: var(--focus-ring-offset);
    }

    /* Default disabled styles */
    &:where([disabled]) {
      cursor: not-allowed;
      opacity: 0.5;
      pointer-events: none;
    }
  }

  :where(ul, ol):where([role="list"]) {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  kbd {
    border: 1px solid;
    border-radius: 0.3em;
    box-shadow: 0 0.1em 0 currentColor;
    font-family: var(--font-mono);
    font-size: var(--text-xx-small);
    color: var(--color-muted);
    font-weight: 600;
    opacity: 0.7;
    padding: 0 0.4em;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;
  }

  turbo-frame {
    display: contents;
  }

  .turbo-progress-bar {
    visibility: hidden;
  }

  /* Form inputs - dark mode support */
  input,
  textarea,
  select {
    background: var(--color-bg-white);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.75rem;
    transition: border-color 0.2s;

    &:focus {
      outline: none;
      border-color: var(--color-primary);
    }

    &::placeholder {
      color: var(--color-muted);
    }

    &[type="checkbox"],
    &[type="radio"] {
      /* Checkboxes and radios keep browser default styling */
      background: transparent;
      padding: 0;
      width: auto;
      height: auto;
    }
  }

  /* Specific adjustments for search inputs */
  input[type="search"] {
    background: var(--color-bg-white);
    color: var(--color-text);
  }
}

@layer components {
  /* Page container - Full height wrapper for all pages */
  .page-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: var(--main-width);
    margin: 0 auto;
    padding: var(--main-padding);
    overflow: hidden;
    box-sizing: border-box;
  }

  /* Page content - Scrollable content area within container */
  .page-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
  }

  /* Footer styles */
  footer {
    flex-shrink: 0;
    width: 100%;
    text-align: center;
    padding: 1.5rem 1rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-light);

    small {
      font-size: var(--text-x-small);
      color: var(--color-text-light);
    }
  }
}

@layer utilities {
  /* Display */
  .hidden { display: none !important; }
  .d-none { display: none !important; }
  .no-scroll { overflow: hidden !important; }
  .offscreen { position: fixed; opacity: 0; pointer-events: none; }
  .disabled-look { opacity: 0.4; }

  .hide-on-touch {
    @media (any-hover: none) {
      display: none;
    }
  }

  .show-on-touch {
    display: none;

    @media (any-hover: none) {
      display: unset;
    }
  }

  /* Sizing */
  .full-width { inline-size: 100%; }
  .min-width { min-inline-size: 0; }
  .half-width { inline-size: 50%; }
  .max-width { max-inline-size: 100%; }
  .min-content { inline-size: min-content; }
  .fit-content { inline-size: fit-content; }
  .max-inline-size { max-inline-size: 100%; }

  /* Icon sizes */
  .icon-xs { width: 16px; height: 16px; }
  .icon-sm { width: 20px; height: 20px; }
  .icon-md { width: 24px; height: 24px; }
  .icon-lg { width: 32px; height: 32px; }

  /* Flexbox utilities */
  .flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .flex-items-center {
    display: flex;
    align-items: center;
  }
}
