/* app.css - Application Components (CSS Nesting)
 * ===============================================
 * MODERNIZED: Uses native CSS nesting (baseline 2023, 96%+ support)
 */

@layer states {
  .reaction-button {

    &:hover,
    &:focus-visible {
      transform: translateY(-1px);
      border-color: var(--color-accent);
      box-shadow: 0 6px 16px var(--shadow-accent-alt);
      outline: none;
    }
  }
}

@layer components {

  /* SVG sprite icons: <svg class="icon"><use href="...#icon-name"/></svg> */
  svg.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
    flex: 0 0 auto;
    vertical-align: -0.125em;
    fill: currentColor;
    pointer-events: none;
  }

  :where(.field.checkbox, .chat-log, .chat-log-list) {
    display: flex;
    gap: var(--size-2);
  }

  :where(.flash) {
    padding: var(--size-2);
  }

  /* ========================================
     ICON BUTTON - All states nested
     ======================================== */
  .icon-btn {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 1rem;
    border: var(--border-width) solid transparent;
    background: var(--veil-2);
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    text-decoration: none;
    transition:
      background 0.2s var(--motion-snappy),
      border-color 0.2s var(--motion-snappy);

    &:hover {
      background: var(--veil-8);
      border-color: var(--veil-15);
    }

    &.is-active {
      background: var(--accent-veil-15);
      color: var(--color-accent);
      border-color: var(--accent-veil-35);
    }

    &:focus-visible {
      outline: 2px solid var(--color-accent);
      outline-offset: 2px;
      background: var(--accent-veil-35);
    }

    /* Large variant: 3rem (48px) for prominent actions */
    &.large {
      width: 3rem;
      height: 3rem;

      & svg.icon {
        font-size: 1.5rem;
      }
    }

    /* Ghost variant: transparent background */
    &.ghost {
      background: transparent;

      &:hover {
        background: var(--veil-8);
      }
    }
  }

  /* Mobile message actions - Maintain 44px touch targets via padding */
  @media (max-width: 640px) {
    .message-actions {
      opacity: 1;
    }

    /* Visual size can be smaller, but touch target via padding stays 44px */
    .msg-action-btn {
      width: 1.75rem;
      height: 1.75rem;
      /* Extend touch target with padding - actual clickable area is 44px */
      padding: calc((2.75rem - 1.75rem) / 2);
      margin: calc((2.75rem - 1.75rem) / -2);
    }
  }

  /* ========================================
     FORM ELEMENTS
     ======================================== */
  fieldset {
    border: none;
    margin: 0;
    padding: 0 0 var(--size-3);
  }

  legend {
    font-weight: 600;
    margin-bottom: var(--size-2);
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: var(--size-1);
    margin-bottom: var(--size-3);
    font-size: 0.95rem;

    & input,
    & select {
      padding: 0.85rem 1rem;
      border-radius: var(--radius-sm);
      border: var(--border-width) solid var(--border);
      background: var(--bg-surface-alt);
      color: var(--color-text);
    }

    &.checkbox {
      flex-direction: row;
      align-items: center;
    }
  }

  .chat-input {
    height: 2.75rem;
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border);
    background: var(--bg-surface);
    color: var(--color-text);
    width: 100%;
    min-width: 0;

    &:focus-visible {
      outline: 2px solid var(--color-accent);
      outline-offset: 2px;
    }
  }

  /* ========================================
     BUTTONS - CTA and Ghost
     ======================================== */
  .cta {
    width: 100%;
    padding: 0.95rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--color-accent);
    color: var(--color-on-accent, #fff);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 12px 24px var(--accent-veil-35);
    transition: box-shadow 0.2s var(--motion-snappy);

    &:hover {
      background: var(--color-accent-alt);
      color: var(--color-on-accent);
      transform: translateY(-2px);
      box-shadow: 0 16px 32px var(--shadow-accent-alt);
    }
  }

  .ghost {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    border: 2px solid var(--veil-8);
    background: var(--veil-2);
    color: var(--color-text);
    cursor: pointer;
    transition:
      background 0.2s var(--motion-snappy),
      border-color 0.2s var(--motion-snappy);

    &:hover {
      background: var(--veil-8);
      border-color: var(--veil-30);
    }

    &.is-active {
      background: var(--veil-8);
      border-color: var(--veil-30);
    }
  }

  .flash {
    border-radius: var(--radius-sm);
    margin-top: var(--size-2);
  }

  /* ========================================
     ROOM SHELL - Layout container
     ======================================== */
  .room-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: visible;
    gap: 0;
    padding: 0;

    &.media-focus {
      & .app-sidebar {
        display: none;
      }

      & .chat-log {
        padding: var(--size-4);
      }

      & .user-id-card {
        display: none;
      }

      @media (width <=640px) {
        & .composer-bar {
          display: none;
        }
      }
    }

    &.nudge-animation {
      animation: nudge-shake 0.5s ease-in-out;
    }

    @media (width <=960px) {
      flex-direction: column;
    }

    @media (width <=768px) {
      gap: var(--size-3);
    }
  }

  /* ========================================
     HEADER ELEMENTS
     ======================================== */
  .header-actions {
    display: inline-flex;
    gap: 0.2rem;
    flex-wrap: wrap;
    align-items: center;
  }

  .header-icon {
    font-size: 20px;
    width: 20px;
    height: 20px;
    line-height: 1;
    display: inline-block;
  }

  .header-extras {
    font-family: var(--font-mono);
    font-size: var(--font-size-0);
    color: var(--text-2);

    & span {
      display: inline-block;
      min-width: 5ch;
      text-align: right;
      font-variant-numeric: tabular-nums;
    }
  }

  .brand-tagline {
    font-weight: 400;
    opacity: 0.7;
    font-size: 0.9em;
  }

  /* ========================================
     USER ID CARD
     ======================================== */
  .user-id-card {
    margin: var(--size-3);
    padding: var(--size-3);
    border-radius: var(--radius-md);
    border: 2px dashed var(--accent-veil-35);
    background: var(--accent-veil-15);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--size-3);
    flex-wrap: wrap;
    box-shadow: inset 0 0 0 1px var(--veil-4);
  }

  .pill {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: var(--color-surface);
    border: 1px solid var(--veil-12);
    font-size: 0.8rem;
    color: var(--color-text);
  }

  .room-key-value {
    user-select: all;
    background: var(--surface-3);
    padding: 0.2em 0.5em;
    border-radius: var(--radius-1);
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-1);
  }

  /* ========================================
     FOOTER ELEMENTS
     ======================================== */
  .main-relative {
    position: relative;
  }

  .footer-relative {
    position: relative;
    overflow: hidden;
  }

  .footer-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--size-3);
    flex-wrap: wrap;
    height: 100%;
    padding: 0 var(--size-3);
    font-size: 0.85rem;
    color: var(--color-muted);
    transition: opacity 0.2s;
  }

  .footer-nav {
    display: flex;
    gap: var(--size-2);
  }

  .footer-link {
    color: inherit;
    text-decoration: none;
  }

  .footer-hover-overlay {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    left: auto;
    bottom: auto;
    width: auto;
    max-width: calc(100vw - 3rem);
    min-width: 200px;
    padding: var(--size-3) var(--size-4);
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-2);
    box-shadow: var(--shadow-4);
    display: flex;
    align-items: center;
    gap: var(--size-2);
    font-weight: 600;
    font-size: 0.95rem;
    z-index: 1000;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  /* Variant colors based on statusTone */
  .footer-hover-overlay[data-tone="success"] {
    border-left: 4px solid var(--success);
  }

  .footer-hover-overlay[data-tone="error"] {
    border-left: 4px solid var(--danger);
  }

  .footer-hover-overlay[data-tone="info"] {
    border-left: 4px solid var(--primary);
  }

  .footer-hover-overlay[data-tone="warn"] {
    border-left: 4px solid var(--warning);
  }

  /* ========================================
     UTILITY ELEMENTS
     ======================================== */
  .vertical-divider {
    width: 1px;
    height: 16px;
    background: var(--border);
  }

  .room-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .room-name {
    color: var(--text-muted);
  }

  .flex-spacer {
    flex: 1;
  }

  .peer-count-badge {
    font-weight: 700;
    font-size: 0.9rem;
    font-family: var(--font-mono);
  }

  .upload-form-hidden {
    display: none;
  }

  .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-3);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

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

  .spin {
    animation: spin 1s linear infinite;
  }

  .empty-state-icon {
    font-size: 3rem;
    color: var(--veil-20);
  }

  .loading-center {
    text-align: center;
    padding: 1rem;
  }

  .welcome-cta {
    width: auto;
    display: inline-block;
  }

  /* ========================================
     REACTION PICKER
     ========================================
     NOTE: Styles moved to reaction-picker.webc component (webc:scoped).
     Visibility now controlled via Alpine x-show + props from parent,
     NOT via parent CSS selectors (proper component encapsulation).
     See: frontend/_components/chat/reaction-picker.webc
     ======================================== */

  /* ========================================
     MEDIA QUERIES - Component-level responsive
     ======================================== */
  @media (width <=768px) {

    :where(.app-sidebar, .app-main, .app-header, .app-footer,
      .modal-panel, input, select, textarea, button,
      .icon-btn, .chat-bubble) {
      border-width: 2px;
    }

    :where(.icon-btn:hover, input:focus, button:hover, .cta:hover) {
      border-color: var(--primary);
    }

    .upload-form {
      display: none;
    }
  }
} /* End first @layer components block */

