:root {
    /* Color Palette - Premium Dark Mode */
    --bg-main: #0F172A; /* Slate 900 */
    --bg-chat: #1E293B; /* Slate 800 */
    --bg-header: #0F172A;
    --bg-input: #1E293B;
    --bg-bubble-bot: #334155; /* Slate 700 */
    --bg-bubble-user: #3B82F6; /* Blue 500 */
    --text-main: #F8FAFC; /* Slate 50 */
    --text-muted: #94A3B8; /* Slate 400 */
    --accent: #3B82F6; /* Blue 500 */
    --accent-hover: #2563EB; /* Blue 600 */
    --success: #10B981; /* Emerald 500 */
    --danger: #EF4444; /* Red 500 */
    --border-color: rgba(255, 255, 255, 0.1);
    
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    
    --msg-strong-color: #fff;
    --msg-code-bg: rgba(0,0,0,0.3);
    
    --bg-secondary: #1E293B; /* Slate 800 */
    --bg-bubble-other: #475569; /* Slate 600 */
}

:root.theme-light {
    --bg-main: #E2E8F0; /* Slate 200 */
    --bg-chat: #FFFFFF; /* White */
    --bg-header: #FFFFFF;
    --bg-input: #F8FAFC;
    --bg-bubble-bot: #E2E8F0; /* Slate 200 */
    --bg-bubble-user: #3B82F6; /* Blue 500 */
    --text-main: #0F172A; /* Slate 900 */
    --text-muted: #64748B; /* Slate 500 */
    --border-color: rgba(0, 0, 0, 0.15); /* Stronger border */
    --msg-strong-color: #0F172A; /* Slate 900 */
    --msg-code-bg: rgba(0, 0, 0, 0.05);
    
    --bg-secondary: #CBD5E1; /* Slate 300 */
    --bg-bubble-other: var(--bg-bubble-user); /* Same as user in light mode */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    height: 100%;
    height: 100dvh;
}

body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
}



/* Ecosystem Layout */
.ecosystem-layout {
    display: flex;
    width: 100vw;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-main);
}

/* Sidebar */
.ecosystem-sidebar {
    width: 260px;
    background-color: var(--bg-header);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 20px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-nav {
    list-style: none;
    padding: 15px 10px;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item i {
    width: 24px;
    text-align: center;
}

.nav-item:hover:not(.disabled) {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--text-main);
}

.nav-item.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    border-left: 4px solid var(--accent);
}

.nav-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Main Area */
.ecosystem-main {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view-container {
    display: none; /* hidden by default */
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
}

.view-container.active-view {
    display: flex;
    flex-direction: column;
}

/* Global Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none; /* hidden on desktop */
}

/* App Container (Parking Bot) */
#app-container.view-container {
    width: 100%;
    background-color: var(--bg-main);
}

.app-layout-grid {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 20px;
    padding: 20px;
    box-sizing: border-box;
}

.chat-container {
    flex: 1;
    min-width: 0; /* Essential for flexbox to not squish or overflow on small iPads */
    max-width: 800px;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-chat);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

