/* ========================================
   ICAR Guàrdies - Estils Corporatius
   Il·lustre Col·legi de l'Advocacia de Reus
   ======================================== */

:root {
    /* Colors Corporatius */
    --primary: #1a3a5c;
    --primary-dark: #0f2540;
    --primary-light: #2a5a8c;
    --secondary: #c9a227;
    --secondary-light: #e6c655;
    --secondary-dark: #9a7a1a;
    
    /* Neutrals */
    --white: #ffffff;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #868e96;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;
    
    /* Semantic */
    --success: #2f9e44;
    --error: #e03131;
    --warning: #f59f00;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Typography */
    --font-family: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    
    /* Borders */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
}

/* ========================================
   Reset & Base
   ======================================== */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.6;
    color: var(--gray-800);
    background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-200) 100%);
    min-height: 100vh;
}

/* ========================================
   App Container
   ======================================== */

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--white);
    box-shadow: var(--shadow-xl);
}

@media (min-width: 1024px) {
    .app-container {
        margin: var(--space-xl) auto;
        min-height: calc(100vh - var(--space-2xl) * 2);
        border-radius: var(--radius-xl);
        overflow: hidden;
    }
}

/* ========================================
   Header
   ======================================== */

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 4px solid var(--secondary);
}

.header-content {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.logo-section {
    flex-shrink: 0;
}

.logo {
    height: 70px;
    width: auto;
    filter: brightness(0) invert(1);
    transition: transform var(--transition-base);
}

.logo:hover {
    transform: scale(1.02);
}

.title-section h1 {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-xs);
}

.subtitle {
    font-size: var(--font-size-sm);
    color: var(--secondary-light);
    font-weight: 400;
    letter-spacing: 0.02em;
}

@media (max-width: 640px) {
    .header {
        padding: var(--space-md);
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .logo {
        height: 50px;
    }
    
    .title-section h1 {
        font-size: var(--font-size-xl);
    }
}

/* ========================================
   Chat Container
   ======================================== */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    scroll-behavior: smooth;
}

/* ========================================
   Messages
   ======================================== */

.message {
    display: flex;
    gap: var(--space-md);
    max-width: 85%;
    animation: messageSlideIn var(--transition-slow) ease-out;
}

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

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

.message.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--secondary);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
    color: var(--white);
}

.message-avatar svg {
    width: 20px;
    height: 20px;
}

.message-content {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    border: 1px solid var(--gray-200);
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--white);
    border-color: transparent;
}

.message-header {
    margin-bottom: var(--space-xs);
}

.message-sender {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--primary);
}

.message.user .message-sender {
    color: var(--secondary-light);
}

.message-text {
    font-size: var(--font-size-md);
    line-height: 1.7;
}

.message-text p {
    margin-bottom: var(--space-sm);
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text ul, .message-text ol {
    margin: var(--space-sm) 0;
    padding-left: var(--space-lg);
}

.message-text li {
    margin-bottom: var(--space-xs);
}

.message-text strong {
    font-weight: 600;
    color: var(--primary);
}

.message.user .message-text strong {
    color: var(--secondary-light);
}

.message-text code {
    background: var(--gray-200);
    padding: 0.1em 0.4em;
    border-radius: var(--radius-sm);
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
}

/* ========================================
   Chat Input
   ======================================== */

.chat-input-container {
    padding: var(--space-lg) var(--space-xl);
    background: var(--white);
    border-top: 1px solid var(--gray-200);
}

.chat-input-wrapper {
    display: flex;
    gap: var(--space-md);
    align-items: flex-end;
    background: var(--gray-50);
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-lg);
    padding: var(--space-sm);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 58, 92, 0.1);
}

#userInput {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    padding: var(--space-sm) var(--space-md);
    resize: none;
    max-height: 150px;
    line-height: 1.5;
}

#userInput:focus {
    outline: none;
}

#userInput::placeholder {
    color: var(--gray-500);
}

.action-button {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.action-button:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.action-button:active {
    transform: scale(0.98);
}

.action-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.action-button svg {
    width: 20px;
    height: 20px;
}

.reload-button {
    /* Mismo estilo que send-button */
}

.send-button {
    /* Mismo estilo base ya en action-button */
}

.disclaimer {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    text-align: center;
    margin-top: var(--space-sm);
    padding: 0 var(--space-md);
}

@media (max-width: 640px) {
    .chat-input-container {
        padding: var(--space-md);
    }
}

/* ========================================
   Footer
   ======================================== */

.footer {
    background: var(--gray-100);
    padding: var(--space-md) var(--space-xl);
    border-top: 1px solid var(--gray-200);
}

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

.footer-content p {
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

.footer-links {
    margin-top: var(--space-xs);
}

.footer-links a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--secondary);
}

.footer-links .separator {
    margin: 0 var(--space-sm);
    color: var(--gray-400);
}

/* ========================================
   Loading Overlay
   ======================================== */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 58, 92, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-lg);
    z-index: 1000;
}

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

.loading-overlay p {
    color: var(--white);
    font-size: var(--font-size-lg);
    font-weight: 500;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--primary-light);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ========================================
   Scrollbar Styles
   ======================================== */

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* ========================================
   Utility Classes
   ======================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .chat-input-container,
    .footer,
    .send-button {
        display: none;
    }
    
    .app-container {
        box-shadow: none;
    }
    
    .message-content {
        border: 1px solid var(--gray-400);
    }
}
