/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Whitney', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: #36393f;
    color: #dcddde;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

/* App Layout */
.app {
    display: flex;
    min-height: 100vh;
    flex-direction: row;
}

/* Guild List (Server Sidebar) */
.guild-list {
    width: 72px;
    background-color: #202225;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 8px;
}

.guild-item {
    width: 48px;
    height: 48px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.guild-item:hover {
    transform: scale(1.05);
}

.guild-item.home-guild .guild-icon {
    background: linear-gradient(135deg, #7289da, #5865f2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: border-radius 0.2s ease;
}

.guild-item:hover .guild-icon {
    border-radius: 16px;
}

.guild-icon {
    width: 100%;
    height: 100%;
    background-color: #36393f;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    transition: all 0.2s ease;
}

.separator {
    width: 32px;
    height: 2px;
    background-color: #36393f;
    border-radius: 1px;
    margin: 4px 0;
}

/* Guild Content */
.guild-content {
    display: flex;
    flex: 1;
    min-height: 100vh;
}

/* Channels Sidebar */
.channels {
    width: 240px;
    background-color: #2f3136;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.server-header {
    height: 48px;
    padding: 0 16px;
    border-bottom: 1px solid #202225;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.server-header:hover {
    background-color: #34373c;
}

.server-header h1 {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
}

.dropdown-icon {
    color: #b9bbbe;
    transition: transform 0.2s ease;
}

.server-header:hover .dropdown-icon {
    transform: rotate(180deg);
}

.channel-list {
    flex: 1;
    padding: 16px 8px;
}

.channel-category {
    margin-bottom: 8px;
}

.channel-category h3 {
    font-size: 12px;
    font-weight: 600;
    color: #8e9297;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    padding: 0 8px;
}

.channel-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    color: #8e9297;
    transition: all 0.2s ease;
}

.channel-item:hover {
    background-color: #34373c;
    color: #dcddde;
}

.channel-item.active {
    background-color: #393c43;
    color: #ffffff;
}

.channel-icon {
    margin-right: 8px;
    font-weight: 600;
    font-size: 18px;
    color: #8e9297;
}

.channel-item.active .channel-icon {
    color: #ffffff;
}

/* Chat Area */
.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #36393f;
    min-height: 100vh;
}

.chat-header {
    height: 48px;
    border-bottom: 1px solid #40444b;
    display: flex;
    align-items: center;
    padding: 0 16px;
}

.channel-info {
    display: flex;
    align-items: center;
}

.channel-info .channel-icon {
    margin-right: 8px;
    color: #8e9297;
    font-size: 20px;
}

.channel-name {
    font-weight: 600;
    color: #ffffff;
    font-size: 16px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    min-height: 60vh;
}

.welcome-message {
    text-align: center;
    max-width: 440px;
    margin: 0 auto;
    padding: 40px 0;
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    font-size: 24px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 8px;
}

.welcome-message p {
    color: #b9bbbe;
    line-height: 1.5;
    margin-bottom: 8px;
}

/* Continue Conversation Button */
.continue-conversation {
    padding: 12px 0;
    text-align: center;
    border-bottom: 1px solid #40444b;
}

