/* Added for mobile responsiveness */
html {
    font-size: 16px;
}

:root {
    --bg-color: #1a1a24;
    --text-color: #e0e0e0;
    --accent: #9c5e31;
    --secondary: #3e6990;
    --highlight: #d4a373;
    --dark-accent: #483c32;
    --modal-bg: rgba(20, 20, 30, 0.95);
    --error: #ff4545;
    --success: #45ff45;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Cinzel', serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background-image: url('/api/placeholder/1200/800');
    background-size: cover;
    background-position: center;
    background-blend-mode: overlay;
}

header {
    padding: 1rem;
    background-color: rgba(26, 26, 36, 0.8);
    border-bottom: 2px solid var(--accent);
    text-align: center;
    position: relative;
}

h1 {
    color: var(--highlight);
    font-size: 1.8rem;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
}

.container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.characters {
    width: 220px;
    background-color: rgba(30, 30, 40, 0.8);
    padding: 1rem;
    overflow-y: auto;
    border-right: 1px solid var(--dark-accent);
    display: flex;
    flex-direction: column;
}

.character {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background-color: rgba(60, 60, 80, 0.6);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    position: relative;
}

.character:hover {
    background-color: rgba(80, 80, 110, 0.8);
    border-color: var(--highlight);
}

.character.active {
    background-color: rgba(90, 90, 120, 0.9);
    border-color: var(--highlight);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 0.75rem;
    border: 2px solid var(--accent);
    background-color: var(--dark-accent);
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.char-info {
    flex: 1;
}

.char-name {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--highlight);
}

.char-class {
    font-size: 0.75rem;
    opacity: 0.8;
}

.edit-character {
    position: absolute;
    right: 8px;
    top: 8px;
    font-size: 0.8rem;
    opacity: 0.6;
    cursor: pointer;
    color: var(--highlight);
}

.edit-character:hover {
    opacity: 1;
}

.btn-add-character {
    margin-top: auto;
    padding: 0.5rem;
    background-color: var(--accent);
    color: var(--text-color);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    text-align: center;
    margin-top: 1rem;
}

.btn-add-character:hover {
    background-color: var(--highlight);
    color: var(--bg-color);
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    background-color: rgba(26, 26, 36, 0.7);
}

.message {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 6px;
    max-width: 85%;
    position: relative;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-user {
    background-color: rgba(62, 105, 144, 0.7);
    margin-left: auto;
    border-radius: 12px 12px 2px 12px;
}

.message-ai {
    background-color: rgba(72, 60, 50, 0.7);
    margin-right: auto;
    border-radius: 12px 12px 12px 2px;
    border-left: 3px solid var(--accent);
}

.message-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    margin-right: 0.5rem;
    border: 2px solid var(--accent);
    overflow: hidden;
    background-color: var(--dark-accent);
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-name {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--highlight);
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-left: auto;
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.4;
}

.input-area {
    padding: 1rem;
    background-color: rgba(30, 30, 40, 0.9);
    border-top: 1px solid var(--dark-accent);
    display: flex;
}

textarea {
    flex: 1;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--dark-accent);
    background-color: rgba(40, 40, 50, 0.8);
    color: var(--text-color);
    resize: none;
    height: 60px;
    font-family: 'Lora', serif;
    font-size: 0.95rem;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    margin-left: 0.75rem;
    padding: 0.5rem 1rem;
    background-color: var(--accent);
    color: var(--text-color);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

button:hover {
    background-color: var(--highlight);
    color: var(--bg-color);
}

.system-message {
    text-align: center;
    padding: 0.5rem;
    margin: 0.5rem 0;
    font-style: italic;
    color: var(--highlight);
    opacity: 0.8;
}

.typing-indicator {
    display: flex;
    align-items: center;
    margin: 0.5rem 0;
    opacity: 0.7;
}

.typing-bubble {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--highlight);
    margin-right: 4px;
    animation: typing 1s infinite;
    opacity: 0.7;
}

.typing-bubble:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-bubble:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
    100% { transform: translateY(0); }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background-color: var(--modal-bg);
    width: 90%;
    max-width: 600px;
    border-radius: 8px;
    border: 1px solid var(--accent);
    padding: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--accent);
}

.modal-title {
    color: var(--highlight);
    font-size: 1.2rem;
}

.close-modal {
    background: none;
    color: var(--text-color);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    margin: 0;
}

.close-modal:hover {
    color: var(--highlight);
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--highlight);
}

.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 4px;
    border: 1px solid var(--dark-accent);
    background-color: rgba(40, 40, 50, 0.8);
    color: var(--text-color);
    font-family: 'Lora', serif;
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn-cancel {
    background-color: #555;
}

