:root {
    --font-family: "Lucida Grande", "Hiragino Kaku Gothic ProN", "ヒラギノ角ゴ ProN W3", Meiryo, メイリオ, sans-serif;
    --theme-primary: #ffa600;
    --theme-primary-light: #fff2db;
    --theme-primary-dark: #ee9b00;
    --text-primary: #242424;
    --text-secondary: #434343;
    --text-light: #fafafa;
    --text-accent: #004cee;
    --bg-primary: #f9fafb;
    --bg-secondary: #efefef;
    --bg-tertiary: #e5e7eb;
    --bg-accent: #dbe6ff;
    --bg-dark: #434343;
    --bg-light: #fafafa;
    --color-white: #fff;
    --disabled: #979797;
    --border: #cdcfd3;
}

* {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    box-sizing: border-box;
}

[v-cloak] {
  visibility: hidden;
}

body {
    height: 100vh;
    font-size: 10pt;
    align-items: center;
    background-color: var(--bg-secondary);
}

button {
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

/* ダイアログ */
dialog {
    padding: 0;
    top: 50%;
    left: 50%;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--bg-primary);
    box-shadow: 1px 1px 2px #333;
    position: fixed;
    transform: translate(-50%, -50%);
}

dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.8);
    cursor: pointer;
}

dialog h1 {
    margin: 10px;
    color: var(--text-primary);
    font-size: 18pt;
    font-weight: bold;
    border-bottom: 2px solid var(--theme-primary);
}

dialog p {
    margin: 0 20px;
}

dialog textarea {
    margin: 10px 20px 0;
    width: -webkit-fill-available;
    width: -moz-available;
}

