/* ============================================
   Admin Modal Dialogs
   ============================================ */
@layer components {
  .turbo-modal {
    .turbo-modal__dismiss, .turbo-modal__loading {
      display: none;
    }
    &:has(turbo-frame[aria-busy]) {
      .turbo-modal__loading {
        display: block;
        padding: 2rem;
        padding-top: 0;
        background-color: var(--color-bg);
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
        width: 90%;
        max-width: 500px;
        /* spinner中央寄せ */
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    &:has(.turbo-modal__content), &:has(turbo-frame[aria-busy]) {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.5);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      z-index: 1000;

      .turbo-modal__dismiss, turbo-frame:has(.turbo-modal__content) {
        width: 90%;
        max-width: 500px;
        margin: 0 auto;
      }
      .turbo-modal__dismiss {
        padding: 0;
        padding-right: 1rem;
        background-color: var(--color-bg);
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
        cursor: pointer;
        display: block;
        font-size: 2rem;
        text-align: right;
      }
      .turbo-modal__content {
        display: block;
        padding: 2rem;
        padding-top: 0;
        background-color: var(--color-bg);
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
        max-height: 80vh;
        overflow-y: auto;

        & h1 {
          margin-top: 0;
          margin-bottom: 1.5rem;
        }

        & form > div {
          margin-bottom: 1rem;
        }

        & label {
          display: block;
          margin-bottom: 0.25rem;
          font-weight: 500;
        }

        & input[type="text"],
        & input[type="url"],
        & input[type="datetime-local"] {
          width: 100%;
          padding: 0.5rem;
          border: 1px solid #ced4da;
          border-radius: 4px;
        }

        /* Markdown table styles */
        & .article-body table {
          border-collapse: collapse;
          width: 100%;
          margin: 1rem 0;
        }

        & .article-body table th,
        & .article-body table td {
          border: 1px solid #dee2e6;
          padding: 0.5rem;
          text-align: left;
        }

        & .article-body table th {
          background-color: #f8f9fa;
          font-weight: 600;
        }
      }
      .turbo-modal__actions {
        margin-top: 1.5rem;
        display: flex;
        flex-direction: column;
        text-align: right;
        gap: 1rem;
      }
      @media (prefers-color-scheme: dark) {
        .turbo-modal__dismiss, .turbo-modal__loading, .turbo-modal__content {
          background-color: var(--color-bg-secondary);
          color: var(--color-text);
        }
        .turbo-modal__loading, .turbo-modal__content {
          & input[type="text"],
          & input[type="datetime-local"] {
            background-color: var(--color-bg);
            color: var(--color-text);
            border: 1px solid var(--color-border);
          }

          /* Dark mode table styles */
          & .article-body table th,
          & .article-body table td {
            border-color: var(--color-border);
          }

          & .article-body table th {
            background-color: var(--color-bg-tertiary);
          }
        }
      }
    }
  }
}
