@font-face {
    font-family: "DM Sans";
    src: url('https://polizialocaledigitale.it/wp-content/uploads/dm-sans-variable.woff2') format('woff2-variations');
    font-weight: 100 1000;
    font-style: normal;
    font-display: swap;
}

:root {
    --primary: hsl(220, 100%, 30%);
    --primary-l: hsl(220, 100%, 95%);
    --transition: 300ms;
}

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

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

html {
    font-size: 62.5%;
}

body {
    font-family: "DM Sans", sans-serif;
    background: white;
    height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

body, input, textarea, button {
    font-family: "DM Sans", sans-serif;
    font-size: 1.8rem;
}

.container {
    width: 100%;
    max-width: 90rem;
    height: 100vh;
    margin-inline: auto;
    background: white;
    display: flex;
    flex-direction: column;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    padding: 0.75rem 1.5rem;
    border-radius: 3rem;
    word-wrap: break-word;
    line-height: 1.75;
}

.user-message {
    align-self: flex-end;
    background: var(--primary);
    color: white;
}

.agent-message {
    align-self: flex-start;
    background: #f8f9fa;
    color: #2c3e50;
    border: 0.1rem solid #e9ecef;
}

.message-container {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, auto);
    align-items: flex-end;
    gap: 0.8rem;
    max-width: 90%;
}

@media (max-width: 767px) {
    .messages {
        padding: unset;
    }

    .message-container {
        width: 100%;
        max-width: unset;
        grid-template-columns: unset;
    }

    .container .input-area {
        padding: unset;
        gap: 0.5em;
    }
}

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

.message-container.agent {
    align-self: flex-start;
}

.message-container:hover .copy-button {
    opacity: 1;
}

.copy-button {
    width: 2.8rem;
    height: 2.8rem;
    border: none;
    background: #f8f9fa;
    border: 0.1rem solid #e9ecef;
    border-radius: 100%;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    box-shadow: 0 0.1rem 0.3rem rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    margin-bottom: 0.2rem;
}

.copy-button svg {
    width: 1.4rem;
    height: 1.4rem;
}

.copy-button:hover {
    background: white;
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0.2rem 0.8rem rgba(0, 0, 0, 0.1);
}

.copy-button.copied {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Markdown-style formatting */
.agent-message strong {
    font-weight: 600;
    color: #1a1a1a;
}

.agent-message em {
    font-style: italic;
}

.agent-message h1, .agent-message h2, .agent-message h3 {
    margin: 1.6rem 0 0.8rem 0;
    color: #1a1a1a;
    line-height: 1.3;
}

.agent-message h1 { 
    font-size: 2.4rem; 
}

.agent-message h2 { 
    font-size: 2rem; 
}

.agent-message h3 { 
    font-size: 1.8rem; 
}

.agent-message p {
    margin: 0.8rem 0;
}

.agent-message ul, .agent-message ol {
    margin: 0.8rem 0;
    padding-left: 2.4rem;
}

.agent-message li {
    margin: 0.6rem 0;
}

.agent-message code {
    background: #e9ecef;
    padding: 0.2rem 0.6rem;
    border-radius: 0.3rem;
    font-family: 'Monaco', 'Consolas', monospace;
}

.agent-message pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 1.2rem;
    border-radius: 0.6rem;
    overflow-x: auto;
    margin: 1.2rem 0;
}

.agent-message pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.agent-message blockquote {
    border-left: 0.3rem solid var(--primary);
    padding-left: 1.2rem;
    margin: 0.8rem 0;
    color: #6c757d;
}

.agent-message a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.agent-message a:hover {
    color: hsl(220, 100%, 35%);
    text-decoration: underline;
}

.agent-message .markdown-table {
    width: 100%;
    border: 0.1rem solid #e9ecef;
    margin: 1.2rem 0;
    font-size: 1.6rem;
    background: white;
    border-radius: 0.6rem;
    overflow: hidden;
}

.agent-message .markdown-table th,
.agent-message .markdown-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 0.1rem solid #e9ecef;
}

.agent-message .markdown-table th {
    font-weight: 600;
    color: #1a1a1a;
    border-bottom: 0.2rem solid #e9ecef;
}

.agent-message .markdown-table tr:last-child td {
    border-bottom: none;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.streaming-cursor {
    display: inline-block;
    width: 0.2rem;
    height: 1.2em;
    background: var(--primary);
    margin-left: 0.2rem;
    animation: blink 1s infinite;
    vertical-align: text-bottom;
}

.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 1.4rem 2rem;
    background: #f8f9fa;
    border-radius: 2.2rem;
    border: 0.1rem solid #e9ecef;
    box-shadow: 0 0.2rem 0.8rem rgba(0, 0, 0, 0.08);
    max-width: 8rem;
    position: relative;
    overflow: hidden;
}

.typing-indicator::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 2s infinite;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.typing-indicator span {
    display: inline-block;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.4;
    animation: typing 1.4s infinite ease-in-out;
    transform: scale(0.8);
}

.typing-indicator span:nth-child(2) { 
    animation-delay: 150ms; 
}

.typing-indicator span:nth-child(3) { 
    animation-delay: 300ms; 
}

