/**
 * Chatbot Sidebar Styles
 * Left Sidebar, Search, Chat List, Sections, Icon Sidebar, Mobile
 */

/* ========== Left Sidebar ========== */
.sidebar {
    width: 280px;
    min-width: 250px;
    max-width: 320px;
    min-height: 400px;
    background: var(--wa-bg-dark);
    border-right: 1px solid var(--wa-border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, min-width 0.3s ease;
}

.sidebar.collapsed {
    width: 60px;
    min-width: 60px;
}

.sidebar-header {
    padding: 10px 16px;
    background: var(--wa-bg-panel);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    gap: 8px;
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    font-size: 1.2rem;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-text);
}

.sidebar.collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

.sidebar-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
    transition: opacity 0.2s;
}

.sidebar.collapsed .logo span {
    display: none;
}

.sidebar-header .logo i {
    font-size: 1.5rem;
    color: var(--wa-green);
}

.sidebar-header .actions {
    transition: opacity 0.2s;
}

.sidebar.collapsed .actions {
    display: none;
}

.sidebar-header .actions button {
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    font-size: 1.2rem;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
}

.sidebar-header .actions button:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-text);
}

/* Web Agent 버튼 */
.sidebar-header .actions .webagent-btn {
    color: #22c55e;
}

.sidebar-header .actions .webagent-btn:hover {
    color: #16a34a;
    background: rgba(34, 197, 94, 0.15);
}

/* ========== Search Box ========== */
.search-box {
    padding: 12px;
    background: var(--wa-bg-dark);
    transition: opacity 0.2s;
}

.sidebar.collapsed .search-box,
.sidebar.collapsed .sync-status-bar,
.sidebar.collapsed .ws-status,
.sidebar.collapsed .sidebar-section {
    display: none;
}

/* Hide sync status and websocket status */
.sync-status-bar,
.ws-status {
    display: none !important;
}

.search-box input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 8px 12px 8px 36px;
    color: var(--wa-text);
    font-size: 0.875rem;
    transition: all 0.15s;
}

.search-box input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.search-box input::placeholder {
    color: var(--wa-text-secondary);
    opacity: 0.6;
}

.search-box .search-icon {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--wa-text-secondary);
    opacity: 0.5;
    font-size: 0.875rem;
}

.search-wrapper {
    position: relative;
}

/* ========== Chat List ========== */
.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--wa-border);
    transition: background 0.15s;
}

.chat-item:hover {
    background: var(--wa-bg-hover);
}

.chat-item.active {
    background: var(--wa-bg-active);
}

.chat-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--wa-green-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-right: 12px;
    flex-shrink: 0;
}

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

