#root {
    container-type: inline-size;
    container-name: chainlit-app;
    width: 100%;
    min-height: 100vh;
}

/* ==========================================
  NOTE: ChainlitデフォルトUIの非表示化
========================================== */
#header {
    display: none;
}

#welcome-screen {
    display: none !important;
}

.watermark {
    display: none !important;
}

.ai-message > .inline-block:first-of-type {
    display: none !important;
}

/* =========================
  NOTE: ユーザーメッセージ全体
========================= */
[data-step-type='user_message']:not(:first-of-type) {
    padding-block: 24px 0 !important;
}

[data-step-type='user_message'] .group {
    justify-content: flex-end;
}

/* =========================
  NOTE: ユーザーメッセージ吹き出し本体
========================= */
[data-step-type='user_message'] .bg-accent {
    --width: 384px;

    padding: 12px !important;
    border-radius: 12px 2px 12px 12px;
    width: var(--width) !important;
    max-height: 200px;
    overflow-y: auto;
    flex-grow: 0 !important;
    background: #ebf5ff;
    border: 1px solid #e0f0ff;
    box-shadow: 0px 0px 2px rgba(204, 204, 212, 0.1), 0px 2px 4px rgba(204, 204, 212, 0.24);
    max-width: 100% !important;
}

[data-step-type='user_message'] .bg-accent:has(.bg-accent) {
    padding: 0 !important;
}

@container chainlit-app (max-width: 360px) {
    [data-step-type='user_message'] .bg-accent {
        --width: 100%;
    }
}

/* =========================
  NOTE: メッセージのテキスト
========================= */
[role='article'] {
    font-size: 14px !important;
    line-height: 1.8 !important;
}

/* =========================
  NOTE: メッセージ編集時の確認ボタン
========================= */
.confirm-edit {
    background-color: #1f70c2 !important;

    @media (any-hover: hover) {
        &:hover {
            background-color: #175491 !important;
        }
    }
}

/* ==========================================
  NOTE: チャット入力欄
========================================== */

/* NOTE: チャット入力欄コンテナ */
#message-composer {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-end !important;
    gap: 8px !important;
    padding: 0 !important;
    min-height: 44px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* NOTE: テキストエリアのコンテナ */
#message-composer > .relative.w-full {
    flex: 1 1 auto !important;
    width: auto !important;
}

/* NOTE: テキストエリア本体 */
#chat-input {
    width: 100% !important;
    color: #333333 !important;
    background-color: #fafafa !important;
    border: 1px solid #f0f0f0 !important;
    border-radius: 6px !important;
    padding: 8px 12px !important;
    min-height: 40px !important;
    box-shadow: none !important;
    margin: 0 !important;
    outline: none !important;
    max-height: 200px !important;
    overflow-y: auto;
}

/*
 * NOTE: 初期表示の際にheightの高さが過剰に設定されてしまうケースがあるため、未入力時は高さを固定する
 */
#chat-input:placeholder-shown {
    height: 40px !important;
    overflow-y: hidden !important;
}

#chat-input:focus-within,
#chat-input:focus {
    border-color: #1f71c2 !important;
}
#chat-input::placeholder {
    color: #aaa !important;
}

/* NOTE: ボタンのコンテナ */
#message-composer > .flex.items-center.justify-between {
    flex: 0 0 40px !important;
    width: 40px !important;
    height: 40px !important;
    margin: 0 !important;
}

/*
    NOTE: uploadボタンを非表示
    uploadのみ非表示にしても、送信ボタン押下後に状態の変更によってuploadボタンが再レンダリングで一瞬表示されてしまうため、
    親要素ごと非表示にする
*/
#message-composer .flex.items-center.-ml-1\.5:has(#upload-button-input) {
    display: none !important;
}

/* NOTE: 送信ボタン本体 */
#chat-submit {
    position: static !important; /* NOTE: 絶対配置を解除してFlexに従わせる */
    width: 40px !important;
    height: 40px !important;
    background-color: #1f71c2 !important;
    border-radius: 8px !important;
    padding: 0 !important;
    /* NOTE: SVGアイコンを背景として注入 */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 12L6 18L18 12L6 6L8 12ZM8 12H12' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 24px 24px !important;
    opacity: unset !important;
}

/* NOTE: デフォルトのSVGアイコンを隠す */
#chat-submit svg {
    display: none !important;
}

/* NOTE: ボタンのホバー・非アクティブ状態 */
#chat-submit:hover {
    background-color: #175491 !important;
}

#chat-submit:disabled {
    background-color: #e8eaed !important;
    cursor: not-allowed !important;
}

/*
  NOTE:
   - メッセージ未入力時のボタン
   - chainlitのデフォルトでdisbledが付与されておりdisabled時の背景色のスタイルを上書き
*/
#message-composer:has(#chat-input:placeholder-shown) #chat-submit:disabled {
    background-color: #1f71c2 !important;
}