/* Micro Dashboard */
.micro-dashboard {
    flex: 0 0 auto;
    width: 300px;
    max-width: 320px;
    background-color: var(--bg-panel);
    border-radius: var(--radius-lg);
    border: var(--glass-border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.micro-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.micro-header h2 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

.micro-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.micro-stats-row {
    display: flex;
    gap: 8px;
}

.micro-stats-row .stats-card {
    flex: 1;
    min-width: 0;
    padding: 10px;
    gap: 8px;
}

.micro-stat {
    padding: 12px;
}

.micro-stat .stat-icon {
    font-size: 20px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.micro-stat .stat-info {
    min-width: 0;
    overflow: hidden;
}

.micro-stat .stat-info .stat-label {
    font-size: 0.7rem;
    white-space: normal;
    line-height: 1.1;
}
.micro-stat .stat-info .stat-value {
    font-size: 1.1rem;
}

.micro-section-header {
    font-size: 1rem;
    color: var(--text-main);
    margin-top: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.micro-section-header h3 {
    font-size: 0.9rem;
    margin: 0;
}

.micro-movimientos-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.micro-mov-item {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.85rem;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.micro-mov-icon {
    font-size: 1.2rem;
}

/* --- Premium Extensions --- */
.weather-widget {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(16, 185, 129, 0.05));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
}

.weather-icon {
    font-size: 2rem;
    color: #FBBF24; /* Amber 400 */
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
}

.weather-info {
    flex: 1;
    min-width: 0;
}

.weather-temp {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.weather-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cadence-widget {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 15px;
}

.cadence-title {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.cadence-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 4px;
    height: 75px;
    padding-top: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.theme-light .cadence-bars {
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.cadence-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
}

.cadence-bar {
    width: 100%;
    max-width: 12px;
    background-color: var(--accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.5s ease;
}

.cadence-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .ecosystem-sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
    }

    .ecosystem-sidebar.active {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }
}

/* Allow sidebar to be toggled even on desktop/landscape iPad */
.ecosystem-sidebar.force-hidden {
    display: none; /* simple display none when toggled off manually in wide mode */
}

@media (max-width: 1024px) {
    .mobile-menu-toggle {
        display: block; /* Show the hamburger button */
    }
}

@media (max-width: 767px) {
    .mobile-only {
        display: block !important;
    }
    
    #app-container.view-container {
        border: none;
        max-width: 100%;
        padding: 0;
    }
    
    .app-layout-grid {
        padding: 0;
        flex-direction: column;
        overflow-y: auto;
        display: flex;
    }
    
    .chat-container {
        border: none;
        border-radius: 0;
        height: 100%;
        flex: 1;
        box-shadow: none;
        margin-bottom: 0px;
    }

    .micro-dashboard {
        display: none !important;
    }
}

.chat-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
    /* Fix for iOS Safari not clipping child backgrounds with border-radius */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    -webkit-mask-image: -webkit-radial-gradient(white, black);
}

/* Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8B5CF6);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: white;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.bot-name {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.badge {
    background-color: rgba(59, 130, 246, 0.2);
    color: var(--accent);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.bot-status {
    font-size: 13px;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 5px;
}

.bot-status::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
}

.icon-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.icon-btn.active:hover {
    background: var(--accent);
    filter: brightness(1.1);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.icon-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.05);
}

/* Chat Area */
.chat-messages {
    flex: 1;
    min-height: 0; /* Critical for flexbox scrolling */
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-image: radial-gradient(circle at center, rgba(59, 130, 246, 0.03) 0%, transparent 100%);
}

/* Ajustes para Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- VISTA ESQUEMÁTICA MAPA VILLAS --- */
.villas-dashboard {
    display: flex;
    flex-direction: column;
    gap: 30px;
    width: 100%;
}

.map-zone {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    width: 100%;
}

.zone-title {
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.zone-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
}

.villa-card {
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px 0;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.villa-card:hover {
    background-color: var(--accent);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
    border-color: var(--accent);
}

.message {
    display: flex;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out forwards;
    position: relative;
}

/* Reply overlay icon */
.message-reply-action {
    position: absolute;
    top: -10px;
    cursor: pointer;
    background: var(--bg-header);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    transition: all 0.2s;
    font-size: 12px;
    box-shadow: var(--shadow-md);
    opacity: 0.7; /* Always slightly visible to be discoverable */
    z-index: 5;
}

.message.bot .message-reply-action { right: -10px; }
.message.user .message-reply-action { left: -10px; }

.message:hover .message-reply-action {
    opacity: 1;
    color: var(--accent);
    transform: scale(1.1);
}
.message-reply-action:hover {
    color: var(--accent);
    background: var(--bg-bubble-bot);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.bot, .message.other-user {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
}

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    position: relative;
    line-height: 1.5;
    font-size: 15px;
    box-shadow: var(--shadow-md);
    word-break: break-word;
}

.message.bot .message-content {
    background-color: var(--bg-bubble-bot);
    border-bottom-left-radius: 4px;
}

.message.other-user .message-content {
    background-color: var(--bg-bubble-other);
    border-bottom-left-radius: 4px;
    color: var(--text-main); /* Default, but will be overridden for light theme */
}

:root.theme-light .message.other-user .message-content {
    color: #fff; /* Blue background in light mode needs white text */
}

/* Also ensure strong tags inside other-user in light mode are white */
:root.theme-light .message.other-user .message-content strong {
    color: #fff;
}

.other-user-name {
    font-size: 12px;
    font-weight: 700;
    color: #93C5FD; /* Blue 300 */
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.message.user .other-user-name,
:root.theme-light .message.other-user .other-user-name {
    color: rgba(255, 255, 255, 0.85);
}

.message-context-ref {
    font-size: 11px;
    background-color: var(--msg-code-bg);
    border-left: 3px solid var(--accent);
    padding: 6px 8px;
    margin-bottom: 8px;
    border-radius: 4px;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Improve contrast for reply box inside blue bubbles */
.message.user .message-context-ref,
:root.theme-light .message.other-user .message-context-ref {
    background-color: rgba(255, 255, 255, 0.15);
    border-left-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.9);
}

.message.user .message-context-ref strong,
:root.theme-light .message.other-user .message-context-ref strong {
    color: #fff;
}

.message.user .message-content {
    background-color: var(--bg-bubble-user);
    border-bottom-right-radius: 4px;
    color: #ffffff;
}

.message p {
    margin-bottom: 6px;
}
.message p:last-of-type {
    margin-bottom: 0;
}

.message-time {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
    user-select: none;
}

.message.user .message-time,
:root.theme-light .message.other-user .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Formatting inside bot messages */
.message strong {
    color: var(--msg-strong-color);
}
.message code {
    background-color: var(--msg-code-bg);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

/* Image inside message */
.message-img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: block;
}

/* Inline Keyboards (Buttons inside chat) */
.inline-keyboard {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.inline-btn {
    flex: 1 1 calc(50% - 4px);
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
    text-align: center;
}

.inline-btn:hover {
    background-color: var(--bg-bubble-bot);
    transform: translateY(-1px);
}

.inline-btn.full-width {
    flex: 1 1 100%;
}

.chat-input-area {
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border-color);
    z-index: 10;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.attachment-preview-container {
    position: absolute;
    bottom: 80px;
    left: 16px;
    background: var(--bg-bubble-bot);
    padding: 8px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    border: 1px solid var(--border-color);
    z-index: 20;
}

.attachment-preview-container img {
    max-width: 100px;
    max-height: 100px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.remove-attachment-btn {
    background: var(--danger);
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    position: absolute;
    top: -8px;
    right: -8px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Reply Preview UI */
.reply-preview-container {
    background-color: var(--bg-bubble-bot);
    border-left: 4px solid var(--accent);
    padding: 8px 12px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    margin-bottom: -1px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    z-index: 10;
}

.reply-preview-text {
    flex: 1;
    overflow: hidden;
}

.reply-sender {
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 2px;
    display: block;
}

#reply-text {
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-reply-btn {
    width: 24px;
    height: 24px;
    font-size: 14px;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background-color: var(--bg-input);
    border-radius: 24px;
    padding: 6px 16px;
    gap: 12px;
    border: 1px solid var(--border-color);
    transition: border-color 0.3s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.message-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    outline: none;
    padding: 0;
    height: 40px;
    line-height: 40px;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    color: var(--accent);
}

.send-btn:hover {
    color: var(--accent-hover);
    background: transparent;
}

/* Typing Indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Utilities for Markdown parsing */
.bot-msg-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 5px;
}

.bot-msg-list {
    list-style: none;
    margin: 8px 0;
}

.bot-msg-list li {
    margin-bottom: 4px;
    position: relative;
    padding-left: 12px;
}
.bot-msg-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--accent);
}

/* History Loader */
.history-loader {
    text-align: center;
    padding: 15px 0;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
}

/* Search Bar */
.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-secondary);
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    gap: 10px;
}
.search-bar input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 8px 15px;
    color: var(--text-primary);
    outline: none;
    font-size: 14px;
}
.search-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}
.search-count {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 5px;
}
.icon-btn-small {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s;
}
.icon-btn-small:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.1);
}
.message.highlight-search .message-content {
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.5);
    transition: all 0.3s;
}
.message.highlight-search.active .message-content {
    box-shadow: 0 0 0 4px rgba(255, 193, 7, 1), 0 0 20px rgba(255, 193, 7, 0.5);
    background-color: rgba(255, 193, 7, 0.1);
}

