/* Classical/Historical Theme for Historical Figure Chatbot */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600;700&family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,400&display=swap');

/* CSS Variables for easy theming */
:root {
    --gold: #c9a227;
    --gold-light: #e8d48a;
    --gold-dark: #8b6914;
    --parchment: #f4edd8;
    --parchment-light: #faf6eb;
    --parchment-dark: #e8dcc0;
    --ink: #2c2416;
    --ink-light: #5c4a32;
    --ink-muted: #8b7355;
    --marble: #f5f2eb;
    --shadow: rgba(44, 36, 22, 0.15);
    --shadow-dark: rgba(44, 36, 22, 0.25);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Cormorant Garamond', Georgia, serif;
    background: linear-gradient(135deg, var(--marble) 0%, var(--parchment-dark) 100%);
    min-height: 100vh;
    color: var(--ink);
    font-size: 1.1rem;
    line-height: 1.6;
}

#app {
    min-height: 100vh;
}

/* ============================================
   CONFIGURATION SCREEN
   ============================================ */
.config-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0L30 60M0 30L60 30' stroke='%23c9a22710' stroke-width='1' fill='none'/%3E%3C/svg%3E");
}

.config-card {
    background: linear-gradient(180deg, var(--parchment-light) 0%, var(--parchment) 100%);
    border: 3px solid var(--gold);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 550px;
    box-shadow:
        0 10px 40px var(--shadow-dark),
        inset 0 1px 0 rgba(255,255,255,0.5),
        inset 0 -1px 0 rgba(0,0,0,0.05);
    position: relative;
}

/* Decorative corners */
.config-card::before,
.config-card::after {
    content: '✦';
    position: absolute;
    color: var(--gold);
    font-size: 1.5rem;
}

.config-card::before {
    top: 10px;
    left: 15px;
}

.config-card::after {
    bottom: 10px;
    right: 15px;
}

.config-card h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--ink);
    letter-spacing: 0.05em;
}

/* Greek key decorative border */
.config-card h1::after {
    content: '';
    display: block;
    width: 150px;
    height: 12px;
    margin: 1rem auto 1.5rem;
    background: url("data:image/svg+xml,%3Csvg width='24' height='12' viewBox='0 0 24 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 6h6v-6h6v6h-6v6h6v-6h6v6h-6v-6' fill='none' stroke='%23c9a227' stroke-width='1.5'/%3E%3C/svg%3E") repeat-x center;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 0.5rem;
    letter-spacing: 0.03em;
}

input[type="text"] {
    width: 100%;
    padding: 0.85rem 1rem;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.1rem;
    border: 2px solid var(--gold-light);
    border-radius: 8px;
    background: rgba(255,255,255,0.7);
    color: var(--ink);
    transition: all 0.3s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--gold);
    background: rgba(255,255,255,0.9);
    box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.2);
}

input[type="text"]::placeholder {
    color: var(--ink-muted);
    font-style: italic;
}

input[type="file"] {
    width: 100%;
    padding: 0.75rem;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem;
    border: 2px solid var(--gold-light);
    border-radius: 8px;
    background: rgba(255,255,255,0.7);
    color: var(--ink);
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    font-family: 'Cinzel', serif;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 1rem;
}

.upload-area {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--gold);
    border-radius: 10px;
    padding: 2rem;
    cursor: pointer;
    background: rgba(255,255,255,0.5);
    transition: all 0.3s ease;
    min-height: 180px;
}

.upload-area:hover {
    background: rgba(255,255,255,0.8);
    border-color: var(--gold-dark);
    box-shadow: 0 4px 12px var(--shadow);
}

.upload-placeholder {
    text-align: center;
}

.upload-placeholder svg {
    height: 3.5rem;
    width: 3.5rem;
    color: var(--gold);
    margin-bottom: 0.75rem;
}

.upload-placeholder p {
    color: var(--ink-light);
    font-size: 1.1rem;
}

.preview-container {
    text-align: center;
}

.preview-container img {
    max-height: 150px;
    max-width: 100%;
    margin-bottom: 0.75rem;
    border-radius: 8px;
    border: 3px solid var(--gold);
    box-shadow: 0 4px 12px var(--shadow);
}

.preview-container p {
    font-size: 0.9rem;
    color: var(--ink-muted);
    font-style: italic;
}

