:root {
    --input-primary-color: #242b7d;
    --scrollbar-track: #3a3a3c;
    --scrollbar-thumb: #b5b5b5;
    --scrollbar-thumb-hover: #898989;
}

body {
    padding-top: 0px;
    margin: 0px;
    background-color: #2b2b2d;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

div {
    box-sizing: border-box;
}

#header {
    box-shadow: none;
    background-color: transparent;
}

#apps {
    span {
        color: #cecece;
    }
}

#title {
    color: #cecece;
}

h1,
p {
    color: #cecece;
}

.main-container {
    width: 100vw;
    height: calc(100vh - 60px);
    position: fixed;
    top: 60px;
    left: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
}

/* スマホ対応: 画面幅が768px以下の場合 */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 60px;
        left: -250px;
        width: 250px;
        height: calc(100vh - 60px);
        z-index: 1000;
        background-color: #2b2b2d;
        transition: transform 0.3s ease;
        border-right: 2px solid #323232;
    }

    .sidebar.mobile-open {
        transform: translateX(250px);
    }

    .main-view {
        width: 100%;
        margin: 0;
        border-radius: 0;
    }

    /* モバイル用サイドバー切り替えボタン */
    .mobile-sidebar-toggle {
        position: fixed;
        top: 70px;
        left: 10px;
        z-index: 1001;
        width: 40px;
        height: 40px;
        background-color: #323232;
        border: none;
        border-radius: 50%;
        color: #cecece;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .mobile-sidebar-toggle:hover {
        background-color: #58585b;
    }

    /* サイドバーオーバーレイ */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

.sidebar {
    min-width: 250px;
    background-color: transparent;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;

    .new-chat {
        margin: 0;
        outline-color: #cccbd4;
        position: relative;

        p {
            color: #cccbd4;
        }

        .left {
            margin: 0 5px 0 0;
            vertical-align: middle;
        }
    }

    .shortcuts {
        flex-grow: 1;
        overflow: auto;

        .container {
            display: flex;
            flex-direction: column;
            align-items: stretch;

            .shortcut-section {
                font-weight: 600;
                user-select: none;
            }

            .shortcuts-list {
                display: flex;
                align-items: stretch;
                flex-direction: column;

                .user-item {
                    position: relative;
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    gap: 10px;
                    border-radius: 5px;
                    cursor: pointer;
                    padding: 5px;
                    user-select: none;

                    img {
                        width: 25px;
                        height: 25px;
                        border-radius: 50%;
                    }

                    .emoji-icon {
                        width: 25px;
                        height: 25px;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        font-size: 16px;
                        background-color: #323232;
                        border-radius: 50%;
                    }

                    .user-name {
                        flex-grow: 1;
                        margin: 0;
                    }

                    &:hover {
                        background-color: #3a3a3c;
                    }

                    &.unread {
                        background-color: rgba(31, 33, 57, 0.2);
                        border-left: 2px solid #1f2139;

                        .user-name {
                            color: #ffffff;
                            font-weight: 600;
                        }

                        /* 未読ドット */
                        &::after {
                            content: '';
                            position: absolute;
                            top: 50%;
                            right: 8px;
                            transform: translateY(-50%);
                            width: 8px;
                            height: 8px;
                            background-color: #adb0d8;
                            border-radius: 50%;
                        }
                    }
                }
            }
        }
    }
}

.main-view {
    flex-grow: 1;
    background-color: #141414;
    border-radius: 20px;
    margin-right: 10px;
    margin-bottom: 10px;
}

#home-view {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;

    .actions-header {
        display: flex;
        flex-direction: row;
        align-items: center;
        padding: 20px;
        gap: 15px;

        .view-title {
            margin: 0;
            font-size: x-large;
            flex-grow: 1;
        }

        /* スマホ対応: ボタンのサイズ調整 */
        @media (max-width: 768px) {
            padding: 15px;
            gap: 10px;

            .view-title {
                font-size: large;
            }
        }
    }

    .users-list {
        flex-grow: 1;
        background-color: transparent;
        overflow: auto;

        .container {
            .user-item {
                user-select: none;
                display: flex;
                flex-direction: row;
                align-items: center;
                gap: 15px;
                margin: 5px 15px;
                border-radius: 15px;
                cursor: pointer;

                img {
                    margin: 10px;
                    width: 50px;
                    height: 50px;
                    border-radius: 50%;
                }

                .emoji-icon {
                    margin: 10px;
                    width: 50px;
                    height: 50px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    font-size: 24px;
                    background-color: #323232;
                    border-radius: 50%;
                }

                .detail {
                    flex-grow: 1;
                    display: flex;
                    flex-direction: column;
                    gap: 5px;

                    p {
                        margin: 0;
                        color: #a8a8a8;
                    }

                    .user-name {
                        font-weight: 600;
                    }
                }

                &:hover {
                    background-color: #3a3a3c;
                }

                &.unread {
                    .detail p {
                        color: white;
                    }
                }

                /* スマホ対応: タップ反応の改善 */
                @media (max-width: 768px) {
                    margin: 3px 10px;
                    min-height: 70px;

                    &:active {
                        background-color: #3a3a3c;
                    }
                }
            }
        }
    }
}