/* Toast */
.toast {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 1000;
    pointer-events: none;
    transition: opacity 0.3s;
}

/* INFO Photo Card */
.info-card-container {
    position: relative;
    margin-top: 10px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background-color: #000;
    background-size: cover;
    background-position: center;
}
.info-text-overlay {
    position: relative;
    z-index: 1;
    background: linear-gradient(to top, rgba(0,0,0,1) 0%, rgba(0,0,0,0.6) 100%);
    padding: 15px;
    width: 100%;
    color: #ffffff;
}
.info-text-overlay strong {
    color: #ffffff;
}
.expand-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 32px;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    text-shadow: 0 0 10px rgba(0,0,0,0.8);
    z-index: 2;
}
.info-card-container:hover .expand-icon {
    opacity: 1;
}

/* Modal */
.modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
}
.modal-content {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    object-fit: contain;
}
.modal-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}
/* =========================================================
   LOGIN SCREEN
   ========================================================= */
.login-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.login-box {
    background: var(--bg-bot);
    padding: 40px;
    border-radius: var(--radius-lg);
    border: var(--border-light);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: relative;
}

.login-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-header i {
    font-size: 48px;
    color: var(--accent);
    filter: drop-shadow(0 0 12px rgba(59, 130, 246, 0.5));
}