/* ========================================
   PANEL STYLES - Component styles
   ======================================== */
@layer components {
  
  /* Small popover panel (e.g. Filter dropdown)
     Uses HTML5 popover attribute - goes to browser's top layer (no z-index needed) */
  .action-panel {
    background: var(--bg-panel);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-panel);
    padding: 1rem;
    box-shadow: var(--shadow-pop);
    width: 260px;
    gap: 0.5rem;
  
    /* Popover: Only apply display:flex when open (preserve native display:none for closed) */
    &[popover] {
      position: fixed;
      top: 5rem;
      right: 1rem;
      margin: 0;
      /* Override browser default popover margin */
    }
  
    &[popover]:popover-open {
      display: flex;
      flex-direction: column;
    }
  
    /* Non-popover usage (legacy) */
    &:not([popover]) {
      display: flex;
      flex-direction: column;
    }
  
    /* Popover backdrop (mobile only - subtle dim) */
    &[popover]::backdrop {
      background: rgb(0 0 0 / 30%);
      backdrop-filter: blur(2px);
  
      @media (min-width: 769px) {
        background: transparent;
        backdrop-filter: none;
      }
    }
  
    & h3 {
      margin-bottom: 0.5rem;
      font-size: 1rem;
      border-bottom: 1px solid var(--border);
      padding-bottom: 0.25rem;
    }
  
    & .close-btn {
      width: 2.25rem;
      height: 2.25rem;
      border-radius: 999px;
    }
  }
  
  .panel-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--size-2);
  }
  
  /* Mobile modal panel height constraint */
  @media (max-width: 768px) {
    .modal-panel {
      max-height: calc(100vh - 6rem - env(safe-area-inset-bottom, 0px));
      max-height: calc(100dvh - 6rem - env(safe-area-inset-bottom, 0px));
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }
  }
  
  /* Panel CTA buttons */
  .panel .cta,
  .panel .primary,
  .modal-panel .cta,
  .modal-panel .primary {
    background: var(--blue-6);
    color: #fff;
    border-color: var(--blue-6);
    font-weight: 600;
    opacity: 1;
  
    &:hover {
      background: var(--blue-7);
      border-color: var(--blue-7);
    }
  
    &.small {
      padding: var(--size-2) var(--size-3);
    }
  }
  
  /* ========================================
     UX IMPROVEMENTS
     ======================================== */
  
  /* Search Highlighting */
  .search-highlight {
    background: var(--yellow-3);
    color: var(--gray-9);
    padding: 0 2px;
    border-radius: 2px;
  }
  
  /* Read Receipts - Blue for Read */
  .message-status .status-read {
    color: var(--blue-6);
  }
  
  /* Swipe to Reply Visual Feedback */
  .chat-entry {
    transition: transform 0.2s ease;
  
    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%) translateX(-100%);
      width: 2rem;
      height: 2rem;
      background: var(--primary);
      border-radius: var(--radius-round);
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.15s ease;
    }
  
    &[style*="translateX"] {
      position: relative;
    }
  }
  
  /* Chat Log Position Relative for Jump Button */
  .chat-log {
    position: relative;
  }
  
  /* ========================================
     LINK PREVIEWS & MENTIONS
     ======================================== */
  .message-link {
    color: var(--blue-6);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
  
    &:hover {
      color: var(--blue-7);
      text-decoration-style: solid;
    }
  }
  
  .mention {
    background: var(--blue-1);
    color: var(--blue-7);
    padding: 0 4px;
    border-radius: var(--radius-1);
    font-weight: 500;
  
    &.mention-self {
      background: var(--yellow-2);
      color: var(--yellow-9);
    }
  }
  
  /* Delete Button - Danger Style */
  .msg-action-btn--danger:hover {
    background: var(--red-1);
    color: var(--red-6);
  }
  
  /* ========================================
     PEER ANIMATIONS
     ======================================== */
  @keyframes nudge-shake {
  
    0%,
    100% {
      transform: translateX(0);
    }
  
    10%,
    30%,
    50%,
    70%,
    90% {
      transform: translateX(-4px);
    }
  
    20%,
    40%,
    60%,
    80% {
      transform: translateX(4px);
    }
  }
  
  
  /* Mobile view content spacing fix */
  @media (max-width: 480px) {
    .view-content {
      padding: var(--size-2) var(--size-3) !important;
  }
}} /* End second @layer components block */