.btn-cancel:hover {
    background-color: #777;
}

.tab-nav {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--dark-accent);
}

.tab-btn {
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    margin: 0;
    opacity: 0.7;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    opacity: 1;
    border-bottom-color: var(--accent);
    color: var(--highlight);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.checkbox-group {
    display: flex;
    align-items: center;
    margin: 0.5rem 0;
}

.checkbox-group input {
    margin-right: 0.5rem;
}

.api-status {
    position: absolute;
    top: 10px;
    right: 20px;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.api-status.connected {
    background-color: rgba(0, 128, 0, 0.6);
}

.api-status.disconnected {
    background-color: rgba(128, 0, 0, 0.6);
}

.api-settings-btn {
    position: absolute;
    top: 10px;
    right: 110px;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    background-color: var(--secondary);
    color: var(--text-color);
    cursor: pointer;
}

.api-settings-btn:hover {
    background-color: var(--accent);
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 1rem;
    border-radius: 6px;
    color: white;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 80%;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background-color: rgba(0, 128, 0, 0.9);
}

.toast.error {
    background-color: rgba(128, 0, 0, 0.9);
}

.trait-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.trait-tag {
    background-color: rgba(60, 60, 80, 0.6);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
}

.trait-tag .remove-trait {
    margin-left: 0.4rem;
    cursor: pointer;
    font-size: 0.7rem;
}

.trait-tag .remove-trait:hover {
    color: var(--highlight);
}

.add-trait-form {
    display: flex;
    margin-top: 0.5rem;
}

.add-trait-form input {
    flex: 1;
    padding: 0.4rem;
    font-size: 0.8rem;
}

.add-trait-form button {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
}

.catchphrase-item {
    background-color: rgba(60, 60, 80, 0.6);
    padding: 0.6rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    position: relative;
}

.remove-catchphrase {
    position: absolute;
    right: 6px;
    top: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}

.remove-catchphrase:hover {
    color: var(--highlight);
}

.add-catchphrase-form {
    margin-top: 1rem;
}

.add-catchphrase-form textarea {
    width: 100%;
    padding: 0.4rem;
    font-size: 0.8rem;
    min-height: 60px;
    margin-bottom: 0.5rem;
}

/* Mobile menu toggle button */
.menu-toggle {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--highlight);
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
    padding: 0.5rem;
    z-index: 10;
    min-height: 44px;
    min-width: 44px;
}

/* Header adjustments for mobile */
header {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 4;
}

/* Improve touch targets */
.edit-character, .remove-trait, .remove-catchphrase, .close-modal {
    padding: 0.4rem;
    margin: -0.4rem;
    min-height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

button, .btn-add-character {
    min-height: 44px;
}

.form-input, .form-textarea, .form-select, .checkbox-group input {
    min-height: 44px;
}

/* Media Queries for Responsive Design */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    
    body {
        overflow: auto;
    }
    
    .container {
        flex-direction: column;
        overflow: visible;
    }
    
    .menu-toggle {
        display: block;
    }
    
    /* Mobile sidebar handling */
    .characters {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 80%;
        max-width: 300px;
        transform: translateX(-100%);
        z-index: 10;
        transition: transform 0.3s ease;
    }
    
    .characters.open {
        transform: translateX(0);
    }
    
    .sidebar-overlay.open {
        display: block;
    }
    
    .chat-area {
        height: calc(100vh - 64px); /* Adjust based on header height */
    }
    
    /* Reposition API controls on mobile */
    .api-status {
        top: auto;
        bottom: 10px;
        right: 10px;
    }
    
    .api-settings-btn {
        top: auto;
        bottom: 10px;
        right: 110px;
    }
    
    /* Mobile input area */
    .input-area {
        flex-direction: column;
    }
    
    .input-area button {
        margin-left: 0;
        margin-top: 0.5rem;
        height: 44px;
    }
    
    textarea {
        min-height: 60px;
        max-height: 120px;
    }
    
    /* Adjust message width for readability */
    .message {
        max-width: 95%;
    }
    
    /* Modal adjustments for mobile */
    .modal {
        width: 95%;
        max-height: 80vh;
        padding: 1rem;
    }
    
    .form-actions {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .form-actions button {
        flex: 1;
        min-width: 120px;
    }
    
    /* Tab navigation scrolling */
    .tab-nav {
        overflow-x: auto;
        white-space: nowrap;
    }
    
    /* Form adjustments */
    .add-trait-form {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .add-trait-form input {
        flex: 1;
        min-width: 120px;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 13px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .characters {
        width: 85%;
    }
    
    .message {
        max-width: 100%;
    }
    
    .tab-btn {
        padding: 0.5rem 0.7rem;
    }
}