/* ============================================
   MINORSYS IA - Generador de Demandas
   Con Sidebar de Historial de Chats
   ============================================ */

:root {
    --primary: #2C3E50;
    --primary-light: #34495E;
    --primary-dark: #1A252F;
    --white: #FFFFFF;
    --gray-50: #F8F9FA;
    --gray-100: #F1F3F5;
    --gray-200: #E9ECEF;
    --gray-300: #DEE2E6;
    --gray-400: #CED4DA;
    --gray-500: #ADB5BD;
    --gray-600: #6C757D;
    --error: #E74C3C;
    --success: #27AE60;
    --font-main: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'SF Mono', 'Consolas', monospace;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 24px;
    --sidebar-width: 280px;
}

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

html, body {
    height: 100%;
}

body {
    font-family: var(--font-main);
    background-color: var(--gray-50);
    color: var(--primary);
    line-height: 1.6;
}

/* ============================================
   LOGIN / REGISTER PAGE
   ============================================ */

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
}

.logo-text {
    font-size: 1.75rem;
    font-weight: 300;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.logo-accent {
    font-weight: 600;
}

.tagline {
    color: var(--gray-600);
    font-size: 0.95rem;
    font-weight: 400;
}

.auth-section {
    background: var(--white);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
}

.auth-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-width: 0;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary);
}

.form-group input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--white);
    width: 100%;
    min-width: 0;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.1);
}

.form-group input::placeholder {
    color: var(--gray-400);
}

.form-group .hint {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

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

.btn-primary:active {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    background: var(--gray-400);
    cursor: not-allowed;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--gray-300);
}

.btn-small:hover {
    background: var(--gray-100);
}

.error-message {
    color: var(--error);
    font-size: 0.875rem;
    min-height: 1.25rem;
}

.success-message {
    color: var(--success);
    font-size: 0.875rem;
    min-height: 1.25rem;
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--gray-600);
    font-size: 0.875rem;
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.footer {
    margin-top: 2rem;
    color: var(--gray-500);
    font-size: 0.8rem;
}

.hidden {
    display: none !important;
}

/* ============================================
   APP LAYOUT WITH SIDEBAR
   ============================================ */

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    background: var(--primary-dark);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    flex-shrink: 0;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    width: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.btn-new-chat {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    color: var(--white);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: rgba(255,255,255,0.15);
}

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius);
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
    overflow: hidden;
}

.chat-item:hover {
    background: rgba(255,255,255,0.1);
}

.chat-item.active {
    background: rgba(255,255,255,0.15);
    color: var(--white);
}

.chat-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-date {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info-sidebar {
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout-sidebar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    color: rgba(255,255,255,0.8);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout-sidebar:hover {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}

/* Empty state */
.sidebar-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 0.85rem;
}

/* ============================================
   CHAT CONTAINER
   ============================================ */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--white);
    min-width: 0;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--white);
    gap: 1rem;
}

.header-left {
    min-width: 120px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-toggle-sidebar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-toggle-sidebar:hover {
    background: var(--gray-100);
    color: var(--primary);
}

.logo-small {
    width: 28px;
    height: 28px;
}

.logo-text-small {
    font-size: 1.1rem;
    font-weight: 300;
    color: var(--primary);
}

.header-center {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.current-chat-title {
    font-size: 0.9rem;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.header-right {
    min-width: 120px;
    justify-content: flex-end;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-delete-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-delete-chat:hover {
    background: var(--gray-100);
    color: var(--error);
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.welcome-message {
    text-align: center;
    padding: 3rem 2rem;
    max-width: 500px;
    margin: auto;
}

.welcome-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

.welcome-message h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--primary);
}

.welcome-message p {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.welcome-hint {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: 1rem;
}

/* Message Bubbles */
.message {
    max-width: 80%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    line-height: 1.5;
}

.message-user {
    align-self: flex-end;
    background: var(--primary);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message-assistant {
    align-self: flex-start;
    background: var(--gray-100);
    color: var(--primary);
    border-bottom-left-radius: 4px;
}

.message-assistant pre {
    background: var(--gray-200);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.5rem 0;
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.message-assistant code {
    font-family: var(--font-mono);
    background: var(--gray-200);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.5rem;
}

/* File attachments in messages */
.message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.message-file-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    font-size: 0.8rem;
}

.message-file-item svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Download DOCX Button */
.btn-download-docx {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.625rem 1rem;
    background: var(--success);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-download-docx:hover {
    background: #219a52;
}

.btn-download-docx:disabled {
    background: var(--gray-400);
    cursor: wait;
}

.btn-download-docx svg {
    width: 16px;
    height: 16px;
}

/* Input Area */
.chat-input-container {
    padding: 1rem 1.5rem 1.5rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
}

/* File Preview Area */
.file-preview-area {
    max-width: 800px;
    margin: 0 auto 0.75rem;
    padding: 0.75rem;
    background: var(--gray-100);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
}

.file-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-300);
    font-size: 0.875rem;
    color: var(--primary);
}

.file-preview-item .file-icon {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.file-preview-item .file-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-item .file-size {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.file-preview-item .file-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--gray-500);
    transition: color 0.2s;
    display: flex;
}

.file-preview-item .file-remove:hover {
    color: var(--error);
}

.file-preview-item .file-remove svg {
    width: 16px;
    height: 16px;
}

.input-hint {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-500);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-xl);
    padding: 0.5rem 0.75rem;
    box-shadow: var(--shadow-md);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form:focus-within {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg), 0 0 0 3px rgba(44, 62, 80, 0.1);
}

.btn-attach {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--gray-500);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-attach:hover {
    background: var(--gray-100);
    color: var(--primary);
}

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

.chat-form textarea {
    flex: 1;
    padding: 0.5rem;
    border: none;
    font-size: 1rem;
    font-family: var(--font-main);
    resize: none;
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
    background: transparent;
}

.chat-form textarea:focus {
    outline: none;
}

.chat-form textarea::placeholder {
    color: var(--gray-400);
}

.btn-send {
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    flex-shrink: 0;
    transition: all 0.2s;
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-light);
    transform: scale(1.05);
}

.btn-send:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--gray-600);
    font-size: 0.875rem;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    .auth-section {
        padding: 1.5rem;
        max-width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .chat-header {
        padding: 0.5rem 0.75rem;
    }

    .logo-small, .logo-text-small {
        display: none;
    }

    .chat-messages {
        padding: 1rem;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-container {
        padding: 0.75rem 1rem 1rem;
    }

    .chat-form {
        padding: 0.375rem 0.5rem;
        border-radius: var(--radius-lg);
        gap: 0.25rem;
    }

    .btn-attach {
        width: 36px;
        height: 36px;
    }

    .btn-send {
        width: 40px;
        height: 40px;
    }

    .file-preview-item .file-name {
        max-width: 100px;
    }

    .input-hint {
        font-size: 0.7rem;
    }
}