/* NOTE: 入力中のローディング（停止）ボタン */
#message-composer button[id*="stop"] {
    position: static !important;
    width: 40px !important;
    height: 40px !important;
    background-color: #e0f0ff !important;
    background-image: none !important;
    border-radius: 9999px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#message-composer button[id*="stop"]::after {
    content: "" !important;
    display: block !important;
    width: 12px !important;
    height: 12px !important;
    background-color: #1f71c2 !important;
    border-radius: 2px !important;
}

#message-composer button[id*="stop"] svg {
    display: none !important;
}

/* =========================
  NOTE: 以下、カスタムコンポーネント用
========================= */
.u-text {
    font-size: 14px;
    line-height: 1.8;
}

.u-text-small {
    font-size: 12px;
    line-height: 1.8;
}

.u-text-black {
    color: #222;
}

.u-text-gray {
    color: #666;
}

.u-text-emphasized {
    font-weight: 600;
}

.u-text-underline {
    text-decoration: underline;
}

/* =========================
  NOTE: 追加ボタン
========================= */
.c-add-button {
    --button-width: 56px;
    --background-color: #1f70c2;
    --label-color: #fff;
    --icon-size: 14px;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 8px 16px;
    background-color: var(--background-color);
    width: var(--button-width);
    height: 100%;
    border-radius: 0 8px 8px 0;
    font-size: 10px;
    font-weight: bold;
    color: var(--label-color);
    cursor: pointer;

    &.is-disabled {
        --background-color: #e8eaed;
        --label-color: #aaa;
        cursor: not-allowed;
    }

    &.is-loading {
        --background-color: #e5e5e5;
        --label-color: #ccd0d8;
        cursor: wait;
    }

    &.is-open {
        border-radius: 0 8px 0 0;
    }

    @media (any-hover: hover) {
        &:not(.is-disabled, .is-loading):hover {
            --background-color: #175491;
        }
    }
}

.c-add-button__icon,
.c-add-button__label,
.c-add-button__loading,
.c-add-button svg {
    pointer-events: none;
}

.c-add-button__icon {
    width: var(--icon-size);
    aspect-ratio: 1;
    display: inline-flex;
    align-items: center;
    color: inherit;

    svg path {
        fill: currentColor;
    }
}

.c-add-button__icon--completed {
    color: #666;
}

.c-add-button__label {
    color: inherit;
    line-height: 1.8;
    white-space: nowrap;
}

.c-add-button__loading {
    width: 24px;
    aspect-ratio: 1;
    color: inherit;
    animation: add-waiting 1s 0s linear infinite;
}

@keyframes add-waiting {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* =========================
  NOTE: ビデオカード, マニュアルカード
========================= */
.c-card {
    width: 100%;
    background: #fafafa;
    outline: 1px solid #e5e5e5;
    outline-offset: -1px;
    border-radius: 8px;
}

.c-card--add {
    display: grid;
    grid-template-columns: 1fr max-content;
    align-items: center;
}

.c-card__body {
    display: grid;
    grid-template-columns: 40px 1fr;
    align-items: center;
    column-gap: 16px;
    padding: 8px 16px;
}

.c-card__prefix {
    background: #f0f0f0;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.c-card__icon {
    width: 20px;
    aspect-ratio: 1;
    display: inline-flex;
    align-items: center;
    color: #666;

    svg path {
        fill: currentColor;
    }
}

.c-card__detail-row {
    line-height: initial !important;
}

/* =========================
  NOTE: コースカード
========================= */
.c-course-card {
    width: 100%;
    outline: 1px solid #e5e5e5;
    outline-offset: -1px;
    border-radius: 8px;
    background: #fafafa;
}

.c-course-card:is(.c-course-card--add) {
    position: relative;
}

.c-course-card__trigger {
    display: block;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;

    &::-webkit-details-marker {
        display: none;
    }

    .c-course-card:is(.c-course-card--add) & {
        padding-inline-end: 56px;
    }
}

.c-course-card__info {
    display: grid;
    grid-template-columns: 1fr max-content;
    align-items: center;
    column-gap: 16px;
    padding: 12px 16px;

    @container chainlit-app (max-width: 360px) {
        padding-block: 8px;
    }
}

.c-course-card__icon-list {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-block-start: 8px;
}

.c-course-card__icon-list-item {
    display: flex;
    gap: 4px;
    align-items: center;
}

.c-course-card__icon {
    width: 18px;
    aspect-ratio: 1;
    display: inline-flex;
    align-items: center;
    color: #666;

    svg path {
        fill: currentColor;
    }
}

.c-course-card__arrow {
    width: 24px;
    aspect-ratio: 1;
    display: inline-flex;
    align-items: center;
    color: #222;

    svg path {
        fill: currentColor;
    }

    &.is-open {
        transform: rotateX(180deg);
    }
}

.c-course-card__detail {
    border-top: 1px solid #e5e5e5;
    padding: 8px 16px 8px 24px;
    transform: translateY(-1px);
}

.c-course-card__detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-block: 9px;

    &:first-of-type {
        padding-block-start: 0;
    }

    &:last-of-type {
        padding-block-end: 0;
    }

    &:not(:last-of-type) {
        border-bottom: 1px solid #e5e5e5;
    }
}

