/*-----------------チャットウィジェット ここから-----------------*/
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
}

.chat-widget-toggle-btn {
    position: relative;
    background: #4E8DBC;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.2s;
}

.chat-widget-toggle-btn:hover {
    background: #3A80B5;
    transform: scale(1.1);
}

.chat-widget-toggle-btn svg {
    width: 24px;
    height: 24px;
}

.chat-widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #FF0000;
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 384px;
    height: 600px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1001;
}

.chat-widget-header {
    background: #4E8DBC;
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-widget-header h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.chat-widget-header-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-widget-header-btn svg {
    width: 20px;
    height: 20px;
}

.chat-widget-search {
    padding: 16px;
    border-bottom: 1px solid #E3E3E3;
}

.chat-widget-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #C2C2C2;
    border-radius: 8px;
    font-size: 14px;
}

.chat-widget-search-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(78, 141, 188, 0.3);
    border-color: #4E8DBC;
}

.chat-widget-rank-tabs {
    padding: 8px 16px;
    background: #F3F3F3;
    border-bottom: 1px solid #E3E3E3;
}

.chat-widget-rank-tabs-inner {
    display: flex;
    background: #fff;
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.chat-widget-rank-tab {
    flex: 1;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: #555;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-widget-rank-tab:hover {
    background: #F3F3F3;
}

.chat-widget-rank-tab.active {
    background: #4E8DBC;
    color: #fff;
}

.chat-widget-user-list {
    flex: 1;
    overflow-y: auto;
    background: #fff;
}

.chat-widget-user-list-header {
    padding: 8px 16px;
    background: #F3F3F3;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
}

.chat-widget-user-item {
    width: 100%;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
}

.chat-widget-user-item:hover {
    background: #F3F3F3;
}

.chat-widget-user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 48px;
    color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-user-info {
    flex: 1;
    min-width: 0;
}

.chat-widget-user-name-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-widget-user-name {
    font-weight: 600;
    color: #333;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-widget-user-unread-badge {
    background: #FF0000;
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-widget-user-message-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-widget-user-message {
    font-size: 13px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-widget-user-message-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.chat-widget-user-message--deleted {
    font-style: italic;
    color: #bbb;
}

.chat-widget-user-time {
    font-size: 12px;
    color: #aaa;
    flex-shrink: 0;
}

.chat-widget-empty {
    padding: 32px 16px;
    text-align: center;
    color: #888;
}

.chat-widget-empty-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 8px;
    color: #aaa;
}

.chat-widget-empty-text {
    font-size: 14px;
}

.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #F3F3F3;
}

.chat-widget-load-more {
    display: flex;
    justify-content: center;
    padding-bottom: 8px;
}

.chat-widget-load-more-btn {
    font-size: 14px;
    color: #4E8DBC;
    background: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-widget-load-more-btn:hover {
    color: #3A80B5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chat-widget-load-more-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-widget-load-more-btn svg {
    width: 16px;
    height: 16px;
}

.chat-widget-load-more-btn-content {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-widget-date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.chat-widget-date-label {
    font-size: 12px;
    color: #888;
    background: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-widget-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 16px;
}

.chat-widget-msg.own {
    justify-content: flex-end;
}

.chat-widget-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chat-widget-msg-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
}

.chat-widget-msg.own .chat-widget-msg-content {
    align-items: flex-end;
}

.chat-widget-msg-bubble {
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    word-wrap: break-word;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-widget-msg.own .chat-widget-msg-bubble {
    background: #4E8DBC;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-widget-msg.other .chat-widget-msg-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
}

.chat-widget-msg-deleted {
    background: #f0f0f0 !important;
    color: #999 !important;
    font-style: italic;
}

.chat-widget-msg-file {
    padding: 8px;
}

.chat-widget-msg-file img {
    border-radius: 8px;
    max-width: 100%;
    max-height: 240px;
    display: block;
}

.chat-widget-msg-file-name {
    font-size: 12px;
    margin-top: 4px;
    word-break: break-all;
    overflow-wrap: anywhere;
}

.chat-widget-msg.own .chat-widget-msg-file-name {
    color: rgba(255, 255, 255, 0.9);
}

.chat-widget-msg.other .chat-widget-msg-file-name {
    color: #666;
}

.chat-widget-msg-pdf {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 8px;
    text-decoration: none;
    transition: opacity 0.2s;
}

.chat-widget-msg.own .chat-widget-msg-pdf {
    color: #fff;
}

.chat-widget-msg.other .chat-widget-msg-pdf {
    color: #333;
}

.chat-widget-msg-pdf:hover {
    opacity: 0.8;
}

.chat-widget-msg-pdf-icon {
    font-size: 32px;
    color: #FF0000;
}

.chat-widget-msg-pdf-info {
    flex: 1;
    min-width: 0;
}

.chat-widget-msg-pdf-name {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-widget-msg-pdf-size {
    font-size: 12px;
    opacity: 0.75;
}

.chat-widget-msg-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 12px;
}

.chat-widget-msg.own .chat-widget-msg-meta {
    justify-content: flex-end;
    margin-right: 8px;
}

.chat-widget-msg.other .chat-widget-msg-meta {
    margin-left: 8px;
}

.chat-widget-msg-time {
    color: #888;
}

.chat-widget-msg-read-icon {
    width: 16px;
    height: 16px;
}

.chat-widget-msg-delete-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    color: #bbb;
    border-radius: 4px;
    line-height: 1;
}

.chat-widget-msg-delete-btn:hover {
    color: #e53e3e;
    background: #fff0f0;
}

.chat-widget-msg-read-icon.read {
    color: #4E8DBC;
}

.chat-widget-msg-read-icon.unread {
    color: #aaa;
}

.chat-widget-input {
    border-top: 1px solid #E3E3E3;
    background: #fff;
    padding: 16px;
}

.chat-widget-file-preview {
    margin-bottom: 8px;
    padding: 8px;
    background: #F3F3F3;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-widget-file-preview-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}

.chat-widget-file-preview-icon {
    width: 20px;
    height: 20px;
    color: #666;
}

.chat-widget-file-preview-name {
    font-size: 14px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-widget-file-preview-close {
    background: transparent;
    border: none;
    color: #FF0000;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-file-preview-close:hover {
    color: #cc0000;
}

.chat-widget-file-preview-close svg {
    width: 20px;
    height: 20px;
}

.chat-widget-input-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-widget-file-btn {
    flex-shrink: 0;
    cursor: pointer;
}

.chat-widget-file-btn input {
    display: none;
}

.chat-widget-file-btn-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: #F3F3F3;
    border-radius: 8px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-widget-file-btn-label:hover {
    background: #E3E3E3;
}

.chat-widget-file-btn-label svg {
    width: 24px;
    height: 24px;
}

.chat-widget-textarea-wrapper {
    flex: 1;
}

.chat-widget-file-hint {
    margin: 4px 0 0;
    font-size: 11px;
    color: #999;
    text-align: right;
}

.chat-widget-file-error {
    margin: 4px 0 0;
    font-size: 11px;
    color: #E53E3E;
    text-align: right;
}

.chat-widget-textarea {
    display: block;
    width: 100%;
    resize: none;
    border: 1px solid #C2C2C2;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    font-family: inherit;
    max-height: 120px;
    min-height: 48px;
    box-sizing: border-box;
}

.chat-widget-textarea:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(78, 141, 188, 0.3);
    border-color: #4E8DBC;
}

.chat-widget-send-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: #4E8DBC;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-widget-send-btn:hover {
    background: #3A80B5;
}

.chat-widget-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-widget-send-btn svg {
    width: 24px;
    height: 24px;
}

.chat-widget-loading {
    margin-top: 8px;
    font-size: 14px;
    color: #888;
}

.chat-widget-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    margin-right: 8px;
}

.chat-widget-header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.chat-widget-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border:none;
    background-color: #fff;
    flex-shrink: 0;
}