dialog button {
    margin: 0 10px;
    padding: 0.4rem 0.6rem;
    min-width: 120px;
    color: var(--text-primary);
    border: none;
    border-radius: 4px;
    box-shadow: 0 0 4px -3px rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

dialog button.button-blue {
    color: var(--text-light);
    background-color: var(--theme-primary);
}
dialog button.button-blue:hover {
    filter: brightness(1.1);
}
dialog button.button-blue:active {
    filter: brightness(.9);
}

dialog button.button-gray {
    background-color: var(--bg-secondary);
}
dialog button.button-gray:hover {
    filter: brightness(1.1);
}
dialog button.button-gray:active {
    filter: brightness(.9);
}

dialog .buttons-row {
    margin: 20px 10px;
    display: flex;
    justify-content: center;
}

.chat-app {
    width: 100%;
    /* max-width: 420px; */
    height: 100vh;
    background-color: var(--color-white);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 8px 12px 6px;
    color: var(--color-white);
    gap: 12px;
    align-items: center;
    display: flex;
    justify-content: space-between;
    background-color: var(--theme-primary);
}

.chat-header button {
    margin-right: 20px;
    padding: 8px 12px;
    color: var(--theme-primary);
    font-weight: bold;
    cursor: pointer;
    border: none;
    border-radius: 10px;
    background-color: var(--color-white);
    transition: filter .3s;
    
    &:hover {
        filter: brightness(.95);
        transition: filter .3s;
    }
    &:active {
        filter: brightness(.9);
        transition: filter .1s;
    }
}

.chat-header .header-info {
    -webkit-user-select: none;
    user-select: none;
    min-width: 0;

    & h1 {
        min-width: 0;
        font-size: 10pt;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    & span {
        font-size: 8pt;
        opacity: 0.8;
    }
}

.chat-body {
    flex: 1;
    padding: 8px;
    padding-bottom: 20px;
    overflow-y: auto;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    gap: 12px;
    overscroll-behavior: contain;
}

.message {
    display: flex;
}

.message.received {
    justify-content: flex-start;
}

.message.sent {
    justify-content: flex-end;
}

.avatar {
    width: 28px;
    height: 28px;
    color: var(--text-light);
    font-weight: bold;
    align-items: center;
    display: flex;
    flex-shrink: 0;
    justify-content: center;
    border-radius: 50%;
    background-color: attr(data-bg-color type(<color>), var(--bg-tertiary));

    & img {
        margin-top: 8px;
        width: 30px;
        border-radius: 50%;
        -webkit-user-select: none;
        user-select: none;
    }
}

.content {
    margin: 0 4px;
    display: flex;
}

.received .content {
    flex-direction: column;
    justify-content: flex-start;
}

.sent .content {
    flex-direction: row;
    justify-content: flex-end;
}

.content-header {
    display: flex;
    align-items: end;

    & .name {
        margin: 0 4px;
    }

    & .time {
        margin-left: 6px;
        font-size: .725rem;
        color: var(--text-secondary);
    }

    & .info {
        margin-right: 6px;
        font-size: .725rem;
        color: var(--text-secondary);
        -webkit-user-select: none;
        user-select: none;
    }
}

.bubble {
    width: clamp(100px, 40vw, 250px);
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    word-break: break-word;
}

.received .bubble {
    color: var(--text-primary);
    border-top-left-radius: 6px;
    background-color: var(--bg-tertiary);

    &::selection {
        color: var(--text-light);
        background-color: var(--bg-dark);
    }
}

.sent .bubble {
    color: var(--text-primary);
    border-bottom-right-radius: 6px;
    background-color: var(--theme-primary-light);

    &::selection {
        color: var(--text-accent);
        background-color: var(--bg-accent);
    }
}

.thread-info {
    width: 100%;
    text-align: center;

    & small {
        font-size: .725rem;
    }
}

.chat-indication {
    padding: 4px 6px;
    width: 100%;
    font-size: .825rem;
    left: 0;
    bottom: 60px;
    display: flex;
    position: absolute;
    background-color: var(--theme-primary-light);
    overflow: hidden;
    opacity: 0;
    transition: opacity .3s;

    & li {
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    &.show {
        opacity: .8;
        transition: opacity .3s;
    }

    &.dark {
        background-color: var(--bg-dark);
        color: var(--text-light);
        opacity: .8;
        transition: opacity 0s;
    }
}

.chat-input-area {
    padding: 4px 8px;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: flex-end;
    border-top: 1px solid var(--bg-tertiary);
    background-color: var(--color-white);
    position: relative;
}

.chat-input-area textarea {
    padding: 12px 20px 12px 12px; /* オーバーレイと合わせる */
    width: 100%;
    /* 行の高さは１～３行分に制限する */
    min-height: 44px;
    max-height: 108px;
    color: transparent;
    font-size: 14px;
    line-height: 1.5;
    caret-color: var(--text-primary);
    flex: 1 1 auto;
    border: none;
    background-color: transparent;
    overflow-y: auto;
    outline: none;
    resize: none;
    box-sizing: border-box;
    position: relative;
    z-index: 2;

    &:disabled {
        background-color: var(--disabled);
        cursor: not-allowed;
    }
}

.chat-input-area button {
    padding: 12px 16px;
    color: white;
    font-weight: bold;
    line-height: 28px;
    white-space: nowrap;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background-color: var(--theme-primary);
    transition: filter .3s;
    
    &:hover {
        filter: brightness(1.1);
        transition: filter .3s;
    }
    &:active {
        filter: brightness(.9);
        transition: filter .1s;
    }

    &:disabled {
        filter: brightness(.6);
        cursor: not-allowed;
    }
}

/* メンション候補のポップアップ表示 */
.mention-popup {
    position: absolute;
    bottom: 100%;
    left: 6px;
    width: 260px;
    background-color: var(--color-white);
    border: 1px solid var(--bg-tertiary);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    z-index: 50;
}

.mention-popup ul {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    max-height: 30vh;
    overflow-y: auto;
}

.mention-popup li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    
    &.selected {
        background-color: var(--theme-primary-light);
    }
}

.mention-avatar {
    width: 28px;
    height: 28px;
    color: var(--text-light);
    font-weight: bold;
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: attr(data-bg-color type(<color>), var(--bg-tertiary));
}

.mention-name {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.mention-popup li:hover {
    background-color: var(--theme-primary-light);
}

/* 入力ボックス内でメンションをハイライトするためのオーバーレイ表示 */
.input-wrapper {
    min-width: 0;
    flex: 1 1 auto;    
    border: 1px solid var(--border);
    border-radius: 10px;
    position: relative;
    overflow: hidden;

    &:has(textarea:focus) {
        border-color: var(--theme-primary);
    }
}

.input-overlay {
    position: absolute;
    max-height: 10ch;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 20px 12px 12px; /* 入力ボックスと合わせる */
    pointer-events: none;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    box-sizing: border-box;
    z-index: 1;
}

.input-overlay .mention {
    color: var(--theme-primary);
    background-color: none;
    padding: 0;
    border-radius: 0;
    display: inline;
}

.bubble .mention {
    padding: 0;
    color: var(--theme-primary-dark);
    border-radius: 0;
    background-color: transparent;
}

.receive .bubble .mention {
    color: var(--theme-primary-dark);
}
.sent .bubble .mention {
    color: var(--theme-primary-dark);
}
.bubble .mention-self {
    margin-right: 6px;
    padding: 0 4px;
    color: var(--text-light);
    border-radius: 6px;
    background-color: var(--theme-primary-dark);
}

/* ローディング */
.loading-container {
    padding: 0 10px;
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}
.loading-dots {
    margin: 30px auto;
    width: 10px;
    height: 10px;
    color: var(--theme-primary);
    border-radius: 5px;
    background-color: var(--theme-primary);
    position: relative;
    animation: dots 1s infinite linear alternate;
    animation-delay: .5s;
  }

  .loading-dots::before, .loading-dots::after {
    content: '';
    top: 0;
    position: absolute;
    display: inline-block;
  }

  .loading-dots::before {
    width: 10px;
    height: 10px;
    left: -15px;
    color: var(--theme-primary);
    border-radius: 5px;
    background-color: var(--theme-primary);
    animation: dots 1s infinite alternate;
    animation-delay: 0s;
  }

  .loading-dots::after {
    width: 10px;
    height: 10px;
    left: 15px;
    color: var(--theme-primary);
    border-radius: 5px;
    background-color: var(--theme-primary);
    animation: dots 1s infinite alternate;
    animation-delay: 1s;
  }

  @keyframes dots {
    0% {
      background-color: var(--theme-primary);
    }
    50%,
    100% {
      background-color: var(--theme-primary-light);
    }
  }

.loading-spinner {
    margin: 4px;
    width: 14px;
    height: 14px;
    top: 50%;
    border: 4px solid var(--theme-primary-light);
    border-top-color: var(--theme-primary);
    border-radius: 50%;
    position: relative;
    animation: spinner 1.2s infinite cubic-bezier(.52, .26, .38, .74);
}

@keyframes spinner {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
/* ローディングここまで */