.chat-item .info .name {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .info .preview {
    font-size: 0.8rem;
    color: var(--wa-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .meta {
    text-align: right;
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-item .meta .time {
    font-size: 0.7rem;
    color: var(--wa-text-secondary);
}

.chat-item .meta .badge {
    background: var(--wa-green);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    margin-top: 4px;
}

/* Edit and Delete buttons on chat item */
.chat-item .edit-btn,
.chat-item .delete-btn {
    opacity: 0;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-item .edit-btn {
    color: var(--wa-text-secondary);
}

.chat-item .delete-btn {
    color: #ef4444;
}

.chat-item:hover .edit-btn,
.chat-item:hover .delete-btn {
    opacity: 1;
}

.chat-item .edit-btn:hover {
    color: var(--wa-green);
}

.chat-item .delete-btn:hover {
    color: #f87171;
}

/* ========== Scrollable Wrapper ========== */
.sidebar-scroll-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-scroll-wrapper::-webkit-scrollbar {
    width: 4px;
}

.sidebar-scroll-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-scroll-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.sidebar-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ========== Sidebar Sections ========== */
.sidebar-section {
    padding: 0 8px;
}

.chat-section {
    padding-bottom: 24px;
}

.chat-section .section-header-with-actions {
    padding: 0 4px 8px;
    margin-bottom: 4px;
}

.projects-section {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 20px;
}

.section-header-with-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 4px 12px;
}

.section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--wa-text-secondary);
    opacity: 0.5;
    margin-right: auto;
}

.section-actions-inline {
    display: flex;
    gap: 4px;
}

.icon-btn {
    padding: 4px 6px;
    background: transparent;
    color: var(--wa-text-secondary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: all 0.15s;
    opacity: 0.6;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
}

.icon-btn:nth-child(2):hover {
    color: #ef4444;
}



/* ========== Date Group Headers (Claude.ai) ========== */
.date-group {
    margin-top: 12px;
}

.date-group:first-child {
    margin-top: 0;
}

.date-group-header {
    padding: 0 8px 4px;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--wa-text-secondary);
    opacity: 0.5;
}

/* ========== Chat/Project Items (Exact Claude.ai) ========== */
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 5px 8px;
    margin: 0;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.1s;
    position: relative;
    gap: 8px;
    border: none;
}

.sidebar-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.sidebar-item.active {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-item .item-icon {
    display: none;
}

.sidebar-item .item-info {
    flex: 1;
    min-width: 0;
}

.sidebar-item .item-name {
    font-weight: 400;
    font-size: 0.875rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--wa-text);
}

.sidebar-item .item-preview,
.sidebar-item .item-meta,
.sidebar-item .item-time {
    display: none;
}

.sidebar-item .edit-btn,
.sidebar-item .delete-btn {
    opacity: 0;
    background: none;
    border: none;
    padding: 5px;
    cursor: pointer;
    transition: opacity 0.15s;
    font-size: 0.9rem;
    border-radius: 4px;
    color: var(--wa-text-secondary);
}

.sidebar-item:hover .edit-btn,
.sidebar-item:hover .delete-btn {
    opacity: 1;
}

.sidebar-item .edit-btn:hover,
.sidebar-item .delete-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-item .delete-btn:hover {
    color: #ef4444;
}

/* ========== Project Group ========== */
.project-group {
    margin-bottom: 4px;
}

.project-group-header .group-action {
    opacity: 0;
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    padding: 5px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.9rem;
    border-radius: 4px;
}

.project-group-header:hover .group-action {
    opacity: 1;
}

.project-group-header .group-action:hover {
    background: rgba(255, 255, 255, 0.1);
}

.project-chat-list {
    padding-left: 16px;
    background: transparent;
    margin-bottom: 0;
}

.project-chat-list.collapsed {
    display: none;
}

.sidebar-item.project-chat {
    padding: 7px 12px;
    font-size: 0.8125rem;
}

.sidebar-item.project-chat .item-icon {
    display: none;
}

.sidebar-item.project-chat {
    padding: 8px 16px;
}

/* ========== New Chat Button (legacy) ========== */
.new-chat-btn {
    margin: 12px;
    padding: 10px;
    background: var(--wa-green);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}

.new-chat-btn:hover {
    background: #00c896;
}

/* ========== Sidebar Task Badge ========== */
.sidebar-task-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    background: var(--wa-green);
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    animation: pulse 2s infinite;
}

/* ========== Icon Sidebar (Collapsed Mode) ========== */
.icon-sidebar {
    width: 60px;
    background: var(--wa-bg-darker);
    border-right: 1px solid var(--wa-border);
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
}

.icon-sidebar-header {
    padding: 10px;
    margin-bottom: 10px;
}

.icon-sidebar-header .logo-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--wa-green-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--wa-text);
    cursor: pointer;
}

.icon-sidebar-header .logo-icon:hover {
    background: var(--wa-green);
}

.icon-new-chat {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--wa-green);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    cursor: pointer;
    margin-bottom: 12px;
}

.icon-new-chat:hover {
    background: #00c896;
}

.icon-chat-list {
    flex: 1;
    overflow-y: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.icon-chat-item {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--wa-bg-panel);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    color: var(--wa-text-secondary);
    transition: all 0.2s;
    position: relative;
}

.icon-chat-item:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-text);
}

.icon-chat-item.active {
    background: var(--wa-green-dark);
    color: var(--wa-text);
}

.icon-chat-item .chat-initial {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
}

.icon-chat-item::after {
    content: attr(data-title);
    position: absolute;
    left: 55px;
    background: var(--wa-bg-panel);
    color: var(--wa-text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.icon-chat-item:hover::after {
    opacity: 1;
}

.icon-sidebar-footer {
    padding: 10px;
    border-top: 1px solid var(--wa-border);
    margin-top: auto;
}

.icon-sidebar-footer button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.icon-sidebar-footer button:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-text);
}

/* ========== Back button for mobile chat view ========== */
.back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    font-size: 1.3rem;
    padding: 8px;
    cursor: pointer;
    margin-right: 8px;
}

.back-btn:hover {
    color: var(--wa-text);
}

