/* ============================================================
   Strukturado ERP - Asistente Admin Chat Interface
   ============================================================ */

/* ---------- Reset & Variables ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-primary-dark: #1e40af;

    --color-sidebar-bg: #1e1e2e;
    --color-sidebar-hover: #2a2a3e;
    --color-sidebar-text: #cdd6f4;
    --color-sidebar-muted: #6c7086;
    --color-sidebar-border: #313244;

    --color-bg: #f8f9fb;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;

    --color-user-bubble: #2563eb;
    --color-user-text: #ffffff;
    --color-bot-bubble: #f1f5f9;
    --color-bot-text: #1e293b;

    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-success: #22c55e;

    --color-code-bg: #1e293b;
    --color-code-text: #e2e8f0;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --sidebar-width: 260px;
    --header-height: 60px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", Menlo, Consolas, monospace;

    --transition: 150ms ease;
}

html, body {
    height: 100%;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- Login Screen ---------- */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e1e2e 0%, #2a2a3e 50%, #1e1e2e 100%);
    padding: 20px;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    animation: fadeSlideUp 0.4s ease;
}

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

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.logo-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
}

.logo-placeholder.small {
    width: 36px;
    height: 36px;
    font-size: 16px;
    margin-bottom: 0;
    border-radius: var(--radius-sm);
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--color-text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-group input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-group input::placeholder {
    color: var(--color-text-muted);
}

.login-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--color-danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    outline: none;
}

.btn:active {
    transform: scale(0.98);
}

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

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

.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.btn-full {
    width: 100%;
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* ---------- Chat Screen Layout ---------- */
.chat-screen {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--color-sidebar-border);
}

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

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

.sidebar-title {
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
}

.sidebar-label {
    font-size: 11px;
    color: var(--color-sidebar-muted);
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-sidebar-muted);
    padding: 8px 12px 6px;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-sidebar-text);
    font-size: 13px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-align: left;
}

.sidebar-btn:hover {
    background: var(--color-sidebar-hover);
    color: #ffffff;
}

.sidebar-btn svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-btn:hover svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--color-sidebar-border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 4px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    color: var(--color-sidebar-text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-btn {
    color: var(--color-danger) !important;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.1) !important;
}

/* ---------- Chat Main ---------- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--color-bg);
}

/* ---------- Chat Header ---------- */
.chat-header {
    height: var(--header-height);
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.chat-header-info h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.chat-header-status {
    font-size: 12px;
    color: var(--color-text-secondary);
}

/* ---------- Messages Container ---------- */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}

.messages-list {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ---------- Messages ---------- */
.message {
    display: flex;
    gap: 12px;
    max-width: 100%;
    animation: msgFadeIn 0.25s ease;
}

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

.message-avatar {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.bot-avatar {
    background: #e0e7ff;
    color: var(--color-primary);
}

.user-avatar-msg {
    background: var(--color-primary);
    color: white;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.bot-bubble {
    background: var(--color-bot-bubble);
    color: var(--color-bot-text);
    border-top-left-radius: var(--radius-sm);
}

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

.user-bubble {
    background: var(--color-user-bubble);
    color: var(--color-user-text);
    border-top-right-radius: var(--radius-sm);
}

.user-message .message-content {
    align-items: flex-end;
}

.message-time {
    font-size: 11px;
    color: var(--color-text-muted);
    padding: 0 4px;
}

/* ---------- Typing Indicator ---------- */
.typing-indicator {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
}

.typing-bubble {
    display: inline-flex;
    padding: 14px 20px !important;
}

.typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.typing-dots span {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

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

/* ---------- Markdown Content Inside Bot Bubbles ---------- */
.bot-bubble p {
    margin-bottom: 8px;
}

.bot-bubble p:last-child {
    margin-bottom: 0;
}

.bot-bubble strong {
    font-weight: 700;
}

.bot-bubble em {
    font-style: italic;
}

.bot-bubble code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: rgba(0, 0, 0, 0.07);
    padding: 2px 6px;
    border-radius: 4px;
}

.bot-bubble pre {
    background: var(--color-code-bg);
    color: var(--color-code-text);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
    line-height: 1.5;
}

.bot-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.bot-bubble ul, .bot-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.bot-bubble li {
    margin-bottom: 4px;
}

.bot-bubble blockquote {
    border-left: 3px solid var(--color-primary);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--color-text-secondary);
}

.bot-bubble h1, .bot-bubble h2, .bot-bubble h3, .bot-bubble h4 {
    margin: 12px 0 6px;
    font-weight: 700;
}

.bot-bubble h1 { font-size: 18px; }
.bot-bubble h2 { font-size: 16px; }
.bot-bubble h3 { font-size: 15px; }
.bot-bubble h4 { font-size: 14px; }

/* ---------- Markdown Tables ---------- */
.bot-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
}

.bot-bubble thead {
    background: rgba(0, 0, 0, 0.06);
}

.bot-bubble th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 700;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

.bot-bubble td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
}

.bot-bubble tr:last-child td {
    border-bottom: none;
}

.bot-bubble tr:hover td {
    background: rgba(0, 0, 0, 0.02);
}

/* ---------- File Downloads ---------- */
.file-downloads {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.file-download-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition);
}

.file-download-link:hover {
    background: #bfdbfe;
}

.file-download-link svg {
    flex-shrink: 0;
}

/* ---------- Input Area ---------- */
.input-area {
    padding: 0 24px 16px;
    max-width: 848px;
    margin: 0 auto;
    width: 100%;
}

.input-wrapper {
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
    overflow: hidden;
}

.input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.file-preview {
    padding: 8px 12px 0;
}

.file-preview-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    padding: 4px 8px 4px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
}

.file-preview-remove {
    background: none;
    border: none;
    color: var(--color-primary-dark);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.7;
    transition: opacity var(--transition);
}

.file-preview-remove:hover {
    opacity: 1;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 8px;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}

.upload-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

#message-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 4px;
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--color-text);
    resize: none;
    max-height: 150px;
    line-height: 1.5;
    background: transparent;
}

#message-input::placeholder {
    color: var(--color-text-muted);
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--color-primary);
    color: white;
    cursor: pointer;
    transition: background var(--transition), opacity var(--transition), transform var(--transition);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.94);
}

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

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 6px;
}

/* ---------- Error Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--color-danger);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 4.7s forwards;
    max-width: 400px;
}

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

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

/* ---------- Scrollbar ---------- */
.messages-container::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track,
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--color-sidebar-border);
    border-radius: 3px;
}

/* ---------- Responsive (small desktop / tablet) ---------- */
@media (max-width: 900px) {
    .sidebar {
        width: 220px;
        min-width: 220px;
    }
}

@media (max-width: 700px) {
    .sidebar {
        display: none;
    }

    .input-area {
        padding: 0 12px 12px;
    }

    .messages-list {
        padding: 0 12px;
    }
}

/* ---------- Selection ---------- */
::selection {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

/* ---------- Focus visible ---------- */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible {
    outline: none;
}