.c-course-card__link {
    flex-grow: 1;
}

.c-course-card__add {
    position: absolute;
    top: 1px;
    right: 1px;
}

/* =========================
  NOTE: 回答コンテナ
========================= */
.c-answer-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* =========================
  NOTE: 選択肢ボタン
========================= */
.c-choice-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.c-choice-button {
    --choice-background-color: #f7f7f7;
    --choice-stroke-color: #d4d4d4;
    --choice-stroke-width: 1px;
    --choice-label-color: #444;

    background: var(--choice-background-color);
    border: 1px solid var(--choice-stroke-color);
    border-radius: 8px;
    padding: 7px 8px;
    font-size: 12px;
    font-weight: 600;
    max-width: 100%;
    text-align: left;
    color: var(--choice-label-color);

    &.is-disabled {
        --choice-stroke-color: #f0f0f0;
        --choice-label-color: #d4d4d4;

        cursor: not-allowed;
    }

    @media (any-hover: hover) {
        &:not(.is-disabled):hover {
            --choice-background-color: #d4d4d4;
            --choice-stroke-width: 0;
        }
    }
}

.c-choice-button__label {
    color: inherit;
}

/* =========================
  NOTE: カードリスト
========================= */
.c-card-list {
    padding: 24px 16px;
    background: #f0f0f0;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.c-card-list__list {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* =========================
  NOTE: まとめて追加ボタン
========================= */
.c-bulk-add-button {
    --background-color: #1f70c2;
    --label-color: #fff;
    --icon-size: 12px;

    display: flex;
    width: 100%;
    justify-content: center;
    align-items: center;
    gap: 4px;
    color: var(--label-color);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background-color: var(--background-color);
    border-radius: 9999px;
    padding-block: 8px;

    &.is-disabled {
        --background-color: #e5e5e5;
        --label-color: #ccd0d8;
        cursor: not-allowed;
    }

    &.is-loading {
        --background-color: #e5e5e5;
        --label-color: #ccd0d8;
        cursor: wait;
    }

    @media (any-hover: hover) {
        &:not(.is-disabled, .is-loading):hover {
            --background-color: #175491;
        }
    }
}

.c-bulk-add-button__icon {
    width: var(--icon-size);
    aspect-ratio: 1;
    display: inline-flex;
    align-items: center;
    color: inherit;

    svg path {
        fill: currentColor;
    }
}

.c-bulk-add-button__loading {
    width: 20px;
    aspect-ratio: 1;
    color: inherit;
    animation: add-waiting 1s 0s linear infinite;
}

.c-bulk-add-button__label {
    color: inherit;
}

/* =========================
  NOTE: セグメンテッドコントロール
========================= */
.c-segmented-control-list {
    max-width: 100%;
    width: 100%;
}

.c-segmented-control-list__inner {
    display: grid;
    grid-template-columns: repeat(2, 50%);
    align-items: center;
    background: #f7f7f7;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    gap: 2px;
    overflow: hidden;
}

.c-segmented-control-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: #666;
    border-radius: 8px;
    padding: 4px 8px;
    line-height: 1.8;
    letter-spacing: calc(14px * 0.06);

    &:not(.is-disabled):hover,
    &:not(.is-disabled).is-current {
        background: #fff;
        box-shadow:
            0 3px 8px 0 rgba(#000, 0.2),
            0 0 1px 0 rgba(#000, 0.3)
    }

    &.is-disabled {
        color: #aaa;
        cursor: auto;
    }
}

.c-segmented-control-button__label {
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.8;
    font-size: 14px;
}

/* =========================
  NOTE: Heading
========================= */
.c-heading {
    display: block;
    margin: 0;
    padding: 0;
    font-weight: 600;
    line-height: 1.5;
    font-size: 16px;
    letter-spacing: calc(16px * 0.06);
}

/* =========================
  NOTE: Paragraph
========================= */
.c-paragraph {
    font-size: 14px;
    line-height: 180%;
    letter-spacing: calc(14px * 0.04);
}

/* =========================
  NOTE: ローディングアイコン
========================= */
.c-loading-icon {
    display: flex;
    align-items: center;
    gap: 2px;
    width: 24px;
    height: 24px;
}

.c-loading-icon__dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #ccd0d8;
    animation: loading-bounce 1.2s ease-in-out infinite;
}

.c-loading-icon__dot:nth-child(1) {
    animation-delay: 0;
}

.c-loading-icon__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.c-loading-icon__dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes loading-bounce {
    0%,
    60%,
    100% {
        transform: translateY(0);
        background: #ccd0d8;
    }

    30% {
        transform: translateY(-2px);
        background: #9aa2b1;
    }
}