#chat-view {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;

    .actions-header {
        display: flex;
        flex-direction: row;
        align-items: center;
        padding: 10px 15px;
        border-bottom: 2px solid #323232;
        gap: 15px;

        .back-button {
            flex-shrink: 0;
            border-radius: 50%;

            span {
                color: #cecece;
            }

            &:hover {
                background-color: #2b2b2d;
            }
        }

        img {
            width: 35px;
            height: 35px;
            border-radius: 50%;
            user-select: none;
            -webkit-user-drag: none;
        }

        .view-title {
            margin: 0;
            font-size: 20px;
            font-weight: normal;
            flex-grow: 1;
        }

        /* スマホ対応: ヘッダー調整 */
        @media (max-width: 768px) {
            padding: 8px 10px;
            gap: 10px;

            .view-title {
                font-size: 18px;
            }

            img {
                width: 30px;
                height: 30px;
            }
        }
    }

    .chat-area {
        display: flex;
        flex-direction: column;
        align-items: center;
        overflow: auto;
        flex-grow: 1;
        -webkit-overflow-scrolling: touch;

        .container {
            padding: 20px 30px;
            max-width: 1000px;
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 0;

            .system-message {
                font-family: 'Noto Sans JP', sans-serif;
                font-style: oblique;
                font-size: smaller;
                color: #58585b;
                text-align: center;
                margin: 20px 0 0 0;

                &.error {
                    color: #ff6b6b;
                }
            }

            .chat-item {
                display: flex;
                flex-direction: column;
                align-items: flex-start;
                width: 100%;
                margin-top: 20px;

                .metadata {
                    margin: 0;
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    font-size: smaller;
                    gap: 10px;
                    margin-left: 50px;
                    margin-bottom: 5px;

                    .user-name {
                        color: #cecece;
                        font-weight: 600;
                    }

                    .timestamp {
                        color: #58585b;
                    }
                }

                .message {
                    display: flex;
                    flex-direction: row;
                    max-width: 80%;
                    align-items: flex-start;

                    p {
                        background-color: #323232;
                        color: white;
                        padding: 12px 15px;
                        border-radius: 18px;
                        margin: 0;
                        white-space: pre-wrap;
                        word-wrap: break-word;
                        line-height: 1.4;
                    }

                    img {
                        -webkit-user-drag: none;
                        user-select: none;
                        width: 35px;
                        height: 35px;
                        border-radius: 50%;
                        flex-shrink: 0;
                    }
                }

                &.mine {
                    align-items: flex-end;

                    .metadata {
                        margin-left: 0;
                        justify-content: flex-end;
                    }

                    .message {
                        position: relative;
                        flex-direction: row-reverse;

                        .message-text {
                            background-color: #2d3160;
                            color: white;
                            padding: 12px 15px;
                            border-radius: 18px;
                            margin: 0;
                            white-space: pre-wrap;
                            word-wrap: break-word;
                            line-height: 1.4;
                        }

                        .read-status {
                            position: absolute;
                            bottom: -2px;
                            left: -20px;
                            font-size: 10px;
                            color: #58585b;
                            background-color: #141414;
                            padding: 1px 4px;
                            border-radius: 6px;
                            font-weight: 500;
                            white-space: nowrap;
                            transition: color 0.2s ease;

                            &.read {
                                color: white;
                            }

                            &.unread {
                                color: #58585b;
                            }
                        }
                    }

                    .read-details {
                        margin-top: 4px;
                        margin-right: 50px;
                        text-align: right;

                        .read-count {
                            font-size: 11px;
                            color: #58585b;
                            cursor: pointer;

                            &:hover {
                                color: #cecece;
                            }
                        }
                    }

                    .message-actions {
                        position: absolute;
                        top: -25px;
                        right: 0px;
                        display: flex;
                        gap: 5px;
                        opacity: 0;
                        transition: opacity 0.2s ease;
                        z-index: 10;
                    }

                    .message:hover .message-actions {
                        opacity: 1;
                    }

                    &[data-is-editing="true"] .message .message-actions {
                        opacity: 0;
                    }
                }

                &.grouped {
                    margin-top: 3px;

                    .message img {
                        opacity: 0;
                    }
                }
            }

            .message-action-btn {
                width: 30px;
                height: 30px;
                border: none;
                border-radius: 50%;
                background-color: #323232;
                cursor: pointer;
                display: flex;
                align-items: center;
                justify-content: center;
                transition: background-color 0.2s ease;

                &:hover {
                    background-color: #58585b;
                }

                span {
                    font-size: 14px;
                    color: #cecece;
                }
            }

            .edit-btn:hover {
                background-color: #2d3160;
            }

            .delete-btn:hover {
                background-color: #7d2d2d;
            }

            /* メッセージコンテンツのレイアウト調整 */
            .message-content {
                flex-grow: 1;
                display: flex;
                flex-direction: row;
                gap: 15px;
            }

            /* 編集用テキストエリア */
            .message-edit-input {
                width: 100%;
                min-height: 50px;
                max-height: 200px;
                background-color: #2d3160;
                color: white;
                border: 2px solid #1f2139;
                border-radius: 18px;
                padding: 12px 15px;
                font-family: inherit;
                font-size: inherit;
                line-height: 1.4;
                resize: none;
                outline: none;
                box-sizing: border-box;

                &:focus {
                    border-color: #4a5394;
                }
            }

            /* 編集アクションボタン */
            .edit-actions {
                display: none;
                gap: 8px;
                margin-top: 8px;
                justify-content: flex-end;
            }

            .edit-save-btn,
            .edit-cancel-btn {
                padding: 6px 12px;
                border: none;
                border-radius: 15px;
                font-size: 12px;
                font-weight: 500;
                cursor: pointer;
                transition: all 0.2s ease;
            }

            .edit-save-btn {
                background-color: #2d3160;
                color: white;

                &:hover {
                    background-color: #4a5394;
                }
            }

            .edit-cancel-btn {
                background-color: #323232;
                color: #cecece;

                &:hover {
                    background-color: #58585b;
                }
            }

            /* 編集済みマーク */
            .edited-mark {
                font-size: 11px;
                color: #a0a0a0;
                font-style: italic;
                opacity: 0.8;
                margin-left: 8px;
            }

            /* 編集モード時のスタイル調整 */
            .chat-item.mine[data-is-editing="true"] .message {
                flex-direction: column;
                align-items: stretch;
                max-width: 85%;
            }

            /* 削除アニメーション */
            .chat-item.deleting {
                opacity: 0.5;
                transform: translateX(20px);
                transition: all 0.3s ease;
            }

            /* スマホ対応: パディングとマージン調整 */
            @media (max-width: 768px) {
                padding: 15px 15px;

                .chat-item {
                    .metadata {
                        margin-left: 40px;
                    }

                    .message {
                        max-width: 85%;

                        img {
                            width: 30px;
                            height: 30px;
                        }

                        p {
                            padding: 10px 12px;
                        }
                    }

                    &.mine .read-details {
                        margin-right: 40px;
                    }
                }
            }
        }
    }

    .input-area {
        min-height: 120px;
        border-top: 2px solid #323232;
        display: flex;
        flex-direction: column;
        justify-content: start;
        align-items: center;
        padding: 15px 50px 0 50px;

        .container {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 10px;
            max-width: 1000px;
            width: 100%;

            #message-input {
                box-sizing: border-box;
                resize: none;
                flex-grow: 1;
                line-height: 1.4;
                background-color: transparent;
                border-radius: calc(0.5lh + 10px);
                height: 47px;
                color: #cecece;
                outline: none;
                border: 2px solid #323232;
                font-size: medium;
                padding: 10px 15px;

                &:focus {
                    border-color: #1f2139;
                }
            }

            .send-button {
                span {
                    color: #cecece;
                }

                &:hover {
                    background-color: #58585b;
                }
            }
        }

        /* スマホ対応: 入力エリア調整 */
        @media (max-width: 768px) {
            padding: 15px 15px 0 15px;
            min-height: 100px;

            .container {
                gap: 8px;

                #message-input {
                    font-size: 16px;
                    /* iOS Safariでのズーム防止 */
                    padding: 8px 12px;
                    height: 42px;
                }

                .send-button {
                    width: 42px;
                    height: 42px;
                }
            }
        }
    }
}