.document-list {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255,255,255,0.6);
    border-radius: 8px;
    border: 1px solid var(--gold-light);
}

.document-list p {
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    color: var(--ink);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.document-list ul {
    list-style: none;
}

.document-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
    background: var(--parchment-light);
    border-radius: 4px;
    border-left: 3px solid var(--gold);
}

.remove-btn {
    color: #b91c1c;
    font-size: 0.85rem;
    font-family: 'Cinzel', serif;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.remove-btn:hover {
    background: rgba(185, 28, 28, 0.1);
}

/* Knowledge Bank Section */
.knowledge-bank-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px dashed var(--gold-light);
}

.helper-text {
    font-size: 0.9rem;
    color: var(--ink-muted);
    margin-bottom: 0.75rem;
    font-style: italic;
}

.secondary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 500;
    background: rgba(255,255,255,0.7);
    color: var(--ink);
    padding: 0.8rem 1.25rem;
    border: 2px solid var(--gold);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-btn:hover {
    background: var(--gold-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow);
}

.secondary-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.secondary-btn svg {
    flex-shrink: 0;
}

.knowledge-banks {
    margin-top: 1rem;
}

.loading-text {
    text-align: center;
    color: var(--ink-muted);
    font-style: italic;
    padding: 1rem;
    background: rgba(255,255,255,0.5);
    border-radius: 8px;
    animation: pulse-opacity 1.5s infinite;
}

@keyframes pulse-opacity {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

#knowledge-banks-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.knowledge-bank-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem;
    background: rgba(255,255,255,0.7);
    border: 2px solid var(--gold-light);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.knowledge-bank-item:hover {
    border-color: var(--gold);
    background: rgba(255,255,255,0.9);
}

.knowledge-bank-item.selected {
    border-color: var(--gold);
    background: rgba(201, 162, 39, 0.15);
}

.kb-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--gold);
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
}

.kb-content {
    flex: 1;
}

.kb-title {
    font-family: 'Cinzel', serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--ink);
    margin-bottom: 0.25rem;
}

.kb-description {
    font-size: 0.85rem;
    color: var(--ink-muted);
    line-height: 1.4;
}

.kb-add-btn {
    margin-top: 1rem;
    width: 100%;
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    font-weight: 500;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: white;
    padding: 0.7rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(201, 162, 39, 0.3);
}

.kb-add-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(201, 162, 39, 0.4);
}

.kb-add-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.primary-btn {
    width: 100%;
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: white;
    padding: 1rem 2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(201, 162, 39, 0.4);
    margin-top: 0.5rem;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201, 162, 39, 0.5);
}

.primary-btn:active {
    transform: translateY(0);
}

/* ============================================
   CHAT SCREEN
   ============================================ */
.chat-container {
    display: flex;
    height: 100vh;
    background: var(--marble);
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 300px;
    min-width: 280px;
    padding: 1.5rem;
    background: linear-gradient(180deg, var(--parchment-light) 0%, var(--parchment) 100%);
    border-right: 3px solid var(--gold);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px var(--shadow);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--gold-light);
}

.header h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.02em;
}

.text-btn {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    color: var(--ink-muted);
    background: none;
    border: 1px solid var(--gold-light);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.text-btn:hover {
    color: var(--ink);
    border-color: var(--gold);
    background: rgba(201, 162, 39, 0.1);
}

.figure-image-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.figure-image-container img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
    border: 4px solid var(--gold);
    box-shadow: 0 8px 25px var(--shadow-dark);
}

.voice-info {
    padding: 1rem 0;
    border-top: 2px solid var(--gold-light);
    margin-bottom: 0.5rem;
}

.voice-info h3 {
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.voice-info p {
    font-size: 0.85rem;
    color: var(--ink-muted);
    line-height: 1.4;
    font-style: italic;
}

.voice-info .voice-tag {
    display: inline-block;
    background: rgba(201, 162, 39, 0.15);
    color: var(--gold-dark);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: 'Cinzel', serif;
    margin-right: 0.3rem;
    margin-bottom: 0.3rem;
    font-style: normal;
}

.knowledge-sources {
    flex: 1;
    padding-top: 1rem;
    border-top: 2px solid var(--gold-light);
    overflow-y: auto;
}

.knowledge-sources h3 {
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.knowledge-sources ul {
    list-style: none;
}

.knowledge-sources li {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: rgba(255,255,255,0.5);
    border-radius: 6px;
    border-left: 3px solid var(--gold);
    font-size: 0.95rem;
}

.knowledge-sources li svg {
    height: 1.1rem;
    width: 1.1rem;
    margin-right: 0.6rem;
    color: var(--gold);
    flex-shrink: 0;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--marble) 0%, var(--parchment-light) 100%);
    min-width: 0;
}

.messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.message {
    margin-bottom: 1.25rem;
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    justify-content: flex-end;
}

.message.bot {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    font-size: 1.05rem;
    line-height: 1.6;
    box-shadow: 0 2px 8px var(--shadow);
}

.message.user .message-bubble {
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: white;
    border-radius: 12px 12px 4px 12px;
}

.message.bot .message-bubble {
    background: var(--parchment);
    color: var(--ink);
    border: 2px solid var(--gold-light);
    border-radius: 12px 12px 12px 4px;
}

.message-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.4rem;
}

.message-header svg {
    height: 1rem;
    width: 1rem;
    margin-right: 0.4rem;
}

.message-header span {
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.message.user .message-header span {
    color: rgba(255,255,255,0.9);
}

.message.bot .message-header span {
    color: var(--gold-dark);
}

/* Input Area */
.input-area {
    padding: 1.25rem 1.5rem;
    background: var(--parchment);
    border-top: 3px solid var(--gold);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Auto-speak Toggle */
.auto-speak-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-right: 0.5rem;
    border-right: 1px solid var(--gold-light);
    margin-right: 0.25rem;
}

.auto-speak-toggle .toggle-label {
    font-size: 0.75rem;
    color: var(--olive);
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 22px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

.input-area input[type="text"] {
    flex: 1;
    padding: 0.9rem 1.1rem;
    font-size: 1.05rem;
    border: 2px solid var(--gold-light);
    border-radius: 8px;
    background: white;
}

.input-area input[type="text"]:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.15);
}

/* Speak Button */
.speak-btn {
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: white;
    padding: 0.85rem;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(201, 162, 39, 0.3);
}

.speak-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(201, 162, 39, 0.4);
}

.speak-btn svg {
    height: 1.5rem;
    width: 1.5rem;
}

/* Loading state - RED pulsing */
.speak-btn.loading {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    animation: pulse-red 1s infinite;
    box-shadow: 0 3px 10px rgba(220, 38, 38, 0.4);
}

@keyframes pulse-red {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Ready state - GREEN */
.speak-btn.ready {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    box-shadow: 0 3px 10px rgba(22, 163, 74, 0.4);
}

/* Playing state - GREEN pulsing */
.speak-btn.playing {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    animation: pulse-green 0.8s infinite;
    box-shadow: 0 3px 10px rgba(22, 163, 74, 0.4);
}

@keyframes pulse-green {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Send Button */
.send-btn {
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: white;
    padding: 0.85rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(201, 162, 39, 0.3);
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(201, 162, 39, 0.4);
}

.send-btn svg {
    height: 1.5rem;
    width: 1.5rem;
}

/* API Toggle */
.api-toggle-container {
    display: flex;
    align-items: center;
    position: absolute;
    top: 15px;
    right: 20px;
    background: var(--parchment);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    border: 2px solid var(--gold-light);
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 10;
}

.toggle-label {
    margin-left: 10px;
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    color: var(--ink-muted);
    font-weight: 500;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gold-light);
    transition: .3s;
    border: 2px solid var(--gold);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    box-shadow: 0 2px 4px var(--shadow);
}

input:checked + .slider {
    background-color: var(--gold);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.slider.round {
    border-radius: 26px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Character Container (3D) */
.character-container {
    display: none;
}

/* Responsive Design */
@media (max-width: 900px) {
    .chat-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
        border-right: none;
        border-bottom: 3px solid var(--gold);
    }

    .figure-image-container img {
        max-height: 120px;
    }

    .message-bubble {
        max-width: 85%;
    }
}

@media (max-width: 600px) {
    .config-card {
        padding: 1.5rem;
    }

    .config-card h1 {
        font-size: 1.4rem;
    }

    .input-area {
        padding: 1rem;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .auto-speak-toggle {
        order: -1;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--gold-light);
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
        justify-content: center;
    }

    .speak-btn, .send-btn {
        padding: 0.7rem;
    }
}