@keyframes typing {
    0%, 80%, 100% {
        opacity: 0.4;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    50%, 100% {
        left: 100%;
    }
}

.input-area {
    padding: 3rem;
    display: flex;
    gap: 1.2rem;
    background: white;
    align-items: center;
    min-width: 0; /* Allow flex items to shrink below content size */
}

.mode-toggle {
    position: relative;
    padding: 1.2rem;
    border-radius: 100%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.mode-toggle:hover {
    background: var(--primary);
}

.mode-toggle.disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

.mode-icon {
    line-height: 0;
    color: white;
}

.mode-icon svg {
    height: 2rem;
    width: 2rem;
}

.mode-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 0.5rem;
    background: white;
    border: 0.1rem solid #ddd;
    border-radius: 0.8rem;
    box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 18rem;
    display: none;
}

.mode-menu.show {
    display: block;
}

.mode-option {
    padding: 1.2rem 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.4rem;
}

.mode-option:hover {
    background: #f8f9fa;
}

.mode-option[data-selected="true"] {
    background: var(--primary-l);
    color: var(--primary);
    font-weight: 500;
}

.mode-option:first-child {
    border-radius: 0.8rem 0.8rem 0 0;
}

.mode-option:last-child {
    border-radius: 0 0 0.8rem 0.8rem;
}

.mode-emoji {
    line-height: 0;
}

.mode-emoji svg {
    height: 1.8rem;
    width: 1.8rem;
}

.input-wrapper {
    flex: 1;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0; /* Allow flex item to shrink */
}

.message-input {
    flex: 1;
    height: 100%;
    padding: 0.75rem 4.5rem 0.75rem 1.5rem;
    border: 0.1rem solid #ddd;
    border-radius: 100vw;
    outline: none;
    transition: var(--transition);
    min-width: 0; /* Allow input to shrink */
    width: 100%; /* Ensure it uses available space */
}

.message-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.3rem var(--primary-l);
}

.attach-button {
    position: absolute;
    right: 1rem;
    width: 3rem;
    height: 3rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #666;
    transition: var(--transition);
}

.attach-button:hover {
    background: #f0f0f0;
    color: var(--primary);
}

.attach-button svg {
    height: 2rem;
    width: 2rem;
}

.attach-button.has-file {
    color: white;
    background: var(--primary);
}

.file-input {
    display: none;
}

.send-button {
    padding: 1.2rem;
    background: linear-gradient(135deg, var(--primary) 0%, hsl(220, 100%, 35%) 100%);
    color: white;
    border: none;
    border-radius: 100%;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 4.8rem;
    height: 4.8rem;
}

.send-button:disabled { 
    opacity: 50%; 
    cursor: not-allowed;
}

.send-button svg {
    height: 2rem;
    width: 2rem;
}

/* Add mode indicator */
.mode-indicator {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    text-transform: uppercase;
}

.mode-indicator.default {
    background: #6c757d;
}

.mode-indicator.controdeduzione {
    background: #dc3545;
}

.mode-indicator.ordinanza {
    background: #28a745;
}

.error-message {
    background: #fee;
    color: #c00;
    border: 0.1rem solid #fcc;
}

/* Scrollbar styling */
.messages::-webkit-scrollbar {
    width: 0.8rem;
}

.messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 0.4rem;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive design for mobile and narrow screens */
@media (max-width: 768px) {
    
    .message-input {
        padding: 0.75rem 3.5rem 0.75rem 1.2rem;
        font-size: 0.75em;
    }
    
    .send-button {
        padding: 1rem;
        width: 4.2rem;
        height: 4.2rem;
    }
    
    .send-button svg {
        height: 1.8rem;
        width: 1.8rem;
    }
    
    .mode-toggle {
        padding: 1rem;
    }
    
    .mode-icon svg {
        height: 1.8rem;
        width: 1.8rem;
    }
}

@media (max-width: 480px) {
    
    .message-input {
        padding: 0.75rem 3rem 0.75rem 1rem;
    }
    
    .send-button {
        padding: 0.8rem;
        width: 3.8rem;
        height: 3.8rem;
    }
    
    .send-button svg {
        height: 1.6rem;
        width: 1.6rem;
    }
    
    .mode-toggle {
        padding: 0.8rem;
    }
    
    .mode-icon svg {
        height: 1.6rem;
        width: 1.6rem;
    }
    
    .attach-button {
        width: 2.5rem;
        height: 2.5rem;
        right: 0.5rem;
    }
    
    .attach-button svg {
        height: 1.8rem;
        width: 1.8rem;
    }
}
/* Chat Continue Dialog Overlay */
.chat-continue-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-continue-dialog {
    background: white;
    border-radius: 1.2rem;
    padding: 3rem;
    max-width: 50rem;
    width: 90%;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(2rem);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chat-continue-dialog h3 {
    font-size: 2.4rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: #1a1a1a;
}

.chat-continue-dialog p {
    font-size: 1.6rem;
    color: #666;
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

.chat-continue-buttons {
    display: flex;
    gap: 1.2rem;
    justify-content: flex-end;
}

.chat-continue-buttons button {
    padding: 1.2rem 2.4rem;
    border: none;
    border-radius: 0.8rem;
    font-size: 1.6rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-continue-buttons button.primary {
    background: var(--primary);
    color: white;
}

.chat-continue-buttons button.primary:hover {
    background: hsl(220, 100%, 25%);
    transform: translateY(-0.2rem);
}

.chat-continue-buttons button.secondary {
    background: #f0f0f0;
    color: #333;
}

.chat-continue-buttons button.secondary:hover {
    background: #e0e0e0;
}

.chat-continue-buttons button:active {
    transform: translateY(0);
}