.progress {
    background-color: #141414;
}

/* ドロップダウンメニュー */
.dropdown-menu {
    position: fixed;
    background-color: #2b2b2d;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    border: 1px solid #323232;
    min-width: 280px;

    &.hidden {
        display: none;
    }

    .dropdown-option {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 15px;
        cursor: pointer;
        transition: background-color 0.2s;
        user-select: none;

        &:hover {
            background-color: #58585b;
        }

        &:first-child {
            border-radius: 10px 10px 0 0;
        }

        &:last-child {
            border-radius: 0 0 10px 10px;
        }

        &:only-child {
            border-radius: 10px;
        }

        .dropdown-icon {
            width: 35px;
            height: 35px;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #1f2139;
            border-radius: 8px;
            flex-shrink: 0;

            span {
                color: #cecece;
                font-size: 18px;
            }
        }

        .dropdown-text {
            flex-grow: 1;

            .dropdown-title {
                margin: 0 0 2px 0;
                font-weight: 600;
                font-size: 14px;
                color: #cecece;
            }

            .dropdown-description {
                margin: 0;
                color: #a0a0a0;
                font-size: 12px;
            }
        }
    }

    /* スマホ対応: ドロップダウンメニュー */
    @media (max-width: 768px) {
        min-width: 260px;
        max-width: 90vw;

        .dropdown-option {
            padding: 15px 12px;
        }
    }
}