/* ========== Mobile Responsive ========== */
@media (max-width: 768px) {
    /* Show icon sidebar, hide full sidebar */
    .icon-sidebar {
        display: flex;
        width: 54px;
        flex-shrink: 0;
        padding: 6px 0;
    }

    .sidebar {
        display: none;
    }

    /* Show full sidebar on mobile when chat not selected */
    .sidebar.show-mobile {
        display: flex;
        width: calc(100% - 54px);
        max-width: none;
        position: fixed;
        top: 0;
        left: 54px;
        right: 0;
        bottom: 0;
        z-index: 90;
        animation: slideInFromLeft 0.25s ease;
    }

    /* Show back button */
    .back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 40px;
        min-height: 40px;
    }

    /* Disable tooltips on mobile */
    .icon-chat-item::after {
        display: none;
    }

    /* Touch-friendly icon items */
    .icon-new-chat,
    .icon-chat-item {
        width: 42px;
        height: 42px;
    }

    .icon-new-chat i,
    .icon-chat-item i {
        font-size: 1.1rem;
    }

    /* Larger search input */
    .search-box input {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 10px 12px 10px 36px;
        min-height: 42px;
        border-radius: 10px;
    }

    /* Touch-friendly sidebar items */
    .sidebar-item,
    .chat-item {
        min-height: 52px;
        padding: 10px 14px;
    }

    .sidebar-item .item-icon,
    .chat-item .avatar {
        width: 38px;
        height: 38px;
    }

    /* Always show edit and delete buttons on mobile */
    .chat-item .edit-btn,
    .chat-item .delete-btn,
    .sidebar-item .edit-btn,
    .sidebar-item .delete-btn {
        opacity: 0.7;
        min-width: 36px;
        min-height: 36px;
    }

    /* Sidebar header compact */
    .sidebar-header {
        min-height: 50px;
        padding: 8px 12px;
    }

    .sidebar-header .logo {
        font-size: 0.95rem;
    }

    .sidebar-header .logo i {
        font-size: 1.2rem;
    }

    /* Section headers */
    .section-header {
        min-height: 44px;
        padding: 10px 14px;
    }

    .section-title {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .icon-sidebar {
        width: 48px;
        padding: 4px 0;
    }

    .sidebar.show-mobile {
        left: 48px;
        width: calc(100% - 48px);
    }

    .icon-new-chat,
    .icon-chat-item {
        width: 38px;
        height: 38px;
    }

    .icon-new-chat i,
    .icon-chat-item i {
        font-size: 1rem;
    }

    .sidebar-header {
        min-height: 44px;
        padding: 6px 10px;
    }

    .sidebar-header .logo {
        font-size: 0.9rem;
    }

    .sidebar-header .logo i {
        font-size: 1.1rem;
    }

    .sidebar-item,
    .chat-item {
        min-height: 48px;
        padding: 8px 10px;
    }

    .sidebar-item .item-icon,
    .chat-item .avatar {
        width: 34px;
        height: 34px;
        margin-right: 8px;
    }

    .sidebar-item .item-name,
    .chat-item .info .name {
        font-size: 0.85rem;
    }

    .sidebar-item .item-preview,
    .chat-item .info .preview {
        font-size: 0.7rem;
    }

    /* Search box compact */
    .search-box {
        padding: 6px 10px;
    }

    .search-box input {
        padding: 8px 10px 8px 32px;
        min-height: 38px;
        font-size: 15px;
    }

    /* Section headers compact */
    .section-header {
        min-height: 40px;
        padding: 8px 10px;
    }

    .section-title {
        font-size: 0.75rem;
    }
}

/* Mobile Landscape */
@media (max-width: 900px) and (orientation: landscape) {
    .icon-sidebar {
        width: 50px;
    }

    .sidebar.show-mobile {
        left: 50px;
        width: calc(100% - 50px);
    }

    .sidebar-header {
        min-height: 48px;
        padding: 6px 12px;
    }

    .sidebar-item,
    .chat-item {
        min-height: 48px;
        padding: 8px 12px;
    }
}

@keyframes slideInFromLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ========== Sync Status Bar ========== */
.sync-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--wa-border);
}

.sync-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.sync-badge.local {
    background: rgba(148, 163, 184, 0.2);
    color: var(--wa-text-secondary);
}

.sync-badge.synced {
    background: rgba(0, 168, 132, 0.2);
    color: var(--wa-green);
}

.sync-badge i {
    font-size: 0.75rem;
}

.sync-now-btn {
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.sync-now-btn:hover:not(:disabled) {
    background: var(--wa-bg-hover);
    color: var(--wa-green);
}

.sync-now-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sync-now-btn i {
    transition: transform 0.3s;
}

.sync-now-btn:hover:not(:disabled) i {
    transform: rotate(180deg);
}

/* ========== User ID Modal Styles ========== */
.modal-small {
    max-width: 400px !important;
}

.sync-info {
    margin-top: 16px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.sync-info-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 0;
    font-size: 0.8rem;
    color: var(--wa-text-secondary);
}

.sync-info-item i {
    color: var(--wa-green);
    margin-top: 2px;
    flex-shrink: 0;
}

.sync-info-item:first-child {
    padding-top: 0;
}

.sync-info-item:last-child {
    padding-bottom: 0;
}