.continue-btn {
    background: linear-gradient(135deg, #43b581, #57f287);
    border: none;
    border-radius: 6px;
    color: white;
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    margin: 0 auto;
}

.continue-btn:hover {
    background: linear-gradient(135deg, #3aa76d, #4ae374);
    transform: scale(1.05);
}

.continue-btn:active {
    transform: scale(0.98);
}

.continue-btn svg {
    width: 18px;
    height: 18px;
}

.continue-btn.loading {
    background: #4f545c;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Messages */
.message {
    display: flex;
    padding: 8px 0;
    transition: background-color 0.1s ease;
}

.message:hover {
    background-color: #32353b;
    margin: 0 -16px;
    padding: 8px 16px;
    border-radius: 4px;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 16px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #7289da, #5865f2, #43b581, #faa61a, #f04747);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    font-size: 16px;
}

.message-content {
    flex: 1;
}

.message-header {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.message-author {
    font-weight: 600;
    color: #ffffff;
    margin-right: 8px;
    font-size: 16px;
}

.message-author.moderator {
    color: #f04747 !important;
}

.message-author.moderator::after {
    content: 'MOD';
    background-color: #f04747;
    color: #ffffff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 4px;
    border-radius: 3px;
    margin-left: 6px;
    text-transform: uppercase;
}

.message-timestamp {
    font-size: 12px;
    color: #72767d;
    font-weight: 400;
}

.message-text {
    color: #dcddde;
    line-height: 1.375;
    word-wrap: break-word;
}

/* System Messages */
.message.system-message {
    background-color: #2d3748;
    border-left: 4px solid #faa61a;
    padding: 8px 16px;
    margin: 8px 0;
    border-radius: 4px;
}

.message.system-message .message-avatar {
    background: linear-gradient(135deg, #faa61a, #ed8936) !important;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message.system-message .message-author {
    color: #faa61a !important;
    font-weight: 600;
}

.message.system-message .message-text {
    color: #e2e8f0;
    font-weight: 500;
}

/* Narrator Messages */
.message.narrator-message {
    background-color: #2c2f33;
    border-left: 4px solid #8e9297;
    padding: 8px 16px;
    margin: 8px 0;
    border-radius: 4px;
    font-style: italic;
}

.message.narrator-message .message-avatar {
    background: linear-gradient(135deg, #8e9297, #72767d) !important;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message.narrator-message .message-author {
    color: #8e9297 !important;
    font-weight: 600;
    font-style: italic;
}

.message.narrator-message .message-text {
    color: #b9bbbe;
    font-style: italic;
    font-weight: 400;
}

.message-author.narrator {
    color: #8e9297 !important;
    font-style: italic;
}

/* Message Input */
.message-input-container {
    padding: 24px;
    background-color: #36393f;
    border-top: 1px solid #40444b;
}

.message-input {
    background-color: #40444b;
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
}

#promptInput {
    flex: 1;
    background: none;
    border: none;
    color: #dcddde;
    font-size: 16px;
    padding: 16px 0;
    outline: none;
}

#promptInput::placeholder {
    color: #72767d;
}

.generate-btn {
    background: linear-gradient(135deg, #7289da, #5865f2);
    border: none;
    border-radius: 6px;
    color: white;
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.generate-btn:hover {
    background: linear-gradient(135deg, #677bc4, #4752c4);
    transform: scale(1.05);
}

.generate-btn:active {
    transform: scale(0.98);
}

.generate-btn svg {
    width: 18px;
    height: 18px;
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading .generate-btn {
    background: #4f545c;
    cursor: not-allowed;
}

/* Animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message {
    animation: messageSlideIn 0.3s ease-out;
}

/* Scrollbar */
.messages-container::-webkit-scrollbar {
    width: 14px;
}

.messages-container::-webkit-scrollbar-thumb {
    background-color: #202225;
    border: 3px solid #36393f;
    border-radius: 7px;
}

.messages-container::-webkit-scrollbar-track {
    background-color: #36393f;
}

/* Character Selection */
.character-selection {
    padding: 16px 24px;
    border-bottom: 1px solid #40444b;
    background-color: #2f3136;
    display: block;
}

.character-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.character-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-characters-btn {
    background: linear-gradient(135deg, #4f545c, #5d6269);
    border: none;
    border-radius: 6px;
    color: white;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.toggle-characters-btn:hover {
    background: linear-gradient(135deg, #5d6269, #6c7176);
    transform: scale(1.05);
}

.toggle-characters-btn svg {
    width: 14px;
    height: 14px;
}

.show-characters-section {
    padding: 12px 24px;
    border-bottom: 1px solid #40444b;
    background-color: #2f3136;
    text-align: center;
}

.show-characters-btn {
    background: linear-gradient(135deg, #7289da, #5865f2);
    border: none;
    border-radius: 6px;
    color: white;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    margin: 0 auto;
}

.show-characters-btn:hover {
    background: linear-gradient(135deg, #677bc4, #4752c4);
    transform: scale(1.05);
}

.show-characters-btn svg {
    width: 14px;
    height: 14px;
}

.character-section h3 {
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px;
    max-width: 700px;
}

.character-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    background-color: #40444b;
    position: relative;
}

.character-option:hover {
    background-color: #4f545c;
    transform: scale(1.02);
}

.character-option.selected {
    border-color: #5865f2;
    background: linear-gradient(135deg, #5865f2, #7289da);
    transform: scale(1.05);
}

.character-option.selected::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    background-color: #43b581;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

.character-image {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 6px;
}

.character-name {
    font-size: 12px;
    font-weight: 500;
    color: #dcddde;
    text-align: center;
}

.character-option.selected .character-name {
    color: #ffffff;
    font-weight: 600;
}

.auto-select-btn {
    background: linear-gradient(135deg, #43b581, #57f287);
    border: none;
    border-radius: 6px;
    color: white;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.auto-select-btn:hover {
    background: linear-gradient(135deg, #3aa76d, #4ae374);
    transform: scale(1.05);
}

.auto-select-btn:active {
    transform: scale(0.98);
}

.auto-select-btn svg {
    width: 14px;
    height: 14px;
}

.auto-select-btn.loading {
    background: #4f545c;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Custom Character Modal */
.custom-character-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background-color: #2f3136;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #40444b;
}

.modal-header h3 {
    color: #ffffff;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #b9bbbe;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: #40444b;
    color: #ffffff;
}

.modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    color: #ffffff;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group textarea {
    width: 100%;
    background-color: #40444b;
    border: 1px solid #40444b;
    border-radius: 4px;
    color: #dcddde;
    padding: 12px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

.form-group input[type="text"]:focus,
.form-group input[type="url"]:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #7289da;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: #72767d;
}

.color-picker {
    display: flex;
    align-items: center;
    gap: 12px;
}

.form-group input[type="color"] {
    width: 60px;
    height: 40px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

.color-preview {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #7289da;
    border: 2px solid #40444b;
    transition: background-color 0.2s ease;
}

.character-count {
    text-align: right;
    font-size: 12px;
    color: #72767d;
    margin-top: 4px;
}

.form-group small {
    display: block;
    color: #8e9297;
    font-size: 12px;
    margin-top: 4px;
}

.avatar-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    margin-top: 8px;
    border: 2px solid #40444b;
    background-color: #40444b;
    background-size: cover;
    background-position: center;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #40444b;
    background-color: #2c2f33;
}

.cancel-btn {
    background: none;
    border: 1px solid #4f545c;
    border-radius: 4px;
    color: #dcddde;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn:hover {
    background-color: #4f545c;
    border-color: #5d6269;
}

.create-btn {
    background: linear-gradient(135deg, #43b581, #57f287);
    border: none;
    border-radius: 4px;
    color: white;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.create-btn:hover {
    background: linear-gradient(135deg, #3aa76d, #4ae374);
}

.create-btn:disabled {
    background: #4f545c;
    cursor: not-allowed;
    opacity: 0.6;
}

.character-option.custom-character {
    position: relative;
}

.character-option.custom-character .delete-character {
    position: absolute;
    top: 2px;
    right: 2px;
    background-color: #f04747;
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.character-option.custom-character:hover .delete-character {
    display: flex;
}

.character-option.custom-character .delete-character:hover {
    background-color: #d73527;
    transform: scale(1.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .app {
        flex-direction: column;
    }
    
    .guild-list {
        width: 100%;
        height: 60px;
        flex-direction: row;
        justify-content: center;
        padding: 8px 12px;
        order: 2;
        border-top: 1px solid #40444b;
    }
    
    .guild-content {
        flex-direction: column;
        order: 1;
    }
    
    .channels {
        width: 100%;
        min-height: auto;
        max-height: 200px;
        overflow-y: auto;
    }
    
    .chat {
        min-height: calc(100vh - 260px);
    }
    
    .messages-container {
        min-height: 40vh;
    }
    
    .character-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .character-image {
        width: 40px;
        height: 40px;
    }
    
    .character-selection {
        padding: 12px 16px;
    }
    
    .message-input-container {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .character-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .guild-list {
        height: 50px;
        padding: 6px 8px;
    }
    
    .guild-item {
        width: 35px;
        height: 35px;
    }
}