.chat-widget-header-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* アニメーション */
@keyframes chatWidgetFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.chat-widget-window {
    animation: chatWidgetFadeIn 0.2s ease-out;
}

/* Alpine.jsのアニメーション用 */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

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

/* モバイル対応 */
/* SP底面ナビバー（商談中など）との重なりを避けるため位置を上げる */
@media screen and (max-width: 640px) {
    .chat-widget {
        bottom: 60px;
        right: 10px;
    }
}

@media (max-width: 480px) {
    .chat-widget-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        bottom: 8px;
        right: 8px;
    }

    .chat-widget-toggle {
        bottom: 8px;
        right: 8px;
    }
}

@media (max-width: 360px) {
    .chat-widget-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
}

/* ツールバー（添付・定型文） */
.chat-widget-toolbar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.chat-widget-toolbar-btn {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 5px;
    padding: 4px 10px;
    background: #f0f4f8;
    border: 1px solid #d0d9e3;
    border-radius: 12px;
    font-size: 12px;
    color: #555;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
    white-space: nowrap;
}

.chat-widget-toolbar-btn:hover {
    background: #e2eaf2;
    border-color: #b0bec9;
}

.chat-widget-toolbar-btn input[type="file"] {
    display: none;
}

/* 定型文 */
.chat-widget-templates-popover {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    background: #fff;
    border: 1px solid #d0d9e3;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    min-width: 200px;
    max-width: 280px;
    overflow: hidden;
    z-index: 100;
}

.chat-widget-templates-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    transition: background 0.1s;
    line-height: 1.4;
}

.chat-widget-templates-item:last-child {
    border-bottom: none;
}

.chat-widget-templates-item:hover {
    background: #f5f8ff;
    color: #3A80B5;
}

/* 取扱商品 */
.chat-widget-toolbar-btn--product {
    background: #f0f4f0;
    border-color: #c3d4c3;
    color: #3a7a3a;
}

.chat-widget-toolbar-btn--product:hover {
    background: #e4ede4;
    border-color: #a8c4a8;
}

.chat-widget-product-popover {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: #fff;
    border: 1px solid #d0d9e3;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    width: 280px;
    max-width: calc(100vw - 32px);
    overflow: hidden;
    z-index: 100;
}

.chat-widget-product-popover-header {
    padding: 10px 14px 8px;
    font-size: 12px;
    font-weight: bold;
    color: #3a7a3a;
    border-bottom: 1px solid #f0f0f0;
}

.chat-widget-product-popover-body {
    padding: 10px 14px;
    font-size: 13px;
    color: #333;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 220px;
    overflow-y: auto;
}

/*-----------------チャットウィジェット ここまで-----------------*/

