/* ========== CSS RESET & VARIABLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f2e;
    --bg-tertiary: #252b3b;
    --bg-hover: #2d3548;
    --text-primary: #e1e8ed;
    --text-secondary: #8899a6;
    --text-muted: #657786;
    --border-color: #38444d;
    --accent-primary: #1c2146;
    --accent-hover: #151a38;
    --success: #17bf63;
    --warning: #ffad1f;
    --error: #e0245e;
    --info: #1da1f2;
    --scrollbar-track: #1a1f2e;
    --scrollbar-thumb: #38444d;
    --code-bg: #1e2433;
    --shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f9fa;
    --bg-tertiary: #e8ecef;
    --bg-hover: #d8dee3;
    --text-primary: #14171a;
    --text-secondary: #536471;
    --text-muted: #657786;
    --border-color: #cfd9de;
    --accent-primary: #2d3458;
    --accent-hover: #232944;
    --success: #00ba7c;
    --warning: #f59e0b;
    --error: #dc2626;
    --info: #1d9bf0;
    --scrollbar-track: #e8ecef;
    --scrollbar-thumb: #cfd9de;
    --code-bg: #f3f4f6;
    --shadow: rgba(0, 0, 0, 0.1);
}

/* ========== BASE STYLES ========== */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* ========== LAYOUT ========== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    height: 32px;
    width: auto;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-center {
    display: flex;
    gap: 10px;
    align-items: center;
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.security-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: rgba(23, 191, 99, 0.1);
    border: 1px solid var(--success);
    border-radius: 12px;
    font-size: 12px;
    color: var(--success);
}

/* ========== BUTTONS ========== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-icon {
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-icon:hover {
    background: var(--bg-hover);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    background: #c41e4a;
}

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

/* ========== MAIN CONTENT ========== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    position: absolute;
    z-index: 10;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
}

.new-session-btn {
    width: 100%;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.session-item {
    padding: 12px;
    margin-bottom: 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

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

.session-item.active {
    background: var(--accent-primary);
    color: #fff;
}

.session-info {
    flex: 1;
    overflow: hidden;
}

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

.session-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.session-item.active .session-meta {
    color: rgba(255, 255, 255, 0.8);
}

.session-delete {
    opacity: 0;
    padding: 4px 8px;
    background: var(--error);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.session-item:hover .session-delete {
    opacity: 1;
}

/* ========== CHAT CONTAINER ========== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

.single-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
}

.dual-chat {
    display: none;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
}

.dual-chat.active {
    display: flex;
}

/* ========== DUAL CHAT PANELS ========== */
.dual-panels {
    display: flex;
    flex: 1;
    gap: 1px;
    background: var(--border-color);
    overflow: hidden;
}

.dual-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}

.dual-panel-header {
    padding: 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    text-align: center;
}

/* ========== MESSAGES ========== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-primary);
}

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    color: #fff;
}

.message.user .message-avatar {
    background: var(--success);
}

.message.moderator .message-avatar {
    background: var(--warning);
}

.message-content {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
}

.message.user .message-content {
    background: var(--accent-primary);
    color: #fff;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.user .message-text {
    color: #fff;
}

.message-image {
    margin: 10px 0;
    max-width: 100%;
    text-align: center;
}

.message-image img {
    max-width: 500px;
    width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image img:hover {
    transform: scale(1.02);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

.message.user .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* ========== TTS BUTTON ========== */
.tts-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
    font-size: 16px;
    line-height: 1;
}

.tts-btn:hover {
    opacity: 1;
}

.tts-btn.playing {
    opacity: 1;
    animation: pulse 1.5s infinite;
}

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

/* ========== TAUGUARD BADGE ========== */
.tauguard-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(28, 33, 70, 0.3);
    border: 1px solid var(--accent-primary);
    border-radius: 4px;
    font-size: 11px;
    margin-top: 8px;
    color: var(--accent-primary);
}

.risk-low { 
    color: var(--success); 
    border-color: var(--success); 
    background: rgba(23, 191, 99, 0.1); 
}