/* 招待コード表示 */
.invite-code-display {
    text-align: center;
    margin-bottom: 20px;

    .invite-code-text {
        font-family: 'JetBrains Mono', monospace;
        font-size: 2rem;
        font-weight: 700;
        color: #1f2139;
        background-color: #cecece;
        padding: 15px 20px;
        border-radius: 10px;
        margin: 0 0 10px 0;
        letter-spacing: 0.2em;
        user-select: all;
    }

    .invite-code-description {
        font-size: 0.9rem;
        color: #a0a0a0;
        margin: 0;
        line-height: 1.4;
    }

    /* スマホ対応: 招待コード表示 */
    @media (max-width: 768px) {
        .invite-code-text {
            font-size: 1.5rem;
            padding: 12px 15px;
            letter-spacing: 0.15em;
        }
    }
}

/* 空の状態 */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #58585b;
    text-align: center;
    padding: 40px;

    .material-symbols-rounded {
        font-size: 4rem;
        margin-bottom: 20px;
        opacity: 0.5;
    }

    h2 {
        margin: 0 0 10px 0;
        color: #cecece;
    }

    p {
        margin: 0;
        color: #a0a0a0;
    }

    /* スマホ対応: 空の状態 */
    @media (max-width: 768px) {
        padding: 20px;

        .material-symbols-rounded {
            font-size: 3rem;
        }

        h2 {
            font-size: 1.2rem;
        }

        p {
            font-size: 0.9rem;
        }
    }
}

/* ローディング状態 */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #58585b;

    .material-symbols-rounded {
        animation: spin 1s linear infinite;
        margin-right: 10px;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* スマホ向けスクロールバーを非表示 */
@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }
}

/* 既存のモバイル対応CSS */
@media (max-width: 768px) {
    .message-actions {
        right: -40px;
        opacity: 0.7;
        /* タッチデバイスでは常に少し表示 */
    }

    .message-action-btn {
        width: 28px;
        height: 28px;

        span {
            font-size: 12px;
        }
    }

    .chat-item.mine .message {
        max-width: 90%;
    }

    .chat-item.mine[data-is-editing="true"] .message {
        max-width: 95%;
    }

    .edit-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .edit-save-btn,
    .edit-cancel-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* タッチデバイス用の調整 */
@media (hover: none) {
    .chat-item.mine .message-actions {
        opacity: 0.7;
    }

    .chat-item.mine:active .message-actions {
        opacity: 1;
    }

    /* タップ時のフィードバック改善 */
    .user-item:active,
    .dropdown-option:active,
    button:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}