.login-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* Formularios de Custodia */
#car-matricula, #car-marca, #car-nombre, #car-hab, #car-plaza, #car-ticket,
#mc-matricula, #mc-marca, #mc-nombre, #mc-hab, #mc-plaza,
#inv-guest {
    text-transform: uppercase;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.input-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.input-group input,
.input-group select {
    width: 100%;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.login-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.login-btn:hover {
    background: var(--accent-hover);
}

.login-error {
    color: var(--danger);
    font-size: 14px;
    text-align: center;
    font-weight: 500;
    min-height: 20px;
}
.login-error:empty {
    display: none;
}

.login-toggle {
    text-align: center;
    margin-top: 8px;
}

.login-toggle a {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s;
}

.login-toggle a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* =========================================================
   SETTINGS & PROFILE
   ========================================================= */
.settings-dropdown-container {
    position: relative;
    display: inline-block;
}
.settings-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-header);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    min-width: 180px;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    margin-top: 8px;
}
.settings-dropdown button {
    background: none;
    border: none;
    color: var(--text-main);
    padding: 10px 16px;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-dropdown button:hover {
    background: var(--bg-input);
}

.profile-modal-content {
    background: var(--bg-header);
    padding: 20px; /* Reduced from 30px for better mobile fit */
    border-radius: var(--radius-lg);
    width: 95%; /* 95% on mobile */
    max-width: 400px !important;
    max-height: 90vh; /* Prevent overflow on small screens */
    overflow-y: auto; /* Allow scrolling if content is too tall */
    display: flex;
    flex-direction: column;
    gap: 15px; /* Reduced gap */
    box-sizing: border-box; /* Explicitly ensure border-box */
    position: relative;
}
.profile-modal-content h2 {
    font-size: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.profile-modal-content p {
    color: var(--text-muted);
    font-size: 14px;
}
.primary-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}
.primary-btn:hover {
    background: var(--accent-hover);
}

.danger-btn {
    background-color: var(--danger);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s ease, filter 0.2s ease;
}

.danger-btn:hover {
    filter: brightness(0.9);
}

.dept-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    margin-left: 6px;
    text-transform: uppercase;
    display: inline-block;
}
.dept-botones { background: #f59e0b; color: #fff; }
.dept-conserjeria { background: #10b981; color: #fff; }
.dept-recepcion { background: #3b82f6; color: #fff; }
.dept-guest { background: #8b5cf6; color: #fff; }
.dept-sin-asignar { background: #4b5563; color: #d1d5db; border: 1px solid #6b7280; }

/* User Directory Styles */
.user-card {
    display: flex;
    align-items: center;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    padding: 12px 15px;
    border-radius: 8px;
    gap: 12px;
}

.user-status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.user-status-dot.online {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.user-status-dot.offline {
    background-color: var(--danger);
}

.user-card-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.user-card-name {
    font-weight: 600;
    color: var(--text-main);
    font-size: 1.05rem;
}

.user-card-dept {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.user-card-role {
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 12px;
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    border: 1px solid rgba(59, 130, 246, 0.3);
    font-weight: bold;
    margin-left: auto;
}

/* =========================================================
   VILLA DETAILS PANEL (Glassmorphism)
   ========================================================= */
.villa-details-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 320px;
    background: rgba(var(--bg-card-rgb, 18, 18, 18), 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 20;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideInRight 0.3s ease-out;
}

.theme-light .villa-details-panel {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

@keyframes slideInRight {
    from {
        transform: translateX(120%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.villa-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
}

.theme-light .villa-details-header {
    background: rgba(0, 0, 0, 0.05);
}

.villa-details-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.villa-details-content {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
}

.villa-room-card {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.villa-room-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.villa-room-number {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 5px;
}

.villa-room-status {
    font-size: 0.8rem;
    padding: 3px 8px;
    border-radius: 12px;
    margin-bottom: 5px;
    display: inline-block;
}

.villa-room-status.status-free {
    background: rgba(150, 150, 150, 0.2);
    color: var(--text-muted);
}

.villa-room-status.status-occupied {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.villa-room-guest {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
    font-size: 0.85rem;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.villa-room-guest i {
    width: 14px;
    color: var(--accent);
    margin-right: 5px;
}

.guest-name, .guest-car {
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* Contextual Help Button */
.contextual-help-btn {
    color: var(--accent);
    opacity: 0.8;
    transition: all 0.3s ease;
}
.contextual-help-btn:hover {
    opacity: 1;
    background: rgba(59, 130, 246, 0.1);
    transform: scale(1.1);
}

/* Map Active Villa */
.map-villa-active { 
    fill: #3B82F6 !important; 
    stroke: #3B82F6 !important;
    stroke-width: 2px !important;
    transition: all 0.3s ease; 
}


/* Room Status Quick Actions */
.room-status-bar { display: flex; gap: 5px; margin-top: 10px; padding: 6px; background: rgba(255, 255, 255, 0.05); border-radius: 8px; border: 1px solid var(--border); }
.room-status-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 6px; font-size: 0.7rem; font-weight: 600; border: 1px solid transparent; border-radius: 6px; cursor: pointer; background: transparent; color: var(--text-muted); transition: all 0.2s ease; }
.room-status-btn:hover { background: rgba(255,255,255,0.05); }
.room-status-btn.sucia { border-color: rgba(239, 68, 68, 0.3); color: #EF4444; }
.room-status-btn.en-limpieza { border-color: rgba(59, 130, 246, 0.3); color: #3B82F6; }
.room-status-btn.limpia { border-color: rgba(16, 185, 129, 0.3); color: #10B981; }
.room-status-btn.active.sucia { background: rgba(239, 68, 68, 0.15); border-color: #EF4444; }
.room-status-btn.active.en-limpieza { background: rgba(59, 130, 246, 0.15); border-color: #3B82F6; }
.room-status-btn.active.limpia { background: rgba(16, 185, 129, 0.15); border-color: #10B981; }

/* Camera Dropdown Menu */
.attachment-dropdown-container {
    position: relative;
    display: flex;
    align-items: center;
}

.attachment-dropdown-menu {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    background: var(--bg-header);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 100;
    min-width: 180px;
}

.attachment-dropdown-menu.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.dropdown-item {
    background: transparent;
    border: none;
    padding: 10px 15px;
    text-align: left;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: var(--surface-active);
}

.dropdown-item i {
    color: var(--accent-primary);
}

/* Lightbox Styles */
.lightbox-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
    from {transform: scale(0.9); opacity: 0;}
    to {transform: scale(1); opacity: 1;}
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 10001;
}

.lightbox-close:hover,
.lightbox-close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

.lightbox-prev, .lightbox-next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -50px;
    color: white;
    font-weight: bold;
    font-size: 24px;
    transition: 0.3s;
    border-radius: 0 3px 3px 0;
    user-select: none;
    background-color: rgba(0,0,0,0.3);
}

.lightbox-next {
    right: 0;
    border-radius: 3px 0 0 3px;
}

.lightbox-prev {
    left: 0;
}

.lightbox-prev:hover, .lightbox-next:hover {
    background-color: rgba(0,0,0,0.8);
}

/* Multiple image preview in chat input */
.image-preview-container {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 5px;
    margin-bottom: 10px;
    max-height: 80px;
}

.image-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--border-color);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.6);
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
}

/* Chat message image grid */
.message-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 5px;
    margin-top: 5px;
}

.message-image-grid img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image-grid img:hover {
    transform: scale(1.02);
}

/* Make single image still look good but clickable */
.chat-message img.clickable-image {
    cursor: pointer;
    transition: transform 0.2s;
}
.chat-message img.clickable-image:hover {
    transform: scale(1.02);
}

/* Fix for select options text color in dark mode */
select option {
    background-color: var(--bg-card, #2b303b);
    color: var(--text-main, #ffffff);
}

.dept-royal { background: #ec4899; color: #fff; }
.dept-duty { background: #ef4444; color: #fff; }
.dept-prevencion { background: #0ea5e9; color: #fff; }