.risk-medium { 
    color: var(--warning); 
    border-color: var(--warning); 
    background: rgba(255, 173, 31, 0.1); 
}

.risk-high { 
    color: var(--error); 
    border-color: var(--error); 
    background: rgba(224, 36, 94, 0.1); 
}

/* ========== CODE BLOCKS ========== */
.message-text pre {
    background: var(--code-bg);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid var(--border-color);
}

.message-text code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.message-text pre code {
    background: transparent;
    padding: 0;
}

/* ========== TYPING INDICATOR ========== */
.typing-indicator {
    display: none;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s;
}

.typing-indicator.active {
    display: flex;
}

.typing-dots {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-10px); opacity: 1; }
}

/* ========== INPUT AREA ========== */
.input-area {
    padding: 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.file-preview {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    margin-bottom: 10px;
}

.file-preview.active {
    display: flex;
}

.file-info {
    flex: 1;
    font-size: 13px;
}

.file-name {
    font-weight: 500;
    color: var(--accent-primary);
}

.file-size {
    color: var(--text-muted);
    font-size: 12px;
}

.image-preview-container {
    margin-bottom: 10px;
    display: none;
}

.image-preview-container.active {
    display: block;
}

.image-preview {
    max-width: 200px;
    max-height: 200px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 50px;
    max-height: 200px;
    transition: border-color 0.2s;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.input-buttons {
    display: flex;
    gap: 6px;
}

/* ========== EMOJI PICKER ========== */
.emoji-picker-container {
    position: relative;
}

.emoji-picker {
    display: none;
    position: absolute;
    bottom: 50px;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 100;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-picker.active {
    display: block;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}

.emoji-btn {
    padding: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    font-size: 20px;
    transition: background 0.2s;
}

.emoji-btn:hover {
    background: var(--bg-hover);
}

/* ========== DUAL CONTROLS ========== */
.dual-controls {
    padding: 15px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dual-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.loop-counter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 13px;
    border: 1px solid var(--border-color);
}

.loop-counter.warning {
    border-color: var(--warning);
    color: var(--warning);
    animation: pulse-warning 1s infinite;
}

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

/* ========== MODALS ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px var(--shadow);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.modal-close:hover {
    background: var(--bg-hover);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ========== FORMS ========== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-range {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
}

.form-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: none;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-bottom: 8px;
}

.form-checkbox input[type="checkbox"],
.form-checkbox input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.settings-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* ========== IMAGE MODAL ========== */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-modal.active {
    display: flex;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 32px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.image-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========== TOASTS ========== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 12px var(--shadow);
    animation: slideIn 0.3s;
    min-width: 300px;
}

@keyframes slideIn {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 14px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--error); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.info { border-left: 4px solid var(--info); }

/* ========== RATE LIMIT WARNING ========== */
.rate-limit-warning {
    background: rgba(255, 173, 31, 0.1);
    border: 1px solid var(--warning);
    border-radius: 6px;
    padding: 8px 12px;
    margin: 10px 20px;
    font-size: 13px;
    color: var(--warning);
    display: none;
    align-items: center;
    gap: 8px;
}

.rate-limit-warning.active {
    display: flex;
}

/* ========== UTILITIES ========== */
.hidden {
    display: none !important;
}

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

.text-muted {
    color: var(--text-muted);
}

.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

.shimmer {
    background: linear-gradient(90deg, var(--bg-tertiary) 0%, var(--bg-hover) 50%, var(--bg-tertiary) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        box-shadow: 2px 0 8px var(--shadow);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .header {
        padding: 10px 15px;
    }

    .app-title {
        display: none;
    }

    .dual-panels {
        flex-direction: column;
    }

    .message {
        max-width: 95%;
    }

    .modal {
        max-width: 100%;
    }

    .btn-text {
        display: none;
    }

    .toast-container {
        left: 20px;
        right: 20px;
        max-width: none;
    }

    .toast {
        min-width: 0;
    }

    .security-badge {
        display: none;
    }
}
